2 third - test program that tests queueing by sending messages with various
3 tags, receiving them in particular order.
16 void sleep( int secs )
19 /* Also needs include <time.h>? */
20 struct timespec rqtp = { 10, 0 };
21 nanosleep(&rqtp, NULL);
25 while (MPI_Wtime() - t < (double)secs) ;
30 /* Define VERBOSE to get printed output */
31 int main( int argc, char **argv )
33 int rank, size, to, from, tag, count;
34 int src, dest, waiter;
37 int st_source, st_tag;
42 MPI_Status statuses[2];
44 MPI_Init( &argc, &argv );
45 MPI_Comm_rank( MPI_COMM_WORLD, &rank );
46 MPI_Comm_size( MPI_COMM_WORLD, &size );
53 /* waiter = dest; */ /* Receiver delays, so msgs unexpected */
54 /* waiter = src; */ /* Sender delays, so recvs posted */
55 waiter = 10000; /* nobody waits */
63 sprintf(data,"First message, type 2001");
64 count = strlen(data) + 1;
65 MPI_Isend( data, count, MPI_CHAR, to, tag, MPI_COMM_WORLD, &rq[0] );
67 printf("%d sent :%s:\n", rank, data );
70 sprintf(data,"Second message, type 2002");
71 count = strlen(data) + 1;
72 MPI_Isend( data, count, MPI_CHAR, to, tag, MPI_COMM_WORLD, &rq[1] );
73 MPI_Waitall( 2, rq, statuses );
75 printf("%d sent :%s:\n", rank, data );
83 from = MPI_ANY_SOURCE;
87 MPI_Recv(data, count, MPI_CHAR, from, tag, MPI_COMM_WORLD, &status );
89 MPI_Get_count( &status, MPI_CHAR, &st_count );
90 if (st_count != strlen("Second message, type 2002") + 1) {
91 printf( "Received wrong length!\n" );
94 st_source = status.MPI_SOURCE;
95 st_tag = status.MPI_TAG;
96 printf( "Status info: source = %d, tag = %d, count = %d\n",
97 st_source, st_tag, st_count );
98 printf( "%d received :%s:\n", rank, data);
101 MPI_Recv(data, count, MPI_CHAR, from, tag, MPI_COMM_WORLD, &status );
103 MPI_Get_count( &status, MPI_CHAR, &st_count );
104 if (st_count != strlen("First message, type 2001") + 1) {
105 printf( "Received wrong length!\n" );
108 st_source = status.MPI_SOURCE;
109 st_tag = status.MPI_TAG;\
110 printf( "Status info: source = %d, tag = %d, count = %d\n",
111 st_source, st_tag, st_count );
112 printf( "%d received :%s:\n", rank, data);
116 printf( "Process %d exiting\n", rank );