Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Merge branch 'v3_8_x'
[simgrid.git] / teshsuite / smpi / mpich-test / pt2pt / reqcreate.c
1 #include <stdio.h>
2 #include "mpi.h"
3 #include <stdlib.h>
4 #include "test.h"
5
6 /* Test request creation */
7
8 int main( int argc, char **argv )
9 {
10     int i, n, n_goal = 2048, rc, len, buf[1];
11     MPI_Request *req_array;
12     MPI_Status status;
13     char msg[MPI_MAX_ERROR_STRING];
14
15     MPI_Init( &argc, &argv );
16     MPI_Errhandler_set( MPI_COMM_WORLD, MPI_ERRORS_RETURN );
17
18     n = n_goal;
19
20     req_array = (MPI_Request *)malloc( n * sizeof(MPI_Request) );
21     
22     for (i=0; i<n; i++) {
23         rc = MPI_Irecv( buf, 1, MPI_INT, 0, i, MPI_COMM_WORLD, req_array + i );
24         if (rc) {
25             fprintf( stderr, "Error when creating request number %d\n", i );
26             MPI_Error_string( rc, msg, &len );
27             fprintf( stderr, "%s\n", msg );
28             n = i + 1;
29             break;
30         }
31     }
32     for (i=0; i<n; i++) {
33         rc = MPI_Cancel( req_array + i );
34         if (rc) {
35             fprintf( stderr, "Error when canceling request number %d\n", i );
36             MPI_Error_string( rc, msg, &len );
37             fprintf( stderr, "%s\n", msg );
38             n = i + 1;
39             break;
40         }
41         rc = MPI_Request_free( req_array + i );
42         if (rc) {
43             fprintf( stderr, "Error when freeing request number %d\n", i );
44             MPI_Error_string( rc, msg, &len );
45             fprintf( stderr, "%s\n", msg );
46             n = i + 1;
47             break;
48         }
49     }
50
51     printf( "Completed test of %d request creations (with cancel)\n", n );
52
53     for (i=0; i<n; i++) {
54         rc = MPI_Irecv( buf, 1, MPI_INT, MPI_PROC_NULL, i, MPI_COMM_WORLD, 
55                         req_array + i );
56         if (rc) {
57             fprintf( stderr, "Error when creating request number %d\n", i );
58             MPI_Error_string( rc, msg, &len );
59             fprintf( stderr, "%s\n", msg );
60             n = i + 1;
61             break;
62         }
63     }
64     for (i=0; i<n; i++) {
65         rc = MPI_Wait( req_array + i, &status );
66         if (rc) {
67             fprintf( stderr, "Error when waiting on request number %d\n", i );
68             MPI_Error_string( rc, msg, &len );
69             fprintf( stderr, "%s\n", msg );
70             n = i + 1;
71             break;
72         }
73     }
74
75     printf( "Completed test of %d request creations (with wait)\n", n );
76     if (n != n_goal) {
77         printf (
78 "This MPI implementation limits the number of request that can be created\n\
79 This is allowed by the standard and is not a bug, but is a limit on the\n\
80 implementation\n" );
81     }
82     free( req_array );
83     MPI_Finalize( );
84     return 0;
85 }