xref: /petsc/src/sys/tutorials/ex16f.F90 (revision 4e278199b78715991f5c71ebbd945c1489263e6c)
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  ::  myRank,mySize
11      character(len=80) :: outputString
12
13      ! Every PETSc routine should begin with the PetscInitialize() routine.
14
15      call PetscOptionsSetValue(PETSC_NULL_OPTIONS,"-no_signal_handler","true",ierr)
16      call PetscInitialize(PETSC_NULL_CHARACTER,ierr)
17      if (ierr/=0) then
18        write(6,*) 'Unable to initialize PETSc'
19        stop
20      endif
21
22      ! Since when PetscInitialize() returns with an error the PETSc data structures
23      ! may not be set up hence we cannot call CHKERRA() hence directly return the error code.
24
25      ! Since PetscOptionsSetValue() is called before the PetscInitialize() we cannot call
26      ! CHKERRA() on the error code and just return it directly.
27
28      ! We can now change the communicator universe for PETSc
29
30      call MPI_Comm_size(MPI_COMM_WORLD,mySize,ierr); CHKERRA(ierr)
31      call MPI_Comm_rank(MPI_COMM_WORLD,myRank,ierr); CHKERRA(ierr)
32      write(outputString,*) 'Number of processors =',mySize,'rank =',myRank,'\n'
33      call PetscPrintf(PETSC_COMM_WORLD,outputString,ierr); CHKERRA(ierr)
34      call PetscFinalize(ierr)
35
36end program main
37
38!/*TEST
39!
40!   test:
41!      requires: define(PETSC_USE_LOG)
42!      nsize: 2
43!      args: -options_view -get_total_flops
44!      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)"
45!
46!TEST*/
47