5 #if defined(NEEDS_STDLIB_PROTOTYPES)
9 int main( int argc, char **argv )
12 int count, dest, source, sendtag, recvtag, len, rc;
13 int rank, size, errcnt = 0;
17 MPI_Init( &argc, &argv );
19 MPI_Comm_dup( MPI_COMM_WORLD, &comm );
20 MPI_Errhandler_set( comm, MPI_ERRORS_RETURN );
22 MPI_Comm_rank( MPI_COMM_WORLD, &rank );
23 MPI_Comm_size( MPI_COMM_WORLD, &size );
24 /* Check recoverable errors */
26 rc = MPI_Sendrecv_replace( (char *)0, 1, MPI_INT, 0, 0,
27 0, 0, comm, &status );
30 fprintf( stderr, "Failed to detect null buffer\n" );
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 );
37 fprintf( stderr, "Failed to detect null datatype\n" );
42 /* Check non-contiguous datatypes */
43 MPI_Type_vector( 1, 1, 10, MPI_INT, &dtype );
44 MPI_Type_commit( &dtype );
46 buf = (int *)malloc( 10 * 10 * sizeof(int) );
47 dest = (rank + 1) % size;
48 source = (rank + size - 1) % size;
53 MPI_Sendrecv_replace( buf, count, dtype, dest,
54 sendtag, source, recvtag, MPI_COMM_WORLD, &status );
55 MPI_Get_count( &status, dtype, &len );
58 fprintf( stderr, "Computed %d for count, should be %d\n", len, 0 );
61 MPI_Type_free( &dtype );
62 MPI_Comm_free( &comm );
64 printf( "Completed test of MPI_Sendrecv_replace\n" );