Actual source code: ex1f.F90

  1: ! Introductory example that illustrates printing: Fortran Example
  2: #include <petsc/finclude/petscsys.h>
  3: program main
  4:   use petscsys

  6:   implicit none
  7:   PetscErrorCode    :: ierr
  8:   PetscMPIInt       :: rank, size
  9:   character(len=80) :: outputString

 11:   ! Every PETSc routine should begin with the PetscInitialize() routine.
 12:   PetscCallA(PetscInitialize(ierr))

 14:   ! We can now change the communicator universe for PETSc
 15:   PetscCallMPIA(MPI_Comm_size(PETSC_COMM_WORLD, size, ierr))
 16:   PetscCallMPIA(MPI_Comm_rank(PETSC_COMM_WORLD, rank, ierr))

 18:   ! Here we would like to print only one message that represents all the processes in the group
 19:   ! We use PetscPrintf() with the
 20:   ! communicator PETSC_COMM_WORLD.  Thus, only one message is
 21:   ! printed representng PETSC_COMM_WORLD, i.e., all the processors.

 23:   write (outputString, *) 'No of Processors = ', size, ', rank = ', rank, '\n'
 24:   PetscCallA(PetscPrintf(PETSC_COMM_WORLD, outputString, ierr))

 26:   ! Here a barrier is used to separate the two program states.
 27:   PetscCallMPIA(MPI_Barrier(PETSC_COMM_WORLD, ierr))

 29:   ! Here we simply use PetscPrintf() with the communicator PETSC_COMM_SELF,
 30:   ! where each process is considered separately and prints independently
 31:   ! to the screen.  Thus, the output from different processes does not
 32:   ! appear in any particular order.

 34:   write (outputString, *) rank, 'Jumbled Hello World\n'
 35:   PetscCallA(PetscPrintf(PETSC_COMM_SELF, outputString, ierr))

 37:   ! Always call PetscFinalize() before exiting a program.  This routine
 38:   ! - finalizes the PETSc libraries as well as MPI
 39:   ! - provides summary and diagnostic information if certain runtime
 40:   !   options are chosen (e.g., -log_view).  See PetscFinalize()
 41:   !  manpage for more information.

 43:   PetscCallA(PetscFinalize(ierr))

 45: end program main
 46: !/*TEST
 47: !
 48: !   test:
 49: !
 50: !TEST*/