5 void addem ( int *, int *, int *, MPI_Datatype * );
6 void assoc ( int *, int *, int *, MPI_Datatype * );
8 void addem(invec, inoutvec, len, dtype)
9 int *invec, *inoutvec, *len;
13 for ( i=0; i<*len; i++ )
14 inoutvec[i] += invec[i];
17 #define BAD_ANSWER 100000
20 The operation is inoutvec[i] = invec[i] op inoutvec[i]
21 (see 4.9.4). The order is important.
23 Note that the computation is in process rank (in the communicator)
24 order, independant of the root.
26 void assoc(invec, inoutvec, len, dtype)
27 int *invec, *inoutvec, *len;
31 for ( i=0; i<*len; i++ ) {
32 if (inoutvec[i] <= invec[i] ) {
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;
40 inoutvec[i] = invec[i];
44 int main( int argc, char **argv )
51 MPI_Op op_assoc, op_addem;
53 MPI_Init( &argc, &argv );
54 MPI_Comm_rank( MPI_COMM_WORLD, &rank );
55 MPI_Comm_size( MPI_COMM_WORLD, &size );
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 );
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 );
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",
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",
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",
101 MPI_Op_free( &op_assoc );
102 MPI_Op_free( &op_addem );
105 printf( "[%d] done with ERRORS(%d)!\n", rank, errors );