Actual source code: ex16f.F90

petsc-3.12.5 2020-03-29
Report Typos and Errors
  1: ! Tests calling PetscOptionsSetValue() before PetscInitialize(): Fortran Example

  3: program main
  4:  #include <petsc/finclude/petscsys.h>
  5:       use petscsys
  6: 
  7:       implicit none
  8:       PetscErrorCode :: ierr
  9:       PetscMPIInt  ::  myRank,mySize
 10:       character(len=80) :: outputString
 11: 
 12:       ! Every PETSc routine should begin with the PetscInitialize() routine.
 13: 
 14:       call PetscOptionsSetValue(PETSC_NULL_OPTIONS,"-no_signal_handler","true",ierr)
 15:       call PetscInitialize(PETSC_NULL_CHARACTER,ierr)
 16:       if (ierr/=0) then
 17:         write(6,*) 'Unable to initialize PETSc'
 18:         stop
 19:       endif
 20: 
 21:       ! Since when PetscInitialize() returns with an error the PETSc data structures
 22:       ! may not be set up hence we cannot call CHKERRA() hence directly return the error code.

 24:       ! Since PetscOptionsSetValue() is called before the PetscInitialize() we cannot call
 25:       ! CHKERRA() on the error code and just return it directly.
 26: 
 27:       ! We can now change the communicator universe for PETSc

 29:       call MPI_Comm_size(MPI_COMM_WORLD,mySize,ierr); CHKERRA(ierr)
 30:       call MPI_Comm_rank(MPI_COMM_WORLD,myRank,ierr); CHKERRA(ierr)
 31:       write(outputString,*) 'Number of processors =',mySize,'rank =',myRank,'\n'
 32:       call PetscPrintf(PETSC_COMM_WORLD,outputString,ierr); CHKERRA(ierr)
 33:       call PetscFinalize(ierr)

 35: end program main

 37: !/*TEST
 38: !
 39: !   test:
 40: !      nsize: 2
 41: !      args: -options_view -get_total_flops
 42: !      filter: egrep -v "(malloc|display|nox|Total flops|saws_port_auto_select|vecscatter_mpi1|options_left|error_output_stdout|check_pointer_intensity|cuda_initialize)"
 43: !
 44: !TEST*/