Parallel computing on cell array.
1 visualización (últimos 30 días)
Mostrar comentarios más antiguos
Hello,
In my code I've created an object oriented data type named 'particle' as a custom defined class.
particle wth numeric fields (positionx, positiony, velocityx, velocityy).
Creating a new particle is via the constructor of the particle class.
p1 = particle(1,1,4,4);
Because there are lots of particles, these are all stored in a cell array (which can handle any data type).
pArray = cell(1,n);
pArray{1} = p1;
Then access to the fields of any particle is simply by the dot notation.
pArray{1}.positionx;
pArray{1}.positiony;
pArray{1}.velocityx;
pArray{1}.velocityy;
and so forth....
I wanted to process the particles in pArray more quickly by dividing them among workers of the parallel pool. So I decided to convert pArray from a cell array to a distributed cell array.
pArray = distributed(pArray)
But now the fields of each particle cannot be accessed by this method using the dot notation. I've tried this both inside an spmd block and outside of an spmd block
The line here
pArray(1).positionx
gives the following error.
Error using indexing (line 40)
Distributed SUBSREF only supports () indexing unless the underlying data type is table.
Error in distributed/subsref>iSubsRefHelper (line 126)
[varargout{:}] = subsref(coDd, substruct(s_type, varargin));
Error in distributedutil.distributedSpmdWrapper>iInnerWrapper (line 82)
[varargout{:}] = fcnH( varargin{:} );
Error in spmd_feval_fcn>get_f/body (line 78)
[outCell{:}] = fcnH( inCell{:} );
Then within an spmd block these lines
spmd
pArray(1).positionx;
end
gives this error.
Error using matlab_tests3 (line 80)
Error detected on workers 3 6 7 8.
Caused by:
Error using indexing (line 27)
Distributed arrays only support simple subscripting.
I've just started using Matlab's parallel computing functionality so I'm just learning at this stage.
Is there a way to access the field data of an OO data structure stored in a cell array when using parallel computing techniques?
Any advice would be very helpful.
Thank you
Phil.
4 comentarios
Walter Roberson
el 13 de Mayo de 2024
So don't mark the array as distributed; let the array be sliced automatically.
Respuestas (1)
Walter Roberson
el 12 de Mayo de 2024
Use a cell array.
Inside the parfor:
p1 = pArray{i};
x = p1.positionx;
y = p1.positiony;
and so on
Ver también
Categorías
Más información sobre Distributed Arrays en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!