Skip to content

Commit

Permalink
Merge branch 'jose/library-load' into 'main'
Browse files Browse the repository at this point in the history
Update code that loads dynamic libraries

See merge request slepc/slepc!179
  • Loading branch information
joseeroman committed Mar 24, 2021
2 parents bc79791 + ac2c837 commit 51b1ff1
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 14 deletions.
2 changes: 1 addition & 1 deletion src/eps/tutorials/ex2.c
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
29 changes: 16 additions & 13 deletions src/sys/slepcinit.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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!");
Expand All @@ -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);
Expand All @@ -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);
Expand Down

0 comments on commit 51b1ff1

Please sign in to comment.