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.
32 static int ibm_test(int rank, int size)
43 out = malloc(MAXLEN * 64 * sizeof(int));
44 in = malloc(MAXLEN * sizeof(int));
46 for (j = 1; j <= MAXLEN; j *= 10) {
47 root = (root + 1) % size;
49 for (i = 0; i < j * size; i++)
52 MPI_Scatter(out, j, MPI_INT, in, j, MPI_INT, root, MPI_COMM_WORLD);
54 for (k = 0; k < j; k++) {
55 if (in[k] != k + rank * j) {
56 fprintf(stderr, "task %d bad answer (%d) at index %d k of %d (should be %d)",rank, in[k], k, j, (k + rank * j));
63 MPI_Barrier(MPI_COMM_WORLD);
67 /** small test: the root sends a single distinct double to other processes */
68 static int small_test(int rank, int size)
72 int sendcount = 1; // one double to each process
75 double *sndbuf = NULL;
77 int root = 0; // arbitrary choice
79 // on root, initialize sendbuf
81 sndbuf = malloc(size * sizeof(double));
82 for (i = 0; i < size; i++) {
83 sndbuf[i] = (double) i;
87 retval = MPI_Scatter(sndbuf, sendcount, MPI_DOUBLE, &rcvd, recvcount, MPI_DOUBLE, root, MPI_COMM_WORLD);
91 if (retval != MPI_SUCCESS) {
92 fprintf(stderr, "(%s:%d) MPI_Scatter() returned retval=%d\n", __FILE__, __LINE__, retval);
96 if ((double) rank != rcvd) {
97 fprintf(stderr, "[%d] has %f instead of %d\n", rank, rcvd, rank);
103 int main(int argc, char **argv)
107 MPI_Init(&argc, &argv);
108 MPI_Comm_size(MPI_COMM_WORLD, &size);
109 MPI_Comm_rank(MPI_COMM_WORLD, &rank);
113 printf("** Small Test Result: ...\n");
114 if (!small_test(rank, size))
115 printf("\t[%d] failed.\n", rank);
117 printf("\t[%d] ok.\n", rank);
119 MPI_Barrier(MPI_COMM_WORLD);
123 printf("** IBM Test Result: ...\n");
124 if (!ibm_test(rank, size))
125 printf("\t[%d] failed.\n", rank);
127 printf("\t[%d] ok.\n", rank);