Skip to content

Commit cbc6884

Browse files
Merge pull request #608 from E3SM-Project/jayeshkrishna/better_handle_gptl_init
Some tools that are built with the SCORPIO library sometimes need access to GPTL before SCORPIO is initialized (and hence might initialize GPTL before PIO_init). So we now query the GPTL library to know the library init status before initializing (and appropriately finalizing) the lib.
2 parents 2d88c64 + 484d0cb commit cbc6884

File tree

1 file changed

+13
-2
lines changed

1 file changed

+13
-2
lines changed

src/clib/pioc_support.cpp

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,14 @@ extern "C"{
3232
void PIOc_warn(int iosysid, int ncid, const char *fname, int line, const char *uwarn_msg);
3333
int PIOc_error(int iosysid, int ncid, int err_num, const char *fname, int line, const char *uerr_msg);
3434

35+
#ifdef TIMING_INTERNAL
36+
/* GPTL does not export this function via the header file. So adding the func decl here for
37+
* portability acorss multiple versions of GPTL
38+
* FIXME: Modify all versions of GPTL that we use to export this function
39+
*/
40+
extern int GPTLis_initialized (void);
41+
#endif
42+
3543
#if defined(__cplusplus)
3644
}
3745
#endif
@@ -697,13 +705,16 @@ void pio_finalize_logging(void)
697705
* Initialize GPTL timer library, if needed
698706
* The library is only initialized if the timing is internal
699707
*/
708+
/* Indicate if GPTL was initialized inside the library */
709+
static bool GPTL_was_init_in_lib = false;
700710
void pio_init_gptl(void )
701711
{
702712
#ifdef TIMING_INTERNAL
703713
pio_timer_ref_cnt += 1;
704-
if(pio_timer_ref_cnt == 1)
714+
if((pio_timer_ref_cnt == 1) && (!GPTLis_initialized()))
705715
{
706716
GPTLinitialize();
717+
GPTL_was_init_in_lib = true;
707718
}
708719
#endif
709720
}
@@ -716,7 +727,7 @@ void pio_finalize_gptl(void)
716727
{
717728
#ifdef TIMING_INTERNAL
718729
pio_timer_ref_cnt -= 1;
719-
if(pio_timer_ref_cnt == 0)
730+
if((pio_timer_ref_cnt == 0) && (GPTL_was_init_in_lib))
720731
{
721732
GPTLfinalize();
722733
}

0 commit comments

Comments
 (0)