Open MPI Version = 1.4.2
OS = Ubuntu 10.04 LTS and CentOS 5.3
When I run the mpi program below in the terminal, the function fgets hangs.
How do I know it? I do a printf before and later the call of fgets and only
the message "before fgets()" is showed.
However, when I run the same program at Eclipse 3.6 with CDT
7.0.0.201006141710 or using gdb it runs normally.
If you change the command in the function popen to another one(for
instance: "ls -l"), it will run correctly.
I use the following commands to compile and run the program:
compile : mpicc teste.c -o teste.run
run : mpirun -np 4 ./teste.run
Does anyone know why the program behaves like that?
Thanks in advance,
Matheus Bersot.
MPI_PROGRAM:
#include <stdio.h>
#include "mpi.h"
int main(int argc, char *argv[])
{
int rank, nprocs;
FILE * pFile = NULL;
char mystring [100];
MPI_Init(&argc,&argv);
MPI_Comm_size(MPI_COMM_WORLD,&nprocs);
MPI_Comm_rank(MPI_COMM_WORLD,&rank);
if(rank == 0)
{
pFile = popen ("ompi-ps" , "r");
if (pFile == NULL) perror ("Error opening file");
else {
while(!feof(pFile))
{
printf("before fgets()\n");
fgets (mystring , 100 , pFile);
printf("after fgets()\n");
puts (mystring);
}
pclose (pFile);
}
}
MPI_Finalize();
return 0;
}