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