Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Merge branch 'v3_8_x'
[simgrid.git] / teshsuite / smpi / mpich-test / pt2pt / sndrcvrep.c
1 #include "mpi.h"
2 #include <stdio.h>
3 #include <stdlib.h>
4
5 #if defined(NEEDS_STDLIB_PROTOTYPES)
6 #include "protofix.h"
7 #endif
8
9 int main( int argc, char **argv )
10 {
11     MPI_Status   status;
12     int          count, dest, source, sendtag, recvtag, len, rc;
13     int          rank, size, errcnt = 0;
14     MPI_Comm     comm;
15     int          *buf;
16     MPI_Datatype dtype;
17     MPI_Init( &argc, &argv );
18
19     MPI_Comm_dup( MPI_COMM_WORLD, &comm );
20     MPI_Errhandler_set( comm, MPI_ERRORS_RETURN );
21
22     MPI_Comm_rank( MPI_COMM_WORLD, &rank );
23     MPI_Comm_size( MPI_COMM_WORLD, &size );
24     /* Check recoverable errors */
25     if (rank == 0) {
26         rc = MPI_Sendrecv_replace( (char *)0, 1, MPI_INT, 0, 0,
27                                    0, 0, comm, &status );
28         if (!rc) {
29             errcnt++;
30             fprintf( stderr, "Failed to detect null buffer\n" );
31         }
32         buf = 0; /* Give buf a value before use */
33         rc = MPI_Sendrecv_replace( buf, 1, MPI_DATATYPE_NULL, 0,
34                                    0, 0, 0, comm, &status );
35         if (!rc) {
36             errcnt++;
37             fprintf( stderr, "Failed to detect null datatype\n" );
38         }
39         /* Could be others */
40     }
41
42     /* Check non-contiguous datatypes */
43     MPI_Type_vector( 1, 1, 10, MPI_INT, &dtype );
44     MPI_Type_commit( &dtype );
45
46     buf    = (int *)malloc( 10 * 10 * sizeof(int) );
47     dest   = (rank + 1) % size;
48     source = (rank + size - 1) % size;
49
50     count   = 0;
51     sendtag = 1;
52     recvtag = 1;
53     MPI_Sendrecv_replace( buf, count, dtype, dest, 
54                           sendtag, source, recvtag, MPI_COMM_WORLD, &status );
55     MPI_Get_count( &status, dtype, &len );
56     if (len != 0) {
57         errcnt ++;
58         fprintf( stderr, "Computed %d for count, should be %d\n", len, 0 );
59     }
60     
61     MPI_Type_free( &dtype );
62     MPI_Comm_free( &comm );
63     if (rank == 0) {
64         printf( "Completed test of MPI_Sendrecv_replace\n" );
65     }
66     MPI_Finalize();
67     return 0;
68 }