How to use parfor-loop or parallel computation on a cluster?

13 views (last 30 days)
Dear Matlabers,
I am trying to use parfor-loop on a cluster, therefore I wrote a script to test. the script-1 run successfully, but consumed more time than on my own pc, it seems that it only use one processor; therefore, I invoked matlabpool in the script-2, but this script even doesn't run on the cluster and gave error:
"To get started, type one of these: helpwin, helpdesk, or demo.For product information, visit www.mathworks.com.
Error using matlabpool>iVerifyJava (line 163) matlabpool is not supported because: Java is not currently available.
Error in matlabpool (line 122) iVerifyJava(); Error in TestPara (line 16)matlabpool open;"
Now, my question is how can I change my script to use parfor-loop on a cluster?
thank you in advance!
George
% script-1 parfor-loop
itr = 1E8;
tic;
parfor i = 1:itr
tx (i)= 2*i;
end
t = toc;
fileID = fopen('timeNormal.txt','w');
fprintf(fileID,' Time 1 is: %6.2f seconds \n',t);
fclose(fileID);
% script-2 matlabpool
matlabpool open;
tic,
parfor i = 1:itr
tx (i)= 2*i;
end
t = toc;
fileID = fopen('time2.txt','w');
fprintf(fileID,' Time 2 is: %6.2f seconds \n',t);
fclose(fileID);
matlabpool close

Accepted Answer

Edric Ellis
Edric Ellis on 7 Aug 2012
You should send 'script-1' as a batch script for execution on your cluster with an open MATLABPOOL, like this:
j = batch('script_2', 'Matlabpool', 4);
This will run automatically configure an open matlabpool on the cluster of size 4. This blog entry shows you the stages you go through from running scripts on your desktop to running them with PARFOR on a cluster: http://blogs.mathworks.com/loren/2012/04/20/running-scripts-on-a-cluster-using-the-batch-command-in-parallel-computing-toolbox/

More Answers (1)

George
George on 7 Aug 2012
Edited: George on 7 Aug 2012
But when I use batch, I couldn't find the output file.
however, it works on my own computer. so where is wrong?
here, I firstly wrote a script1.m
itr = 1E5;
tic;
parfor i = 1:itr
tx (i)= 2*i;
end
t = toc;
%
fileID = fopen('Result.txt','w');
fprintf(fileID,' Time 1 is: %6.2f seconds \n',t);
fprintf(fileID,' Max: %6.2f \n',max(tx));
fclose(fileID);
and then I wrote another batch script to run the script1.m
job = batch('script1', 'matlabpool', 5);
delete(job)
again, thank you.
kind regards,
George

Products

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!