Actual source code: ex2f.F90

      1: ! Synchronized 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=PETSC_MAX_PATH_LEN) :: outputString

     11:   ! Every PETSc program should begin with the PetscInitialize() routine.

     13:   PetscCallA(PetscInitialize(ierr))

     15:   ! The following MPI calls return the number of processes
     16:   ! being used and the rank of this process in the group

     18:   PetscCallMPIA(MPI_Comm_size(MPI_COMM_WORLD, size, ierr))
     19:   PetscCallMPIA(MPI_Comm_rank(MPI_COMM_WORLD, rank, ierr))

     21:   ! Here we would like to print only one message that represents
     22:   ! all the processes in the group
     23:   write (outputString, *) 'No of Processors = ', size, ', rank = ', rank, '\n'
     24:   PetscCallA(PetscPrintf(PETSC_COMM_WORLD, outputString, ierr))

     26:   write (outputString, *) rank, 'Synchronized Hello World\n'
     27:   PetscCallA(PetscSynchronizedPrintf(PETSC_COMM_WORLD, outputString, ierr))

     29:   write (outputString, *) rank, 'Synchronized Hello World - Part II\n'
     30:   PetscCallA(PetscSynchronizedPrintf(PETSC_COMM_WORLD, outputString, ierr))
     31:   PetscCallA(PetscSynchronizedFlush(PETSC_COMM_WORLD, PETSC_STDOUT, ierr))

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

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

     39:   PetscCallA(PetscFinalize(ierr))
     40: end program main

     42: !/*TEST
     43: !
     44: !   test:
     45: !
     46: !TEST*/