CFD Online Logo CFD Online URL
www.cfd-online.com
[Sponsors]
Home > Forums > Software User Forums > OpenFOAM > OpenFOAM Programming & Development

Field on Processor forgets values?!

Register Blogs Community New Posts Updated Threads Search

Like Tree1Likes
  • 1 Post By olesen

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
Old   December 20, 2023, 21:00
Question 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
Luke99 is on a distinguished road
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;
	}
}
Thats the code I'm using (uniqueCellNo is a simple volScalarField)

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

Last edited by Luke99; December 21, 2023 at 05:36.
Luke99 is offline   Reply With Quote

Old   December 21, 2023, 05:56
Default
  #2
Senior Member
 
Mark Olesen
Join Date: Mar 2009
Location: https://olesenm.github.io/
Posts: 1,714
Rep Power: 40
olesen has a spectacular aura aboutolesen has a spectacular aura about
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());
If your version of OpenFOAM doesn't have that specific identity function:
Code:
const globalIndex gi(mesh.nCells());

List<label> uniqueIds(mesh.nCells())
std::iota(uniqueIds.begin(), uniqueIds.end(), gi.localStart());
Luke99 likes this.
olesen is offline   Reply With Quote

Old   December 21, 2023, 06:35
Default
  #3
New Member
 
Luke Hirl
Join Date: Jul 2023
Location: Gießen
Posts: 16
Rep Power: 3
Luke99 is on a distinguished road
Well that seems a lot easier and it works.
Thank you very much
Luke99 is offline   Reply With Quote

Reply

Tags
assignment, parallel, parallel calculation


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are On


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


All times are GMT -4. The time now is 11:38.