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