Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
remove warning with mc
[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             exit(EXIT_FAILURE);
49         }
50     }
51
52     sb = (int *)malloc(size*chunk*sizeof(int));
53     if ( !sb ) {
54         perror( "can't allocate send buffer" );
55         MPI_Abort(MPI_COMM_WORLD,EXIT_FAILURE);
56         exit(EXIT_FAILURE);
57     }
58     rb = (int *)malloc(size*chunk*sizeof(int));
59     if ( !rb ) {
60         perror( "can't allocate recv buffer");
61         free(sb);
62         MPI_Abort(MPI_COMM_WORLD,EXIT_FAILURE);
63         exit(EXIT_FAILURE);
64     }
65     for ( i=0 ; i < size*chunk ; ++i ) {
66         sb[i] = rank + 1;
67         rb[i] = 0;
68     }
69
70     /* fputs("Before MPI_Alltoall\n",stdout); */
71
72     /* This should really send MPI_CHAR, but since sb and rb were allocated
73        as chunk*size*sizeof(int), the buffers are large enough */
74     status = MPI_Alltoall(sb,chunk,MPI_INT,rb,chunk,MPI_INT,
75                           MPI_COMM_WORLD);
76
77     /* fputs("Before MPI_Allreduce\n",stdout); */
78
79     MTest_Finalize( status );
80
81     free(sb);
82     free(rb);
83
84     MPI_Finalize();
85
86     return MTestReturnValue( status );
87 }
88