From ac2c8376d9e99293ca8ca5af3ad452a1d3d50924 Mon Sep 17 00:00:00 2001 From: "Jose E. Roman" Date: Tue, 23 Mar 2021 20:13:28 +0100 Subject: [PATCH] Sync with PETSc: update code that loads dynamic libraries --- src/eps/tutorials/ex2.c | 2 +- src/sys/slepcinit.c | 29 ++++++++++++++++------------- 2 files changed, 17 insertions(+), 14 deletions(-) diff --git a/src/eps/tutorials/ex2.c b/src/eps/tutorials/ex2.c index 20bfd0954..f09a5d2de 100644 --- a/src/eps/tutorials/ex2.c +++ b/src/eps/tutorials/ex2.c @@ -118,7 +118,7 @@ int main(int argc,char **argv) suffix: 1 test: suffix: 2 - args: -dynamic_library_preload + args: -library_preload testset: args: -n 30 -eps_type ciss -terse diff --git a/src/sys/slepcinit.c b/src/sys/slepcinit.c index f77d57c83..a78097480 100644 --- a/src/sys/slepcinit.c +++ b/src/sys/slepcinit.c @@ -138,7 +138,7 @@ static PetscErrorCode SlepcLoadDynamicLibrary(const char *name,PetscBool *found) } #endif -#if defined(PETSC_HAVE_THREADSAFETY) +#if defined(PETSC_USE_SINGLE_LIBRARY) && !(defined(PETSC_HAVE_DYNAMIC_LIBRARIES) && defined(PETSC_USE_SHARED_LIBRARIES)) SLEPC_EXTERN PetscErrorCode STInitializePackage(void); SLEPC_EXTERN PetscErrorCode DSInitializePackage(void); SLEPC_EXTERN PetscErrorCode FNInitializePackage(void); @@ -158,18 +158,19 @@ SLEPC_EXTERN PetscErrorCode LMEInitializePackage(void); */ PetscErrorCode SlepcInitialize_DynamicLibraries(void) { -#if (defined(PETSC_HAVE_DYNAMIC_LIBRARIES) && defined(PETSC_USE_SHARED_LIBRARIES)) || defined(PETSC_HAVE_THREADSAFETY) PetscErrorCode ierr; -#endif -#if defined(PETSC_HAVE_DYNAMIC_LIBRARIES) && defined(PETSC_USE_SHARED_LIBRARIES) - PetscBool found,preload; -#endif + PetscBool preload = PETSC_FALSE; PetscFunctionBegin; -#if defined(PETSC_HAVE_DYNAMIC_LIBRARIES) && defined(PETSC_USE_SHARED_LIBRARIES) - preload = PETSC_FALSE; - ierr = PetscOptionsGetBool(NULL,NULL,"-dynamic_library_preload",&preload,NULL);CHKERRQ(ierr); +#if defined(PETSC_HAVE_THREADSAFETY) + /* These must be all initialized here because it is not safe for individual threads to call these initialize routines */ + preload = PETSC_TRUE; +#endif + + ierr = PetscOptionsGetBool(NULL,NULL,"-library_preload",&preload,NULL);CHKERRQ(ierr); if (preload) { +#if defined(PETSC_HAVE_DYNAMIC_LIBRARIES) && defined(PETSC_USE_SHARED_LIBRARIES) + PetscBool found; #if defined(PETSC_USE_SINGLE_LIBRARY) ierr = SlepcLoadDynamicLibrary("",&found);CHKERRQ(ierr); if (!found) SETERRQ(PETSC_COMM_SELF,PETSC_ERR_FILE_OPEN,"Unable to locate SLEPc dynamic library\nYou cannot move the dynamic libraries!"); @@ -189,10 +190,8 @@ PetscErrorCode SlepcInitialize_DynamicLibraries(void) ierr = SlepcLoadDynamicLibrary("lme",&found);CHKERRQ(ierr); if (!found) SETERRQ(PETSC_COMM_SELF,PETSC_ERR_FILE_OPEN,"Unable to locate SLEPc LME dynamic library\nYou cannot move the dynamic libraries!"); #endif - } -#endif - -#if defined(PETSC_HAVE_THREADSAFETY) +#else /* defined(PETSC_HAVE_DYNAMIC_LIBRARIES) && defined(PETSC_USE_SHARED_LIBRARIES) */ +#if defined(PETSC_USE_SINGLE_LIBRARY) ierr = STInitializePackage();CHKERRQ(ierr); ierr = DSInitializePackage();CHKERRQ(ierr); ierr = FNInitializePackage();CHKERRQ(ierr); @@ -204,7 +203,11 @@ PetscErrorCode SlepcInitialize_DynamicLibraries(void) ierr = NEPInitializePackage();CHKERRQ(ierr); ierr = MFNInitializePackage();CHKERRQ(ierr); ierr = LMEInitializePackage();CHKERRQ(ierr); +#else + SETERRQ(PETSC_COMM_WORLD,PETSC_ERR_SUP,"Cannot use -library_preload with multiple static SLEPc libraries"); #endif +#endif /* defined(PETSC_HAVE_DYNAMIC_LIBRARIES) && defined(PETSC_USE_SHARED_LIBRARIES) */ + } #if defined(SLEPC_HAVE_HPDDM) ierr = KSPRegister(KSPHPDDM,KSPCreate_HPDDM);CHKERRQ(ierr);