using parfor loop to optimize code

4 views (last 30 days)
erool
erool on 4 Mar 2014
Edited: Matt J on 6 Mar 2014
I am new to parallel computing, I have a set of netcdf files in a directory and I am reading each file and calculating a pv value through a function. Since the computation is slow I prefer to do it in parallel. I tried using parfor loop but it did not work. Would be glad if I get any help regarding using this code in parallel.
for e=1:44
for t=1:90
dir=['/..../f2000_' num2str(e)'-000' num2str(t) '.nc'];
pfull=ncread(dir1,'lev');
u=ncread(dir,'U');
v=ncread(dir,'V');
temp=ncread(dir,'T');
lat=ncread(dir,'lat');
lon=ncread(dir,'lon');
[pv,rv,sv]=pv_qg_3d_modified(lon,lat,pfull(kk),u, v, temp);
pv1(t,:,:)=pv;
end
save(['/..../pv_' num2str(e) '.mat','pv1'];
end
  3 Comments
Ashish Uthama
Ashish Uthama on 5 Mar 2014
"did not work" is ambiguous. Did you get an error or was the performance not as you expected it to be?
Use the profiler tool on your existing code to verify that the computation is indeed the bottleneck. If you have large netcdf files, you might actually be limited by the data IO speed from your storage. Adding PARFOR in this case might actually make the problem worse!
erool
erool on 6 Mar 2014
Sorry, I wasn't being more specific and thank you for the feedback. The error it gives me is "The variable pv1 in a parfor cannot be classified". It works fine with just the 'for' loop.

Sign in to comment.

Accepted Answer

Matt J
Matt J on 6 Mar 2014
Edited: Matt J on 6 Mar 2014
Make sure pv is not defined prior to the loops. It should appear for the very first time at the line
[pv,rv,sv]=pv_qg_3d_modified(lon,lat,pfull(kk),u, v, temp);
For more info, see

More Answers (0)

Categories

Find more on Loops and Conditional Statements in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!