HP-MPI User's Guide (11th Edition)
Example applications
ping_pong.c
Appendix A 227
#ifdef CHECK
for (j = 0; j < nbytes; j++) {
if (buf[j] != (char) (j + i)) {
printf("error: buf[%d] = %d, not
%d\n",j,
buf[j], j + i);
break;
}
}
#endif
}
stop = MPI_Wtime();
printf("%d bytes: %.2f usec/msg\n",
nbytes, (stop - start) / NLOOPS / 2 *
1000000);
if (nbytes > 0) {
printf("%d bytes: %.2f MB/sec\n",
nbytes,nbytes / 1000000./
((stop - start) / NLOOPS /
2));
}
}
else {
/*
* warm-up loop
*/
for (i = 0; i < 5; i++) {
MPI_Recv(buf, nbytes, MPI_CHAR,0, 1,
MPI_COMM_WORLD, &status);
MPI_Send(buf, nbytes, MPI_CHAR, 0, 1,
MPI_COMM_WORLD);
}
for (i = 0; i < NLOOPS; i++) {
MPI_Recv(buf, nbytes, MPI_CHAR,0, 1000 + i,
MPI_COMM_WORLD,&status);
MPI_Send(buf, nbytes, MPI_CHAR,0, 2000 + i,
MPI_COMM_WORLD);
}
}
MPI_Finalize();
exit(0);
}
ping_pong output
The output from running the ping_pong executable is shown below. The
application was run with -np2.