Effacer les filtres
Effacer les filtres

Parallel computing on cell array.

18 vues (au cours des 30 derniers jours)
Phillip le 12 Mai 2024
Commenté : Walter Roberson le 13 Mai 2024
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.
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
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
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
  4 commentaires
Phillip le 13 Mai 2024
However, as you've indicated an object array could be used to store an object of the 'particle' class.
pXArray = createArray(1,4,"particle");
then access is as before;
But there still seems to be a problem if this object array is converted to a distributed array.
There is the following error.
Error using distributed (line 344)
A distributed array cannot be created with data of class: particle.
Error in matlab_tests3 (line 94)
pXXArray = distributed(pXArray)
Walter Roberson
Walter Roberson le 13 Mai 2024
So don't mark the array as distributed; let the array be sliced automatically.

Connectez-vous pour commenter.

Réponses (1)

Walter Roberson
Walter Roberson le 12 Mai 2024
Use a cell array.
Inside the parfor:
p1 = pArray{i};
x = p1.positionx;
y = p1.positiony;
and so on
  1 commentaire
Phillip le 12 Mai 2024
Hi Walter
Thanks, yes will have a go with a parfor loop.
The cell array itself wasn't really the problem, but when it was converted to a distributed array then access to the object's field variables did not work.

Connectez-vous pour commenter.




Community Treasure Hunt

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

Start Hunting!

Translated by