1 #include <petscsys.h>
2 #include <petscmatelemental.h>
3 #include <petsc/private/petscimpl.h>
4
5 /*@
6 PetscElementalInitializePackage - Initialize Elemental package
7
8 Collective on `MPI_COMM_WORLD`, not `PETSC_COMM_WORLD`
9
10 Level: developer
11
12 Note:
13 Can be called outside of `PetscInitialize()` and `PetscFinalize()`.
14 If called outside of these functions, it is the user's responsibility
15 to make sure that `PETSC_COMM_WORLD` is either unset (default value is `MPI_COMM_NULL`),
16 or that it is not `MPI_UNEQUAL` to `MPI_COMM_WORLD`.
17 Users who do not have a custom `PETSC_COMM_WORLD` do not have to call this function.
18
19 .seealso: `MATELEMENTAL`, `PetscElementalFinalizePackage()`
20 @*/
PetscElementalInitializePackage(void)21 PetscErrorCode PetscElementalInitializePackage(void)
22 {
23 if (El::Initialized()) return PETSC_SUCCESS;
24 if (PETSC_COMM_WORLD != MPI_COMM_NULL) { /* MPI has been initialized and PETSC_COMM_WORLD has been set */
25 PetscMPIInt result;
26 PetscCallMPI(MPI_Comm_compare(PETSC_COMM_WORLD, MPI_COMM_WORLD, &result));
27 if (result == MPI_UNEQUAL) return PETSC_ERR_MPI; /* cannot use Elemental with PETSC_COMM_WORLD and MPI_COMM_WORLD comparing to MPI_UNEQUAL, call PetscElementalInitializePackage()/PetscElementalFinalizePackage() collectively */
28 }
29 El::Initialize(); /* called by PetscInitialize_DynamicLibraries(void) or users */
30 if (PetscInitializeCalled) { /* true if MPI is initialized by PETSc, false if MPI has been initialized outside and thus PETSC_COMM_WORLD can't be set to something else than MPI_COMM_NULL, see src/sys/objects/pinit.c */
31 PetscCall(PetscRegisterFinalize(PetscElementalFinalizePackage));
32 }
33 return PETSC_SUCCESS;
34 }
35
36 /*@
37 PetscElementalInitialized - Determine whether Elemental is initialized
38
39 Not Collective
40
41 Output Parameter:
42 . isInitialized - `PETSC_TRUE` if elemental is initialized, `PETSC_FALSE` otherwise
43
44 Level: developer
45
46 Note:
47 Can be called outside of `PetscInitialize()` and `PetscFinalize()`.
48
49 .seealso: `MATELEMENTAL`, `PetscElementalInitializePackage()`
50 @*/
PetscElementalInitialized(PetscBool * isInitialized)51 PetscErrorCode PetscElementalInitialized(PetscBool *isInitialized)
52 {
53 if (isInitialized) *isInitialized = (PetscBool)El::Initialized();
54 return PETSC_SUCCESS;
55 }
56
57 /*@
58 PetscElementalFinalizePackage - Finalize Elemental package
59
60 Collective on `MPI_COMM_WORLD`, not `PETSC_COMM_WORLD`
61
62 Level: developer
63
64 Note:
65 Can be called outside of `PetscInitialize()` and `PetscFinalize()`.
66 Users who do not call `PetscElementalInitializePackage()` do not have to call this function.
67
68 .seealso: `MATELEMENTAL`, `PetscElementalInitializePackage()`
69 @*/
PetscElementalFinalizePackage(void)70 PetscErrorCode PetscElementalFinalizePackage(void)
71 {
72 if (El::Initialized()) El::Finalize();
73 return PETSC_SUCCESS;
74 }
75