Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Add new entry in Release_Notes.
[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
20 int main(int argc, char *argv[])
21 {
22     int rank, size;
23     int chunk = 128;
24     int i;
25     int *sb;
26     int *rb;
27     int status;
28
29     MTest_Init(&argc, &argv);
30     MPI_Comm_rank(MPI_COMM_WORLD, &rank);
31     MPI_Comm_size(MPI_COMM_WORLD, &size);
32
33     for (i = 1; i < argc; ++i) {
34         if (argv[i][0] != '-')
35             continue;
36         switch (argv[i][1]) {
37         case 'm':
38             chunk = atoi(argv[++i]);
39             break;
40         default:
41             fprintf(stderr, "Unrecognized argument %s\n", argv[i]);
42             MPI_Abort(MPI_COMM_WORLD, EXIT_FAILURE);
43         }
44     }
45
46     sb = (int *) malloc(size * chunk * sizeof(int));
47     if (!sb) {
48         perror("can't allocate send buffer");
49         MPI_Abort(MPI_COMM_WORLD, EXIT_FAILURE);
50     }
51     rb = (int *) malloc(size * chunk * sizeof(int));
52     if (!rb) {
53         perror("can't allocate recv buffer");
54         free(sb);
55         MPI_Abort(MPI_COMM_WORLD, EXIT_FAILURE);
56     }
57     for (i = 0; i < size * chunk; ++i) {
58         sb[i] = rank + 1;
59         rb[i] = 0;
60     }
61
62     /* fputs("Before MPI_Alltoall\n",stdout); */
63
64     /* This should really send MPI_CHAR, but since sb and rb were allocated
65      * as chunk*size*sizeof(int), the buffers are large enough */
66     status = MPI_Alltoall(sb, chunk, MPI_INT, rb, chunk, MPI_INT, MPI_COMM_WORLD);
67
68     /* fputs("Before MPI_Allreduce\n",stdout); */
69
70     MTest_Finalize(status);
71
72     free(sb);
73     free(rb);
74
75     MPI_Finalize();
76
77     return MTestReturnValue(status);
78 }