The attached program illustrates the problem. It forks, and the child calls MPI_Init. This works fine unless I'm inside gdb. Inside gdb, MPI_Init silently crashes.
I'm using OpenMPI 1.6.0 on Mac 10.8.2. I'm running the program directly, not through mpirun. Any ideas what might be wrong? Thanks, Geoffrey cone:scratch% /usr/local/bin/mpicc -o fork-bug fork-bug.c cone:scratch% ./fork-bug We're an MPI program! child status = 0 cone:scratch% gdb ./fork-bug gdb ./fork-bug GNU gdb 6.3.50-20050815 (Apple version gdb-1824) (Thu Nov 15 10:42:43 UTC 2012) Copyright 2004 Free Software Foundation, Inc. GDB is free software, covered by the GNU General Public License, and you are welcome to change it and/or distribute copies of it under certain conditions. Type "show copying" to see the conditions. There is absolutely no warranty for GDB. Type "show warranty" for details. This GDB was configured as "x86_64-apple-darwin"...Reading symbols for shared libraries ... done (gdb) run Reading symbols for shared libraries ++............................. done child status = 5 Program exited normally. (gdb) cone:scratch%
#include <mpi.h> #include <stdio.h> #include <unistd.h> #include <sys/wait.h> #include <string.h> #include <errno.h> #define CAREFUL 0 #if CAREFUL int main(int argc, char** argv) { int pid = fork(); if (pid < 0) { printf("fork failed: %s\n",strerror(errno)); return 1; } if (pid) { // Parent int status; pid = wait(&status); if (pid < 0) { printf("wait failed: %s\n",strerror(errno)); return 1; } printf("child status = %d\n",status); } else { // Child int r = MPI_Init(&argc,&argv); if (r != MPI_SUCCESS) { printf("MPI_Init failed: r = %d\n",r); return 1; } printf("We're an MPI program!\n"); r = MPI_Finalize(); if (r != MPI_SUCCESS) { printf("MPI_Finalized failed: r = %d\n",r); return 1; } } // Everything worked return 0; } #else int main(int argc, char** argv) { int pid = fork(); if (pid) { // Parent int status; wait(&status); printf("child status = %d\n",status); } else { // Child MPI_Init(&argc,&argv); printf("We're an MPI program!\n"); MPI_Finalize(); } return 0; } #endif