5 * MESSAGE PASSING INTERFACE TEST CASE SUITE
7 * Copyright IBM Corp. 1995
9 * IBM Corp. hereby grants a non-exclusive license to use, copy, modify, and
10 *distribute this software for any purpose and without fee provided that the
11 *above copyright notice and the following paragraphs appear in all copies.
13 * IBM Corp. makes no representation that the test cases comprising this
14 * suite are correct or are an accurate representation of any standard.
16 * In no event shall IBM be liable to any party for direct, indirect, special
17 * incidental, or consequential damage arising out of the use of this software
18 * even if IBM Corp. has been advised of the possibility of such damage.
20 * IBM CORP. SPECIFICALLY DISCLAIMS ANY WARRANTIES INCLUDING, BUT NOT LIMITED
21 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
22 * PURPOSE. THE SOFTWARE PROVIDED HEREUNDER IS ON AN "AS IS" BASIS AND IBM
23 * CORP. HAS NO OBLIGATION TO PROVIDE MAINTENANCE, SUPPORT, UPDATES,
24 * ENHANCEMENTS, OR MODIFICATIONS.
25 * ***************************************************************************
27 static int ibm_test(int rank, int size)
37 for (j = 1; j <= MAXLEN; j *= 10) {
38 for (i = 0; i < j; i++)
41 MPI_Reduce(out, in, j, MPI_INT, MPI_SUM, root, MPI_COMM_WORLD);
44 for (k = 0; k < j; k++) {
45 if (in[k] != k * size) {
46 printf("bad answer (%d) at index %d of %d (should be %d)", in[k],
60 int main(int argc, char **argv)
65 int sum = -99, sum_mirror = -99, min = 999, max = -999;
71 MPI_Init(&argc, &argv);
72 MPI_Comm_size(MPI_COMM_WORLD, &size);
73 MPI_Comm_rank(MPI_COMM_WORLD, &rank);
75 if (argc > 1 && !strcmp(argv[1], "-q"))
78 start_timer = MPI_Wtime();
80 value = rank + 1; /* easy to verify that sum= (size*(size+1))/2; */
82 //printf("[%d] has value %d\n", rank, value);
83 MPI_Reduce(&value, &sum, 1, MPI_INT, MPI_SUM, root, MPI_COMM_WORLD);
84 MPI_Reduce(&value, &sum_mirror, 1, MPI_INT, MPI_SUM, root,
87 MPI_Reduce(&value, &min, 1, MPI_INT, MPI_MIN, root, MPI_COMM_WORLD);
88 MPI_Reduce(&value, &max, 1, MPI_INT, MPI_MAX, root, MPI_COMM_WORLD);
90 printf("** Scalar Int Test Result:\n");
91 printf("\t[%d] sum=%d ... validation ", rank, sum);
92 if (((size * (size + 1)) / 2 == sum) && (sum_mirror == sum))
95 printf("failed (sum=%d,sum_mirror=%d while both sould be %d.\n",
96 sum, sum_mirror, (size * (size + 1)) / 2);
97 printf("\t[%d] min=%d ... validation ", rank, min);
102 printf("\t[%d] max=%d ... validation ", rank, max);
108 printf("Elapsed time=%lf s\n", MPI_Wtime() - start_timer);
111 MPI_Barrier(MPI_COMM_WORLD);
114 printf("** IBM Test Result: ... \n");
115 if (!ibm_test(rank, size))
116 printf("\t[%d] failed.\n", rank);
118 printf("\t[%d] ok.\n", rank);