hello_mpi.c 648 Bytes
Newer Older
hautreux's avatar
hautreux committed
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
#include <mpi.h>
#include <stdlib.h>
#include <sys/unistd.h>
#include <stdio.h>
#include <string.h>

int main(int argc,char**argv)
{
  int mpiRank, mpiSize, i;
  char hostname[128];
  int nthreads, tid, cpuid;  

  MPI_Init(&argc,&argv);
  MPI_Comm_rank(MPI_COMM_WORLD, &mpiRank);
  MPI_Comm_size(MPI_COMM_WORLD, &mpiSize);

  gethostname(hostname, sizeof hostname);

  if ( mpiRank== 0) 
		printf("Run executed using %d MPI processes \n", mpiSize);

	for(i = 0; i < mpiSize; i++) {
    MPI_Barrier(MPI_COMM_WORLD);
    if (i == mpiRank) {
  		printf("%s: MPI n° %d -> cpuid %d \n",hostname, mpiRank,sched_getcpu());
    }
	}

  MPI_Finalize();
}