Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
[mc] Ignore stdout/stderr of the umpire tests
[simgrid.git] / teshsuite / smpi / isp / umpire / no-error-waitall-any_src.c
1 /* -*- Mode: C; -*- */
2 /* Creator: Bronis R. de Supinski (bronis@llnl.gov) Fri Mar  17 2000 */
3 /* no-error.c -- do some MPI calls without any errors */
4
5 #include <stdio.h>
6 #include "mpi.h"
7
8 #define buf_size 128
9
10 int
11 main (int argc, char **argv)
12 {
13   int nprocs = -1;
14   int rank = -1;
15   char processor_name[128];
16   int namelen = 128;
17   int buf0[buf_size];
18   int buf1[buf_size];
19   MPI_Status statuses[2];
20   MPI_Request reqs[2];
21
22   /* init */
23   MPI_Init (&argc, &argv);
24   MPI_Comm_size (MPI_COMM_WORLD, &nprocs);
25   MPI_Comm_rank (MPI_COMM_WORLD, &rank);
26   MPI_Get_processor_name (processor_name, &namelen);
27   printf ("(%d) is alive on %s\n", rank, processor_name);
28   fflush (stdout);
29
30   MPI_Barrier (MPI_COMM_WORLD);
31
32   /* the following code is "correct although its result */
33   /* is non-deterministic - in task 0, either buf0 will */
34   /* hold result of memset to 0 and buf1 will hold result */
35   /* of memset to 1 or buf0 will hold result of memset to */
36   /* 1 and buf1 will hold result of memset to 0; in task 1, */
37   /* buf1 will mirror task 0 buf1 result while, in task 2, */
38   /* buf0 will mirror task 0 buf0 result; thus buf0 may */
39   /* be equal to buf1 in tasks 1 and 2 or it may not... */
40   if (nprocs < 3)
41     {
42       printf ("not enough tasks\n");
43     }
44   else if (rank == 0)
45     {
46       MPI_Irecv (buf0, buf_size, MPI_INT, 
47                  MPI_ANY_SOURCE, 0, MPI_COMM_WORLD, &reqs[0]);
48
49       MPI_Irecv (buf1, buf_size, MPI_INT, 
50                  MPI_ANY_SOURCE, 0, MPI_COMM_WORLD, &reqs[1]);
51
52       MPI_Waitall (2, reqs, statuses);
53
54       MPI_Send (buf1, buf_size, MPI_INT, 1, 1, MPI_COMM_WORLD);
55
56       MPI_Send (buf0, buf_size, MPI_INT, 2, 2, MPI_COMM_WORLD);
57     }
58   else if (rank == 1)
59     {
60       memset (buf0, 0, buf_size);
61
62       MPI_Send (buf0, buf_size, MPI_INT, 0, 0, MPI_COMM_WORLD);
63
64       MPI_Recv (buf1, buf_size, MPI_INT, 0, 1, MPI_COMM_WORLD, statuses);
65     }
66   else if (rank == 2)
67     {
68       memset (buf1, 1, buf_size);
69
70       MPI_Send (buf1, buf_size, MPI_INT, 0, 0, MPI_COMM_WORLD);
71
72       MPI_Recv (buf0, buf_size, MPI_INT, 0, 2, MPI_COMM_WORLD, statuses);
73     }
74
75   MPI_Barrier (MPI_COMM_WORLD);
76
77   MPI_Finalize ();
78   printf ("(%d) Finished normally\n", rank);
79 }
80
81 /* EOF */