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 :: myRank,mySize
10: character(len=80) :: outputString
12: ! Every PETSc routine should begin with the PetscInitialize() routine.
14: call PetscInitialize(PETSC_NULL_CHARACTER,ierr)
15: if (ierr/= 0) then
16: write(6,*) 'Unable to initialize PETSc'
17: stop
18: endif
20: ! We can now change the communicator universe for PETSc
22: call MPI_Comm_size(PETSC_COMM_WORLD,mySize,ierr); CHKERRA(ierr)
23: call MPI_Comm_rank(PETSC_COMM_WORLD,myRank,ierr); CHKERRA(ierr)
25: ! Here we would like to print only one message that represents all the processes in the group
26: ! We use PetscPrintf() with the
27: ! communicator PETSC_COMM_WORLD. Thus, only one message is
28: ! printed representng PETSC_COMM_WORLD, i.e., all the processors.
30: write(outputString,*) 'No of Processors = ', mySize, ', rank = ',myRank,'\n'
31: call PetscPrintf(PETSC_COMM_WORLD,outputString,ierr); CHKERRA(ierr)
33: ! Here a barrier is used to separate the two program states.
35: call MPI_Barrier(PETSC_COMM_WORLD,ierr); CHKERRA(ierr)
37: ! Here we simply use PetscPrintf() with the communicator PETSC_COMM_SELF,
38: ! where each process is considered separately and prints independently
39: ! to the screen. Thus, the output from different processes does not
40: ! appear in any particular order.
42: write(outputString,*) myRank,'Jumbled Hello World\n'
43: call PetscPrintf(PETSC_COMM_SELF,outputString,ierr); CHKERRA(ierr)
45: ! Always call PetscFinalize() before exiting a program. This routine
46: ! - finalizes the PETSc libraries as well as MPI
47: ! - provides summary and diagnostic information if certain runtime
48: ! options are chosen (e.g., -log_view). See PetscFinalize()
49: ! manpage for more information.
51: call PetscFinalize(ierr)
53: end program main
54: !/*TEST
55: !
56: ! test:
57: !
58: !TEST*/