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 )
17 struct { double a; int b; } in[TABLE_SIZE], out[TABLE_SIZE];
21 /* Initialize the environment and some variables */
22 MTest_Init( &argc, &argv );
23 MPI_Comm_rank( MPI_COMM_WORLD, &rank );
24 MPI_Comm_size( MPI_COMM_WORLD, &size );
26 /* Initialize the maxloc data */
27 for ( i=0; i<TABLE_SIZE; i++ ) a[i] = 0;
28 for ( i=rank; i<TABLE_SIZE; i++ ) a[i] = (double)rank + 1.0;
30 /* Copy data to the "in" buffer */
31 for (i=0; i<TABLE_SIZE; i++) {
37 MPI_Reduce( in, out, TABLE_SIZE, MPI_DOUBLE_INT, MPI_MAXLOC, 0, MPI_COMM_WORLD );
38 MPI_Bcast ( out, TABLE_SIZE, MPI_DOUBLE_INT, 0, MPI_COMM_WORLD );
40 /* Check to see that we got the right answers */
41 for (i=0; i<TABLE_SIZE; i++)
43 if (out[i].b != rank) {
44 printf("MAX (ranks[%d] = %d != %d\n", i, out[i].b, rank );
48 /* Initialize the minloc data */
49 for ( i=0; i<TABLE_SIZE; i++ ) a[i] = 0;
50 for ( i=rank; i<TABLE_SIZE; i++ ) a[i] = -(double)rank - 1.0;
52 /* Copy data to the "in" buffer */
53 for (i=0; i<TABLE_SIZE; i++) {
59 MPI_Allreduce( in, out, TABLE_SIZE, MPI_DOUBLE_INT, MPI_MINLOC, MPI_COMM_WORLD );
61 /* Check to see that we got the right answers */
62 for (i=0; i<TABLE_SIZE; i++)
64 if (out[i].b != rank) {
65 printf("MIN (ranks[%d] = %d != %d\n", i, out[i].b, rank );
70 MTest_Finalize( errors );
72 return MTestReturnValue( errors );