Parallelization and esfit
Posted: Sun Jul 27, 2014 11:05 am
I've been experimenting with running simulations in parallel and have found (unsurprisingly) a significant increase in speed. If I'm doing "manual fitting" i.e. exploring a single parameter space in a for loop I will run the sims in parallel. i.e.
This works really well for exploring whatever parameter space you want. I've tried using a parfor loop as well, but I like the ability to check to see when a single job is done. Additionally a parfor loop means you can't use the main command window of MATLAB while the loop is running, which you can do with parfeval (just limit the number of workers so your CPU isn't at 100%!).
With esfit I can't take as much advantage of the parallelization in MATLAB. I can run multiple fits at a time on different workers, but other than the ability to run two fits at once its not all that beneficial. I wouldn't think it would be too difficult to implement this kind of parallelization in esfit, as you could just run your pepper/garlic/etc in parallel then calculate the residuals as the outputs become available. As I imagine it, it would just be another option available in the FitOpt structure, i.e.
I'm running MATLAB 2014a, but parfeval was first implemented in 2013b. The parfor command has been available since MATLAB 2006b.
Thoughts?
Code: Select all
%Generic Experimental Parameters
Exp.mwFreq=9.6;
Exp.Range=[200 400];
Exp.nPoints=1000;
%Build the Structure space to be explored, in this case g(3)
Sys=cell{100,1};
for i=1:100
Sys{i}.S=1/2;
Sys{i}.g=[2, 2, 2+0.01*i];
Sys{i}.lw=0.5;
end
%Start the pool of workers and run the sims
parpool(4) %starts parallel pool with 4 workers
p=cell(100,1) %These will be the job handles. works with parfeval but not parfevalOnAll
for i=1:100
p{i}=parfeval(gcp,@pepper,2,Sys{i},Exp);
end
%Fetch all of the data in Spec and plot
Spec=zeros(100,1000);
for i=1:100
[B,Spec(i,:)]=fetchOutputs(p{i});
hold on;
plot(B,Spec(i,:)/max(Spec(i,:))+0.1*i); %Scale to 1 and stack the spectra for easier visualization
end
With esfit I can't take as much advantage of the parallelization in MATLAB. I can run multiple fits at a time on different workers, but other than the ability to run two fits at once its not all that beneficial. I wouldn't think it would be too difficult to implement this kind of parallelization in esfit, as you could just run your pepper/garlic/etc in parallel then calculate the residuals as the outputs become available. As I imagine it, it would just be another option available in the FitOpt structure, i.e.
Code: Select all
%Assume that Spec, Sys, Vary, Exp and pepOpt are all accounted for already
FitOpt.Method = 'simplex';
FitOpt.Parallel = 4; %Number of Workers to be started in the pool
esfit('pepper',Spec,Sys,Vary,Exp,pepOpt,FitOpt);
Thoughts?