diff --git a/.gitignore b/.gitignore index c86041d16..eb7f8585b 100644 --- a/.gitignore +++ b/.gitignore @@ -34,6 +34,7 @@ src/test/ams_driver src/test/ij src/test/ij_assembly src/test/ij_mv +src/test/ij_mm src/test/maxwell_unscaled src/test/sstruct src/test/sstruct_fac diff --git a/src/config/HYPRE_config.h.cmake.in b/src/config/HYPRE_config.h.cmake.in index 727df052a..a8981c9ae 100644 --- a/src/config/HYPRE_config.h.cmake.in +++ b/src/config/HYPRE_config.h.cmake.in @@ -170,5 +170,8 @@ /* As F77_FUNC, but for C identifiers containing underscores. */ #define HYPRE_F77_FUNC_(name,NAME) name ## __ +/* Deprecated function macro */ +#define HYPRE_DEPRECATED(reason) _Pragma(reason) + /* Define to 1 if using host memory only */ #cmakedefine HYPRE_USING_HOST_MEMORY 1 diff --git a/src/config/HYPRE_config.h.in b/src/config/HYPRE_config.h.in index a84c4253a..4890f9acf 100644 --- a/src/config/HYPRE_config.h.in +++ b/src/config/HYPRE_config.h.in @@ -65,6 +65,9 @@ /* Define to 1 if in debug mode */ #undef HYPRE_DEBUG +/* Deprecated function macro */ +#undef HYPRE_DEPRECATED + /* Main development branch? */ #undef HYPRE_DEVELOP_BRANCH diff --git a/src/config/configure.in b/src/config/configure.in index 921bbeb81..7b518b6b1 100644 --- a/src/config/configure.in +++ b/src/config/configure.in @@ -89,6 +89,8 @@ HYPRE_TIME="M4_HYPRE_TIME" HYPRE_BUGS="M4_HYPRE_BUGS" HYPRE_SRCDIR="M4_HYPRE_SRCDIR" +AC_DEFINE(HYPRE_DEPRECATED(reason), _Pragma(reason), [Deprecated function macro]) + AC_DEFINE_UNQUOTED(HYPRE_RELEASE_NAME, ["$HYPRE_NAME"], [Release name]) AC_DEFINE_UNQUOTED(HYPRE_RELEASE_VERSION, ["$HYPRE_VERSION"], [Release version]) AC_DEFINE_UNQUOTED(HYPRE_RELEASE_NUMBER, [$HYPRE_NUMBER], [Release number]) diff --git a/src/configure b/src/configure index 5e48bd249..06b12edbd 100755 --- a/src/configure +++ b/src/configure @@ -3212,6 +3212,10 @@ HYPRE_BUGS="https://github.com/hypre-space/hypre/issues" HYPRE_SRCDIR="`pwd`" +printf "%s\n" "#define HYPRE_DEPRECATED(reason) _Pragma(reason)" >>confdefs.h + + + printf "%s\n" "#define HYPRE_RELEASE_NAME \"$HYPRE_NAME\"" >>confdefs.h @@ -12487,3 +12491,4 @@ fi mv HYPRE_config.h HYPRE_config.h.tmp sed 's/FC_FUNC/HYPRE_FC_FUNC/g' < HYPRE_config.h.tmp > HYPRE_config.h rm -f HYPRE_config.h.tmp + diff --git a/src/docs/usr-manual/solvers-boomeramg.rst b/src/docs/usr-manual/solvers-boomeramg.rst index e929205c5..3632ff643 100644 --- a/src/docs/usr-manual/solvers-boomeramg.rst +++ b/src/docs/usr-manual/solvers-boomeramg.rst @@ -170,7 +170,7 @@ GPU-supported Options In general, CUDA unified memory is required for running BoomerAMG solvers on GPUs. However, hypre can also be built without ``--enable-unified-memory`` if -all the selected parameters have GPU-support. +all the selected parameters have GPU-support. The currently available GPU-supported BoomerAMG options include: * Coarsening: PMIS (8) @@ -187,7 +187,7 @@ on GPUs is shown below. cudaSetDevice(device_id); /* GPU binding */ ... - HYPRE_Init(); /* must be the first HYPRE function call */ + HYPRE_Initialize(); /* must be the first HYPRE function call */ ... /* AMG in GPU memory (default) */ HYPRE_SetMemoryLocation(HYPRE_MEMORY_DEVICE); @@ -238,7 +238,7 @@ on GPUs is shown below. ... HYPRE_Finalize(); /* must be the last HYPRE function call */ -``HYPRE_Init()`` must be called and precede all the other ``HYPRE_`` functions, and +``HYPRE_Initialize()`` must be called and precede all the other ``HYPRE_`` functions, and ``HYPRE_Finalize()`` must be called before exiting. Miscellaneous @@ -253,4 +253,3 @@ algorithms. For 3-dimensional problems a better choice appears to be 0.5, when using the default coarsening algorithm. However, the choice of the strength threshold is problem dependent and therefore there could be better choices than the two suggested ones. - diff --git a/src/examples/ex1.c b/src/examples/ex1.c index bd0338ce2..4014768d0 100644 --- a/src/examples/ex1.c +++ b/src/examples/ex1.c @@ -65,7 +65,7 @@ int main (int argc, char *argv[]) } /* Initialize HYPRE */ - HYPRE_Init(); + HYPRE_Initialize(); /* Print GPU info */ /* HYPRE_PrintDeviceInfo(); */ diff --git a/src/examples/ex10.cxx b/src/examples/ex10.cxx index da4838944..35ebff83f 100644 --- a/src/examples/ex10.cxx +++ b/src/examples/ex10.cxx @@ -57,7 +57,7 @@ int main(int argc, char *argv[]) MPI_Comm_rank(MPI_COMM_WORLD, &mypid); /* Initialize HYPRE */ - HYPRE_Init(); + HYPRE_Initialize(); /* Print GPU info */ /* HYPRE_PrintDeviceInfo(); */ diff --git a/src/examples/ex11.c b/src/examples/ex11.c index 0a816528d..dc432a5c3 100644 --- a/src/examples/ex11.c +++ b/src/examples/ex11.c @@ -74,7 +74,7 @@ int main (int argc, char *argv[]) MPI_Comm_size(MPI_COMM_WORLD, &num_procs); /* Initialize HYPRE */ - HYPRE_Init(); + HYPRE_Initialize(); /* Print GPU info */ /* HYPRE_PrintDeviceInfo(); */ diff --git a/src/examples/ex12.c b/src/examples/ex12.c index ebcebf431..b1d08940f 100644 --- a/src/examples/ex12.c +++ b/src/examples/ex12.c @@ -68,7 +68,7 @@ int main (int argc, char *argv[]) MPI_Comm_size(MPI_COMM_WORLD, &num_procs); /* Initialize HYPRE */ - HYPRE_Init(); + HYPRE_Initialize(); /* Print GPU info */ /* HYPRE_PrintDeviceInfo(); */ diff --git a/src/examples/ex12cuf.cuf b/src/examples/ex12cuf.cuf index 27b907fbb..95bf616ae 100644 --- a/src/examples/ex12cuf.cuf +++ b/src/examples/ex12cuf.cuf @@ -86,7 +86,7 @@ call MPI_Comm_rank(MPI_COMM_WORLD, myid, ierr) call MPI_Comm_size(MPI_COMM_WORLD, num_procs, ierr) - call HYPRE_Init(ierr) + call HYPRE_Initialize(ierr) if (num_procs .ne. 2) then if (myid .eq. 0) then @@ -490,4 +490,3 @@ deallocate(values) end - diff --git a/src/examples/ex12f.f b/src/examples/ex12f.f index 7203af0d2..acc5269eb 100644 --- a/src/examples/ex12f.f +++ b/src/examples/ex12f.f @@ -84,7 +84,7 @@ call MPI_Comm_rank(MPI_COMM_WORLD, myid, ierr) call MPI_Comm_size(MPI_COMM_WORLD, num_procs, ierr) - call HYPRE_Init(ierr) + call HYPRE_Initialize(ierr) if (num_procs .ne. 2) then if (myid .eq. 0) then @@ -510,4 +510,3 @@ stop end - diff --git a/src/examples/ex12f_cptr.f b/src/examples/ex12f_cptr.f index 5eab43ae9..9b47092ae 100644 --- a/src/examples/ex12f_cptr.f +++ b/src/examples/ex12f_cptr.f @@ -95,7 +95,7 @@ call MPI_Comm_rank(MPI_COMM_WORLD, myid, ierr) call MPI_Comm_size(MPI_COMM_WORLD, num_procs, ierr) - call HYPRE_Init(ierr) + call HYPRE_Initialize(ierr) if (num_procs .ne. 2) then if (myid .eq. 0) then @@ -501,4 +501,3 @@ stop end - diff --git a/src/examples/ex13.c b/src/examples/ex13.c index 99f869430..164591b71 100644 --- a/src/examples/ex13.c +++ b/src/examples/ex13.c @@ -175,7 +175,7 @@ int main (int argc, char *argv[]) MPI_Comm_size(MPI_COMM_WORLD, &num_procs); /* Initialize HYPRE */ - HYPRE_Init(); + HYPRE_Initialize(); /* Print GPU info */ /* HYPRE_PrintDeviceInfo(); */ diff --git a/src/examples/ex14.c b/src/examples/ex14.c index a8089ec94..bfe35fdaa 100644 --- a/src/examples/ex14.c +++ b/src/examples/ex14.c @@ -172,7 +172,7 @@ int main (int argc, char *argv[]) MPI_Comm_size(MPI_COMM_WORLD, &num_procs); /* Initialize HYPRE */ - HYPRE_Init(); + HYPRE_Initialize(); /* Print GPU info */ /* HYPRE_PrintDeviceInfo(); */ diff --git a/src/examples/ex15.c b/src/examples/ex15.c index 8e9ae9e1d..efdc9cc63 100644 --- a/src/examples/ex15.c +++ b/src/examples/ex15.c @@ -247,7 +247,7 @@ int main (int argc, char *argv[]) MPI_Comm_size(MPI_COMM_WORLD, &num_procs); /* Initialize HYPRE */ - HYPRE_Init(); + HYPRE_Initialize(); /* Print GPU info */ /* HYPRE_PrintDeviceInfo(); */ diff --git a/src/examples/ex15big.c b/src/examples/ex15big.c index afd240a57..6c1301c05 100644 --- a/src/examples/ex15big.c +++ b/src/examples/ex15big.c @@ -237,7 +237,7 @@ int main (int argc, char *argv[]) MPI_Comm_size(MPI_COMM_WORLD, &num_procs); /* Initialize HYPRE */ - HYPRE_Init(); + HYPRE_Initialize(); /* Print GPU info */ /* HYPRE_PrintDeviceInfo(); */ diff --git a/src/examples/ex16.c b/src/examples/ex16.c index d90e3a693..02a7cbb76 100644 --- a/src/examples/ex16.c +++ b/src/examples/ex16.c @@ -255,7 +255,7 @@ int main (int argc, char *argv[]) MPI_Comm_size(MPI_COMM_WORLD, &num_procs); /* Initialize HYPRE */ - HYPRE_Init(); + HYPRE_Initialize(); /* Print GPU info */ /* HYPRE_PrintDeviceInfo(); */ diff --git a/src/examples/ex17.c b/src/examples/ex17.c index 17316740b..1ed86bbd5 100644 --- a/src/examples/ex17.c +++ b/src/examples/ex17.c @@ -54,7 +54,7 @@ int main (int argc, char *argv[]) MPI_Comm_size(MPI_COMM_WORLD, &num_procs); /* Initialize HYPRE */ - HYPRE_Init(); + HYPRE_Initialize(); /* Print GPU info */ /* HYPRE_PrintDeviceInfo(); */ diff --git a/src/examples/ex18.c b/src/examples/ex18.c index 9efb7f935..6ae68cf6c 100644 --- a/src/examples/ex18.c +++ b/src/examples/ex18.c @@ -58,7 +58,7 @@ int main (int argc, char *argv[]) MPI_Comm_size(MPI_COMM_WORLD, &num_procs); /* Initialize HYPRE */ - HYPRE_Init(); + HYPRE_Initialize(); /* Print GPU info */ /* HYPRE_PrintDeviceInfo(); */ diff --git a/src/examples/ex18comp.c b/src/examples/ex18comp.c index 5431d45df..a9c7aaeb8 100644 --- a/src/examples/ex18comp.c +++ b/src/examples/ex18comp.c @@ -58,7 +58,7 @@ int main (int argc, char *argv[]) MPI_Comm_size(MPI_COMM_WORLD, &num_procs); /* Initialize HYPRE */ - HYPRE_Init(); + HYPRE_Initialize(); /* Print GPU info */ /* HYPRE_PrintDeviceInfo(); */ diff --git a/src/examples/ex2.c b/src/examples/ex2.c index e97f04121..3e80377ca 100644 --- a/src/examples/ex2.c +++ b/src/examples/ex2.c @@ -67,7 +67,7 @@ int main (int argc, char *argv[]) } /* Initialize HYPRE */ - HYPRE_Init(); + HYPRE_Initialize(); /* Print GPU info */ /* HYPRE_PrintDeviceInfo(); */ diff --git a/src/examples/ex3.c b/src/examples/ex3.c index 8949c2c8d..9b4596bc1 100644 --- a/src/examples/ex3.c +++ b/src/examples/ex3.c @@ -153,7 +153,7 @@ int main (int argc, char *argv[]) } /* Initialize HYPRE */ - HYPRE_Init(); + HYPRE_Initialize(); /* Print GPU info */ /* HYPRE_PrintDeviceInfo(); */ diff --git a/src/examples/ex4.c b/src/examples/ex4.c index b5bd0a7a7..202f0278b 100644 --- a/src/examples/ex4.c +++ b/src/examples/ex4.c @@ -245,7 +245,7 @@ int main (int argc, char *argv[]) MPI_Comm_size(MPI_COMM_WORLD, &num_procs); /* Initialize HYPRE */ - HYPRE_Init(); + HYPRE_Initialize(); /* Print GPU info */ /* HYPRE_PrintDeviceInfo(); */ diff --git a/src/examples/ex5.c b/src/examples/ex5.c index 708930954..7afa32ce7 100644 --- a/src/examples/ex5.c +++ b/src/examples/ex5.c @@ -70,7 +70,7 @@ int main (int argc, char *argv[]) MPI_Comm_size(MPI_COMM_WORLD, &num_procs); /* Initialize HYPRE */ - HYPRE_Init(); + HYPRE_Initialize(); /* Print GPU info */ /* HYPRE_PrintDeviceInfo(); */ diff --git a/src/examples/ex5big.c b/src/examples/ex5big.c index c4d14effa..29bc872d4 100644 --- a/src/examples/ex5big.c +++ b/src/examples/ex5big.c @@ -73,7 +73,7 @@ int main (int argc, char *argv[]) MPI_Comm_size(MPI_COMM_WORLD, &num_procs); /* Initialize HYPRE */ - HYPRE_Init(); + HYPRE_Initialize(); /* Default problem parameters */ n = 33; diff --git a/src/examples/ex5cuf.cuf b/src/examples/ex5cuf.cuf index b13395e05..f94813229 100644 --- a/src/examples/ex5cuf.cuf +++ b/src/examples/ex5cuf.cuf @@ -86,7 +86,7 @@ call MPI_COMM_SIZE(MPI_COMM_WORLD, num_procs, ierr) mpi_comm = MPI_COMM_WORLD - call HYPRE_Init(ierr) + call HYPRE_Initialize(ierr) call HYPRE_SetMemoryLocation(HYPRE_MEMORY_DEVICE, ierr) call HYPRE_SetExecutionPolicy(HYPRE_EXEC_DEVICE, ierr) diff --git a/src/examples/ex5f.f b/src/examples/ex5f.f index 88df9279d..a7dd56fb5 100644 --- a/src/examples/ex5f.f +++ b/src/examples/ex5f.f @@ -79,14 +79,14 @@ call MPI_COMM_SIZE(MPI_COMM_WORLD, num_procs, ierr) mpi_comm = MPI_COMM_WORLD - call HYPRE_Init(ierr) + call HYPRE_Initialize(ierr) call HYPRE_SetMemoryLocation(HYPRE_MEMORY_DEVICE, ierr) call HYPRE_SetExecutionPolicy(HYPRE_EXEC_DEVICE, ierr) call HYPRE_SetSpGemmUseVendor(0, ierr) -! Call omp target after HYPRE_Init() +! Call omp target after HYPRE_Initialize() !$omp target enter data map(alloc:rhs_values) !$omp target enter data map(alloc:x_values) diff --git a/src/examples/ex5f_cptr.f b/src/examples/ex5f_cptr.f index c92e96c61..bc6bb95c8 100644 --- a/src/examples/ex5f_cptr.f +++ b/src/examples/ex5f_cptr.f @@ -108,7 +108,7 @@ call MPI_COMM_SIZE(MPI_COMM_WORLD, num_procs, ierr) mpi_comm = MPI_COMM_WORLD - call HYPRE_Init(ierr) + call HYPRE_Initialize(ierr) call HYPRE_SetMemoryLocation(HYPRE_MEMORY_DEVICE, ierr) call HYPRE_SetExecutionPolicy(HYPRE_EXEC_DEVICE, ierr) diff --git a/src/examples/ex6.c b/src/examples/ex6.c index ae6db5e1d..14c529773 100644 --- a/src/examples/ex6.c +++ b/src/examples/ex6.c @@ -63,7 +63,7 @@ int main (int argc, char *argv[]) MPI_Comm_size(MPI_COMM_WORLD, &num_procs); /* Initialize HYPRE */ - HYPRE_Init(); + HYPRE_Initialize(); /* Print GPU info */ /* HYPRE_PrintDeviceInfo(); */ diff --git a/src/examples/ex7.c b/src/examples/ex7.c index 5e895b27b..a00344d56 100644 --- a/src/examples/ex7.c +++ b/src/examples/ex7.c @@ -244,7 +244,7 @@ int main (int argc, char *argv[]) MPI_Comm_size(MPI_COMM_WORLD, &num_procs); /* Initialize HYPRE */ - HYPRE_Init(); + HYPRE_Initialize(); /* Print GPU info */ /* HYPRE_PrintDeviceInfo(); */ diff --git a/src/examples/ex8.c b/src/examples/ex8.c index bc5afae52..c4ebd475a 100644 --- a/src/examples/ex8.c +++ b/src/examples/ex8.c @@ -61,7 +61,7 @@ int main (int argc, char *argv[]) MPI_Comm_size(MPI_COMM_WORLD, &num_procs); /* Initialize HYPRE */ - HYPRE_Init(); + HYPRE_Initialize(); /* Print GPU info */ /* HYPRE_PrintDeviceInfo(); */ diff --git a/src/examples/ex9.c b/src/examples/ex9.c index 805cf5c10..a21441e19 100644 --- a/src/examples/ex9.c +++ b/src/examples/ex9.c @@ -88,7 +88,7 @@ int main (int argc, char *argv[]) MPI_Comm_size(MPI_COMM_WORLD, &num_procs); /* Initialize HYPRE */ - HYPRE_Init(); + HYPRE_Initialize(); /* Print GPU info */ /* HYPRE_PrintDeviceInfo(); */ diff --git a/src/test/TEST_ij/state.jobs b/src/test/TEST_ij/state.jobs new file mode 100644 index 000000000..20badf211 --- /dev/null +++ b/src/test/TEST_ij/state.jobs @@ -0,0 +1,12 @@ +#!/bin/sh +# Copyright (c) 1998 Lawrence Livermore National Security, LLC and other +# HYPRE Project Developers. See the top-level COPYRIGHT file for details. +# +# SPDX-License-Identifier: (Apache-2.0 OR MIT) + +#============================================================================= +# Test library initialization (sequential and parallel) +#============================================================================= + +mpirun -np 1 ./ij -test_init > state.out.1 +mpirun -np 4 ./ij -test_init > state.out.100 diff --git a/src/test/TEST_ij/state.saved b/src/test/TEST_ij/state.saved new file mode 100644 index 000000000..911e5e902 --- /dev/null +++ b/src/test/TEST_ij/state.saved @@ -0,0 +1,13 @@ +# Output file: state.out.1 +hypre library has not been initialized or finalized yet +hypre library has been initialized +hypre library has been finalized +hypre library has been re-initialized +hypre library has been finalized + +# Output file: state.out.100 +hypre library has not been initialized or finalized yet +hypre library has been initialized +hypre library has been finalized +hypre library has been re-initialized +hypre library has been finalized diff --git a/src/test/TEST_ij/state.saved.florentia b/src/test/TEST_ij/state.saved.florentia new file mode 100644 index 000000000..911e5e902 --- /dev/null +++ b/src/test/TEST_ij/state.saved.florentia @@ -0,0 +1,13 @@ +# Output file: state.out.1 +hypre library has not been initialized or finalized yet +hypre library has been initialized +hypre library has been finalized +hypre library has been re-initialized +hypre library has been finalized + +# Output file: state.out.100 +hypre library has not been initialized or finalized yet +hypre library has been initialized +hypre library has been finalized +hypre library has been re-initialized +hypre library has been finalized diff --git a/src/test/TEST_ij/state.saved.lassen b/src/test/TEST_ij/state.saved.lassen new file mode 100644 index 000000000..911e5e902 --- /dev/null +++ b/src/test/TEST_ij/state.saved.lassen @@ -0,0 +1,13 @@ +# Output file: state.out.1 +hypre library has not been initialized or finalized yet +hypre library has been initialized +hypre library has been finalized +hypre library has been re-initialized +hypre library has been finalized + +# Output file: state.out.100 +hypre library has not been initialized or finalized yet +hypre library has been initialized +hypre library has been finalized +hypre library has been re-initialized +hypre library has been finalized diff --git a/src/test/TEST_ij/state.saved.lassen_cpu b/src/test/TEST_ij/state.saved.lassen_cpu new file mode 100644 index 000000000..911e5e902 --- /dev/null +++ b/src/test/TEST_ij/state.saved.lassen_cpu @@ -0,0 +1,13 @@ +# Output file: state.out.1 +hypre library has not been initialized or finalized yet +hypre library has been initialized +hypre library has been finalized +hypre library has been re-initialized +hypre library has been finalized + +# Output file: state.out.100 +hypre library has not been initialized or finalized yet +hypre library has been initialized +hypre library has been finalized +hypre library has been re-initialized +hypre library has been finalized diff --git a/src/test/TEST_ij/state.sh b/src/test/TEST_ij/state.sh new file mode 100755 index 000000000..fa5b5a10e --- /dev/null +++ b/src/test/TEST_ij/state.sh @@ -0,0 +1,22 @@ +#!/bin/sh +# Copyright (c) 1998 Lawrence Livermore National Security, LLC and other +# HYPRE Project Developers. See the top-level COPYRIGHT file for details. +# +# SPDX-License-Identifier: (Apache-2.0 OR MIT) + +TNAME=`basename $0 .sh` + +#============================================================================= +# Compare with baseline case +#============================================================================= + +FILES="\ + ${TNAME}.out.1\ + ${TNAME}.out.100\ +" + +for i in $FILES +do + echo "# Output file: $i" + tail -3 $i +done > ${TNAME}.out diff --git a/src/test/ams_driver.c b/src/test/ams_driver.c index bb587ac25..95a39eb9e 100644 --- a/src/test/ams_driver.c +++ b/src/test/ams_driver.c @@ -135,14 +135,14 @@ hypre_int main (hypre_int argc, char *argv[]) /*----------------------------------------------------------------- * GPU Device binding - * Must be done before HYPRE_Init() and should not be changed after + * Must be done before HYPRE_Initialize() and should not be changed after *-----------------------------------------------------------------*/ hypre_bind_device(myid, num_procs, hypre_MPI_COMM_WORLD); /*----------------------------------------------------------- * Initialize : must be the first HYPRE function to call *-----------------------------------------------------------*/ - HYPRE_Init(); + HYPRE_Initialize(); /* default memory location */ HYPRE_SetMemoryLocation(memory_location); diff --git a/src/test/ij.c b/src/test/ij.c index 4c60e0f3e..bb3d3f439 100644 --- a/src/test/ij.c +++ b/src/test/ij.c @@ -209,6 +209,7 @@ main( hypre_int argc, HYPRE_Real Q_trunc = 0; /* Specific tests */ + HYPRE_Int test_init = 0; HYPRE_Int test_ij = 0; HYPRE_Int test_multivec = 0; HYPRE_Int test_scaling = 0; @@ -481,19 +482,75 @@ main( hypre_int argc, hypre_MPI_Comm_size(hypre_MPI_COMM_WORLD, &num_procs ); hypre_MPI_Comm_rank(hypre_MPI_COMM_WORLD, &myid ); + /* Should we test library initialization? */ + for (arg_index = 1; arg_index < argc; arg_index ++) + { + if (strcmp(argv[arg_index], "-test_init") == 0) + { + test_init = 1; + break; + } + } + /*----------------------------------------------------------------- * GPU Device binding - * Must be done before HYPRE_Init() and should not be changed after + * Must be done before HYPRE_Initialize() and should not be changed after *-----------------------------------------------------------------*/ hypre_bind_device(myid, num_procs, hypre_MPI_COMM_WORLD); - time_index = hypre_InitializeTiming("Hypre init"); - hypre_BeginTiming(time_index); - /*----------------------------------------------------------- * Initialize : must be the first HYPRE function to call *-----------------------------------------------------------*/ - HYPRE_Init(); + + if (test_init) + { + /* The library should not be initialized or finalized */ + if (!HYPRE_Initialized() && !HYPRE_Finalized()) + { + hypre_ParPrintf(hypre_MPI_COMM_WORLD, "hypre library has not been initialized or finalized yet\n"); + } + + HYPRE_Initialize(); + + /* Check if the library is in initialized state */ + if (HYPRE_Initialized() && !HYPRE_Finalized()) + { + hypre_ParPrintf(hypre_MPI_COMM_WORLD, "hypre library has been initialized\n"); + } + + HYPRE_Finalize(); + + /* Check if the library is in finalized state */ + if (!HYPRE_Initialized() && HYPRE_Finalized()) + { + hypre_ParPrintf(hypre_MPI_COMM_WORLD, "hypre library has been finalized\n"); + } + + HYPRE_Initialize(); + + /* Check if the library is in initialized state */ + if (HYPRE_Initialized() && !HYPRE_Finalized()) + { + hypre_ParPrintf(hypre_MPI_COMM_WORLD, "hypre library has been re-initialized\n"); + } + + HYPRE_Finalize(); + + /* Check if the library is in finalized state */ + if (!HYPRE_Initialized() && HYPRE_Finalized()) + { + hypre_ParPrintf(hypre_MPI_COMM_WORLD, "hypre library has been finalized\n"); + } + + hypre_MPI_Finalize(); + + return 0; + } + + time_index = hypre_InitializeTiming("Hypre init"); + hypre_BeginTiming(time_index); + + HYPRE_Initialize(); hypre_EndTiming(time_index); hypre_PrintTiming("Hypre init times", hypre_MPI_COMM_WORLD); diff --git a/src/test/ij_assembly.c b/src/test/ij_assembly.c index d7117fafe..abf22e5c3 100644 --- a/src/test/ij_assembly.c +++ b/src/test/ij_assembly.c @@ -115,7 +115,7 @@ main( hypre_int argc, /*----------------------------------------------------------------- * GPU Device binding - * Must be done before HYPRE_Init() and should not be changed after + * Must be done before HYPRE_Initialize() and should not be changed after *-----------------------------------------------------------------*/ hypre_bind_device(myid, num_procs, hypre_MPI_COMM_WORLD); @@ -123,7 +123,7 @@ main( hypre_int argc, /* Initialize Hypre: must be the first Hypre function to call */ time_index = hypre_InitializeTiming("Hypre init"); hypre_BeginTiming(time_index); - HYPRE_Init(); + HYPRE_Initialize(); hypre_EndTiming(time_index); hypre_PrintTiming("Hypre init times", hypre_MPI_COMM_WORLD); hypre_FinalizeTiming(time_index); diff --git a/src/test/ij_device.c b/src/test/ij_device.c index 7debec0ae..02dec86f1 100644 --- a/src/test/ij_device.c +++ b/src/test/ij_device.c @@ -116,14 +116,14 @@ main( hypre_int argc, /*----------------------------------------------------------------- * GPU Device binding - * Must be done before HYPRE_Init() and should not be changed after + * Must be done before HYPRE_Initialize() and should not be changed after *-----------------------------------------------------------------*/ hypre_bind_device(myid, num_procs, hypre_MPI_COMM_WORLD); /*----------------------------------------------------------- * Initialize : must be the first HYPRE function to call *-----------------------------------------------------------*/ - HYPRE_Init(); + HYPRE_Initialize(); hypre_SetNumThreads(5); hypre_printf("CPU #OMP THREADS %d\n", hypre_NumThreads()); diff --git a/src/test/ij_mm.c b/src/test/ij_mm.c index f4a9b1f7c..25b554a86 100644 --- a/src/test/ij_mm.c +++ b/src/test/ij_mm.c @@ -787,14 +787,14 @@ main( hypre_int argc, /*----------------------------------------------------------------- * GPU Device binding - * Must be done before HYPRE_Init() and should not be changed after + * Must be done before HYPRE_Initialize() and should not be changed after *-----------------------------------------------------------------*/ hypre_bind_device(myid, num_procs, hypre_MPI_COMM_WORLD); /*----------------------------------------------------------- * Initialize : must be the first HYPRE function to call *-----------------------------------------------------------*/ - HYPRE_Init(); + HYPRE_Initialize(); if (myid == 0) { diff --git a/src/test/maxwell_unscaled.c b/src/test/maxwell_unscaled.c index 093f7884a..d6e5a1ded 100644 --- a/src/test/maxwell_unscaled.c +++ b/src/test/maxwell_unscaled.c @@ -1377,14 +1377,14 @@ main( hypre_int argc, /*----------------------------------------------------------------- * GPU Device binding - * Must be done before HYPRE_Init() and should not be changed after + * Must be done before HYPRE_Initialize() and should not be changed after *-----------------------------------------------------------------*/ hypre_bind_device(myid, num_procs, hypre_MPI_COMM_WORLD); /*----------------------------------------------------------- * Initialize : must be the first HYPRE function to call *-----------------------------------------------------------*/ - HYPRE_Init(); + HYPRE_Initialize(); /*----------------------------------------------------------- * Read input file @@ -2028,4 +2028,3 @@ main( hypre_int argc, return (0); } - diff --git a/src/test/sstruct.c b/src/test/sstruct.c index 225aaeb3b..170048aea 100644 --- a/src/test/sstruct.c +++ b/src/test/sstruct.c @@ -2469,14 +2469,14 @@ main( hypre_int argc, /*----------------------------------------------------------------- * GPU Device binding - * Must be done before HYPRE_Init() and should not be changed after + * Must be done before HYPRE_Initialize() and should not be changed after *-----------------------------------------------------------------*/ hypre_bind_device(myid, num_procs, comm); /*----------------------------------------------------------- * Initialize : must be the first HYPRE function to call *-----------------------------------------------------------*/ - HYPRE_Init(); + HYPRE_Initialize(); /*----------------------------------------------------------- * Set defaults diff --git a/src/test/sstruct_fac.c b/src/test/sstruct_fac.c index 1c8cd2ec7..71792c3cf 100644 --- a/src/test/sstruct_fac.c +++ b/src/test/sstruct_fac.c @@ -1299,14 +1299,14 @@ main( hypre_int argc, /*----------------------------------------------------------------- * GPU Device binding - * Must be done before HYPRE_Init() and should not be changed after + * Must be done before HYPRE_Initialize() and should not be changed after *-----------------------------------------------------------------*/ hypre_bind_device(myid, num_procs, hypre_MPI_COMM_WORLD); /*----------------------------------------------------------- * Initialize : must be the first HYPRE function to call *-----------------------------------------------------------*/ - HYPRE_Init(); + HYPRE_Initialize(); /*----------------------------------------------------------- * Read input file diff --git a/src/test/struct.c b/src/test/struct.c index a61c20570..6e9c14e18 100644 --- a/src/test/struct.c +++ b/src/test/struct.c @@ -199,14 +199,14 @@ main( hypre_int argc, /*----------------------------------------------------------------- * GPU Device binding - * Must be done before HYPRE_Init() and should not be changed after + * Must be done before HYPRE_Initialize() and should not be changed after *-----------------------------------------------------------------*/ hypre_bind_device(myid, num_procs, hypre_MPI_COMM_WORLD); /*----------------------------------------------------------- * Initialize : must be the first HYPRE function to call *-----------------------------------------------------------*/ - HYPRE_Init(); + HYPRE_Initialize(); #if defined(HYPRE_USING_KOKKOS) Kokkos::initialize (argc, argv); diff --git a/src/test/struct_migrate.c b/src/test/struct_migrate.c index cbbdc67e9..d5bdf2002 100644 --- a/src/test/struct_migrate.c +++ b/src/test/struct_migrate.c @@ -65,14 +65,14 @@ main( hypre_int argc, /*----------------------------------------------------------------- * GPU Device binding - * Must be done before HYPRE_Init() and should not be changed after + * Must be done before HYPRE_Initialize() and should not be changed after *-----------------------------------------------------------------*/ hypre_bind_device(myid, num_procs, hypre_MPI_COMM_WORLD); /*----------------------------------------------------------- * Initialize : must be the first HYPRE function to call *-----------------------------------------------------------*/ - HYPRE_Init(); + HYPRE_Initialize(); #if defined(HYPRE_USING_KOKKOS) Kokkos::initialize (argc, argv); @@ -477,4 +477,3 @@ AddValuesVector( hypre_StructGrid *grid, return ierr; } - diff --git a/src/test/test_mgr.c b/src/test/test_mgr.c index cff116a62..2801357cc 100644 --- a/src/test/test_mgr.c +++ b/src/test/test_mgr.c @@ -275,14 +275,14 @@ main( hypre_int argc, /*----------------------------------------------------------- * Initialize : must be the first HYPRE function to call *-----------------------------------------------------------*/ - HYPRE_Init(); + HYPRE_Initialize(); hypre_EndTiming(time_index); hypre_PrintTiming("Hypre init times", hypre_MPI_COMM_WORLD); hypre_FinalizeTiming(time_index); hypre_ClearTiming(); - /* To be effective, hypre_SetCubMemPoolSize must immediately follow HYPRE_Init */ + /* To be effective, hypre_SetCubMemPoolSize must immediately follow HYPRE_Initialize */ hypre_SetCubMemPoolSize( mempool_bin_growth, mempool_min_bin, mempool_max_bin, mempool_max_cached_bytes ); @@ -1168,5 +1168,3 @@ BuildParFromFile( HYPRE_Int argc, return (0); } - - diff --git a/src/test/test_mgr_gpu.c b/src/test/test_mgr_gpu.c index 9b700b32d..b1ae18bd2 100644 --- a/src/test/test_mgr_gpu.c +++ b/src/test/test_mgr_gpu.c @@ -287,7 +287,7 @@ main( hypre_int argc, /*----------------------------------------------------------- * Initialize : must be the first HYPRE function to call *-----------------------------------------------------------*/ - HYPRE_Init(); + HYPRE_Initialize(); hypre_EndTiming(time_index); hypre_PrintTiming("Hypre init times", hypre_MPI_COMM_WORLD); diff --git a/src/test/zboxloop.c b/src/test/zboxloop.c index 55d711c03..b4c697b72 100644 --- a/src/test/zboxloop.c +++ b/src/test/zboxloop.c @@ -50,7 +50,7 @@ main( hypre_int argc, hypre_MPI_Comm_size(hypre_MPI_COMM_WORLD, &num_procs ); hypre_MPI_Comm_rank(hypre_MPI_COMM_WORLD, &myid ); - HYPRE_Init(); + HYPRE_Initialize(); #if defined(HYPRE_USING_KOKKOS) Kokkos::initialize (argc, argv); @@ -584,4 +584,3 @@ main( hypre_int argc, return (0); } - diff --git a/src/utilities/CMakeLists.txt b/src/utilities/CMakeLists.txt index 926e3075c..b1d8d8179 100644 --- a/src/utilities/CMakeLists.txt +++ b/src/utilities/CMakeLists.txt @@ -45,6 +45,7 @@ set(SRCS mpistubs.c qsplit.c random.c + state.c threading.c timer.c timing.c diff --git a/src/utilities/F90_HYPRE_general.c b/src/utilities/F90_HYPRE_general.c index 39a02f1a6..9ad6bf934 100644 --- a/src/utilities/F90_HYPRE_general.c +++ b/src/utilities/F90_HYPRE_general.c @@ -16,7 +16,14 @@ void hypre_F90_IFACE(hypre_init, HYPRE_INIT) (hypre_F90_Int *ierr) { - *ierr = (hypre_F90_Int) HYPRE_Init(); + *ierr = (hypre_F90_Int) HYPRE_Initialize(); +} + +void +hypre_F90_IFACE(hypre_initialize, HYPRE_INITIALIZE) +(hypre_F90_Int *ierr) +{ + *ierr = (hypre_F90_Int) HYPRE_Initialize(); } void diff --git a/src/utilities/HYPRE_utilities.h b/src/utilities/HYPRE_utilities.h index 09d651e75..8b3e19163 100644 --- a/src/utilities/HYPRE_utilities.h +++ b/src/utilities/HYPRE_utilities.h @@ -122,9 +122,39 @@ typedef HYPRE_Int MPI_Comm; * HYPRE init/finalize *--------------------------------------------------------------------------*/ -HYPRE_Int HYPRE_Init(void); +/** + * Initializes the hypre library. + **/ + +HYPRE_Int HYPRE_Initialize(void); + +/** + * (Required) Initializes the hypre library. This function is provided for backward compatibility. + * Please, use HYPRE_Initialize instead. + **/ + +#define HYPRE_Init() \ + HYPRE_DEPRECATED("GCC warning \"HYPRE_Init is deprecated. Use HYPRE_Initialize() instead.\"") \ + HYPRE_Initialize() + +/** + * (Required) Finalizes the hypre library. + **/ + HYPRE_Int HYPRE_Finalize(void); +/** + * (Optional) Returns true if the hypre library has been initialized but not finalized yet. + **/ + +HYPRE_Int HYPRE_Initialized(void); + +/** + * (Optional) Returns true if the hypre library has been finalized but not re-initialized yet. + **/ + +HYPRE_Int HYPRE_Finalized(void); + /*-------------------------------------------------------------------------- * HYPRE error user functions *--------------------------------------------------------------------------*/ diff --git a/src/utilities/Makefile b/src/utilities/Makefile index a1bf632cf..b5f789924 100644 --- a/src/utilities/Makefile +++ b/src/utilities/Makefile @@ -61,6 +61,7 @@ FILES =\ mpistubs.c\ qsplit.c\ random.c\ + state.c\ threading.c\ timer.c\ timing.c diff --git a/src/utilities/_hypre_utilities.h b/src/utilities/_hypre_utilities.h index 37fa8adc2..c6e21e8cb 100644 --- a/src/utilities/_hypre_utilities.h +++ b/src/utilities/_hypre_utilities.h @@ -14,6 +14,30 @@ extern "C" { #endif +/****************************************************************************** + * Copyright (c) 1998 Lawrence Livermore National Security, LLC and other + * HYPRE Project Developers. See the top-level COPYRIGHT file for details. + * + * SPDX-License-Identifier: (Apache-2.0 OR MIT) + ******************************************************************************/ + +#ifndef hypre_STATE_HEADER +#define hypre_STATE_HEADER + +/*-------------------------------------------------------------------------- + * hypre library state + *--------------------------------------------------------------------------*/ + +typedef enum hypre_State_enum +{ + HYPRE_STATE_NONE = 0, + HYPRE_STATE_INITIALIZED = 1, + HYPRE_STATE_FINALIZED = 2 +} hypre_State; + +extern hypre_State hypre__global_state; + +#endif /* hypre_STATE_HEADER */ /****************************************************************************** * Copyright (c) 1998 Lawrence Livermore National Security, LLC and other * HYPRE Project Developers. See the top-level COPYRIGHT file for details. @@ -32,6 +56,10 @@ extern "C" { #include +/*-------------------------------------------------------------------------- + * typedefs + *--------------------------------------------------------------------------*/ + /* This allows us to consistently avoid 'int' throughout hypre */ typedef int hypre_int; typedef long int hypre_longint; @@ -166,7 +194,6 @@ typedef double hypre_double; #endif #endif /* hypre_GENERAL_HEADER */ - /****************************************************************************** * Copyright (c) 1998 Lawrence Livermore National Security, LLC and other * HYPRE Project Developers. See the top-level COPYRIGHT file for details. @@ -1719,6 +1746,12 @@ HYPRE_Complex hypre_csqrt( HYPRE_Complex value ); #define hypre_csqrt(value) hypre_sqrt(value) #endif +/* state.c */ +HYPRE_Int hypre_Initialized( void ); +HYPRE_Int hypre_Finalized( void ); +HYPRE_Int hypre_SetInitialized( void ); +HYPRE_Int hypre_SetFinalized( void ); + /* general.c */ hypre_Handle* hypre_handle(void); hypre_Handle* hypre_HandleCreate(void); diff --git a/src/utilities/device_utils.c b/src/utilities/device_utils.c index 07fa8bba8..c59d0ee06 100644 --- a/src/utilities/device_utils.c +++ b/src/utilities/device_utils.c @@ -2190,7 +2190,7 @@ hypreGPUKernel_CompileFlagSafetyCheck( hypre_DeviceItem &item, /*-------------------------------------------------------------------- * hypre_CudaCompileFlagCheck * - * Assume this function is called inside HYPRE_Init(), at a place + * Assume this function is called inside HYPRE_Initialize(), at a place * where we do not want to activate memory pooling, so we do not use * hypre's memory model to Alloc and Free. * diff --git a/src/utilities/general.c b/src/utilities/general.c index cdc5c20f7..a9c842155 100644 --- a/src/utilities/general.c +++ b/src/utilities/general.c @@ -20,8 +20,8 @@ hypre_handle(void) if (!_hypre_handle) { hypre_error_w_msg(HYPRE_ERROR_GENERIC, - "ERROR - _hypre_handle is not initialized. Calling HYPRE_Init(). All HYPRE_* or hypre_* function calls should occur between HYPRE_Init() and HYPRE_Finalize().\n"); - HYPRE_Init(); + "ERROR - _hypre_handle is not initialized. Calling HYPRE_Initialize(). All HYPRE_* or hypre_* function calls should occur between HYPRE_Initialize() and HYPRE_Finalize().\n"); + HYPRE_Initialize(); } return _hypre_handle; @@ -235,8 +235,17 @@ hypre_GetDeviceLastError(void) *****************************************************************************/ HYPRE_Int -HYPRE_Init(void) +HYPRE_Initialize(void) { + /* Return if the hypre library is in initialized state */ + if (hypre_Initialized()) + { + return hypre_error_flag; + } + + /* Update library state */ + hypre_SetInitialized(); + #ifdef HYPRE_USING_MEMORY_TRACKER if (!_hypre_memory_tracker) { @@ -250,75 +259,81 @@ HYPRE_Init(void) } #if defined(HYPRE_USING_GPU) || defined(HYPRE_USING_DEVICE_OPENMP) + /* If the library has not been initialized or finalized yet, + meaning that it is the first time HYPRE_Init is being called, + then perform the initialization of device structures below */ + if (!HYPRE_Initialized() && !HYPRE_Finalized()) + { #if !defined(HYPRE_USING_SYCL) - /* With sycl, cannot call hypre_GetDeviceLastError() until after device and queue setup */ - hypre_GetDeviceLastError(); + /* With sycl, cannot call hypre_GetDeviceLastError() until after device and queue setup */ + hypre_GetDeviceLastError(); #endif - /* Notice: the cudaStream created is specific to the device - * that was in effect when you created the stream. - * So, we should first set the device and create the streams - */ - hypre_int device_id; - hypre_GetDevice(&device_id); - hypre_SetDevice(device_id, _hypre_handle); - hypre_GetDeviceMaxShmemSize(device_id, _hypre_handle); + /* Notice: the cudaStream created is specific to the device + * that was in effect when you created the stream. + * So, we should first set the device and create the streams + */ + hypre_int device_id; + hypre_GetDevice(&device_id); + hypre_SetDevice(device_id, _hypre_handle); + hypre_GetDeviceMaxShmemSize(device_id, _hypre_handle); #if defined(HYPRE_USING_DEVICE_MALLOC_ASYNC) - cudaMemPool_t mempool; - cudaDeviceGetDefaultMemPool(&mempool, device_id); - uint64_t threshold = UINT64_MAX; - cudaMemPoolSetAttribute(mempool, cudaMemPoolAttrReleaseThreshold, &threshold); + cudaMemPool_t mempool; + cudaDeviceGetDefaultMemPool(&mempool, device_id); + uint64_t threshold = UINT64_MAX; + cudaMemPoolSetAttribute(mempool, cudaMemPoolAttrReleaseThreshold, &threshold); #endif - /* To include the cost of creating streams/cudahandles in HYPRE_Init */ - /* If not here, will be done at the first use */ + /* To include the cost of creating streams/cudahandles in HYPRE_Init */ + /* If not here, will be done at the first use */ #if defined(HYPRE_USING_CUDA_STREAMS) - hypre_HandleComputeStream(_hypre_handle); + hypre_HandleComputeStream(_hypre_handle); #endif - /* A separate stream for prefetching */ - //hypre_HandleCudaPrefetchStream(_hypre_handle); -#endif // #if defined(HYPRE_USING_GPU) || defined(HYPRE_USING_DEVICE_OPENMP) + /* A separate stream for prefetching */ + //hypre_HandleCudaPrefetchStream(_hypre_handle); #if defined(HYPRE_USING_CUBLAS) - hypre_HandleCublasHandle(_hypre_handle); + hypre_HandleCublasHandle(_hypre_handle); #endif #if defined(HYPRE_USING_CUSPARSE) || defined(HYPRE_USING_ROCSPARSE) - hypre_HandleCusparseHandle(_hypre_handle); + hypre_HandleCusparseHandle(_hypre_handle); #endif #if defined(HYPRE_USING_CURAND) || defined(HYPRE_USING_ROCRAND) - hypre_HandleCurandGenerator(_hypre_handle); + hypre_HandleCurandGenerator(_hypre_handle); #endif #if defined(HYPRE_USING_CUSOLVER) || defined(HYPRE_USING_ROCSOLVER) - hypre_HandleVendorSolverHandle(_hypre_handle); + hypre_HandleVendorSolverHandle(_hypre_handle); #endif /* Check if cuda arch flags in compiling match the device */ #if defined(HYPRE_USING_CUDA) && defined(HYPRE_DEBUG) - hypre_CudaCompileFlagCheck(); -#endif - -#if defined(HYPRE_USING_DEVICE_OPENMP) - HYPRE_OMPOffloadOn(); + hypre_CudaCompileFlagCheck(); #endif #if defined(HYPRE_USING_DEVICE_POOL) - /* Keep this check here at the end of HYPRE_Init() - * Make sure that device pool allocator has not been setup in HYPRE_Init, - * otherwise users are not able to set all the parameters - */ - if ( hypre_HandleCubDevAllocator(_hypre_handle) || - hypre_HandleCubUvmAllocator(_hypre_handle) ) - { - char msg[256]; - hypre_sprintf(msg, "%s %s", "ERROR: device pool allocators have been created in", __func__); - hypre_fprintf(stderr, "%s\n", msg); - hypre_error_w_msg(-1, msg); + /* Keep this check here at the end of HYPRE_Initialize() + * Make sure that device pool allocator has not been setup in HYPRE_Initialize, + * otherwise users are not able to set all the parameters + */ + if ( hypre_HandleCubDevAllocator(_hypre_handle) || + hypre_HandleCubUvmAllocator(_hypre_handle) ) + { + char msg[256]; + hypre_sprintf(msg, "%s %s", "ERROR: device pool allocators have been created in", __func__); + hypre_fprintf(stderr, "%s\n", msg); + hypre_error_w_msg(-1, msg); + } +#endif } +#endif /* if defined(HYPRE_USING_GPU) || defined(HYPRE_USING_DEVICE_OPENMP) */ + +#if defined(HYPRE_USING_DEVICE_OPENMP) + HYPRE_OMPOffloadOn(); #endif #if defined(HYPRE_USING_UMPIRE) @@ -337,6 +352,15 @@ HYPRE_Init(void) HYPRE_Int HYPRE_Finalize(void) { + /* Return if the hypre library has already been finalized */ + if (hypre_Finalized()) + { + return hypre_error_flag; + } + + /* Update library state */ + hypre_SetFinalized(); + #if defined(HYPRE_USING_UMPIRE) hypre_UmpireFinalize(_hypre_handle); #endif diff --git a/src/utilities/general.h b/src/utilities/general.h index 3e49020cc..b5bd30089 100644 --- a/src/utilities/general.h +++ b/src/utilities/general.h @@ -16,6 +16,10 @@ #include +/*-------------------------------------------------------------------------- + * typedefs + *--------------------------------------------------------------------------*/ + /* This allows us to consistently avoid 'int' throughout hypre */ typedef int hypre_int; typedef long int hypre_longint; @@ -150,4 +154,3 @@ typedef double hypre_double; #endif #endif /* hypre_GENERAL_HEADER */ - diff --git a/src/utilities/headers b/src/utilities/headers index 6ac3fa534..ba681a34a 100755 --- a/src/utilities/headers +++ b/src/utilities/headers @@ -33,6 +33,7 @@ extern "C" { # Structures and prototypes #=========================================================================== +cat state.h >> $INTERNAL_HEADER cat general.h >> $INTERNAL_HEADER cat printf.h >> $INTERNAL_HEADER cat error.h >> $INTERNAL_HEADER @@ -110,4 +111,3 @@ cat >> $INTERNAL_HEADER <<@ #endif @ - diff --git a/src/utilities/protos.h b/src/utilities/protos.h index 9e398f9ec..8770dc545 100644 --- a/src/utilities/protos.h +++ b/src/utilities/protos.h @@ -39,6 +39,12 @@ HYPRE_Complex hypre_csqrt( HYPRE_Complex value ); #define hypre_csqrt(value) hypre_sqrt(value) #endif +/* state.c */ +HYPRE_Int hypre_Initialized( void ); +HYPRE_Int hypre_Finalized( void ); +HYPRE_Int hypre_SetInitialized( void ); +HYPRE_Int hypre_SetFinalized( void ); + /* general.c */ hypre_Handle* hypre_handle(void); hypre_Handle* hypre_HandleCreate(void); diff --git a/src/utilities/state.c b/src/utilities/state.c new file mode 100644 index 000000000..ed3caca05 --- /dev/null +++ b/src/utilities/state.c @@ -0,0 +1,88 @@ +/****************************************************************************** + * Copyright (c) 1998 Lawrence Livermore National Security, LLC and other + * HYPRE Project Developers. See the top-level COPYRIGHT file for details. + * + * SPDX-License-Identifier: (Apache-2.0 OR MIT) + ******************************************************************************/ + +#include "_hypre_utilities.h" + +/* Global variable: library state (initialized, finalized, or none) */ +hypre_State hypre__global_state = HYPRE_STATE_NONE; + +/*-------------------------------------------------------------------------- + * HYPRE_Initialized + * + * Public function for hypre_Initialized + *--------------------------------------------------------------------------*/ + +HYPRE_Int +HYPRE_Initialized( void ) +{ + return hypre_Initialized(); +} + +/*-------------------------------------------------------------------------- + * HYPRE_Finalized + * + * Public function for hypre_Finalized + *--------------------------------------------------------------------------*/ + +HYPRE_Int +HYPRE_Finalized( void ) +{ + return hypre_Finalized(); +} + +/*-------------------------------------------------------------------------- + * hypre_Initialized + * + * This function returns True when the library has been initialized, but not + * finalized yet. + *--------------------------------------------------------------------------*/ + +HYPRE_Int +hypre_Initialized( void ) +{ + return (hypre__global_state == HYPRE_STATE_INITIALIZED); +} + +/*-------------------------------------------------------------------------- + * hypre_Finalized + * + * This function returns True when the library is in finalized state; + *--------------------------------------------------------------------------*/ + +HYPRE_Int +hypre_Finalized( void ) +{ + return (hypre__global_state == HYPRE_STATE_FINALIZED); +} + +/*-------------------------------------------------------------------------- + * hypre_SetInitialized + * + * This function sets the library state to initialized + *--------------------------------------------------------------------------*/ + +HYPRE_Int +hypre_SetInitialized( void ) +{ + hypre__global_state = HYPRE_STATE_INITIALIZED; + + return hypre_error_flag; +} + +/*-------------------------------------------------------------------------- + * hypre_SetFinalized + * + * This function sets the library state to finalized + *--------------------------------------------------------------------------*/ + +HYPRE_Int +hypre_SetFinalized( void ) +{ + hypre__global_state = HYPRE_STATE_FINALIZED; + + return hypre_error_flag; +} diff --git a/src/utilities/state.h b/src/utilities/state.h new file mode 100644 index 000000000..079449991 --- /dev/null +++ b/src/utilities/state.h @@ -0,0 +1,24 @@ +/****************************************************************************** + * Copyright (c) 1998 Lawrence Livermore National Security, LLC and other + * HYPRE Project Developers. See the top-level COPYRIGHT file for details. + * + * SPDX-License-Identifier: (Apache-2.0 OR MIT) + ******************************************************************************/ + +#ifndef hypre_STATE_HEADER +#define hypre_STATE_HEADER + +/*-------------------------------------------------------------------------- + * hypre library state + *--------------------------------------------------------------------------*/ + +typedef enum hypre_State_enum +{ + HYPRE_STATE_NONE = 0, + HYPRE_STATE_INITIALIZED = 1, + HYPRE_STATE_FINALIZED = 2 +} hypre_State; + +extern hypre_State hypre__global_state; + +#endif /* hypre_STATE_HEADER */