9 #define MIN_MESSAGE_LENGTH 256
10 #define MAX_MESSAGE_LENGTH (16*1024*1024)
19 void Resetbuf( char *, int );
20 void Checkbuf( char *, int, MPI_Status * );
22 void Resetbuf( char *buf, int len )
29 void Checkbuf( char *buf, int len, MPI_Status *status )
35 MPI_Get_count( status, MPI_CHAR, &count );
37 fprintf( stderr, "Got len of %d but expected %d\n", count, len );
41 for (i=0; i<len; i++) {
45 "Found wrong value in buffer[%d] = %d, expected %d\n",
51 if (err) MPI_Abort( MPI_COMM_WORLD, 1 );
54 int main( int argc, char *argv[] )
57 int msglen_min = MIN_MESSAGE_LENGTH;
58 int msglen_max = MAX_MESSAGE_LENGTH;
59 int rank,poolsize,Master;
60 char *sendbuf,*recvbuf;
65 MPI_Init(&argc,&argv);
66 MPI_Comm_size(MPI_COMM_WORLD,&poolsize);
67 MPI_Comm_rank(MPI_COMM_WORLD,&rank);
70 printf("Expected exactly 2 MPI processes\n");
71 MPI_Abort( MPI_COMM_WORLD, 1 );
75 The following test allows this test to run on small-memory systems
76 that support the sysconf call interface. This test keeps the test from
77 becoming swap-bound. For example, on an old Linux system or a
78 Sony Playstation 2 (really!)
80 #if defined(HAVE_SYSCONF) && defined(_SC_PHYS_PAGES) && defined(_SC_PAGESIZE)
82 long n_pages, pagesize;
84 n_pages = sysconf( _SC_PHYS_PAGES );
85 pagesize = sysconf( _SC_PAGESIZE );
86 /* We want to avoid integer overflow in the size calculation.
87 The best way is to avoid computing any products (such
88 as total memory = n_pages * pagesize) and instead
89 compute a msglen_max that fits within 1/4 of the available
91 if (n_pages > 0 && pagesize > 0) {
92 /* Recompute msglen_max */
93 int msgpages = 4 * ((msglen_max + pagesize - 1)/ pagesize);
94 while (n_pages < msgpages) { msglen_max /= 2; msgpages /= 2; }
96 /* printf ( "before = %d\n", msglen_max ); */
97 MPI_Allreduce( &msglen_max, &actmsglen_max, 1, MPI_INT,
98 MPI_MIN, MPI_COMM_WORLD );
99 msglen_max = actmsglen_max;
100 /* printf ( "after = %d\n", msglen_max ); */
104 Master = (rank == 0);
106 if(Master && verbose)
107 printf("Size (bytes)\n------------\n");
108 for(msglen = msglen_min; msglen <= msglen_max; msglen *= 2) {
110 sendbuf = malloc(msglen);
111 recvbuf = malloc(msglen);
112 if(sendbuf == NULL || recvbuf == NULL) {
113 printf("Can't allocate %d bytes\n",msglen);
114 MPI_Abort( MPI_COMM_WORLD, 1 );
118 for (i=0; i<msglen; i++) {
124 if(Master && verbose)
125 printf("%d\n",msglen);
128 MPI_Barrier(MPI_COMM_WORLD);
132 MPI_Send(sendbuf,msglen,MPI_CHAR,1,TAG1,MPI_COMM_WORLD);
134 Resetbuf( recvbuf, msglen );
135 MPI_Recv(recvbuf,msglen,MPI_CHAR,0,TAG1,MPI_COMM_WORLD,&status);
136 Checkbuf( recvbuf, msglen, &status );
139 MPI_Barrier(MPI_COMM_WORLD);
143 MPI_Send(sendbuf,msglen,MPI_CHAR,1,TAG2,MPI_COMM_WORLD);
145 Resetbuf( recvbuf, msglen );
146 MPI_Recv(recvbuf,msglen,MPI_CHAR,0,TAG2,MPI_COMM_WORLD,&status);
147 Checkbuf( recvbuf, msglen, &status );
150 MPI_Barrier(MPI_COMM_WORLD);
154 /* MPI_Sendrecv( MPI_BOTTOM, 0, MPI_INT, 1, TAGSR,*/
155 /* MPI_BOTTOM, 0, MPI_INT, 1, TAGSR,*/
156 /* MPI_COMM_WORLD, &status );*/
157 /* MPI_Rsend( sendbuf,msglen,MPI_CHAR,1,TAG3,MPI_COMM_WORLD );*/
160 /* Resetbuf( recvbuf, msglen );*/
161 /* MPI_Irecv( recvbuf,msglen,MPI_CHAR,0,TAG3,MPI_COMM_WORLD,&request);*/
162 /* MPI_Sendrecv( MPI_BOTTOM, 0, MPI_INT, 0, TAGSR,*/
163 /* MPI_BOTTOM, 0, MPI_INT, 0, TAGSR,*/
164 /* MPI_COMM_WORLD, &status );*/
165 /* MPI_Wait( &request, &status );*/
166 /* Checkbuf( recvbuf, msglen, &status );*/
169 /* MPI_Barrier(MPI_COMM_WORLD);*/
171 /* Isend/Recv - receive not ready */
173 MPI_Sendrecv( MPI_BOTTOM, 0, MPI_INT, 1, TAGSR,
174 MPI_BOTTOM, 0, MPI_INT, 1, TAGSR,
175 MPI_COMM_WORLD, &status );
176 MPI_Isend(sendbuf,msglen,MPI_CHAR,1,TAG4,MPI_COMM_WORLD, &request);
177 MPI_Wait( &request, &status );
180 Resetbuf( recvbuf, msglen );
181 MPI_Sendrecv( MPI_BOTTOM, 0, MPI_INT, 0, TAGSR,
182 MPI_BOTTOM, 0, MPI_INT, 0, TAGSR,
183 MPI_COMM_WORLD, &status );
184 MPI_Recv(recvbuf,msglen,MPI_CHAR,0,TAG4,MPI_COMM_WORLD,&status);
185 Checkbuf( recvbuf, msglen, &status );
188 MPI_Barrier(MPI_COMM_WORLD);
195 /* If we do not abort, we saw no errors */
196 printf( " No Errors\n" );