Matrix multiplication time explodes after 20k steps

4 Ansichten (letzte 30 Tage)
Arne
Arne am 3 Jul. 2012
Hey all,
I am having some trouble with MATLAB: I wrote this tiny function in which for some reason the time required to do the multiplication w*neuro_act increases by a factor of ~10 after 20k steps.Even saving all data from RAM to disk, clearing all memory and loading it again from the disk doesn`t solve the problem... Can anybody help ? (w is a 4096x4096 Matrix, n is about 30k, run_factor around 40.)
function[electrodes,t_multi]=run_rat_run(pattern,w,sampling,lattice_size,dt,tau,vel_x_1,vel_y_1,alpha)
run_factor=sampling/(dt/1000);
n=size(vel_x_1,1);
neuro_act=reshape(pattern, lattice_size^2, 1);
[r, c]=max(neuro_act);
clear r
electrodes=zeros(n,3);
t_multi=zeros(n,1);
global_time_constant=dt/tau;
for x=1:n
velocity_input=1+alpha*repmat([repmat([vel_x_1(x);vel_y_1(x)],lattice_size/2,1);...
repmat([-vel_y_1(x);-vel_x_1(x)],lattice_size/2,1)],lattice_size/2,1);
for y_n=1:run_factor
arg_f=w*neuro_act+velocity_input;
arg_f(arg_f<0)=0;
neuro_act=neuro_act+global_time_constant*(arg_f-neuro_act);
end
tic
test_=w*neuro_act;
t_multi(x)=toc;
test=[];
t_multi(x)
x
electrodes(x,1)=neuro_act(c);
electrodes(x,2)=neuro_act(c+100);
electrodes(x,3)=neuro_act(c-100);
if mod(x,500) == 0
save temp w neuro_act t_multi electrodes x run_factor alpha global_time_constant sampling lattice_size c
clear all
load temp
load ../data/activity_patterns %load activity patterns and global variables
load ../data/hafting_fig2c_trail2_velocities %load velocities
end
end
  3 Kommentare
Kye Taylor
Kye Taylor am 3 Jul. 2012
You shouldn't want to read from disc each iteration anyways. doing so severly hinders the execution time. Can you just load it once?
Greg
Greg am 3 Jul. 2012
Well, there are instances where the saving and clearing makes sense... But if you're worried about memory fragmentation, the proper thing to use would be the "pack" function. If you're trying to clear all variables except for those ones that you're storing, try a "clearvars -except" command.

Melden Sie sich an, um zu kommentieren.

Antworten (0)

Kategorien

Mehr zu Workspace Variables and MAT-Files finden Sie in Help Center und File Exchange

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by