Actual source code: ex1f.F90

petsc-master 2019-07-16
Report Typos and Errors
  1: ! Introductory example that illustrates printing: Fortran Example
  2: 
  3: 
  4: 
  5: program main
  6: #include <petsc/finclude/petscsys.h> 
  7:       use petscsys
  8:       
  9:       implicit none
 10:       PetscErrorCode    :: ierr
 11:       PetscMPIInt       :: myRank,mySize
 12:       character(len=80) :: outputString
 13:    
 14:       ! Every PETSc routine should begin with the PetscInitialize() routine.
 15: 
 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:       
 23:       ! We can now change the communicator universe for PETSc
 24:      
 25:       call MPI_Comm_size(MPI_COMM_WORLD,mySize,ierr); CHKERRA(ierr)
 26:       call MPI_Comm_rank(MPI_COMM_WORLD,myRank,ierr); CHKERRA(ierr)
 27:      
 28:       ! Here we would like to print only one message that represents all the processes in the group
 29:       ! We use PetscPrintf() with the
 30:       ! communicator PETSC_COMM_WORLD.  Thus, only one message is
 31:       ! printed representng PETSC_COMM_WORLD, i.e., all the processors.
 32:  
 33:       write(outputString,*) 'No of Processors = ', mySize, ', rank = ',myRank,'\n'
 34:       call PetscPrintf(PETSC_COMM_WORLD,outputString,ierr); CHKERRA(ierr)
 35:      
 36:       ! Here a barrier is used to separate the two program states.
 37:       
 38:       call MPI_Barrier(PETSC_COMM_WORLD,ierr); CHKERRA(ierr)
 39: 
 40:   
 41:       ! Here we simply use PetscPrintf() with the communicator PETSC_COMM_SELF,
 42:       ! where each process is considered separately and prints independently
 43:       ! to the screen.  Thus, the output from different processes does not
 44:       ! appear in any particular order.
 45: 
 46:       write(outputString,*) myRank,'Jumbled Hello World\n'
 47:       call PetscPrintf(PETSC_COMM_SELF,outputString,ierr); CHKERRA(ierr)
 48:       
 49:       ! Always call PetscFinalize() before exiting a program.  This routine
 50:       ! - finalizes the PETSc libraries as well as MPI
 51:       ! - provides summary and diagnostic information if certain runtime
 52:       !   options are chosen (e.g., -log_view).  See PetscFinalize()
 53:       !  manpage for more information.
 54: 
 55:       call PetscFinalize(ierr)
 56:       
 57: end program main 
 58: !/*TEST 
 59: ! 
 60: !   test: 
 61: ! 
 62: !TEST*/