MPI_Allreduce in compute_scalar

Dear Users,

I have attached the following files:

  1. fix_Ktest.cpp/.h : A test fix that does nothing but call a dummy function. It has a compute_scalar that calls MPI_Allreduce to sum a double variable across processors that would be available for output using the thermo command

  2. in.Ktest: A test input file that calls the test fix and outputs value of compute_scalar as the last column in the thermo output (f_Test)

  3. Data.Ktest: The test data file invoked by the previous test file

The compute_scalar() function of the fix should return a value of ‘4 * nprocs’. However, this only works for 1 proc. If I use this fix for more than one procs, the value returned by compute_scalar() is zero.

Please note that I have very minimal knowledge of MPI, so I may have missed something very basic. It’s probably a silly bug, your patience and help would be appreciated.



Background: I have a more complex fix that is showing the same problem, however, I have removed all the lines of the code that are irrelevant to the bug under consideration.

fix_Ktest.cpp (2.54 KB)

fix_Ktest.h (1.85 KB)

Data.Ktest (607 KB)

in.KTest (761 Bytes)

This is an off-topic question. Please consult somebody local with mpi experience or post in a mpi training related forum. Thanks,


Thank you Axel.

In any case, if others experience a similar problem, the bug was caused by an incompatibility between the declared types for the send and receive buffer, and the MPI data type passed to MPI_Allreduce. I cannot believe that I spent more than 6 hours trying to figure this out.