LAM/MPI logo

LAM/MPI General User's Mailing List Archives

  |   Home   |   Download   |   Documentation   |   FAQ   |   all just in this list

From: Rahul Nabar (rpnabar_at_[hidden])
Date: 2009-07-07 16:32:08


On Sun, Jul 5, 2009 at 7:10 AM, Jeff Squyres<jsquyres_at_[hidden]> wrote:
> How did you determine that both processes are staying on a single core?

I was using this very simple mpi code in C. It prints only the same
cpu but twice. On "correctly running" machines it loops over all cpus.

##################################

#include "stdio.h"
#include <stdlib.h>

#include <mpi.h>
int main(int argc, char *argv[])
{
        int tid,nthreads;
        char *cpu_name, fn[512];
        FILE *fid;

  /* add in MPI startup routines */
  /* 1st: launch the MPI processes on each node */
  MPI_Init(&argc,&argv);

  /* 2nd: request a thread id, sometimes called a "rank" from
          the MPI master process, which has rank or tid == 0
   */
  MPI_Comm_rank(MPI_COMM_WORLD, &tid);

  /* 3rd: this is often useful, get the number of threads
          or processes launched by MPI, this should be NCPUs-1
   */
  MPI_Comm_size(MPI_COMM_WORLD, &nthreads);

  /* on EVERY process, allocate space for the machine name */
  cpu_name = (char *)calloc(80,sizeof(char));

  /* get the machine name of this particular host ... well
     at least the first 80 characters of it ... */
  gethostname(cpu_name,80);
        sprintf(fn, "%s.log", argv[0]);
        fid = fopen(fn, "w");
        if(fid==NULL)
        { exit(1);
        }

  fprintf(stdout, "hello MPI user: from process = %i on machine=%s, of
NCPU=%i processors\n",
         tid, cpu_name, nthreads);
  MPI_Finalize();
  return(0);

###############################################################################