1 /* -*- Mode: C; c-basic-offset:4 ; indent-tabs-mode:nil ; -*- */
3 * Changes to the original code
4 * (C) 2001 by Argonne National Laboratory.
5 * See COPYRIGHT in top-level directory.
10 From: hook@nas.nasa.gov (Edward C. Hook)
20 #define EXIT_SUCCESS 0
21 #define EXIT_FAILURE 1
24 int main(int argc, char *argv[])
33 MTest_Init(&argc, &argv);
34 MPI_Comm_rank(MPI_COMM_WORLD, &rank);
35 MPI_Comm_size(MPI_COMM_WORLD, &size);
37 for (i = 1; i < argc; ++i) {
38 if (argv[i][0] != '-')
42 chunk = atoi(argv[++i]);
45 fprintf(stderr, "Unrecognized argument %s\n", argv[i]);
46 MPI_Abort(MPI_COMM_WORLD, EXIT_FAILURE);
50 sb = (int *) malloc(size * chunk * sizeof(int));
52 perror("can't allocate send buffer");
53 MPI_Abort(MPI_COMM_WORLD, EXIT_FAILURE);
55 rb = (int *) malloc(size * chunk * sizeof(int));
57 perror("can't allocate recv buffer");
59 MPI_Abort(MPI_COMM_WORLD, EXIT_FAILURE);
61 for (i = 0; i < size * chunk; ++i) {
66 /* fputs("Before MPI_Alltoall\n",stdout); */
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);
72 /* fputs("Before MPI_Allreduce\n",stdout); */
74 MTest_Finalize(status);
81 return MTestReturnValue(status);