Actual source code: ex2f.F90
1: ! Synchronized printing: Fortran Example
2: #include <petsc/finclude/petscsys.h>
3: program main
4: use petscmpi ! or mpi or mpi_f08
5: use petscsys
7: implicit none
8: PetscErrorCode :: ierr
9: PetscMPIInt :: rank, size
10: character(len=PETSC_MAX_PATH_LEN) :: outputString
12: ! Every PETSc program should begin with the PetscInitialize() routine.
14: PetscCallA(PetscInitialize(ierr))
16: ! The following MPI calls return the number of processes
17: ! being used and the rank of this process in the group
19: PetscCallMPIA(MPI_Comm_size(MPI_COMM_WORLD, size, ierr))
20: PetscCallMPIA(MPI_Comm_rank(MPI_COMM_WORLD, rank, ierr))
22: ! Here we would like to print only one message that represents
23: ! all the processes in the group
24: write (outputString, *) 'No of Processors = ', size, ', rank = ', rank, '\n'
25: PetscCallA(PetscPrintf(PETSC_COMM_WORLD, outputString, ierr))
27: write (outputString, *) rank, 'Synchronized Hello World\n'
28: PetscCallA(PetscSynchronizedPrintf(PETSC_COMM_WORLD, outputString, ierr))
30: write (outputString, *) rank, 'Synchronized Hello World - Part II\n'
31: PetscCallA(PetscSynchronizedPrintf(PETSC_COMM_WORLD, outputString, ierr))
32: PetscCallA(PetscSynchronizedFlush(PETSC_COMM_WORLD, PETSC_STDOUT, ierr))
34: ! Here a barrier is used to separate the two program states.
35: PetscCallMPIA(MPI_Barrier(PETSC_COMM_WORLD, ierr))
37: write (outputString, *) rank, 'Jumbled Hello World\n'
38: PetscCallA(PetscPrintf(PETSC_COMM_SELF, outputString, ierr))
40: PetscCallA(PetscFinalize(ierr))
41: end program main
43: !/*TEST
44: !
45: ! test:
46: !
47: !TEST*/