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 / coll13.c
1 #include "mpi.h"
2 #include "test.h"
3
4 /* 
5 From: hook@nas.nasa.gov (Edward C. Hook)
6  */
7
8 #include <stdlib.h>
9 #include <stdio.h>
10
11 #include <string.h>
12 #include <errno.h>
13 #ifndef EXIT_SUCCESS
14 #define EXIT_SUCCESS 0
15 #define EXIT_FAILURE 1
16 #endif
17
18 int main( int argc, char *argv[] )
19 {
20     int rank, size;
21     int i,j;
22     int *sb;
23     int *rb;
24     int status, gstatus, endstatus;
25     endstatus=0;
26     MPI_Init(&argc,&argv);
27     MPI_Comm_rank(MPI_COMM_WORLD,&rank);
28     MPI_Comm_size(MPI_COMM_WORLD,&size);
29
30     for ( i=1 ; i < argc ; ++i ) {
31         if ( argv[i][0] != '-' )
32             continue;
33         switch(argv[i][1]) {
34         default:
35             fprintf(stderr,"Unrecognized argument %s\n",
36                     argv[i]);
37             MPI_Abort(MPI_COMM_WORLD,EXIT_FAILURE);
38         }
39     }
40      
41     
42     /*
43     SMPI addition: we want to test all three alltoall algorithms, thus we use
44     three different sizes.  This is the code that handles these cases:
45
46     if (sendsize < 200 && size > 12) {
47       retval =
48           smpi_coll_tuned_alltoall_bruck(sendbuf, sendcount, sendtype,
49                                          recvbuf, recvcount, recvtype,
50                                          comm);
51     } else if (sendsize < 3000) {
52       retval =
53           smpi_coll_tuned_alltoall_basic_linear(sendbuf, sendcount,
54                                                 sendtype, recvbuf,
55                                                 recvcount, recvtype, comm);
56     } else {
57       retval =
58           smpi_coll_tuned_alltoall_pairwise(sendbuf, sendcount, sendtype,
59                                             recvbuf, recvcount, recvtype,
60                                             comm);
61     }
62     */
63     
64     
65     int sizes [3] ={ 4096, 64, 32};
66     for ( j=0 ; j < 3 ; j++ ) {
67       sb = (int *)malloc(size*sizes[j]*sizeof(int));
68       if ( !sb ) {
69         perror( "can't allocate send buffer" );
70         MPI_Abort(MPI_COMM_WORLD,EXIT_FAILURE);
71       }
72       rb = (int *)malloc(size*sizes[j]*sizeof(int));
73       if ( !rb ) {
74         perror( "can't allocate recv buffer");
75         free(sb);
76         MPI_Abort(MPI_COMM_WORLD,EXIT_FAILURE);
77       }
78       for ( i=0 ; i < size*sizes[j] ; ++i ) {
79         sb[i] = rank + 1;
80         rb[i] = 0;
81       }
82
83       /* fputs("Before MPI_Alltoall\n",stdout); */
84       MPI_Barrier(MPI_COMM_WORLD );
85       /* This should really send MPI_CHAR, but since sb and rb were allocated
86        as chunk*size*sizeof(int), the buffers are large enough */
87       status = MPI_Alltoall(sb,sizes[j],MPI_INT,rb,sizes[j],MPI_INT,
88                             MPI_COMM_WORLD);
89
90       /* fputs("Before MPI_Allreduce\n",stdout); */
91       MPI_Allreduce( &status, &gstatus, 1, MPI_INT, MPI_SUM, 
92                     MPI_COMM_WORLD );
93
94       MPI_Barrier(MPI_COMM_WORLD );
95     /* fputs("After MPI_Allreduce\n",stdout); */
96       if (rank == 0 && gstatus != 0) endstatus ++;
97
98       free(sb);
99       free(rb);
100     }
101     
102     if (rank == 0) {
103       if (endstatus == 0) printf( " No Errors\n" );
104       else 
105         printf("all_to_all returned %d erros\n",endstatus);
106     }
107     MPI_Finalize();
108
109     return(EXIT_SUCCESS);
110 }
111