/* cc -o crisscross crisscross.c -lmpi */ #include #include #include "mpi.h" #include #include #include #define MAX_RR_NAME 7 int main(int argc, char *argv[]) { MPI_Status status; /* MPI status */ int mpierr; /* MPI function return code */ int rank; /* Process rank within MPI_COMM_WORLD */ int nproc; /* Total number of MPI processes */ int tag0=41; /* MPI message tag */ int tag1=42; /* MPI message tag */ int tag2=43; /* MPI message tag */ int warmup=1; /* MPI warmup loops */ char process_name[MPI_MAX_PROCESSOR_NAME + 1]; char partner_name[MPI_MAX_PROCESSOR_NAME + 1]; char rr_blank[] = {" "}; char rr_empty[] = {"???????"}; int n_bytes=128*1024*1024; int n_loops=2; unsigned char* send_buff; unsigned char* recv_buff; int i,j,k,m,count,mismatch; double et1,et2,mbs; double avg_mbs=0, sum_avg_mbs=0; int xfers=0, sum_xfers=0; double max_mbs=-1.0,min_mbs=999999.9; double r_max_mbs,r_min_mbs; time_t curtime; struct tm *loctime; if ( argc > 2 ) { n_loops = atoi(argv[2]); n_loops = n_loops < 1 ? 10 : n_loops; } if ( argc > 1 ) { n_bytes = atoi(argv[1]); n_bytes = n_bytes < 1 ? 32768 : n_bytes; } send_buff = (unsigned char *) valloc(n_bytes); recv_buff = (unsigned char *) valloc(n_bytes); for ( i=0; i %s [4%d]\n",mpierr,process_name,i,partner_name,j); fflush(stderr); MPI_Abort(MPI_COMM_WORLD, -1); } } if ( rank == j ) { mpierr = MPI_Recv(recv_buff, n_bytes, MPI_BYTE, i, tag1, MPI_COMM_WORLD, &status); if (mpierr != MPI_SUCCESS) { fprintf(stderr,"MPI Error %d (MPI_Recv) %s [4%d] <-- %s [4%d]\n",mpierr,process_name,j,partner_name,i); fflush(stderr); MPI_Abort(MPI_COMM_WORLD, -1); } if (k == n_loops+warmup-1) et2 = MPI_Wtime(); } } if ( rank == i ) { mpierr = MPI_Send(&et1, 1, MPI_DOUBLE, j, tag1, MPI_COMM_WORLD); if (mpierr != MPI_SUCCESS) { fprintf(stderr,"MPI Error %d (MPI_Send) %s [4%d] --> %s [4%d]\n",mpierr,process_name,i,partner_name,j); fflush(stderr); MPI_Abort(MPI_COMM_WORLD, -1); } } if ( rank == j ) { mpierr = MPI_Recv(&et1, 1, MPI_DOUBLE, i, tag1, MPI_COMM_WORLD, &status); if (mpierr != MPI_SUCCESS) { fprintf(stderr,"MPI Error %d (MPI_Recv) %s [4%d] <-- %s [4%d]\n",mpierr,process_name,j,partner_name,i); fflush(stderr); MPI_Abort(MPI_COMM_WORLD, -1); } mbs = ((double)n_loops*n_bytes)/(1000000.0*(et2-et1)); if (mbs < 50.0) { printf(" %s [%4d] =====>> %s [%4d] %9.1f mbs SLOW!\n",partner_name,i,process_name,j,mbs); } else { printf(" %s [%4d] =====>> %s [%4d] %9.1f mbs\n",partner_name,i,process_name,j,mbs); } min_mbs = (mbs < min_mbs) ? mbs:min_mbs; max_mbs = (mbs > max_mbs) ? mbs:max_mbs; avg_mbs += mbs; xfers++; mismatch = 0; for ( k=0; k