I am a beginner with Unix and MPI. For the serial program, I run the program by typing make in /directory/buildagain and then ./runPR.sh values.txt. (values.txt just contains the line Chain)

Here is a small portion of my code.

 int main( int argc, char *argv[ ] )
      if( strcmp(argv[1],"-PR") == 0 )
           runPR(argc-2, &argv[2]);
      return 0;

 int runPR(int argc, char* argv[])
      cout<<"run here"<<endl;

      MPI_Status status;
      PetscMPIInt    rank,size;

      //bunch of code that assigns argv2 to include argv and some new strings and sets 
      //argc2=argc plus the  number of new string
      PetscInitialize(&argc2, &argv2,0,0);

      PetscPrintf(PETSC_COMM_WORLD,"Number of processors = %d, rank = %d\n",size,rank);
      PetscSynchronizedPrintf(PETSC_COMM_WORLD,"synchronized rank = %d\n",rank);


      PetscPrintf(PETSC_COMM_SELF,"[%d] Jumbled Hello World\n",rank);

      PROpt opt;
      Solve* ps = new Solve();

      PROpt opt;
      Solve* ps = new Solve();

By typing mpirun -np 4 ./runPR.sh values.txt, I see Number of processors = 1, rank = 0 and synchronized rank = 0 printed 4 times. But I don't see synchronized rank = 1 or 2 or 3 printed out. Why is this?

Here is what run.PR.sh contains


 while read FILE
       echo "Processing ${FILE}..."
          ./makeInp.sh ${FILE} ${FILE} >INP/${FILE}.inp
      mpiexec -np 4 ${DIR} -PR INP/${FILE}.inp
 done < ${FILELIST}

EDIT: I was able to get the helloworld PETSc example to work properly at http://www.mcs.anl.gov/petsc/petsc-current/src/sys/examples/tutorials/ex2.c.html

  • $\begingroup$ I think you are passing argv wrong when you call runPR. argv is already a pointer "of pointers" to strings; there is no need to put the address (&) operator in the argument. Also, why argv[2]? shouldn't it be *(argv)++? $\endgroup$
    – Kbzon
    Oct 14, 2015 at 12:45

1 Answer 1


I can't tell from this code directly, but this behavior is typical of code that never called MPI_Init(). I know that PetscInitialize() is supposed to do that for you, but I'm guessing that since you appear to have failed to assign argv2 and argc2 to anything, that something went wrong during initialization. I'm guessing that this code will fail to compile as is, since argc2 and argv2 aren't even defined in this example.

  • $\begingroup$ To build on this, in my experience this can occur when you have multiple MPI implementations installed and you criss-cross your MPI compiler wrapper with the mpirun command. For instance, you compiled using Intel MPI using mpiifort but you also have an OpenMPI installation to which the mpirun command points. $\endgroup$ Feb 21, 2017 at 14:44

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.