xref: /petsc/src/sys/tests/ex26.c (revision df4cd43f92eaa320656440c40edb1046daee8f75)
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   if (!initialized) return 1;
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     PetscCall(PetscElementalInitialized(&initialized));
30     if (!initialized) return PETSC_ERR_LIB;
31 #endif
32   }
33 #if defined(PETSC_HAVE_ELEMENTAL)
34   PetscCall(PetscElementalFinalizePackage());
35   PetscCall(PetscElementalInitialized(&initialized));
36   if (initialized) return 1;
37   for (i = 0; i < 32; ++i) { /* increasing the upper bound will generate an error in Elemental */
38     PetscFunctionBeginUser;
39     PetscCall(PetscInitialize(&argc, &argv, (char *)0, help));
40     PetscCall(PetscElementalInitialized(&initialized));
41     PetscCheck(initialized, PETSC_COMM_WORLD, PETSC_ERR_LIB, "Uninitialized Elemental");
42     PetscCall(PetscFinalize());
43     PetscCall(PetscElementalInitialized(&initialized));
44     if (initialized) return PETSC_ERR_LIB;
45   }
46 #endif
47   return MPI_Finalize();
48 }
49 
50 /*TEST
51 
52    test:
53       requires: !saws
54 
55    test:
56       requires: !saws
57       suffix: 2
58       nsize: 2
59       output_file: output/ex26_1.out
60 
61 TEST*/
62