error detects in labs in spmd

hi,
I have problem with this code , I can not know what is the reason.
this error what I got:
Starting matlabpool using the 'local' configuration ... connected to 2 labs. Lab 2:
ans =
0
??? Error using ==> spmd_feval at 8 Error detected on lab(s) 2
Error in ==> test at 7 Nofusers=700;k1=1;
Caused by:
You must call TIC without an output argument before calling TOC
without an input argument.
Error stack:
(No remote error stack)
%%%the code%% clc;clear;close all;
N=2; % Number of your CPU core, in my case, 4
matlabpool(N) % open N multicores for the parallel computation
tic
spmd % similar with for loop
Nofusers=700;k1=1;
f=fopen('d:\matlab\r2011a\bin\data_net.txt');
for i=1:Nofusers
gl=fgetl(f);
celcod{i}=str2num(gl);
end
fclose all
toc
matlabpool close % you must close the multicore calculation statement
end
thanks

Réponses (1)

Walter Roberson
Walter Roberson le 24 Jan 2014

0 votes

Your nesting appears to be off. You have the "matlabpool close" and the "toc" before it inside the spmd block.
Each lab is effectively a different MATLAB session. The "tic" before the spmd block is not in the same session as the "toc" inside the spmd block.

9 commentaires

thanks, the problem is not relate tic or toc, although I changed their position. when correct it as u indicated, Starting matlabpool using the 'local' configuration ... connected to 2 labs. I got: Lab 1:
ans =
0
Lab 2:
ans =
0
??? Error using ==> spmd_feval at 8 Error detected on lab(s) 2
Error in ==> test_parfor at 8 Nofusers=700;k1=1;
Caused by:
Cannot execute matlabpool close on the labs.
Error stack:
matlabpool.m at 125
huda nawaf
huda nawaf le 26 Jan 2014
Please I need example show me the difference in terms of time between code use spmd and other code do not use it
d=magic(100)%% array 100*100
B=inv(d); c=B^2;
Thanks in advance
Walter Roberson
Walter Roberson le 26 Jan 2014
Please show your revised code.
huda nawaf
huda nawaf le 27 Jan 2014
Modifié(e) : huda nawaf le 27 Jan 2014
hi Walter, thanks
My real code is more complex, but I try with simple code. I found the time of parallel is longer.that even if I used larger arrays and if code has more processing.
c(1:50,1:100)=4;
c1(1:50,1:100)=5;
celcod{1}=c;
celcod{2}=c1;
c2=[c ;c1];
%%parallel code
matlabpool(2)
tic
spmd
for j=1:50
for i=1:100
s=0;
for k=1:100
f=celcod{labindex}(j,k)+c2(i,k);
s=s+f;
end
ff{labindex}(j,i)=s;
end
end
end
toc
%ff{labindex}(1:6,1:12)
matlabpool close
%%serial code
tic
for j=1:100
for i=1:100
s=0;
for k=1:100
f2=c2(j,k)+c2(i,k);
s=s+f2;
end
f3(j,i)=s;
end
end
toc
Walter Roberson
Walter Roberson le 27 Jan 2014
Okay, so is there any question left at this point?
huda nawaf
huda nawaf le 28 Jan 2014
The above process in serial take long time so I want use parallel , but when use it I found the serial is faster.
Why??
huda nawaf
huda nawaf le 28 Jan 2014
Modifié(e) : Walter Roberson le 28 Jan 2014
walter look below, I took another example
clear, clc
matlabpool open local 2
a=4000;b=2000;
x{1}=rand(a);
x{2}=rand(a);
v=magic(a);
y=rand(a*2);
v1=magic(a*2);
tic
%%parallel code
spmd
tic
c=x{labindex}+ v;
c1=x{labindex}.* v;
c2=x{labindex}./v;
toc;
end
toc
matlabpool close
%%%serial code
tic
x1 = y+v1;
x2=y.*v1;
x3=y./v1;
toc;
%%%% this result what I got
Starting matlabpool using the 'local' configuration ... connected to 2 labs.
Lab 1:
Elapsed time is 0.375403 seconds.
Lab 2:
Elapsed time is 0.306954 seconds.
Elapsed time is 6.215617 seconds.
Sending a stop signal to all the labs ... stopped.
Elapsed time is 0.955548 seconds.
%%%%
I used tic and toc regarding parallel before use spmd and aftr it.
Now I do not know which time I have to depend to know the time of parallel code
do sum the time of lab1 and lab2? or depend the time total time (6.215617)?
thanks
Walter Roberson
Walter Roberson le 28 Jan 2014
Depend on the total time (6.215617)
Your semantic error appears to be repaired.
Was your task to observe "the difference in terms of time between code use spmd and other code do not use it" ? If so then you have done that. Or was your task to come up with some code that runs faster using spmd than with serial? Because if your task was to explain the timings then you should be studying the documentation about how spmd works.
huda nawaf
huda nawaf le 28 Jan 2014
In fact, the last example to know which time I have to depend and why serial faster than parallel. But my problem in first code is to know if I used spmd correctly. thanks

Connectez-vous pour commenter.

Tags

Commenté :

le 28 Jan 2014

Community Treasure Hunt

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

Start Hunting!

Translated by