Logo AND Algorithmique Numérique Distribuée

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