Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Add mpich3 test suite, to replace older one.
[simgrid.git] / teshsuite / smpi / mpich-test / coll / coll11.c
1 #include "mpi.h"
2 #include <stdio.h>
3 #include "test.h"
4
5 void addem ( int *, int *, int *, MPI_Datatype * );
6 void assoc ( int *, int *, int *, MPI_Datatype * );
7
8 void addem(invec, inoutvec, len, dtype)
9 int *invec, *inoutvec, *len;
10 MPI_Datatype *dtype;
11 {
12   int i;
13   for ( i=0; i<*len; i++ ) 
14     inoutvec[i] += invec[i];
15 }
16
17 #define BAD_ANSWER 100000
18
19 /*
20     The operation is inoutvec[i] = invec[i] op inoutvec[i] 
21     (see 4.9.4).  The order is important.
22
23     Note that the computation is in process rank (in the communicator)
24     order, independant of the root.
25  */
26 void assoc(invec, inoutvec, len, dtype)
27 int *invec, *inoutvec, *len;
28 MPI_Datatype *dtype;
29 {
30   int i;
31   for ( i=0; i<*len; i++ )  {
32     if (inoutvec[i] <= invec[i] ) {
33       int rank;
34       MPI_Comm_rank( MPI_COMM_WORLD, &rank );
35       fprintf( stderr, "[%d] inout[0] = %d, in[0] = %d\n", 
36               rank, inoutvec[0], invec[0] );
37       inoutvec[i] = BAD_ANSWER;
38       }
39     else 
40       inoutvec[i] = invec[i];
41   }
42 }
43
44 int main( int argc, char **argv )
45 {
46     int              rank, size, i;
47     int              data;
48     int              errors=0;
49     int              result = -100;
50     int              correct_result;
51     MPI_Op           op_assoc, op_addem;
52
53     MPI_Init( &argc, &argv );
54     MPI_Comm_rank( MPI_COMM_WORLD, &rank );
55     MPI_Comm_size( MPI_COMM_WORLD, &size );
56
57     data = rank;
58
59     correct_result = 0;
60     for (i=0;i<=rank;i++)
61       correct_result += i;
62
63     MPI_Scan ( &data, &result, 1, MPI_INT, MPI_SUM, MPI_COMM_WORLD );
64     if (result != correct_result) {
65         fprintf( stderr, "[%d] Error suming ints with scan\n", rank );
66         errors++;
67         }
68
69     MPI_Scan ( &data, &result, 1, MPI_INT, MPI_SUM, MPI_COMM_WORLD );
70     if (result != correct_result) {
71         fprintf( stderr, "[%d] Error summing ints with scan (2)\n", rank );
72         errors++;
73         }
74
75     data = rank;
76     result = -100;
77     MPI_Op_create( (MPI_User_function *)assoc, 0, &op_assoc );
78     MPI_Op_create( (MPI_User_function *)addem, 1, &op_addem );
79     MPI_Scan ( &data, &result, 1, MPI_INT, op_addem, MPI_COMM_WORLD );
80     if (result != correct_result) {
81         fprintf( stderr, "[%d] Error summing ints with scan (userop)\n", 
82                  rank );
83         errors++;
84         }
85
86     MPI_Scan ( &data, &result, 1, MPI_INT, op_addem, MPI_COMM_WORLD );
87     if (result != correct_result) {
88         fprintf( stderr, "[%d] Error summing ints with scan (userop2)\n", 
89                  rank );
90         errors++;
91         }
92     /*result = -100;
93     data = rank;
94     MPI_Scan ( &data, &result, 1, MPI_INT, op_assoc, MPI_COMM_WORLD );
95     if (result == BAD_ANSWER) {
96         fprintf( stderr, "[%d] Error scanning with non-commutative op\n",
97                  rank );
98         errors++;
99         }*/
100
101     MPI_Op_free( &op_assoc );
102     MPI_Op_free( &op_addem );
103
104     if (errors)
105       printf( "[%d] done with ERRORS(%d)!\n", rank, errors );
106
107     Test_Waitforall( );
108     MPI_Finalize();
109     return errors;
110 }