Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
first commit to add the mpich-test suite to smpi tesh suite. Obviously all tests...
[simgrid.git] / teshsuite / smpi / mpich-test / profile / colluses.c
1 /*
2  * This file checks to see if the collective routine MPI_Allreduce uses
3  * MPI_Send or MPI_Isend to implement the operation.  It should use either
4  * a PMPI routine or a non-MPI routine.  
5  */
6
7 #include "mpi.h"
8 #include <stdio.h>
9
10 static int used_send = 0,
11            used_isend = 0,
12            used_sendrecv = 0;
13 int main( int argc, char *argv[] )
14 {
15     int in, out;
16     int rank;
17     int in_sends[3], out_sends[3];
18
19     MPI_Init( &argc, &argv );
20     
21     MPI_Comm_rank( MPI_COMM_WORLD, &rank );
22     in = 1;
23     MPI_Allreduce( &in, &out, 1, MPI_INT, MPI_SUM, MPI_COMM_WORLD );
24
25     /* Now, see whether MPI routines were used */
26     in_sends[0] = used_send;
27     in_sends[1] = used_isend;
28     in_sends[2] = used_sendrecv;
29     MPI_Reduce( in_sends, out_sends, 3, MPI_INT, MPI_SUM, 0, MPI_COMM_WORLD );
30     if (rank == 0) {
31         int errs = 0;
32         if (in_sends[0] > 0) {
33             printf( " Allreduce used MPI_SEND (%d)\n", in_sends[0] );
34             errs++;
35         }
36         if (in_sends[1] > 0) {
37             printf( " Allreduce used MPI_ISEND (%d)\n", in_sends[1] );
38             errs++;
39         }
40         if (in_sends[2] > 0) {
41             printf( " Allreduce used MPI_SENDRECV (%d)\n", in_sends[2] );
42             errs++;
43         }
44         if (!errs) {
45             printf( " No Errors\n" );
46         }
47     }
48
49     MPI_Finalize( );
50     return 0;
51 }
52
53 /* 
54  * Replacements for MPI_Send, Isend, and Sendrecv that detect their use
55  */
56
57 int MPI_Send( void *buf, int count, MPI_Datatype datatype, int dest, 
58               int tag, MPI_Comm comm )
59 {
60     used_send++;
61     return PMPI_Send( buf, count, datatype, dest, tag, comm );
62 }
63
64 int MPI_Sendrecv( void *sendbuf, int sendcount, MPI_Datatype sendtype, 
65                   int dest, int sendtag, 
66                   void *recvbuf, int recvcount, MPI_Datatype recvtype, 
67                   int source, int recvtag, MPI_Comm comm, MPI_Status *status )
68 {
69     used_sendrecv++;
70     return PMPI_Sendrecv( sendbuf, sendcount, sendtype, dest, sendtag, 
71                           recvbuf, recvcount, recvtype, source, recvtag, 
72                           comm, status ); 
73 }
74
75 int MPI_Isend( void *buf, int count, MPI_Datatype datatype, int dest, int tag,
76                MPI_Comm comm, MPI_Request *request )
77 {
78     used_isend++;
79     return PMPI_Isend( buf, count, datatype, dest, tag, comm, request );
80 }
81