xref: /petsc/src/sys/tutorials/ex16.c (revision 6b51dbe656a721552c9aaa6ea3ff4c3750fc01e6)
1 
2 static char help[] = "Tests calling PetscOptionsSetValue() before PetscInitialize()\n\n";
3 
4 #include <petscsys.h>
5 int main(int argc,char **argv)
6 {
7   PetscErrorCode ierr;
8   PetscMPIInt    rank,size;
9 
10   /*
11     Every PETSc routine should begin with the PetscInitialize() routine.
12     argc, argv - These command line arguments are taken to extract the options
13                  supplied to PETSc and options supplied to MPI.
14     help       - When PETSc executable is invoked with the option -help,
15                  it prints the various options that can be applied at
16                  runtime.  The user can use the "help" variable place
17                  additional help messages in this printout.
18 
19     Since when PetscInitialize() returns with an error the PETSc data structures
20     may not be set up hence we cannot call PetscCall() hence directly return the error code.
21 
22     Since PetscOptionsSetValue() is called before the PetscInitialize() we cannot call
23     PetscCall() on the error code and just return it directly.
24   */
25   ierr = PetscOptionsSetValue(NULL,"-no_signal_handler","true");if (ierr) return ierr;
26   PetscCall(PetscInitialize(&argc,&argv,(char*)0,help));
27   PetscCallMPI(MPI_Comm_size(PETSC_COMM_WORLD,&size));
28   PetscCallMPI(MPI_Comm_rank(PETSC_COMM_WORLD,&rank));
29   PetscCall(PetscPrintf(PETSC_COMM_WORLD,"Number of processors = %d, rank = %d\n",size,rank));
30   PetscCall(PetscFinalize());
31   return 0;
32 }
33 
34 /*TEST
35 
36    test:
37       requires: defined(PETSC_USE_LOG)
38       nsize: 2
39       args: -options_view -get_total_flops
40       filter: egrep -v "(cuda_initialize|malloc|display|nox|Total flops|saws_port_auto_select|vecscatter_mpi1|options_left|error_output_stdout|check_pointer_intensity|use_gpu_aware_mpi|checkstack)"
41 
42 TEST*/
43