CFD Online Discussion Forums

CFD Online Discussion Forums (
-   OpenFOAM Programming & Development (
-   -   Obtain the processor id in parallel code (

albcem July 10, 2009 00:40

Obtain the processor id in parallel code
Hello all,

I am trying to obtain the processor id to perform a serial file writing in a parallel simulation.

Essentially, I am using ofstream as it has the append feature that OFstream does not. OFstream seams to be "parallel aware" while ofstream is not. So I would like to execute a statement like

if ( processor == 0 )
"Perform ofstream based file writing"

So how does one obtain the processor id in the OpenFOAM environment?



olesen July 10, 2009 02:23

Did you check the Pstream documentation?
I think you'll find something useful there.

BTW: assuming you don't care about processor == 0 per se, but if you are on the master process - that information is in the Pstream docs as well.

deepsterblue July 10, 2009 09:07

Try this:

if (Pstream::master())
// Do work here

Hope this helps.

juho July 11, 2009 03:18

The Doxygen Pstream documentation will also be helpful, I'm sure:

albcem August 7, 2009 13:35

The tips helped.

Thanks a lot!


All times are GMT -4. The time now is 18:19.