HP-MPI User's Guide (11th Edition)
Example applications
ping_pong.c
Appendix A 225
ping_pong.c
This C example is used as a performance benchmark to measure the
amount of time it takes to send and receive data between two processes.
The buffers are aligned and offset from each other to avoid cache
conflicts caused by direct process-to-process byte-copy operations
To run this example:
• Define the CHECK macro to check data integrity.
• Increase the number of bytes to at least twice the cache size to obtain
representative bandwidth measurements.
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <mpi.h>
#define NLOOPS 1000
#define ALIGN 4096
main(argc, argv)
int argc;
char *argv[];
{
int i, j;
double start, stop;
int nbytes = 0;
int rank, size;
MPI_Status status;
char *buf;
MPI_Init(&argc, &argv);
MPI_Comm_rank(MPI_COMM_WORLD, &rank);
MPI_Comm_size(MPI_COMM_WORLD, &size);
if (size != 2) {
if ( ! rank) printf("ping_pong: must have two
processes\n");
MPI_Finalize();
exit(0);
}
nbytes = (argc > 1) ? atoi(argv[1]) : 0;
if (nbytes < 0) nbytes = 0;
/*