1 static char help[] = "Tests repeated PetscInitialize/PetscFinalize calls.\n\n"; 2 3 #include <petscsys.h> 4 5 int main(int argc, char **argv) 6 { 7 int i, imax; 8 #if defined(PETSC_HAVE_ELEMENTAL) 9 PetscBool initialized; 10 #endif 11 12 #if defined(PETSC_HAVE_MPIUNI) 13 imax = 32; 14 #else 15 imax = 1024; 16 #endif 17 18 PetscCallMPI(MPI_Init(&argc, &argv)); 19 #if defined(PETSC_HAVE_ELEMENTAL) 20 PetscCall(PetscElementalInitializePackage()); 21 PetscCall(PetscElementalInitialized(&initialized)); 22 PetscCheck(initialized, MPI_COMM_WORLD, PETSC_ERR_PLIB, "Error in Elemental package processing"); 23 #endif 24 for (i = 0; i < imax; ++i) { 25 PetscFunctionBeginUser; 26 PetscCall(PetscInitialize(&argc, &argv, (char *)0, help)); 27 PetscCall(PetscFinalize()); 28 #if defined(PETSC_HAVE_ELEMENTAL) 29 // if Elemental is initialized outside of PETSc it should remain initialized 30 PetscCall(PetscElementalInitialized(&initialized)); 31 PetscCheck(initialized, MPI_COMM_WORLD, PETSC_ERR_PLIB, "Error in Elemental package processing"); 32 #endif 33 } 34 #if defined(PETSC_HAVE_ELEMENTAL) 35 PetscCall(PetscElementalFinalizePackage()); 36 PetscCall(PetscElementalInitialized(&initialized)); 37 PetscCheck(!initialized, MPI_COMM_WORLD, PETSC_ERR_PLIB, "Error in Elemental package processing"); 38 for (i = 0; i < 32; ++i) { /* increasing the upper bound will generate an error in Elemental */ 39 PetscFunctionBeginUser; 40 PetscCall(PetscInitialize(&argc, &argv, (char *)0, help)); 41 PetscCall(PetscElementalInitialized(&initialized)); 42 PetscCheck(initialized, MPI_COMM_WORLD, PETSC_ERR_PLIB, "Error in Elemental package processing"); 43 PetscCheck(initialized, PETSC_COMM_WORLD, PETSC_ERR_LIB, "Uninitialized Elemental"); 44 PetscCall(PetscFinalize()); 45 PetscCall(PetscElementalInitialized(&initialized)); 46 // if Elemental is initialized inside of PETSc it should be uninitialized in PetscFinalize() 47 PetscCheck(!initialized, MPI_COMM_WORLD, PETSC_ERR_PLIB, "Error in Elemental package processing"); 48 } 49 #endif 50 return MPI_Finalize(); 51 } 52 53 /*TEST 54 55 test: 56 requires: !saws 57 58 test: 59 requires: !saws 60 suffix: 2 61 nsize: 2 62 output_file: output/ex26_1.out 63 64 TEST*/ 65