Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Multiply memset size by size of element in umpire.
[simgrid.git] / teshsuite / smpi / isp / umpire / no-error-wait-any_src3.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 #define NUMREPS  3
10
11 int
12 main (int argc, char **argv)
13 {
14   int nprocs = -1;
15   int rank = -1;
16   char processor_name[128];
17   int namelen = 128;
18   int buf0[buf_size];
19   int buf1[buf_size];
20   int i;
21   MPI_Status status;
22   MPI_Request req;
23
24   /* init */
25   MPI_Init (&argc, &argv);
26   MPI_Comm_size (MPI_COMM_WORLD, &nprocs);
27   MPI_Comm_rank (MPI_COMM_WORLD, &rank);
28   MPI_Get_processor_name (processor_name, &namelen);
29   printf ("(%d) is alive on %s\n", rank, processor_name);
30   fflush (stdout);
31   MPI_Barrier (MPI_COMM_WORLD);
32
33   if (NUMREPS < 1)
34     {
35       printf ("not enough repetitions\n");
36     }
37
38   if (nprocs < 2)
39     {
40       printf ("not enough tasks\n");
41     }
42   else if (rank == 0)
43     {
44       memset (buf0, 0, buf_size*sizeof(int));
45
46        MPI_Irecv (buf1, buf_size, MPI_INT,
47                  MPI_ANY_SOURCE, 0, MPI_COMM_WORLD, &req);
48
49       MPI_Send (buf0, buf_size, MPI_INT, 1, 0, MPI_COMM_WORLD);
50
51       for (i = 0; i < NUMREPS; i++) {
52         MPI_Send (buf0, buf_size, MPI_INT, 1, 0, MPI_COMM_WORLD);
53         
54         MPI_Recv (buf0, buf_size, MPI_INT, 1, 0, MPI_COMM_WORLD, &status);
55       }
56
57       MPI_Wait (&req, &status);
58     }
59   else if (rank == 1)
60     {
61       MPI_Irecv (buf1, buf_size, MPI_INT,
62                  MPI_ANY_SOURCE, 0, MPI_COMM_WORLD, &req);
63
64       MPI_Recv (buf0, buf_size, MPI_INT, 0, 0, MPI_COMM_WORLD, &status);
65
66       MPI_Send (buf0, buf_size, MPI_INT, 0, 0, MPI_COMM_WORLD);
67
68       for (i = 0; i < NUMREPS-1; i++) {
69         MPI_Send (buf0, buf_size, MPI_INT, 0, 0, MPI_COMM_WORLD);
70
71         MPI_Recv (buf0, buf_size, MPI_INT, 0, 0, MPI_COMM_WORLD, &status);
72       }
73
74       MPI_Send (buf0, buf_size, MPI_INT, 0, 0, MPI_COMM_WORLD);
75
76       MPI_Wait (&req, &status);
77     }
78
79   MPI_Barrier (MPI_COMM_WORLD);
80
81   MPI_Finalize ();
82   printf ("(%d) Finished normally\n", rank);
83 }
84
85 /* EOF */