Actual source code: ex16f.F90

  1: ! Tests calling PetscOptionsSetValue() before PetscInitialize(): Fortran Example

  3: program main
  4: #include <petsc/finclude/petscsys.h>
  5:       use petscmpi  ! or mpi or mpi_f08
  6:       use petscsys

  8:       implicit none
  9:       PetscErrorCode :: ierr
 10:       PetscMPIInt  ::  myRank,mySize
 11:       character(len=80) :: outputString

 13:       ! Every PETSc routine should begin with the PetscInitialize() routine.

 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

 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.

 25:       ! Since PetscOptionsSetValue() is called before the PetscInitialize() we cannot call
 26:       ! CHKERRA() on the error code and just return it directly.

 28:       ! We can now change the communicator universe for PETSc

 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)

 36: end program main

 38: !/*TEST
 39: !
 40: !   test:
 41: !      requires: defined(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|checkstack)"
 45: !
 46: !TEST*/