using parfor loop to optimize code
4 views (last 30 days)
Show older comments
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
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!
Accepted Answer
More Answers (0)
See Also
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!