Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Merge branch 'master' into master
[simgrid.git] / teshsuite / smpi / isp / umpire / send-recv-ok.c
1 /* -*- Mode: C; -*- */
2
3 #include <stdio.h>
4 #include "mpi.h"
5
6 #define buf_size 128
7
8 int
9 main (int argc, char **argv)
10 {
11   int nprocs = -1;
12   int rank = -1;
13   char processor_name[128];
14   int namelen = 128;
15   int buf0[buf_size];
16   int buf1[buf_size];
17   MPI_Status status;
18
19   /* init */
20   MPI_Init (&argc, &argv);
21   MPI_Comm_size (MPI_COMM_WORLD, &nprocs);
22   MPI_Comm_rank (MPI_COMM_WORLD, &rank);
23   MPI_Get_processor_name (processor_name, &namelen);
24   printf ("(%d) is alive on %s\n", rank, processor_name);
25   fflush (stdout);
26
27   MPI_Barrier (MPI_COMM_WORLD);
28
29   if (nprocs < 2)
30     {
31       printf ("not enough tasks\n");
32     }
33   else if (rank == 0)
34     {
35       memset (buf0, 0, buf_size*sizeof(int));
36       MPI_Send (buf0, buf_size, MPI_INT, 1, 0, MPI_COMM_WORLD);
37       MPI_Recv (buf1, buf_size, MPI_INT, 1, 0, MPI_COMM_WORLD, &status);
38     }
39   else if (rank == 1)
40     {
41       MPI_Recv (buf0, buf_size, MPI_INT, 0, 0, MPI_COMM_WORLD, &status);
42       memset (buf1, 1, buf_size*sizeof(int));
43       MPI_Send (buf1, buf_size, MPI_INT, 0, 0, MPI_COMM_WORLD);
44     }
45
46   MPI_Barrier (MPI_COMM_WORLD);
47
48   MPI_Finalize ();
49   printf ("(%d) Finished normally\n", rank);
50 }
51
52 /* EOF */