From 2f0fe2980e52b7af8a06bdea7f077096e2b28838 Mon Sep 17 00:00:00 2001 From: Jim Edwards Date: Fri, 24 Oct 2014 12:43:16 -0600 Subject: [PATCH] Add GPTLpr_summary_file function --- f_wrappers.c | 35 +++++++++++++++++++++++++++++++++++ gptl.h | 16 ++++++++++------ gptlf.F90 | 9 +++++++++ pr_summary.c | 23 ++++++++++++++++++----- 4 files changed, 72 insertions(+), 11 deletions(-) diff --git a/f_wrappers.c b/f_wrappers.c index 0bc34a5c..5b206ea1 100644 --- a/f_wrappers.c +++ b/f_wrappers.c @@ -22,6 +22,7 @@ #define gptlpr gptlpr_ #define gptlpr_file gptlpr_file_ #define gptlpr_summary gptlpr_summary_ +#define gptlpr_summary_file gptlpr_summary_file_ #define gptlbarrier gptlbarrier_ #define gptlreset gptlreset_ #define gptlstamp gptlstamp_ @@ -57,6 +58,7 @@ #define gptlpr gptlpr_ #define gptlpr_file gptlpr_file__ #define gptlpr_summary gptlpr_summary__ +#define gptlpr_summary_file gptlpr_summary_file__ #define gptlbarrier gptlbarrier_ #define gptlreset gptlreset_ #define gptlstamp gptlstamp_ @@ -94,9 +96,11 @@ int gptlpr (int *procid); int gptlpr_file (char *file, int nc1); #ifdef HAVE_MPI int gptlpr_summary (int *fcomm); +int gptlpr_summary_file (int *fcomm, char *name, int nc1); int gptlbarrier (int *fcomm, char *name, int nc1); #else int gptlpr_summary (void); +int gptlpr_summary_file (char *name, int nc1); int gptlbarrier (void); #endif int gptlreset (void); @@ -176,6 +180,25 @@ int gptlpr_summary (int *fcomm) return GPTLpr_summary (ccomm); } +int gptlpr_summary_file (int *fcomm, char *outfile, int nc1) +{ + MPI_Comm ccomm; + char cname[MAX_CHARS+1]; + int numchars; + + numchars = MIN (nc1, MAX_CHARS); + strncpy (cname, outfile, numchars); + cname[numchars] = '\0'; + +#ifdef HAVE_COMM_F2C + ccomm = MPI_Comm_f2c (*fcomm); +#else + /* Punt and try just casting the Fortran communicator */ + ccomm = (MPI_Comm) *fcomm; +#endif + return GPTLpr_summary_file (ccomm, cname); +} + int gptlbarrier (int *fcomm, char *name, int nc1) { MPI_Comm ccomm; @@ -201,6 +224,18 @@ int gptlpr_summary (void) return GPTLpr_summary (); } +int gptlpr_summary_file (char *outfile, int nc1) +{ + char cname[MAX_CHARS+1]; + int numchars; + + numchars = MIN (nc1, MAX_CHARS); + strncpy (cname, outfile, numchars); + cname[numchars] = '\0'; + + return GPTLpr_summary_file (cname); +} + int gptlbarrier (void) { return GPTLerror ("gptlbarrier: Need to build GPTL with #define HAVE_MPI to enable this routine\n"); diff --git a/gptl.h b/gptl.h index e083571e..c52d3d22 100644 --- a/gptl.h +++ b/gptl.h @@ -99,12 +99,16 @@ extern int GPTLstamp (double *, double *, double *); extern int GPTLpr (const int); extern int GPTLpr_file (const char *); -/* -** Use K&R prototype for these 2 because they require MPI -*/ -extern int GPTLpr_summary (); -extern int GPTLbarrier (); - +#ifdef HAVE_MPI +#include + extern int GPTLpr_summary (MPI_Comm c); + extern int GPTLpr_summary_file (MPI_Comm c, const char *); + extern int GPTLbarrier (MPI_Comm c, const char *); +#else + extern int GPTLpr_summary (); + extern int GPTLpr_summary_file (const char *); + extern int GPTLbarrier (); +#endif extern int GPTLreset (void); extern int GPTLfinalize (void); extern int GPTLget_memusage (int *, int *, int *, int *, int *); diff --git a/gptlf.F90 b/gptlf.F90 index 22496e32..5603980f 100644 --- a/gptlf.F90 +++ b/gptlf.F90 @@ -79,6 +79,11 @@ integer function gptlpr_summary (fcomm) integer :: fcomm end function gptlpr_summary + integer function gptlpr_summary_file (fcomm, name) + integer :: fcomm + character(len=*) :: name + end function gptlpr_summary_file + integer function gptlbarrier (fcomm, name) integer :: fcomm character(len=*) :: name @@ -87,6 +92,10 @@ end function gptlbarrier integer function gptlpr_summary () end function gptlpr_summary + integer function gptlpr_summary_file ( name) + character(len=*) :: name + end function gptlpr_summary_file + integer function gptlbarrier () end function gptlbarrier #endif diff --git a/pr_summary.c b/pr_summary.c index 665bd3d1..e927a96c 100644 --- a/pr_summary.c +++ b/pr_summary.c @@ -45,9 +45,8 @@ static int nthreads; /* Used by both GPTLpr_summary() and get_threadstats() */ */ #ifdef HAVE_MPI -#include -int GPTLpr_summary (MPI_Comm comm) /* communicator */ +int GPTLpr_summary_file (MPI_Comm comm, const char *outfile) /* communicator */ { int ret; /* return code */ int iam; /* my rank */ @@ -76,7 +75,6 @@ int GPTLpr_summary (MPI_Comm comm) /* communicator */ float sigma; /* st. dev. */ unsigned int tsksum; /* part of Chan, et. al. equation */ static const int tag = 98789; /* tag for MPI message */ - static const char *outfile = "timing.summary"; /* file to write to */ static const int nbytes = sizeof (Global); /* number of bytes to be sent/recvd */ static const char *thisfunc = "GPTLpr_summary"; /* this function */ FILE *fp = 0; /* file handle to write to */ @@ -360,12 +358,18 @@ int GPTLpr_summary (MPI_Comm comm) /* communicator */ return 0; } +int GPTLpr_summary (MPI_Comm comm) /* communicator */ +{ + static const char *outfile = "timing.summary"; /* file to write to */ + + return GPTLpr_summary_file(comm, outfile); +} + #else /* No MPI. Mimic MPI version but for only one rank */ -int GPTLpr_summary () +int GPTLpr_summary (const char outfile[]) { - static const char *outfile = "timing.summary"; /* file to write to */ FILE *fp = 0; /* file handle */ Timer **timers; int multithread; /* flag indicates multithreaded or not */ @@ -472,8 +476,17 @@ int GPTLpr_summary () return 0; } +int GPTLpr_summary () /* communicator */ +{ + static const char *outfile = "timing.summary"; /* file to write to */ + + return GPTLpr_summary_file(outfile); +} + #endif /* False branch of HAVE_MPI */ + + /* ** get_threadstats: gather stats for timer "name" over all threads **