CFD Online Discussion Forums

CFD Online Discussion Forums (
-   OpenFOAM Programming & Development (
-   -   Strange behaviour gMax in parallel. (

Fransje April 19, 2011 11:06

Strange behaviour gMax in parallel.
Hello all,

A small technical questions which baffles me..

I'm modifying a remapping boundary condition. All works fine on one processor, but switching to a run in parallel, I get "interesting" results.

If I do:

Pout << newUValues.size() << endl;
Pout << gMax(newUValue) << endl;

I get a value for gMax(newUValues) on all processors, even if newUValues.size() has returned 0.

And if I add:

if( newUValues.size() > 0 )
    Pout << gMax(newUValues) << endl;

The simulation run crashes immediately, although only the processors where the condition newUValues.size() > 0 have run the Pout statement..

Mighty weird. Any ideas why this could be happening?

Kind regards,


l_r_mcglashan April 20, 2011 04:21

What is the error message, i.e. why does it 'crash'? gMax will give you the maximum value in the field newUValue over all processors. Pout outputs to screen the result on each processor; why not just use Info? I'm guessing there's a problem with your if statement in that perhaps there is a loss of synchronisation, or a problem maybe with gMax only being called on some processors, although I can't say for sure without digging more.

One thing I don't understand is why you're using the if statement?

eugene April 20, 2011 05:26

You can't put global reduce functions inside an if statement that will evaluate differently for different processors. The whole point of a gMax (global maximum) statement is that it will be evaluated for all cpus. If some of them can't evaluate the gMax function because it is inside a heterogeneous if statement, then of course the code will crash. You should first evaluate gMax before the if statement and then do whatever you want to do based on the size of the list.

Fransje April 20, 2011 11:59

Dear Laurence, dear Eugene,

Thank you both for your fast replies! It's all clear now.

On hindsight, a "stupid" mistake.. I had somehow misunderstood the true meaning of "global maximum".

But with the help of Eugene's explanations I can understand what's going on..
gMax is defined in FieldFieldFunctions.C, and when called, it makes a call to PstreamReduceOps.H and does a reduce() operation on the variable being gMax-ed to obtain the data on all processors. So if a processor doesn't answer to the reduce() call, all hell will break lose.

@Laurence: The if statement was because I do some computations (boundary layer rescalling) one the variable being if-ed, and that somewhere along the way I was using gMax. So the case here was just a simplified example.

Thank you both for your help.

Kind regards,


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