xref: /petsc/src/sys/tutorials/ex16f.F90 (revision f84028053d197aff3fdf060e86d88b3f1b0f0110)
1! Tests calling PetscOptionsSetValue() before PetscInitialize(): Fortran Example
2
3program main
4#include <petsc/finclude/petscsys.h>
5      use petscmpi  ! or mpi or mpi_f08
6      use petscsys
7
8      implicit none
9      PetscErrorCode :: ierr
10      PetscMPIInt  ::  rank,size
11      character(len=80) :: outputString
12
13      ! Every PETSc routine should begin with the PetscInitialize() routine.
14
15      PetscCallA(PetscOptionsSetValue(PETSC_NULL_OPTIONS,"-no_signal_handler","true",ierr))
16      PetscCallA(PetscInitialize(ierr))
17
18      ! Since when PetscInitialize() returns with an error the PETSc data structures
19      ! may not be set up hence we cannot call CHKERRA() hence directly return the error code.
20
21      ! Since PetscOptionsSetValue() is called before the PetscInitialize() we cannot call
22      ! CHKERRA() on the error code and just return it directly.
23
24      ! We can now change the communicator universe for PETSc
25
26      PetscCallMPIA(MPI_Comm_size(MPI_COMM_WORLD,size,ierr))
27      PetscCallMPIA(MPI_Comm_rank(MPI_COMM_WORLD,rank,ierr))
28      write(outputString,*) 'Number of processors =',size,'rank =',rank,'\n'
29      PetscCallA(PetscPrintf(PETSC_COMM_WORLD,outputString,ierr))
30      PetscCallA(PetscFinalize(ierr))
31end program main
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 "(malloc|display|nox|Total flops|saws_port_auto_select|vecscatter_mpi1|options_left|error_output_stdout|check_pointer_intensity|cuda_initialize|use_gpu_aware_mpi|checkstack)"
40!
41!TEST*/
42