Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Rewrite of the fat trees implementation
[simgrid.git] / teshsuite / smpi / allreduce.c
1 /* Copyright (c) 2012, 2014. The SimGrid Team.
2  * All rights reserved.                                                     */
3
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. */
6
7 #include <stdio.h>
8 #include <mpi.h>
9
10 /**
11  * MESSAGE PASSING INTERFACE TEST CASE SUITE
12  *
13  * Copyright IBM Corp. 1995
14  * 
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.
18
19  * IBM Corp. makes no representation that the test cases comprising this
20  * suite are correct or are an accurate representation of any standard.
21
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.
25
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  * ***************************************************************************
32  **/
33 static int ibm_test(int rank, int size)
34 {
35   int success = 1;
36 #define MAXLEN  10000
37
38   int root = 0, i, j, k;
39   int out[MAXLEN];
40   int in[MAXLEN];
41
42   for (j = 1; j <= MAXLEN; j *= 10) {
43     for (i = 0; i < j; i++)
44       out[i] = i;
45
46     MPI_Allreduce(out, in, j, MPI_INT, MPI_SUM, MPI_COMM_WORLD);
47     MPI_Barrier(MPI_COMM_WORLD);
48
49     if (rank == root) {
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],
53                  k, j, k * size);
54           success = 0;
55           break;
56         }
57       }
58     }
59   }
60   return (success);
61 }
62
63
64
65
66 int main(int argc, char **argv)
67 {
68   int size, rank;
69
70
71   MPI_Init(&argc, &argv);
72   MPI_Comm_size(MPI_COMM_WORLD, &size);
73   MPI_Comm_rank(MPI_COMM_WORLD, &rank);
74
75
76   if (0 == rank)
77     printf("** IBM Test Result: ... \n");
78   if (!ibm_test(rank, size))
79     printf("\t[%d] failed.\n", rank);
80   else
81     printf("\t[%d] ok.\n", rank);
82
83   MPI_Finalize();
84   return 0;
85 }