1! Introductory example that illustrates printing: Fortran Example 2#include <petsc/finclude/petscsys.h> 3program main 4 use petscsys 5 6 implicit none 7 PetscErrorCode :: ierr 8 PetscMPIInt :: rank, size 9 character(len=80) :: outputString 10 11 ! Every PETSc routine should begin with the PetscInitialize() routine. 12 PetscCallA(PetscInitialize(ierr)) 13 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)) 17 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. 22 23 write (outputString, *) 'No of Processors = ', size, ', rank = ', rank, '\n' 24 PetscCallA(PetscPrintf(PETSC_COMM_WORLD, outputString, ierr)) 25 26 ! Here a barrier is used to separate the two program states. 27 PetscCallMPIA(MPI_Barrier(PETSC_COMM_WORLD, ierr)) 28 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. 33 34 write (outputString, *) rank, 'Jumbled Hello World\n' 35 PetscCallA(PetscPrintf(PETSC_COMM_SELF, outputString, ierr)) 36 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. 42 43 PetscCallA(PetscFinalize(ierr)) 44 45end program main 46!/*TEST 47! 48! test: 49! 50!TEST*/ 51