xref: /petsc/src/sys/tutorials/ex16f.F90 (revision 8c8af28eefa46e3bea82adfa51baf2c790322ff8)
1c4762a1bSJed Brown! Tests calling PetscOptionsSetValue() before PetscInitialize(): Fortran Example
2c4762a1bSJed Brown
3c4762a1bSJed Brownprogram main
4c4762a1bSJed Brown#include <petsc/finclude/petscsys.h>
5*8c8af28eSPedro Ricardo C. Souza      use petscmpi  ! or mpi or mpi_f08
6c4762a1bSJed Brown      use petscsys
7c4762a1bSJed Brown
8c4762a1bSJed Brown      implicit none
9c4762a1bSJed Brown      PetscErrorCode :: ierr
10c4762a1bSJed Brown      PetscMPIInt  ::  myRank,mySize
11c4762a1bSJed Brown      character(len=80) :: outputString
12c4762a1bSJed Brown
13c4762a1bSJed Brown      ! Every PETSc routine should begin with the PetscInitialize() routine.
14c4762a1bSJed Brown
15c4762a1bSJed Brown      call PetscOptionsSetValue(PETSC_NULL_OPTIONS,"-no_signal_handler","true",ierr)
16c4762a1bSJed Brown      call PetscInitialize(PETSC_NULL_CHARACTER,ierr)
17c4762a1bSJed Brown      if (ierr/=0) then
18c4762a1bSJed Brown        write(6,*) 'Unable to initialize PETSc'
19c4762a1bSJed Brown        stop
20c4762a1bSJed Brown      endif
21c4762a1bSJed Brown
22c4762a1bSJed Brown      ! Since when PetscInitialize() returns with an error the PETSc data structures
23c4762a1bSJed Brown      ! may not be set up hence we cannot call CHKERRA() hence directly return the error code.
24c4762a1bSJed Brown
25c4762a1bSJed Brown      ! Since PetscOptionsSetValue() is called before the PetscInitialize() we cannot call
26c4762a1bSJed Brown      ! CHKERRA() on the error code and just return it directly.
27c4762a1bSJed Brown
28c4762a1bSJed Brown      ! We can now change the communicator universe for PETSc
29c4762a1bSJed Brown
30c4762a1bSJed Brown      call MPI_Comm_size(MPI_COMM_WORLD,mySize,ierr); CHKERRA(ierr)
31c4762a1bSJed Brown      call MPI_Comm_rank(MPI_COMM_WORLD,myRank,ierr); CHKERRA(ierr)
32c4762a1bSJed Brown      write(outputString,*) 'Number of processors =',mySize,'rank =',myRank,'\n'
33c4762a1bSJed Brown      call PetscPrintf(PETSC_COMM_WORLD,outputString,ierr); CHKERRA(ierr)
34c4762a1bSJed Brown      call PetscFinalize(ierr)
35c4762a1bSJed Brown
36c4762a1bSJed Brownend program main
37c4762a1bSJed Brown
38c4762a1bSJed Brown!/*TEST
39c4762a1bSJed Brown!
40c4762a1bSJed Brown!   test:
41956f8c0dSBarry Smith!      requires: define(PETSC_USE_LOG)
42c4762a1bSJed Brown!      nsize: 2
43c4762a1bSJed Brown!      args: -options_view -get_total_flops
44c20d7725SJed Brown!      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)"
45c4762a1bSJed Brown!
46c4762a1bSJed Brown!TEST*/
47