1 /* Copyright (c) 2012-2014. The SimGrid Team.
2 * All rights reserved. */
4 /* This program is free software; you can redistribute it and/or modify it
5 * under the terms of the license (GNU LGPL) which comes with this package. */
11 * MESSAGE PASSING INTERFACE TEST CASE SUITE
13 * Copyright IBM Corp. 1995
15 * IBM Corp. hereby grants a non-exclusive license to use, copy, modify, and
16 *distribute this software for any purpose and without fee provided that the
17 *above copyright notice and the following paragraphs appear in all copies.
19 * IBM Corp. makes no representation that the test cases comprising this
20 * suite are correct or are an accurate representation of any standard.
22 * In no event shall IBM be liable to any party for direct, indirect, special
23 * incidental, or consequential damage arising out of the use of this software
24 * even if IBM Corp. has been advised of the possibility of such damage.
26 * IBM CORP. SPECIFICALLY DISCLAIMS ANY WARRANTIES INCLUDING, BUT NOT LIMITED
27 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
28 * PURPOSE. THE SOFTWARE PROVIDED HEREUNDER IS ON AN "AS IS" BASIS AND IBM
29 * CORP. HAS NO OBLIGATION TO PROVIDE MAINTENANCE, SUPPORT, UPDATES,
30 * ENHANCEMENTS, OR MODIFICATIONS.
31 * ***************************************************************************
33 static int ibm_test(int rank, int size)
43 for (j = 1; j <= MAXLEN; j *= 10) {
44 for (i = 0; i < j; i++)
47 MPI_Reduce(out, in, j, MPI_INT, MPI_SUM, root, MPI_COMM_WORLD);
50 for (k = 0; k < j; k++) {
51 if (in[k] != k * size) {
52 printf("bad answer (%d) at index %d of %d (should be %d)", in[k],
66 int main(int argc, char **argv)
71 int sum = -99, sum_mirror = -99, min = 999, max = -999;
77 MPI_Init(&argc, &argv);
78 MPI_Comm_size(MPI_COMM_WORLD, &size);
79 MPI_Comm_rank(MPI_COMM_WORLD, &rank);
81 if (argc > 1 && !strcmp(argv[1], "-q"))
84 start_timer = MPI_Wtime();
86 value = rank + 1; /* easy to verify that sum= (size*(size+1))/2; */
88 //printf("[%d] has value %d\n", rank, value);
89 MPI_Reduce(&value, &sum, 1, MPI_INT, MPI_SUM, root, MPI_COMM_WORLD);
90 MPI_Reduce(&value, &sum_mirror, 1, MPI_INT, MPI_SUM, root,
93 MPI_Reduce(&value, &min, 1, MPI_INT, MPI_MIN, root, MPI_COMM_WORLD);
94 MPI_Reduce(&value, &max, 1, MPI_INT, MPI_MAX, root, MPI_COMM_WORLD);
96 printf("** Scalar Int Test Result:\n");
97 printf("\t[%d] sum=%d ... validation ", rank, sum);
98 if (((size * (size + 1)) / 2 == sum) && (sum_mirror == sum))
101 printf("failed (sum=%d,sum_mirror=%d while both sould be %d.\n",
102 sum, sum_mirror, (size * (size + 1)) / 2);
103 printf("\t[%d] min=%d ... validation ", rank, min);
108 printf("\t[%d] max=%d ... validation ", rank, max);
114 printf("Elapsed time=%f s\n", MPI_Wtime() - start_timer);
117 MPI_Barrier(MPI_COMM_WORLD);
120 printf("** IBM Test Result: ... \n");
121 if (!ibm_test(rank, size))
122 printf("\t[%d] failed.\n", rank);
124 printf("\t[%d] ok.\n", rank);