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. */
8 * MESSAGE PASSING INTERFACE TEST CASE SUITE
10 * Copyright IBM Corp. 1995
12 * IBM Corp. hereby grants a non-exclusive license to use, copy, modify, and
13 *distribute this software for any purpose and without fee provided that the
14 *above copyright notice and the following paragraphs appear in all copies.
16 * IBM Corp. makes no representation that the test cases comprising this
17 * suite are correct or are an accurate representation of any standard.
19 * In no event shall IBM be liable to any party for direct, indirect, special
20 * incidental, or consequential damage arising out of the use of this software
21 * even if IBM Corp. has been advised of the possibility of such damage.
23 * IBM CORP. SPECIFICALLY DISCLAIMS ANY WARRANTIES INCLUDING, BUT NOT LIMITED
24 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
25 * PURPOSE. THE SOFTWARE PROVIDED HEREUNDER IS ON AN "AS IS" BASIS AND IBM
26 * CORP. HAS NO OBLIGATION TO PROVIDE MAINTENANCE, SUPPORT, UPDATES,
27 * ENHANCEMENTS, OR MODIFICATIONS.
28 * ***************************************************************************
33 static int ibm_test(int rank, int size)
45 out = malloc(MAXLEN * 64 * sizeof(int));
46 in = malloc(MAXLEN * sizeof(int));
48 for (j = 1; j <= MAXLEN; j *= 10) {
49 root = (root + 1) % size;
51 for (i = 0; i < j * size; i++)
54 MPI_Scatter(out, j, MPI_INT, in, j, MPI_INT, root, MPI_COMM_WORLD);
56 for (k = 0; k < j; k++) {
57 if (in[k] != k + rank * j) {
59 "task %d bad answer (%d) at index %d k of %d (should be %d)",
60 rank, in[k], k, j, (k + rank * j));
67 MPI_Barrier(MPI_COMM_WORLD);
72 * small test: the root sends a single distinct double to other processes
74 static int small_test(int rank, int size)
78 int sendcount = 1; // one double to each process
81 double *sndbuf = NULL;
83 int root = 0; // arbitrary choice
85 // on root, initialize sendbuf
87 sndbuf = malloc(size * sizeof(double));
88 for (i = 0; i < size; i++) {
89 sndbuf[i] = (double) i;
94 MPI_Scatter(sndbuf, sendcount, MPI_DOUBLE, &rcvd, recvcount,
95 MPI_DOUBLE, root, MPI_COMM_WORLD);
99 if (retval != MPI_SUCCESS) {
100 fprintf(stderr, "(%s:%d) MPI_Scatter() returned retval=%d\n", __FILE__,
105 if ((double) rank != rcvd) {
106 fprintf(stderr, "[%d] has %f instead of %d\n", rank, rcvd, rank);
114 int main(int argc, char **argv)
119 MPI_Init(&argc, &argv);
120 MPI_Comm_size(MPI_COMM_WORLD, &size);
121 MPI_Comm_rank(MPI_COMM_WORLD, &rank);
125 printf("** Small Test Result: ...\n");
126 if (!small_test(rank, size))
127 printf("\t[%d] failed.\n", rank);
129 printf("\t[%d] ok.\n", rank);
132 MPI_Barrier(MPI_COMM_WORLD);
136 printf("** IBM Test Result: ...\n");
137 if (!ibm_test(rank, size))
138 printf("\t[%d] failed.\n", rank);
140 printf("\t[%d] ok.\n", rank);