Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Merge branch 'master' of scm.gforge.inria.fr:/gitroot/simgrid/simgrid
[simgrid.git] / teshsuite / smpi / isp / umpire / no-error-any_src.c
1 /* -*- Mode: C; -*- */
2 /* Creator: Bronis R. de Supinski (bronis@llnl.gov) Thu Nov 30 2000 */
3 /* no-error3.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   int i;
16   char processor_name[128];
17   int namelen = 128;
18   int buf[buf_size];
19   MPI_Status status;
20
21   /* init */
22   MPI_Init (&argc, &argv);
23   MPI_Comm_size (MPI_COMM_WORLD, &nprocs);
24   MPI_Comm_rank (MPI_COMM_WORLD, &rank);
25   MPI_Get_processor_name (processor_name, &namelen);
26   printf ("(%d) is alive on %s\n", rank, processor_name);
27   fflush (stdout);
28
29   MPI_Barrier (MPI_COMM_WORLD);
30
31   if (nprocs < 2) {
32       printf ("not enough tasks\n");
33   }
34   else {
35     if (rank == 0) {
36       for (i = 1; i < nprocs; i++) {
37         MPI_Recv (buf, buf_size, MPI_INT,
38                   MPI_ANY_SOURCE, 0, MPI_COMM_WORLD, &status);
39       }
40     }
41     else {
42       memset (buf, 1, buf_size*sizeof(int));
43
44       MPI_Send (buf, buf_size, MPI_INT, 0, 0, MPI_COMM_WORLD);
45     }
46   }
47
48   MPI_Barrier (MPI_COMM_WORLD);
49
50   MPI_Finalize ();
51   printf ("(%d) Finished normally\n", rank);
52 }
53
54 /* EOF */