General C++/OPENFOAM: Field(Array) on Processor forgets values;

37 views Asked by At

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) (You can probably say a cell is like an Element of an array)

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;
    }
}

Thats the code I'm using (uniqueCellNo is a simple volScalarField/Array)

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:

if(Pstream::myProcNo() == 1)
    {
        Pout<<uniqueCellNo[celli]<<endl;
    }

to see if maybe the value assignment fails on all but the master processor. but this works and for the first loop where I do the assignment it prints out the right values to the console. However for every processor except the master it has already forgotten the values by the last loop, with nothing happening in between.

Does anyone know a solution for this. Or can explain to me why the assigned values seem to go out of scope?

0

There are 0 answers