/**************************************************************************** * FILE: mpi_bandwidth.c * DESCRIPTION: * Provides point-to-point communications timings for any even * number of MPI tasks. * AUTHOR: Blaise Barney * LAST REVISED: 04/13/05 ****************************************************************************/ #include "mpi.h" #include #include #include #include #define MAXTASKS 8192 /* Change the next four parameters to suit your case */ #define STARTSIZE 100000 #define ENDSIZE 1000000 #define INCREMENT 100000 #define ROUNDTRIPS 100 int main (int argc, char *argv[]) { int numtasks, rank, n, i, j, rndtrps, nbytes, start, end, incr, src, dest, rc, tag=1, taskpairs[MAXTASKS], namelength; double thistime, bw, bestbw, worstbw, totalbw, avgbw, bestall, avgall, worstall, timings[MAXTASKS/2][3], tmptimes[3], resolution, t1, t2; char msgbuf[ENDSIZE], host[MPI_MAX_PROCESSOR_NAME], hostmap[MAXTASKS][MPI_MAX_PROCESSOR_NAME]; struct timeval tv1, tv2; MPI_Status status; /* Some initializations and error checking */ MPI_Init(&argc,&argv); MPI_Comm_size(MPI_COMM_WORLD, &numtasks); if (numtasks % 2 != 0) { printf("ERROR: Must be an even number of tasks! Quitting...\n"); MPI_Abort(MPI_COMM_WORLD, rc); exit(0); } MPI_Comm_rank(MPI_COMM_WORLD, &rank); start = STARTSIZE; end = ENDSIZE; incr = INCREMENT; rndtrps = ROUNDTRIPS; for (i=0; i= numtasks/2) dest = src = rank - numtasks/2; MPI_Gather(&dest, 1, MPI_INT, &taskpairs, 1, MPI_INT, 0, MPI_COMM_WORLD); if (rank == 0) { resolution = MPI_Wtick(); printf("\n******************** MPI Bandwidth Test ********************\n"); printf("Message start size= %d bytes\n",start); printf("Message finish size= %d bytes\n",end); printf("Incremented by %d bytes per iteration\n",incr); printf("Roundtrips per iteration= %d\n",rndtrps); printf("MPI_Wtick resolution = %e\n",resolution); printf("************************************************************\n"); for (i=0; i bestbw ) bestbw = bw; if (bw < worstbw ) worstbw = bw; } /* Convert to megabytes per second */ bestbw = bestbw/1000000.0; avgbw = (totalbw/1000000.0)/(double)rndtrps; worstbw = worstbw/1000000.0; /* Task 0 collects timings from all relevant tasks */ if (rank == 0) { /* Keep track of my own timings first */ timings[0][0] = bestbw; timings[0][1] = avgbw; timings[0][2] = worstbw; /* Initialize overall averages */ bestall = 0.0; avgall = 0.0; worstall = 0.0; /* Now receive timings from other tasks and print results. Note */ /* that this loop will be appropriately skipped if there are */ /* only two tasks. */ for (j=1; j= numtasks/2) { for (n=start; n<=end; n=n+incr) { for (i=1; i<=rndtrps; i++){ MPI_Recv(&msgbuf, n, MPI_CHAR, src, tag, MPI_COMM_WORLD, &status); MPI_Send(&msgbuf, n, MPI_CHAR, dest, tag, MPI_COMM_WORLD); } } } MPI_Finalize(); } /* end of main */