Actual source code: ex26.c

petsc-3.13.6 2020-09-29
Report Typos and Errors
  1: static char help[] = "Tests repeated PetscInitialize/PetscFinalize calls.\n\n";

  3:  #include <petscsys.h>

  5: int main(int argc, char **argv)
  6: {
  7:   int            i,imax;
  8: #if defined(PETSC_HAVE_ELEMENTAL)
  9:   PetscBool      initialized;
 10: #endif

 13: #if defined(PETSC_HAVE_MPIUNI)
 14:   imax = 32;
 15: #else
 16:   imax = 1024;
 17: #endif

 19:   MPI_Init(&argc, &argv);
 20: #if defined(PETSC_HAVE_ELEMENTAL)
 21:   PetscElementalInitializePackage(); if (ierr) return ierr;
 22:   PetscElementalInitialized(&initialized); if (ierr) return ierr;
 23:   if (!initialized) return 1;
 24: #endif
 25:   for (i = 0; i < imax; ++i) {
 26:     PetscInitialize(&argc, &argv, (char*) 0, help); if (ierr) return ierr;
 27:     PetscFinalize(); if (ierr) return ierr;
 28: #if defined(PETSC_HAVE_ELEMENTAL)
 29:     PetscElementalInitialized(&initialized); if (ierr) return ierr;
 30:     if (!initialized) return PETSC_ERR_LIB;
 31: #endif
 32:   }
 33: #if defined(PETSC_HAVE_ELEMENTAL)
 34:   PetscElementalFinalizePackage(); if (ierr) return ierr;
 35:   PetscElementalInitialized(&initialized); if (ierr) return ierr;
 36:   if (initialized) return 1;
 37:   for (i = 0; i < 32; ++i) { /* increasing the upper bound will generate an error in Elemental */
 38:     PetscInitialize(&argc, &argv, (char*) 0, help); if (ierr) return ierr;
 39:     PetscElementalInitialized(&initialized);
 40:     if (!initialized) SETERRQ(PETSC_COMM_WORLD, PETSC_ERR_LIB, "Uninitialized Elemental");
 41:     PetscFinalize(); if (ierr) return ierr;
 42:     PetscElementalInitialized(&initialized); if (ierr) return ierr;
 43:     if (initialized) return PETSC_ERR_LIB;
 44:   }
 45: #endif
 46:   MPI_Finalize();
 47:   return ierr;
 48: }

 50: /*TEST

 52:    test:

 54:    test:
 55:       suffix: 2
 56:       nsize: 2
 57:       output_file: output/ex26_1.out

 59: TEST*/