xref: /petsc/src/sys/tutorials/ex16.c (revision f97672e55eacc8688507b9471cd7ec2664d7f203)
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   PetscMPIInt    rank,size;
8 
9   /*
10     Every PETSc routine should begin with the PetscInitialize() routine.
11     argc, argv - These command line arguments are taken to extract the options
12                  supplied to PETSc and options supplied to MPI.
13     help       - When PETSc executable is invoked with the option -help,
14                  it prints the various options that can be applied at
15                  runtime.  The user can use the "help" variable place
16                  additional help messages in this printout.
17 
18     Since when PetscInitialize() returns with an error the PETSc data structures
19     may not be set up hence we cannot call PetscCall() hence directly return the error code.
20 
21     Since PetscOptionsSetValue() is called before the PetscInitialize() we cannot call
22     PetscCall() on the error code and just return it directly.
23   */
24   PetscCall(PetscOptionsSetValue(NULL,"-no_signal_handler","true"));
25   PetscCall(PetscInitialize(&argc,&argv,(char*)0,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 }
32 
33 /*TEST
34 
35    test:
36       requires: defined(PETSC_USE_LOG)
37       nsize: 2
38       args: -options_view -get_total_flops
39       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)"
40 
41 TEST*/
42