4
votes

I have this problem: I have one MATLAB function that performs anisotropic diffusion on a volume. For a medical volume it takes about 20 min to complete the execution. Now I want to use this function simultaneously on two different volumes so that the total execution time remains 20 min and not 40 min total using Matlab's Parallel Computing Toolbox. I have a quadcore Macbook so in my thoughts one core should run one the first volume and the second core should run the second volume.

How can I do that?

The functions I want to run simultaneously are:

filt1=anisodiff3D(volume1);
filt2=anisodiff3D(volume2);

Thank you!

2
I know you asked about the parallel computing toolbox solution, but still: I often just start up a second instance of Matlab, which will run in parallel as well. Just to remind you; the parallel computing toolbox isn't always necessary. - Wooly Jumper
I know the topic is one-year old, but I feel my question is worth a comment rather than a question in itself. I have four scripts to run in MATLAB, but, contrary to the question, I cannot index the argument as the names of the scripts have little in common. I would like to assign a specific job to a specific worker (1, 2, 3 or 4) on a local cluster (quadcore) I have the distcomp toolbox. My question is: is it possible or do I have to resort to starting four instances of MATLAB ? Thanks for your answer ! - user89073

2 Answers

4
votes

You first need to create a pool of Matlab processes and then use the parfor construct. I would do like this:

% Useful for operating on parfor
filt = [filt1, filt2];
vol = [volume1, volume2];

% Please note that these are separate processes and sharing data can be challengin
matlabpool(2); % or parpool(2);

% Parallelize the for loop using 2 workers
parfor i = 1 : 2
   filt(i) = anisodiff3D(vol(i));
end
1
votes

You are looking for MATLAB parallel computing toolbox (unless you have got it already). This allows you do multiply things at parallelly (like running two functions). The catch is the IPC between those functions. I believe things get more complicated when you have them communicating with each other. If that's not required, you can use parallel for loop aka PARFOR through that toolbox in order to run two (or more) funcs parallelly.