From: William Cox on
I'm doing a monte carlo simulation of photon movement through water. I'm trying to get MATLAB to utilize my Core i7 processor, but it seems to refuse. I have the parallel processing tool box installed. MATLAB recognizes that I have 4 processors. My code looks like this:

parfor simcount = 1:num_sims
waitbar(simcount/num_sims,h,['Simulation ' num2str(simcount)]);
[output variables ... ] = mc_func(input variables ... );
received_location = vertcat(received_location,rec_loc_final);
travel_distance = vertcat(travel_distance,total_rec_dist);

end

I've tried both 'parfor' and 'for', but each time I run the program, only one processor is used at a time (I can tell by looking at the Task Manager's performance tab).

My understanding is that MATLAB's implicit multi-processor support should divide up the tasks - what am I missing?
From: Edric M Ellis on
"William Cox" <wccox(a)ncsu.edu> writes:

> I'm doing a monte carlo simulation of photon movement through
> water. I'm trying to get MATLAB to utilize my Core i7 processor, but
> it seems to refuse. I have the parallel processing tool box
> installed. MATLAB recognizes that I have 4 processors. My code looks
> like this:
>
> parfor simcount = 1:num_sims
> waitbar(simcount/num_sims,h,['Simulation ' num2str(simcount)]); [output
> variables ... ] = mc_func(input variables ... );
> received_location = vertcat(received_location,rec_loc_final);
> travel_distance = vertcat(travel_distance,total_rec_dist);
>
> end
>
> I've tried both 'parfor' and 'for', but each time I run the program,
> only one processor is used at a time (I can tell by looking at the
> Task Manager's performance tab).
>
> My understanding is that MATLAB's implicit multi-processor support
> should divide up the tasks - what am I missing?

PARFOR is for explicit parallelism - and as such, you need to open a
matlabpool before running your code (the implicit parallelism is for
things like multithreaded elementwise operations). For example, to be
completely explicit,

matlabpool open local 4

will start 4 additional MATLAB workers to work on the body of your
PARFOR loop.

Also, please note that since the workers operating on your PARFOR loop
body are separate MATLAB processes, passing handles for your waitbar
will not work as you expect (likewise persistent/global data etc.). You
could try my simple (and I must admit rather hacky) PARFOR progress
monitor:

<http://www.mathworks.com/matlabcentral/fileexchange/24594-parfor-progress-monitor>

Cheers,

Edric.