Doh! Stupid Programming Mistakes <humor>

Steve smorrey at
Thu Oct 19 05:40:24 MDT 2006

Hello everyone,
I was dabbling with OpenMPI and decided to have a little fun by
modding a piece of sample code.

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

void main (int argc, char *argv[])

    int myrank, size,x;

    MPI_Init(&argc, &argv);                 /* Initialize MPI       */

    for(x = 0; x < 10; x++){
	if(fork() > 0){
		MPI_Comm_rank(MPI_COMM_WORLD, &myrank); /* Get my rank          */
		MPI_Comm_size(MPI_COMM_WORLD, &size);   /* Get the total number of
processors */
		printf("Processor %d of %d: Running!\n", myrank, size);
    MPI_Finalize();                         /* Terminate MPI        */

This code looks harmless at first glance, but turns out it is idiotic,
however it took me a full on hour to figure out why.
Anyone wanna guess whats wrong?

Oh and yeah, don't try to compile this one at home. :)

More information about the PLUG mailing list