6 #if defined(NEEDS_STDLIB_PROTOTYPES)
11 Test to make sure that nonblocking routines actually work
12 In this example, we assume that we do not know the message
15 Just like nblock, but with the probe test.
18 int main( int argc, char **argv )
20 int count, tag, nsend, myid, np, rcnt, scnt, i, j, *send_buf;
24 MPI_Status status, rtn_status;
25 MPI_Request *rsend, *rrecv;
27 MPI_Init( &argc, &argv );
28 MPI_Comm_rank( MPI_COMM_WORLD, &myid );
29 MPI_Comm_size( MPI_COMM_WORLD, &np );
31 MPE_Errors_call_dbx_in_xterm( (argv)[0], (char *)0 );
32 MPE_Signals_call_debugger();
34 if (argc > 2 && argv[1] && strcmp( argv[1], "-first" ) == 0)
35 baselen = atoi(argv[2]);
39 rsend = (MPI_Request *) malloc ( nsend * sizeof(MPI_Request) );
40 rrecv = (MPI_Request *) malloc ( nsend * sizeof(MPI_Request) );
41 recv_buf = (int **) malloc ( nsend * sizeof(int *) );
42 if (!rsend || !rrecv) {
43 fprintf( stderr, "Failed to allocate space for requests\n" );
44 MPI_Abort( MPI_COMM_WORLD, 1 );
47 for (count = baselen; count < 10000; count *= 2) {
48 /* We'll send/recv from everyone */
53 send_buf = (int *)malloc( count * sizeof(int) );
56 for (i=0; i<np; i++) {
58 MPI_Isend( send_buf, count, MPI_INT, i, tag,
59 MPI_COMM_WORLD, &rsend[scnt++] );
61 /* Check sends, one could free memory here if they are done */
62 for (i=0; i<scnt; i++) {
63 MPI_Test( &rsend[i], &finished, &status );
70 for (i=0; i<np; i++) {
72 MPI_Probe(MPI_ANY_SOURCE,tag,MPI_COMM_WORLD,&status);
73 MPI_Get_count(&status,MPI_INT,&length);
74 /* printf("[%d] length = %d\n",myid,length);
76 recv_buf[rcnt] = (int *)malloc(length * sizeof(int));
77 MPI_Recv(recv_buf[rcnt],length,MPI_INT,status.MPI_SOURCE,
78 status.MPI_TAG,MPI_COMM_WORLD,&rtn_status);
85 for (i=0; i<scnt; i++) {
86 MPI_Wait( &rsend[i], &status );
90 for (i=0; i<rcnt; i++) free(recv_buf[i]);
93 MPI_Barrier( MPI_COMM_WORLD );
94 if (myid == 0 && (count % 64) == 0) {
95 printf( "All processes completed for count = %ld ints of data\n",
96 (long)count ); fflush(stdout);