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?