Actual source code: ex16f.F90

petsc-3.11.4 2019-09-28
Report Typos and Errors
  1: ! Tests calling PetscOptionsSetValue() before PetscInitialize(): Fortran Example
  2: 
  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.
 23: 
 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
 28: 
 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)
 34: 
 35: end program main