Wednesday, January 16, 2008

Obscure bug

This lil' MPI program will get its knickers in a twist when run using MPICH. Why? Take a guess.


#include <mpi.h>

void shutdown() {
MPI_Finalize();
exit(0);
}

int main (int argc, char ** argv) {
int w_rank, w_size;

/* Initialise MPI environment */
MPI_Init(&argc, &argv);
MPI_Comm_size(MPI_COMM_WORLD, &w_size);
MPI_Comm_rank(MPI_COMM_WORLD, &w_rank);

/* For some reason, we MUST use only 2 procs */
if (w_size != 2)
{
printf("Sorry mate, use only 2 procs\n");
shutdown();
}

/* Do stuff ... */
printf("Proc %d of %d\n", w_rank, w_size);

/* Finalise MPI environment */
shutdown();
}