|
[Sponsors] |
December 20, 2023, 21:00 |
Field on Processor forgets values?! / Code not running the same on all processors
|
#1 |
New Member
Luke Hirl
Join Date: Jul 2023
Location: Gießen
Posts: 16
Rep Power: 3 |
So I was working on getting my code parallelized and one part of it was assigning unique values to all cells over all processors. (So that no cell had the same value, when you recombine all processors)
Code:
List<scalar> lowCellId(Pstream::nProcs(), 0.0); List<scalar> highCellId(Pstream::nProcs(), 0.0); highCellId[Pstream::myProcNo()] = 1.0 * mesh.nCells(); Pstream::gatherList(highCellId); Pstream::scatterList(highCellId); for (label procX = 0; procX < Pstream::myProcNo(); ++procX) { lowCellId[Pstream::myProcNo()] += highCellId[procX]; } highCellId[Pstream::myProcNo()] += lowCellId[Pstream::myProcNo()]; Pout<< "from" << lowCellId[Pstream::myProcNo()] <<"to"<<highCellId[Pstream::myProcNo()]<<endl; for (scalar celli = lowCellId[Pstream::myProcNo()]; celli < highCellId[Pstream::myProcNo()]; celli += 1) { uniqueCellNo[celli] = celli; if(Pstream::myProcNo() == 1) { Pout<<uniqueCellNo[celli]<<endl; } } forAll(uniqueCellNo,celli) { if(Pstream::myProcNo() == 1) { Pout<<uniqueCellNo[celli]<<endl; } } My Problem is that when running with more than one processor, all uniqueCellNo fields will have the value of zero. Except for the Master Processor. It has the values I expect. So I included the lines: Code:
if(Pstream::myProcNo() == 1) { Pout<<uniqueCellNo[celli]<<endl; } Does anyone know a solution for this. Or can explain to me why the assigned values seem to go out of scope? Last edited by Luke99; December 21, 2023 at 05:36. |
|
December 21, 2023, 05:56 |
|
#2 |
Senior Member
Mark Olesen
Join Date: Mar 2009
Location: https://olesenm.github.io/
Posts: 1,714
Rep Power: 40 |
I will side-step your question entirely and suggest that you take a look at the globalIndex class.
I would probably write something like this: Code:
const globalIndex gi(mesh.nCells()); List<label> uniqueIds = identity(gi.localSize(), gi.localStart()); Code:
const globalIndex gi(mesh.nCells()); List<label> uniqueIds(mesh.nCells()) std::iota(uniqueIds.begin(), uniqueIds.end(), gi.localStart()); |
|
December 21, 2023, 06:35 |
|
#3 |
New Member
Luke Hirl
Join Date: Jul 2023
Location: Gießen
Posts: 16
Rep Power: 3 |
Well that seems a lot easier and it works.
Thank you very much |
|
Tags |
assignment, parallel, parallel calculation |
|
|
Similar Threads | ||||
Thread | Thread Starter | Forum | Replies | Last Post |
How to write the sampled field values of a curved internal surface? | cfdcheckers | OpenFOAM Post-Processing | 3 | July 17, 2021 11:28 |
[Other] dynamicTopoFVMesh and pointDisplacement | RandomUser | OpenFOAM Meshing & Mesh Conversion | 6 | April 26, 2018 08:30 |
''unknown radialModelType type Gidaspow'' PROBLEM WITH THE BED TUTORIAL | AndoniBM | OpenFOAM Running, Solving & CFD | 2 | March 25, 2015 19:44 |
Old and new values of a field | Franko | OpenFOAM Programming & Development | 2 | February 27, 2015 05:06 |
Problem with rhoSimpleFoam | matteo_gautero | OpenFOAM Running, Solving & CFD | 0 | February 28, 2008 07:51 |