From 15b7d163e6c3f72eccea71a26855baf3b670ed08 Mon Sep 17 00:00:00 2001 From: Jan Vales Date: Mon, 30 Jan 2012 02:54:17 +0100 Subject: [PATCH] mpiscan now has timings. --- scan/scan.c | 70 +++++++++++++++++++++++++++++++++++++++++++---------- scan/scan.h | 6 ++++- 2 files changed, 62 insertions(+), 14 deletions(-) diff --git a/scan/scan.c b/scan/scan.c index 256c95b..9789cb6 100755 --- a/scan/scan.c +++ b/scan/scan.c @@ -18,9 +18,18 @@ char* binname = "unset"; void usage () { - fprintf (stderr, "\nUsage: mpirun -node 1-32 -nnp 1 %s [-f ] [-n ]\n", binname); - fprintf (stderr, "\t -f: set the filename of the randfile. (defaults to \"numlist.bin\")\n"); - fprintf (stderr, "\t -n: set the number count to read from randfile. (defaults to -1 = read all)\n\n"); + fprintf(stderr, "\nUsage: mpirun -node 1-32 -nnp 1 %s [-f ] [-n ]\n", binname); + fprintf(stderr, "\t -f: set the filename of the randfile. (defaults to \"numlist.bin\")\n"); + fprintf(stderr, "\t -n: set the number count to read from randfile. (defaults to -1 = read all)\n"); +#ifdef DEBUG + fprintf(stderr, "***** BIG RED WARNING: COMPILED WITH XDEBUG - YOU ARE ON YOUR OWN! *****\n"); +#endif +#ifdef DEBUG + fprintf(stderr, "*** COMPILED WITH DEBUG - size is limited to 64 ***\n"); + fprintf(stderr, "Compile with XDEBUG or without DEBUG to get past this limit.\n"); + fprintf(stderr, "You might want to compile this without the DEBUG flag to get less noice.\n"); +#endif + fprintf(stderr, "\n"); } @@ -41,6 +50,13 @@ int main(int argc, char *argv[]){ unsigned long blocksize; unsigned long *databuf; + /* timings. */ + double startTime = 0; + double prepTime = 0; + double algoTime = 0; + double postpTime = 0; + double endTime = 0; + /* options */ unsigned long size = 0; char *filename = "numlist.bin"; @@ -55,7 +71,14 @@ int main(int argc, char *argv[]){ MPI_Comm_size(MPI_COMM_WORLD,&nodes); MPI_Comm_rank(MPI_COMM_WORLD,&rank); MPI_Get_processor_name(name,&tmp); - //fprintf(stdout, "[%d/%d:%s] openMPI initialised.\n",rank,nodes,name); +#ifdef DEBUG + fprintf(stderr, "***** BIG RED WARNING: COMPILED WITH XDEBUG - YOU ARE ON YOUR OWN! *****\n"); +#endif +#ifdef DEBUG + fprintf(stderr, "*** COMPILED WITH DEBUG - size is limited to 64 ***\n"); + fprintf(stderr, "Compile with XDEBUG or without DEBUG to get past this limit.\n"); + fprintf(stdout, "[%d/%d:%s] openMPI initialised.\n",rank,nodes,name); +#endif /* getopt stuff */ int c; @@ -93,6 +116,11 @@ int main(int argc, char *argv[]){ if (size <= 0 || size > st.st_size){ size = st.st_size; } +#ifdef DEBUG +#ifndef XDEBUG + if (size > 64) size = 64; +#endif +#endif }else{ if(rank == 0){ fprintf (stdout, "[%d/%d:%s] File %s does not exist.\n",rank,nodes,name,filename); @@ -133,36 +161,47 @@ int main(int argc, char *argv[]){ } fprintf(stdout, "[%d/%d:%s] file read - distributing work.\n",rank,nodes,name); + startTime = MPI_Wtime(); MPI_Isend(databuf, size-1, MPI_LONG, 0, KEY, MPI_COMM_WORLD, &request); } - /* stuff done by all others */ + /* stuff done by all nodes */ + if (startTime == 0) startTime = MPI_Wtime(); tmp = rank -1; if(tmp < 0) tmp = 0; MPI_Recv(databuf, size, MPI_LONG, tmp, KEY, MPI_COMM_WORLD, MPI_STATUS_IGNORE); /* propagate data, if not last node. */ if(rank +1 < nodes) MPI_Send(databuf, size, MPI_LONG, rank+1, KEY, MPI_COMM_WORLD); + prepTime = MPI_Wtime(); /* do processing here. */ for(unsigned long i = (rank*blocksize+1); i < ((rank+1)*blocksize) && i < size; i++){ databuf[i] = databuf[(i-1)] + databuf[i]; } - //fprintf(stdout, "[%d/%d:%s] proc array ",rank,nodes,name); - //array_contents(databuf, size); + algoTime = MPI_Wtime(); +#ifdef DEBUG + fprintf(stdout, "[%d/%d:%s] proc array ",rank,nodes,name); + array_contents(databuf, size); +#endif /* receive sums */ if(rank != 0){ MPI_Recv(databuf, rank*blocksize, MPI_LONG, tmp, KEY, MPI_COMM_WORLD, MPI_STATUS_IGNORE); - // fprintf(stdout, "[%d/%d:%s] rcv array ",rank,nodes,name); - // array_contents(databuf, size); +#ifdef DEBUG + fprintf(stdout, "[%d/%d:%s] rcv array ",rank,nodes,name); + array_contents(databuf, size); +#endif for(unsigned long i = rank*blocksize; i < ((rank+1)*blocksize) && i < size; i++){ databuf[i] += databuf[((rank*blocksize)-1)]; } - // fprintf(stdout, "[%d/%d:%s] added array ",rank,nodes,name); - // array_contents(databuf, size); +#ifdef DEBUG + fprintf(stdout, "[%d/%d:%s] added array ",rank,nodes,name); + array_contents(databuf, size); +#endif } + postpTime = MPI_Wtime(); tmp = rank +1; if(tmp >= nodes) tmp = 0; @@ -173,11 +212,16 @@ int main(int argc, char *argv[]){ /* receive result by root */ if(rank == 0){ MPI_Recv(databuf, size, MPI_LONG, nodes-1, KEY, MPI_COMM_WORLD, MPI_STATUS_IGNORE); + endTime = MPI_Wtime(); fprintf(stdout, "[%d/%d:%s] result: %li\n",rank,nodes,name,databuf[size-1]); -// fprintf(stdout, "[%d/%d:%s] res array ",rank,nodes,name); -// array_contents(databuf, size); +#ifdef DEBUG + fprintf(stdout, "[%d/%d:%s] res array ",rank,nodes,name); + array_contents(databuf, size); +#endif } + if(endTime == 0) endTime = MPI_Wtime(); + fprintf(stdout, "[%d/%d:%s] timings: prep:%f algo:%f postp:%f end:%f\n",rank,nodes,name,prepTime-startTime,algoTime-startTime,postpTime-startTime,endTime-startTime); MPI_Finalize(); return 0; } diff --git a/scan/scan.h b/scan/scan.h index 0a496a3..299cb4c 100755 --- a/scan/scan.h +++ b/scan/scan.h @@ -1,3 +1,7 @@ /* * Inclusive scan - header - */ +*/ + +#ifdef XDEBUG +#define DEBUG +#endif -- 2.43.0