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