Search All of the Math Forum:

Views expressed in these public forums are not endorsed by Drexel University or The Math Forum.

Topic: parfor, can not be classified help
Replies: 7   Last Post: Jun 28, 2012 9:19 AM

 Messages: [ Previous | Next ]
 Steven Lord Posts: 17,531 Registered: 12/7/04
Re: parfor, can not be classified help
Posted: Jun 28, 2012 9:19 AM

"PRIYANGA " <p.priyanga19@gmail.com> wrote in message
news:jsgr13\$981\$1@newscl01ah.mathworks.com...
> "Paul Matthews" wrote in message <io21gc\$isj\$1@fred.mathworks.com>...
>> Hi,
>> I'm new to the Parallel Computing toolbox and am having trouble
>> converting some of my code to be compliant to support variable
>> classification within my 'parfor' loop. Could someone help explain what
>> is wrong with this simplified example?
>>
>> Pop(40,10) = zeros;
>> [pop_size, pop_cols] = size(Pop);
>>
>> parfor a = 1 : pop_size
>> Child = rand(1,pop_cols);
>> Pop(a, :) = Child();
>> Pop(a, pop_cols) = inf; %This line causes Pop not to be able to be
>> classified
>> end

http://www.mathworks.com/help/toolbox/distcomp/brdqtjj-1.html#bq_of7_-1

Is Pop the loop variable? No, that's a.
Is Pop a sliced variable? Does it satisfy the four requirements given on
that page? It does not, so it is not a sliced variable. In particular it
fails the "Fixed Index Listing" requirement; in one place you index into it
with a and : and in another you index into it with a and pop_cols.
Similarly Pop is not a broadcast, reduction, or temporary variable.

You can do what you want by modifying the temporary Child variable
(replacing its last element with Inf) and then deleting the third line
inside the PARFOR. That should cause Pop to satisfy the four requirements
for a sliced variable.

parfor a = 1 : pop_size
Child = rand(1,pop_cols);
Child(end) = Inf;
Pop(a, :) = Child();
end

Note I haven't tested this, but I believe it should work.

--
Steve Lord
slord@mathworks.com
http://www.mathworks.com

Date Subject Author
4/12/11 Paul Matthews
4/12/11 Paul Matthews
4/12/11 Steven Lord
4/12/11 Paul Matthews
4/12/11 Paul Matthews
6/28/12 PRIYANGA
6/28/12 PRIYANGA
6/28/12 Steven Lord