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