Discover MakerZone

MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi

Learn more

Discover what MATLAB® can do for your career.

Opportunities for recent engineering grads.

Apply Today

Thread Subject:
calling an object inside parfor

Subject: calling an object inside parfor

From: Joao Ejarque

Date: 5 Sep, 2011 12:23:13

Message: 1 of 2

2 pretty basic questions.
consider the program:

n1=10; n2=20;
V=zeros(n1,n2);
X = rand(1,n2);
Q = inline('operation with x and y','x','y');
matlabpool(n),
parfor j=1:n1
         zj = X(j) + 32;
         yj = j + 3;
         V(j,:) = ones(1,n2) + Q(zj,yj);
end
matlabpool close

The questions:

1) is there any problem in calling in the variable X inside the parfor loop using X(j) as above?
2) any problem with using the inline function Q as above?

Subject: calling an object inside parfor

From: Steven_Lord

Date: 6 Sep, 2011 14:03:05

Message: 2 of 2



"Joao Ejarque" <jme@dreammodel.dk> wrote in message
news:j42evh$cdn$1@newscl01ah.mathworks.com...
> 2 pretty basic questions.
> consider the program:
>
> n1=10; n2=20;
> V=zeros(n1,n2);
> X = rand(1,n2);
> Q = inline('operation with x and y','x','y');
> matlabpool(n),
> parfor j=1:n1
> zj = X(j) + 32;
> yj = j + 3;
> V(j,:) = ones(1,n2) + Q(zj,yj);
> end
> matlabpool close
>
> The questions:
> 1) is there any problem in calling in the variable X inside the parfor
> loop using X(j) as above?
> 2) any problem with using the inline function Q as above?

I don't see any problem offhand with your usage of either X or Q in the
above code assuming Q returns either a scalar or a 1-by-n2 vector when
called that way.

From the fact that it's simple to test whether or not this works if you have
Parallel Computing Toolbox and the body of your inline expression, I'm
guessing that either:

1) you don't have the Toolbox, in which case I _think_ that should work just
fine. Check with your sales representative if you're interested in a trial
of the Toolbox that will allow you to check this.

or 2) you tried this and it failed. In this case, if you want help
determining why it failed, you're going to need to provide some additional
information, like the body of the inline function Q and the exact text of
any error message you received.

--
Steve Lord
slord@mathworks.com
To contact Technical Support use the Contact Us link on
http://www.mathworks.com

Tags for this Thread

No tags are associated with this thread.

What are tags?

A tag is like a keyword or category label associated with each thread. Tags make it easier for you to find threads of interest.

Anyone can tag a thread. Tags are public and visible to everyone.

Contact us