Doh! Stupid Programming Mistakes <humor>

Jacob Fugal lukfugl at
Thu Oct 19 12:35:32 MDT 2006

On 10/19/06, Corey Edwards <tensai at> wrote:
> That depends on what exactly MPI is. From the code I get the impression
> that it's a library that handles parallel execution, in which case the
> whole point is to have multiple processes fork off and remain running.
> If that's the case I believe my code is correct. It could also be that
> each child is supposed to run MPI_Finalize, signalling that it has
> exited and should no longer be included in the process pool. Googling
> around for MPI seems to indicate something along those lines.

Good point, I hadn't considered that maybe MPI_Finalize was meant to
be called for each process. If that's the case, I'd move the
MPI_Finalize call up into the if statement and keep the return. Also
correcting the if statement so that it's the *children* who execute
the block:

  #include <stdio.h>
  #include <mpi.h>

  void main (int argc, char *argv[])
      int myrank, size,x;
      MPI_Init(&argc, &argv);

      for(x = 0; x < 10; x++){
              /* do parent stuff */
          } else {
              /* do child stuff -- I assume it's
               * each child that does this, rather
               * than the parent doing it ten times
              MPI_Comm_rank(MPI_COMM_WORLD, &myrank);
              MPI_Comm_size(MPI_COMM_WORLD, &size);
              printf("Processor %d of %d: Running!\n", myrank, size);

Jacob Fugal

More information about the PLUG mailing list