Actual source code: elemental.cxx
1: #include <petscsys.h>
2: #include <petscmatelemental.h>
3: #include <petsc/private/petscimpl.h>
5: /*@
6: PetscElementalInitializePackage - Initialize Elemental package
8: Collective on `MPI_COMM_WORLD`, not `PETSC_COMM_WORLD`
10: Level: developer
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.
19: .seealso: `MATELEMENTAL`, `PetscElementalFinalizePackage()`
20: @*/
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: }
36: /*@
37: PetscElementalInitialized - Determine whether Elemental is initialized
39: Not Collective
41: Output Parameter:
42: . isInitialized - `PETSC_TRUE` if elemental is initialized, `PETSC_FALSE` otherwise
44: Level: developer
46: Note:
47: Can be called outside of `PetscInitialize()` and `PetscFinalize()`.
49: .seealso: `MATELEMENTAL`, `PetscElementalInitializePackage()`
50: @*/
51: PetscErrorCode PetscElementalInitialized(PetscBool *isInitialized)
52: {
53: if (isInitialized) *isInitialized = (PetscBool)El::Initialized();
54: return PETSC_SUCCESS;
55: }
57: /*@
58: PetscElementalFinalizePackage - Finalize Elemental package
60: Collective on `MPI_COMM_WORLD`, not `PETSC_COMM_WORLD`
62: Level: developer
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.
68: .seealso: `MATELEMENTAL`, `PetscElementalInitializePackage()`
69: @*/
70: PetscErrorCode PetscElementalFinalizePackage(void)
71: {
72: if (El::Initialized()) El::Finalize();
73: return PETSC_SUCCESS;
74: }