Actual source code: ex4f.F

petsc-3.8.4 2018-03-24
Report Typos and Errors
  1: !
  2: !     This introductory example illustrates running PETSc on a subset
  3: !     of processes
  4: !
  5: !/*T
  6: !   Concepts: introduction to PETSc;
  7: !   Concepts: process^subset set PETSC_COMM_WORLD
  8: !   Processors: 2
  9: !T*/
 10: ! -----------------------------------------------------------------------

 12:       program main
 13:  #include <petsc/finclude/petscsys.h>
 14:       use petscsys
 15:       implicit none
 16:       PetscErrorCode ierr
 17:       PetscMPIInt    rank, size

 19: !     We must call MPI_Init() first, making us, not PETSc, responsible
 20: !     for MPI

 22:       call MPI_Init(ierr)

 24: !     We can now change the communicator universe for PETSc

 26:       call MPI_Comm_rank(MPI_COMM_WORLD,rank,ierr)
 27:       call MPI_Comm_split(MPI_COMM_WORLD,mod(rank,2),0,                 &
 28:      &     PETSC_COMM_WORLD,ierr)

 30: !     Every PETSc routine should begin with the PetscInitialize()
 31: !     routine.

 33:       call PetscInitializeNoArguments(ierr)
 34:       if (ierr .ne. 0) then
 35:          print*,'Unable to initialize PETSc'
 36:          stop
 37:       endif

 39: !     The following MPI calls return the number of processes being used
 40: !     and the rank of this process in the group.

 42:       call MPI_Comm_size(PETSC_COMM_WORLD,size,ierr)
 43:       call MPI_Comm_rank(PETSC_COMM_WORLD,rank,ierr)


 46: !     Here we would like to print only one message that represents all
 47: !     the processes in the group.
 48:       if (rank .eq. 0) write(6,100) size,rank
 49:  100  format('No of Procs = ',i4,' rank = ',i4)

 51: !     Always call PetscFinalize() before exiting a program.  This
 52: !     routine - finalizes the PETSc libraries as well as MPI - provides
 53: !     summary and diagnostic information if certain runtime options are
 54: !     chosen (e.g., -log_view).  See PetscFinalize() manpage for more
 55: !     information.

 57:       call PetscFinalize(ierr)

 59:       call MPI_Comm_free(PETSC_COMM_WORLD,ierr)


 62: !     Since we initialized MPI, we must call MPI_Finalize()

 64:       call  MPI_Finalize(ierr)
 65:       end

 67: !
 68: !/*TEST
 69: !
 70: !   test:
 71: !      nsize: 5
 72: !      filter: sort -b
 73: !      filter_output: sort -b
 74: !
 75: !TEST*/