xref: /petsc/src/sys/tutorials/ex1f.F90 (revision f84028053d197aff3fdf060e86d88b3f1b0f0110)
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
9*f8402805SBarry Smith      PetscMPIInt       :: rank,size
10c4762a1bSJed Brown      character(len=80) :: outputString
11c4762a1bSJed Brown
12c4762a1bSJed Brown      ! Every PETSc routine should begin with the PetscInitialize() routine.
1349c86fc7SBarry Smith      PetscCallA(PetscInitialize(PETSC_NULL_CHARACTER,ierr))
14c4762a1bSJed Brown
15c4762a1bSJed Brown      ! We can now change the communicator universe for PETSc
16*f8402805SBarry Smith      PetscCallMPIA(MPI_Comm_size(PETSC_COMM_WORLD,size,ierr))
17*f8402805SBarry Smith      PetscCallMPIA(MPI_Comm_rank(PETSC_COMM_WORLD,rank,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
24*f8402805SBarry Smith      write(outputString,*) 'No of Processors = ', size, ', rank = ',rank,'\n'
2549c86fc7SBarry Smith      PetscCallA(PetscPrintf(PETSC_COMM_WORLD,outputString,ierr))
26c4762a1bSJed Brown
27c4762a1bSJed Brown      ! Here a barrier is used to separate the two program states.
2849c86fc7SBarry 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
35*f8402805SBarry Smith      write(outputString,*) rank,'Jumbled Hello World\n'
3649c86fc7SBarry 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
4449c86fc7SBarry Smith      PetscCallA(PetscFinalize(ierr))
45c4762a1bSJed Brown
46c4762a1bSJed Brownend program main
47c4762a1bSJed Brown!/*TEST
48c4762a1bSJed Brown!
49c4762a1bSJed Brown!   test:
50c4762a1bSJed Brown!
51c4762a1bSJed Brown!TEST*/
52