I am working with a simulation that consists of a cells, objects that interact with each other and evolve over time. I am looking at parallelizing my code using the OpenMP parallel for imperative and want my cells (objects) to be updated per timestep in parallel, below you can see part of the code.
#pragma omp parallel for default(none) shared(cells, maxCellReach, parameters, cellCellJunctions, timestepDistance) firstprivate(timestep), reduction(+ : centerOfMass)
for (auto it = cells.begin(); it != cells.end(); it++) {
maxCellReach = std::max(it->getNucleus()->getCellReach(), maxCellReach);
it->ApplyIntercellularForce(cellCellJunctions, Constants::junctionCreateDistance, parameters);
it->step(timestep, parameters);
centerOfMass += it->GetCenterOfMass();
}
I have read that the loop iterator variable of a openMP parallel for loop is always private. I however, want all the cells to be updated together. Does this code achieve that or do I need a different approach with openMP?
I looked around online, but could not find anything on making loop iterators shared variables or something similar in a for loop.