#define BENCHMARK "OSU MPI Bi-Directional Bandwidth Test" /* * Copyright (C) 2002-2010 the Network-Based Computing Laboratory * (NBCL), The Ohio State University. * * Contact: Dr. D. K. Panda (panda@cse.ohio-state.edu) */ /* This program is available under BSD licensing. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: (1) Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. (2) Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. (3) Neither the name of The Ohio State University nor the names of their contributors may be used to endorse or promote products derived from this software without specific prior written permission. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ #include "osu.h" #include #define MAX_REQ_NUM 1000 #define MAX_ALIGNMENT 65536 #define MAX_MSG_SIZE (1<<22) #define MYBUFSIZE (MAX_MSG_SIZE + MAX_ALIGNMENT) int loop = 100; int window_size = 64; int skip = 10; int loop_large = 20; int window_size_large = 64; int skip_large = 2; int large_message_size = 8192; char s_buf1[MYBUFSIZE]; char r_buf1[MYBUFSIZE]; MPI_Request send_request[MAX_REQ_NUM]; MPI_Request recv_request[MAX_REQ_NUM]; MPI_Status reqstat[MAX_REQ_NUM]; int main(int argc, char *argv[]) { int myid, numprocs, i, j; int size, align_size; char *s_buf, *r_buf; double t_start = 0.0, t_end = 0.0, t = 0.0; MPI_Init(&argc, &argv); MPI_Comm_size(MPI_COMM_WORLD, &numprocs); MPI_Comm_rank(MPI_COMM_WORLD, &myid); // if (myid == 0) { // printf("Attach debugger if necessary, then press \n"); // char c; // c = getchar(); // } // Sync here // MPI_Barrier(MPI_COMM_WORLD); align_size = getpagesize(); assert(align_size <= MAX_ALIGNMENT); s_buf = (char *) (((unsigned long) s_buf1 + (align_size - 1)) / align_size * align_size); r_buf = (char *) (((unsigned long) r_buf1 + (align_size - 1)) / align_size * align_size); if(numprocs != 2) { if(myid == 0) { fprintf(stderr, "This test requires exactly two processes\n"); } MPI_Finalize(); return EXIT_FAILURE; } if(myid == 0) { fprintf(stdout, "# %s %s\n", BENCHMARK, OMB_VERSION); fprintf(stdout, "%-*s%*s\n", 10, "# Size", FIELD_WIDTH, "Bi-Bandwidth (MB/s)"); fflush(stdout); } for(size = 1; size <= MAX_MSG_SIZE; size *= 2) { /* touch the data */ for(i = 0; i < size; i++) { s_buf[i] = 'a'; r_buf[i] = 'b'; } if(size > large_message_size) { loop = loop_large; skip = skip_large; window_size = window_size_large; } if(myid == 0) { for(i = 0; i < loop + skip; i++) { if(i == skip) { t_start = MPI_Wtime(); } for(j = 0; j < window_size; j++) { MPI_Irecv(r_buf, size, MPI_CHAR, 1, 10, MPI_COMM_WORLD, recv_request + j); } for(j = 0; j < window_size; j++) { MPI_Isend(s_buf, size, MPI_CHAR, 1, 100, MPI_COMM_WORLD, send_request + j); } MPI_Waitall(window_size, send_request, reqstat); MPI_Waitall(window_size, recv_request, reqstat); } t_end = MPI_Wtime(); t = t_end - t_start; } else if(myid == 1) { for(i = 0; i < loop + skip; i++) { for(j = 0; j < window_size; j++) { MPI_Irecv(r_buf, size, MPI_CHAR, 0, 100, MPI_COMM_WORLD, recv_request + j); } for (j = 0; j < window_size; j++) { MPI_Isend(s_buf, size, MPI_CHAR, 0, 10, MPI_COMM_WORLD, send_request + j); } MPI_Waitall(window_size, send_request, reqstat); MPI_Waitall(window_size, recv_request, reqstat); } } if(myid == 0) { double tmp = size / 1e6 * loop * window_size * 2; fprintf(stdout, "%-*d%*.*f\n", 10, size, FIELD_WIDTH, FLOAT_PRECISION, tmp / t); fflush(stdout); } } MPI_Finalize(); return EXIT_SUCCESS; } /* vi: set sw=4 sts=4 tw=80: */