Skip to content

`serial` wrapper to run block sequentially on all ranks (for debugging)

I still often use "printf"-debugging. With parallel processes and multi-line output this however gets ugly fairly quick and serializing the output would help. For this I implemented a serial function which executes a function sequentially on all ranks:

serial([&](int rank, int size) {
  std::cout << "I'm rank " << rank << " out of " << size << std::endl;
});

which will always output

I'm rank 0 out of 4.
I'm rank 1 out of 4.
I'm rank 2 out of 4.
I'm rank 3 out of 4.

I find this useful, but obviously one would never want this to be used in production code. So I'm not sure if it is a good idea to add such a function to DUNE? (It might end up used somewhere and really slow things down.)

There are some other ways to split output (e.g. OpenMPI mpirun's --output-filename option), but I find them less convenient.