3
$\begingroup$

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);

      MPI_Comm_size(PETSC_COMM_WORLD,&size);
      MPI_Comm_rank(PETSC_COMM_WORLD,&rank);
      PetscPrintf(PETSC_COMM_WORLD,"Number of processors = %d, rank = %d\n",size,rank);
      PetscSynchronizedPrintf(PETSC_COMM_WORLD,"synchronized rank = %d\n",rank);
      PetscSynchronizedFlush(PETSC_COMM_WORLD);//,PETSC_STDOUT);

      MPI_Barrier(PETSC_COMM_WORLD);

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

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

      PROpt opt;
      Solve* ps = new Solve();
      ps->getFile(&opt,argv[0]);
 }

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

 DIR=/directory/buildagain/bin/Project
 FILELIST=$1

 while read FILE
 do
       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

$\endgroup$
  • $\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 '15 at 12:45
1
$\begingroup$

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.

$\endgroup$
  • $\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$ – sssssssssssss Feb 21 '17 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.