From 974ed669ba4f094eda622d1452f1856cc81669d7 Mon Sep 17 00:00:00 2001 From: Ed Hartnett Date: Sat, 6 Jul 2019 06:01:30 -0600 Subject: [PATCH] moved init of UDF to nc_init_intercomm() --- src/ncint/ncint_pio.c | 21 --------------------- src/ncint/ncintdispatch.c | 32 ++++++++++++++++++++++++++++++++ tests/ncint/tst_pio_udf.c | 3 --- 3 files changed, 32 insertions(+), 24 deletions(-) diff --git a/src/ncint/ncint_pio.c b/src/ncint/ncint_pio.c index e58e1866fad..e99ff43966e 100644 --- a/src/ncint/ncint_pio.c +++ b/src/ncint/ncint_pio.c @@ -13,27 +13,6 @@ /* The default io system id. */ extern int diosysid; -/** - * Same as PIOc_Init_Intracomm(). - * - * @author Ed Hartnett - */ -int -nc_init_intracomm(MPI_Comm comp_comm, int num_iotasks, int stride, int base, int rearr, - int *iosysidp) -{ - int ret; - - if ((ret = PIOc_Init_Intracomm(comp_comm, num_iotasks, stride, base, rearr, - iosysidp))) - return ret; - - /* Remember the io system id. */ - diosysid = *iosysidp; - - return PIO_NOERR; -} - /** * Same as PIOc_free_iosystem(). * diff --git a/src/ncint/ncintdispatch.c b/src/ncint/ncintdispatch.c index 4714728899d..fd1b8dae1f0 100644 --- a/src/ncint/ncintdispatch.c +++ b/src/ncint/ncintdispatch.c @@ -16,6 +16,9 @@ /** Default iosysid. */ int diosysid; +/** Did we initialize user-defined format? */ +int ncint_initialized = 0; + /* This is the dispatch object that holds pointers to all the * functions that make up the NCINT dispatch interface. */ NC_Dispatch NCINT_dispatcher = { @@ -110,6 +113,35 @@ NC_Dispatch NCINT_dispatcher = { const NC_Dispatch* NCINT_dispatch_table = NULL; +/** + * Same as PIOc_Init_Intracomm(). + * + * @author Ed Hartnett + */ +int +nc_init_intracomm(MPI_Comm comp_comm, int num_iotasks, int stride, int base, int rearr, + int *iosysidp) +{ + int ret; + + /* Add our user defined format, if necessary. */ + if (!ncint_initialized) + { + if ((ret = nc_def_user_format(NC_UDF0, &NCINT_dispatcher, NULL))) + return ret; + ncint_initialized++; + } + + if ((ret = PIOc_Init_Intracomm(comp_comm, num_iotasks, stride, base, rearr, + iosysidp))) + return ret; + + /* Remember the io system id. */ + diosysid = *iosysidp; + + return PIO_NOERR; +} + /** * @internal Initialize NCINT dispatch layer. * diff --git a/tests/ncint/tst_pio_udf.c b/tests/ncint/tst_pio_udf.c index 00d9733456b..4a6c7fb1be6 100644 --- a/tests/ncint/tst_pio_udf.c +++ b/tests/ncint/tst_pio_udf.c @@ -56,9 +56,6 @@ main(int argc, char **argv) /* Initialize the intracomm. */ if (nc_init_intracomm(MPI_COMM_WORLD, 1, 1, 0, 0, &iosysid)) ERR; - /* Add our user defined format. */ - if (nc_def_user_format(NC_UDF0, &NCINT_dispatcher, NULL)) ERR; - /* Create a file with a 3D record var. */ if (nc_create(FILE_NAME, NC_UDF0, &ncid)) ERR; if (nc_def_dim(ncid, DIM_NAME_UNLIMITED, dimlen[0], &dimid[0])) ERR;