title: How to run this compiled open MPI program (C)?
body: <p>I am trying to run the example code at the following url. I compiled the program with "mpicc twoGroups.c" and tried to run it as "./a.out", but got the following message: Must specify MP_PROCS= 8. Terminating.</p>
  
  <p><strong>My question is how do you set MP_PROCS=8 ?</strong></p>
  
  <p>Group and Communication Routine examples at here <a href="https://computing.llnl.gov/tutorials/mpi/" rel="nofollow">https://computing.llnl.gov/tutorials/mpi/</a></p>
  
  <pre><code>#include "mpi.h"
  #include &lt;stdio.h&gt;
  #define NPROCS 8
  
  main(int argc, char *argv[])  {
  int        rank, new_rank, sendbuf, recvbuf, numtasks,
             ranks1[4]={0,1,2,3}, ranks2[4]={4,5,6,7};
  MPI_Group  orig_group, new_group;
  MPI_Comm   new_comm;
  
  MPI_Init(&amp;argc,&amp;argv);
  MPI_Comm_rank(MPI_COMM_WORLD, &amp;rank);
  MPI_Comm_size(MPI_COMM_WORLD, &amp;numtasks);
  
  if (numtasks != NPROCS) {
    printf("Must specify MP_PROCS= %d. Terminating.\n",NPROCS);
    MPI_Finalize();
    exit(0);
    }
  
  sendbuf = rank;
  
  /* Extract the original group handle */
  MPI_Comm_group(MPI_COMM_WORLD, &amp;orig_group);
  
  /* Divide tasks into two distinct groups based upon rank */
  if (rank &lt; NPROCS/2) {
    MPI_Group_incl(orig_group, NPROCS/2, ranks1, &amp;new_group);
    }
  else {
    MPI_Group_incl(orig_group, NPROCS/2, ranks2, &amp;new_group);
    }
  
  /* Create new new communicator and then perform collective communications */
  MPI_Comm_create(MPI_COMM_WORLD, new_group, &amp;new_comm);
  MPI_Allreduce(&amp;sendbuf, &amp;recvbuf, 1, MPI_INT, MPI_SUM, new_comm);
  
  MPI_Group_rank (new_group, &amp;new_rank);
  printf("rank= %d newrank= %d recvbuf= %d\n",rank,new_rank,recvbuf);
  
  MPI_Finalize();
  }
  </code></pre>