Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Merge tag 'v3_9_90' into hypervisor
[simgrid.git] / teshsuite / smpi / mpich3-test / coll / coll13.c
1 /* -*- Mode: C; c-basic-offset:4 ; indent-tabs-mode:nil ; -*- */
2 /*
3  *  Changes to the original code
4  *  (C) 2001 by Argonne National Laboratory.
5  *      See COPYRIGHT in top-level directory.
6  */
7 #include "mpi.h"
8
9 /* 
10 From: hook@nas.nasa.gov (Edward C. Hook)
11  */
12
13 #include <stdlib.h>
14 #include <stdio.h>
15 #include "mpitest.h"
16
17 #include <string.h>
18 #include <errno.h>
19 #ifndef EXIT_SUCCESS
20 #define EXIT_SUCCESS 0
21 #define EXIT_FAILURE 1
22 #endif
23
24 int main( int argc, char *argv[] )
25 {
26     int rank, size;
27     int chunk = 128;
28     int i;
29     int *sb;
30     int *rb;
31     int status;
32
33     MTest_Init(&argc,&argv);
34     MPI_Comm_rank(MPI_COMM_WORLD,&rank);
35     MPI_Comm_size(MPI_COMM_WORLD,&size);
36
37     for ( i=1 ; i < argc ; ++i ) {
38         if ( argv[i][0] != '-' )
39             continue;
40         switch(argv[i][1]) {
41         case 'm':
42             chunk = atoi(argv[++i]);
43             break;
44         default:
45             fprintf(stderr,"Unrecognized argument %s\n",
46                     argv[i]);
47             MPI_Abort(MPI_COMM_WORLD,EXIT_FAILURE);
48         }
49     }
50
51     sb = (int *)malloc(size*chunk*sizeof(int));
52     if ( !sb ) {
53         perror( "can't allocate send buffer" );
54         MPI_Abort(MPI_COMM_WORLD,EXIT_FAILURE);
55     }
56     rb = (int *)malloc(size*chunk*sizeof(int));
57     if ( !rb ) {
58         perror( "can't allocate recv buffer");
59         free(sb);
60         MPI_Abort(MPI_COMM_WORLD,EXIT_FAILURE);
61     }
62     for ( i=0 ; i < size*chunk ; ++i ) {
63         sb[i] = rank + 1;
64         rb[i] = 0;
65     }
66
67     /* fputs("Before MPI_Alltoall\n",stdout); */
68
69     /* This should really send MPI_CHAR, but since sb and rb were allocated
70        as chunk*size*sizeof(int), the buffers are large enough */
71     status = MPI_Alltoall(sb,chunk,MPI_INT,rb,chunk,MPI_INT,
72                           MPI_COMM_WORLD);
73
74     /* fputs("Before MPI_Allreduce\n",stdout); */
75
76     MTest_Finalize( status );
77
78     free(sb);
79     free(rb);
80
81     MPI_Finalize();
82
83     return MTestReturnValue( status );
84 }
85