Personal tools
You are here: Home Forum How to use Salome? MEDCOUPLING: access to node coordinates using OpenMP

MEDCOUPLING: access to node coordinates using OpenMP

Up to How to use Salome?

MEDCOUPLING: access to node coordinates using OpenMP

Posted by Laurent Dupuy at January 22. 2021

Re: MEDCOUPLING: access to node coordinates using OpenMP

Posted by Laurent Dupuy at January 22. 2021

Me again, I couldn't post my question under the title...

I am currently exporting a (stress) field on the nodes of a mesh using MEDCoupling. This calculation being rather tedious, I would like to add OpenMP directives to expedite this calculation.

The structure of the output field is a rather simple DataArrayDouble where the values of the stress field are written in a contiguous array, which is well-suited for OpenMP.

The structure of the underlying mesh (even cartesian mesh) seems a bit more tricky, as can be seen in the various getCoordinatesOfNode(id,position) methods, possibly leading to a lot of memory swapping.

My code would look like the follows:

double* stressArray = new double[mesh->getNumberOfNodes()];

#pragma omp parallel for

for(int id=0; id<mesh->getNumberOfNodes(); id++)

{

std::vector<double> position;

mesh->getCoordinatesOfNode(id,position);

double stress = MyFunc(position);

stressArray[id] = stress;

}

MCAuto<DataArrayDouble> stressDataArray( DataArrayDouble::New() );

stressDataArray->useArray(stressArray,true,MEDCoupling::DeallocType::CPP_DEALLOC,mesh->getNumberofNodes(),1);

 

Now, is this the most efficient way to do this calculation? should I export the nodes positions in a separate contiguous array first (especially if I'm calling this function several times) ?

Powered by Ploneboard
Document Actions