Reputation: 123
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!
Upvotes: 4
Views: 2047
Reputation: 5570
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
Upvotes: 4
Reputation: 6824
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.
Upvotes: 1