Actual source code: ex16.c

  1: static char help[] = "Tests calling PetscOptionsSetValue() before PetscInitialize()\n\n";

  3: #include <petscsys.h>
  4: int main(int argc, char **argv)
  5: {
  6:   PetscMPIInt rank, size;

  8:   /*
  9:     Every PETSc routine should begin with the PetscInitialize() routine.
 10:     argc, argv - These command line arguments are taken to extract the options
 11:                  supplied to PETSc and options supplied to MPI.
 12:     help       - When PETSc executable is invoked with the option -help,
 13:                  it prints the various options that can be applied at
 14:                  runtime.  The user can use the "help" variable place
 15:                  additional help messages in this printout.

 17:     Since when PetscInitialize() returns with an error the PETSc data structures
 18:     may not be set up hence we cannot call PetscCall() hence directly return the error code.

 20:     Since PetscOptionsSetValue() is called before the PetscInitialize() we cannot call
 21:     PetscCall() on the error code and just return it directly.
 22:   */
 23:   PetscCall(PetscOptionsSetValue(NULL, "-no_signal_handler", "true"));
 24:   PetscFunctionBeginUser;
 25:   PetscCall(PetscInitialize(&argc, &argv, NULL, help));
 26:   PetscCallMPI(MPI_Comm_size(PETSC_COMM_WORLD, &size));
 27:   PetscCallMPI(MPI_Comm_rank(PETSC_COMM_WORLD, &rank));
 28:   PetscCall(PetscPrintf(PETSC_COMM_WORLD, "Number of processors = %d, rank = %d\n", size, rank));
 29:   PetscCall(PetscFinalize());
 30:   return 0;
 31: }

 33: /*TEST

 35:    test:
 36:       requires: defined(PETSC_USE_LOG)
 37:       nsize: 2
 38:       args: -options_view -get_total_flops
 39:       filter: grep -E -v "(cuda_initialize|Total flops)"

 41: TEST*/