Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
659c1c2ef8860d729e9b7894b1286d2f47d2b98d
[simgrid.git] / teshsuite / smpi / isp / umpire / no-error2.c
1 /* -*- Mode: C; -*- */
2 /* Creator: Bronis R. de Supinski (bronis@llnl.gov) Fri Mar  17 2000 */
3 /* no-error2.c -- do some MPI calls without any errors */
4 /* unlike no-error.c, this uses a raing and calls MPI_Barrier... */
5
6 #include <stdio.h>
7 #include "mpi.h"
8
9 #define buf_size 128
10
11 int
12 main (int argc, char **argv)
13 {
14   int nprocs = -1;
15   int rank = -1;
16   int src, dest;
17   char processor_name[128];
18   int namelen = 128;
19   int buf0[buf_size];
20   int buf1[buf_size];
21   MPI_Status status;
22
23   /* init */
24   MPI_Init (&argc, &argv);
25   MPI_Comm_size (MPI_COMM_WORLD, &nprocs);
26   MPI_Comm_rank (MPI_COMM_WORLD, &rank);
27   MPI_Get_processor_name (processor_name, &namelen);
28   printf ("(%d) is alive on %s\n", rank, processor_name);
29   fflush (stdout);
30
31   src = (rank + 1) % nprocs;
32   dest = (rank - 1 + nprocs) % nprocs;
33
34   memset (buf0, 0, buf_size);
35
36   MPI_Sendrecv (buf0, buf_size, MPI_INT, dest, 0,
37                 buf1, buf_size, MPI_INT, src, 0, MPI_COMM_WORLD, &status);
38
39   memset (buf1, 1, buf_size);
40
41   MPI_Sendrecv (buf1, buf_size, MPI_INT, src, 0,
42                 buf0, buf_size, MPI_INT, dest, 0, MPI_COMM_WORLD, &status);
43
44   memset (buf0, 0, buf_size);
45
46   MPI_Sendrecv (buf0, buf_size, MPI_INT, dest, 0,
47                 buf1, buf_size, MPI_INT, src, 0, MPI_COMM_WORLD, &status);
48
49   MPI_Barrier (MPI_COMM_WORLD);
50
51   MPI_Finalize ();
52   printf ("(%d) Finished normally\n", rank);
53 }
54
55 /* EOF */