Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Merge branch 'v3_8_x'
[simgrid.git] / teshsuite / smpi / mpich-test / pt2pt / sendmany.c
1 #include <stdio.h>
2 #ifdef HAVE_UNISTD_H
3 #include <unistd.h>
4 #endif
5 #include <stdlib.h>
6 #include <assert.h>
7 #include "mpi.h"
8
9 #if defined(NEEDS_STDLIB_PROTOTYPES)
10 #include "protofix.h"
11 #endif
12
13 #define MAXPES 16
14 #define MYBUFSIZE 8*1024
15 static int buffer[MAXPES][MYBUFSIZE];
16
17 #define NUM_RUNS 10
18
19
20 int main ( int argc, char *argv[] )
21 {
22   int i;
23   int count, size;
24   int self, npes;
25   double secs;
26   MPI_Request request[MAXPES];
27   MPI_Status status;
28
29
30   MPI_Init (&argc, &argv);
31   MPI_Comm_rank (MPI_COMM_WORLD, &self);
32   MPI_Comm_size (MPI_COMM_WORLD, &npes);
33
34   assert (npes <= MAXPES);
35
36   for (size = 1; size  <= MYBUFSIZE ; size += size)
37     {
38
39       secs = -MPI_Wtime ();
40       for (count = 0; count < NUM_RUNS; count++)
41         {
42           MPI_Barrier (MPI_COMM_WORLD);
43
44           for (i = 0; i < npes; i++)
45             {
46               if (i == self)
47                 continue;
48               MPI_Irecv (buffer[i], size, MPI_INT, i,
49                          MPI_ANY_TAG, MPI_COMM_WORLD, &request[i]);
50             }
51
52           for (i = 0; i < npes; i++)
53             {
54               if (i == self)
55                 continue;
56               MPI_Send (buffer[self], size, MPI_INT, i, 0, MPI_COMM_WORLD);
57             }
58
59           for (i = 0; i < npes; i++)
60             {
61               if (i == self)
62                 continue;
63               MPI_Wait (&request[i], &status);
64             }
65
66         }
67       MPI_Barrier (MPI_COMM_WORLD);
68       secs += MPI_Wtime ();
69
70       if (self == 0)
71         {
72           secs = secs / (double) NUM_RUNS;
73           printf ( "length = %d ints\n", size );
74           fflush(stdout);
75 /*
76           printf ("%f\n",
77                   (double) (size * sizeof (int) * (npes - 1)) /
78                     (secs * 1024.0 * 1024.0));
79  */
80         }
81     }
82   MPI_Finalize();
83   return (0);
84 }