1 /* -*- Mode: C; c-basic-offset:4 ; indent-tabs-mode:nil ; -*- */
3 * (C) 2001 by Argonne National Laboratory.
4 * See COPYRIGHT in top-level directory.
13 int main(int argc, char **argv)
20 } in[TABLE_SIZE], out[TABLE_SIZE];
24 /* Initialize the environment and some variables */
25 MTest_Init(&argc, &argv);
26 MPI_Comm_rank(MPI_COMM_WORLD, &rank);
27 MPI_Comm_size(MPI_COMM_WORLD, &size);
29 /* Initialize the maxloc data */
30 for (i = 0; i < TABLE_SIZE; i++)
32 for (i = rank; i < TABLE_SIZE; i++)
33 a[i] = (double) rank + 1.0;
35 /* Copy data to the "in" buffer */
36 for (i = 0; i < TABLE_SIZE; i++) {
42 MPI_Reduce(in, out, TABLE_SIZE, MPI_DOUBLE_INT, MPI_MAXLOC, 0, MPI_COMM_WORLD);
43 MPI_Bcast(out, TABLE_SIZE, MPI_DOUBLE_INT, 0, MPI_COMM_WORLD);
45 /* Check to see that we got the right answers */
46 for (i = 0; i < TABLE_SIZE; i++)
48 if (out[i].b != rank) {
49 printf("MAX (ranks[%d] = %d != %d\n", i, out[i].b, rank);
53 /* Initialize the minloc data */
54 for (i = 0; i < TABLE_SIZE; i++)
56 for (i = rank; i < TABLE_SIZE; i++)
57 a[i] = -(double) rank - 1.0;
59 /* Copy data to the "in" buffer */
60 for (i = 0; i < TABLE_SIZE; i++) {
66 MPI_Allreduce(in, out, TABLE_SIZE, MPI_DOUBLE_INT, MPI_MINLOC, MPI_COMM_WORLD);
68 /* Check to see that we got the right answers */
69 for (i = 0; i < TABLE_SIZE; i++)
71 if (out[i].b != rank) {
72 printf("MIN (ranks[%d] = %d != %d\n", i, out[i].b, rank);
77 MTest_Finalize(errors);
79 return MTestReturnValue(errors);