Skip to content

Commit 2f0fe29

Browse files
committed
Add GPTLpr_summary_file function
1 parent 541acc0 commit 2f0fe29

File tree

4 files changed

+72
-11
lines changed

4 files changed

+72
-11
lines changed

f_wrappers.c

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
#define gptlpr gptlpr_
2323
#define gptlpr_file gptlpr_file_
2424
#define gptlpr_summary gptlpr_summary_
25+
#define gptlpr_summary_file gptlpr_summary_file_
2526
#define gptlbarrier gptlbarrier_
2627
#define gptlreset gptlreset_
2728
#define gptlstamp gptlstamp_
@@ -57,6 +58,7 @@
5758
#define gptlpr gptlpr_
5859
#define gptlpr_file gptlpr_file__
5960
#define gptlpr_summary gptlpr_summary__
61+
#define gptlpr_summary_file gptlpr_summary_file__
6062
#define gptlbarrier gptlbarrier_
6163
#define gptlreset gptlreset_
6264
#define gptlstamp gptlstamp_
@@ -94,9 +96,11 @@ int gptlpr (int *procid);
9496
int gptlpr_file (char *file, int nc1);
9597
#ifdef HAVE_MPI
9698
int gptlpr_summary (int *fcomm);
99+
int gptlpr_summary_file (int *fcomm, char *name, int nc1);
97100
int gptlbarrier (int *fcomm, char *name, int nc1);
98101
#else
99102
int gptlpr_summary (void);
103+
int gptlpr_summary_file (char *name, int nc1);
100104
int gptlbarrier (void);
101105
#endif
102106
int gptlreset (void);
@@ -176,6 +180,25 @@ int gptlpr_summary (int *fcomm)
176180
return GPTLpr_summary (ccomm);
177181
}
178182

183+
int gptlpr_summary_file (int *fcomm, char *outfile, int nc1)
184+
{
185+
MPI_Comm ccomm;
186+
char cname[MAX_CHARS+1];
187+
int numchars;
188+
189+
numchars = MIN (nc1, MAX_CHARS);
190+
strncpy (cname, outfile, numchars);
191+
cname[numchars] = '\0';
192+
193+
#ifdef HAVE_COMM_F2C
194+
ccomm = MPI_Comm_f2c (*fcomm);
195+
#else
196+
/* Punt and try just casting the Fortran communicator */
197+
ccomm = (MPI_Comm) *fcomm;
198+
#endif
199+
return GPTLpr_summary_file (ccomm, cname);
200+
}
201+
179202
int gptlbarrier (int *fcomm, char *name, int nc1)
180203
{
181204
MPI_Comm ccomm;
@@ -201,6 +224,18 @@ int gptlpr_summary (void)
201224
return GPTLpr_summary ();
202225
}
203226

227+
int gptlpr_summary_file (char *outfile, int nc1)
228+
{
229+
char cname[MAX_CHARS+1];
230+
int numchars;
231+
232+
numchars = MIN (nc1, MAX_CHARS);
233+
strncpy (cname, outfile, numchars);
234+
cname[numchars] = '\0';
235+
236+
return GPTLpr_summary_file (cname);
237+
}
238+
204239
int gptlbarrier (void)
205240
{
206241
return GPTLerror ("gptlbarrier: Need to build GPTL with #define HAVE_MPI to enable this routine\n");

gptl.h

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -99,12 +99,16 @@ extern int GPTLstamp (double *, double *, double *);
9999
extern int GPTLpr (const int);
100100
extern int GPTLpr_file (const char *);
101101

102-
/*
103-
** Use K&R prototype for these 2 because they require MPI
104-
*/
105-
extern int GPTLpr_summary ();
106-
extern int GPTLbarrier ();
107-
102+
#ifdef HAVE_MPI
103+
#include <mpi.h>
104+
extern int GPTLpr_summary (MPI_Comm c);
105+
extern int GPTLpr_summary_file (MPI_Comm c, const char *);
106+
extern int GPTLbarrier (MPI_Comm c, const char *);
107+
#else
108+
extern int GPTLpr_summary ();
109+
extern int GPTLpr_summary_file (const char *);
110+
extern int GPTLbarrier ();
111+
#endif
108112
extern int GPTLreset (void);
109113
extern int GPTLfinalize (void);
110114
extern int GPTLget_memusage (int *, int *, int *, int *, int *);

gptlf.F90

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,11 @@ integer function gptlpr_summary (fcomm)
7979
integer :: fcomm
8080
end function gptlpr_summary
8181

82+
integer function gptlpr_summary_file (fcomm, name)
83+
integer :: fcomm
84+
character(len=*) :: name
85+
end function gptlpr_summary_file
86+
8287
integer function gptlbarrier (fcomm, name)
8388
integer :: fcomm
8489
character(len=*) :: name
@@ -87,6 +92,10 @@ end function gptlbarrier
8792
integer function gptlpr_summary ()
8893
end function gptlpr_summary
8994

95+
integer function gptlpr_summary_file ( name)
96+
character(len=*) :: name
97+
end function gptlpr_summary_file
98+
9099
integer function gptlbarrier ()
91100
end function gptlbarrier
92101
#endif

pr_summary.c

Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -45,9 +45,8 @@ static int nthreads; /* Used by both GPTLpr_summary() and get_threadstats() */
4545
*/
4646

4747
#ifdef HAVE_MPI
48-
#include <mpi.h>
4948

50-
int GPTLpr_summary (MPI_Comm comm) /* communicator */
49+
int GPTLpr_summary_file (MPI_Comm comm, const char *outfile) /* communicator */
5150
{
5251
int ret; /* return code */
5352
int iam; /* my rank */
@@ -76,7 +75,6 @@ int GPTLpr_summary (MPI_Comm comm) /* communicator */
7675
float sigma; /* st. dev. */
7776
unsigned int tsksum; /* part of Chan, et. al. equation */
7877
static const int tag = 98789; /* tag for MPI message */
79-
static const char *outfile = "timing.summary"; /* file to write to */
8078
static const int nbytes = sizeof (Global); /* number of bytes to be sent/recvd */
8179
static const char *thisfunc = "GPTLpr_summary"; /* this function */
8280
FILE *fp = 0; /* file handle to write to */
@@ -360,12 +358,18 @@ int GPTLpr_summary (MPI_Comm comm) /* communicator */
360358
return 0;
361359
}
362360

361+
int GPTLpr_summary (MPI_Comm comm) /* communicator */
362+
{
363+
static const char *outfile = "timing.summary"; /* file to write to */
364+
365+
return GPTLpr_summary_file(comm, outfile);
366+
}
367+
363368
#else
364369

365370
/* No MPI. Mimic MPI version but for only one rank */
366-
int GPTLpr_summary ()
371+
int GPTLpr_summary (const char outfile[])
367372
{
368-
static const char *outfile = "timing.summary"; /* file to write to */
369373
FILE *fp = 0; /* file handle */
370374
Timer **timers;
371375
int multithread; /* flag indicates multithreaded or not */
@@ -472,8 +476,17 @@ int GPTLpr_summary ()
472476
return 0;
473477
}
474478

479+
int GPTLpr_summary () /* communicator */
480+
{
481+
static const char *outfile = "timing.summary"; /* file to write to */
482+
483+
return GPTLpr_summary_file(outfile);
484+
}
485+
475486
#endif /* False branch of HAVE_MPI */
476487

488+
489+
477490
/*
478491
** get_threadstats: gather stats for timer "name" over all threads
479492
**

0 commit comments

Comments
 (0)