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 responsability
     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:   PetscMPIInt    result;

     26:   if (El::Initialized()) return 0;
     27:   if (PETSC_COMM_WORLD != MPI_COMM_NULL) { /* MPI has been initialized and PETSC_COMM_WORLD has been set */
     28:     MPI_Comm_compare(PETSC_COMM_WORLD,MPI_COMM_WORLD,&result);if (ierr) return ierr;
     29:     if (result == MPI_UNEQUAL) return result; /* cannot use Elemental with PETSC_COMM_WORLD and MPI_COMM_WORLD comparing to MPI_UNEQUAL, call PetscElementalInitializePackage()/PetscElementalFinalizePackage() collectively */
     30:   }
     31:   El::Initialize(); /* called by PetscInitialize_DynamicLibraries(void) or users */
     32:   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 */
     33:     PetscRegisterFinalize(PetscElementalFinalizePackage);if (ierr) return ierr;
     34:   }
     35:   return 0;
     36: }

     38: /*@
     39:    PetscElementalInitialized - Determine whether Elemental is initialized

     41:    Not Collective

     43:    Level: developer

     45:    Note:
     46:    Can be called outside of PetscInitialize() and PetscFinalize().

     48: .seealso: MATELEMENTAL, PetscElementalInitializePackage()
     49: @*/
     50: PetscErrorCode PetscElementalInitialized(PetscBool *isInitialized)
     51: {
     52:   if (isInitialized) *isInitialized = (PetscBool)El::Initialized();
     53:   return 0;
     54: }

     56: /*@
     57:    PetscElementalFinalizePackage - Finalize Elemental package

     59:    Collective on MPI_COMM_WORLD, not PETSC_COMM_WORLD

     61:    Level: developer

     63:    Note:
     64:    Can be called outside of PetscInitialize() and PetscFinalize().
     65:    Users who do not call PetscElementalInitializePackage() do not have to call this function.

     67: .seealso: MATELEMENTAL, PetscElementalInitializePackage()
     68: @*/
     69: PetscErrorCode PetscElementalFinalizePackage(void)
     70: {
     71:   if (El::Initialized()) El::Finalize();
     72:   return 0;
     73: }