Actual source code: ex4f90.F90
1: !
2: ! This introductory example illustrates running PETSc on a subset
3: ! of processes
4: !
5: ! -----------------------------------------------------------------------
7: program main
8: #include <petsc/finclude/petscsys.h>
9: use petscmpi ! or mpi or mpi_f08
10: use petscsys
11: implicit none
13: PetscErrorCode ierr
14: PetscMPIInt rank, size, zero, two
16: ! We must call MPI_Init() first, making us, not PETSc, responsible
17: ! for MPI
19: call MPI_Init(ierr)
20: if (ierr .ne. 0) then
21: print*,'Unable to initialize MPI'
22: stop
23: endif
25: ! We can now change the communicator universe for PETSc
27: zero = 0
28: two = 2
29: call MPI_Comm_rank(MPI_COMM_WORLD,rank,ierr)
30: call MPI_Comm_split(MPI_COMM_WORLD,mod(rank,two),zero,PETSC_COMM_WORLD,ierr)
32: ! Every PETSc routine should begin with the PetscInitialize()
33: ! routine.
35: call PetscInitialize(PETSC_NULL_CHARACTER,ierr)
36: if (ierr .ne. 0) then
37: print*,'Unable to initialize PETSc'
38: stop
39: endif
41: ! The following MPI calls return the number of processes being used
42: ! and the rank of this process in the group.
44: call MPI_Comm_size(PETSC_COMM_WORLD,size,ierr);CHKERRA(ierr)
45: call MPI_Comm_rank(PETSC_COMM_WORLD,rank,ierr);CHKERRA(ierr)
47: ! Here we would like to print only one message that represents all
48: ! the processes in the group.
49: if (rank .eq. 0) write(6,100) size,rank
50: 100 format('No of Procs = ',i4,' rank = ',i4)
52: ! Always call PetscFinalize() before exiting a program. This
53: ! routine - finalizes the PETSc libraries as well as MPI - provides
54: ! summary and diagnostic information if certain runtime options are
55: ! chosen (e.g., -log_view). See PetscFinalize() manpage for more
56: ! information.
58: call PetscFinalize(ierr)
59: call MPI_Comm_free(PETSC_COMM_WORLD,ierr)
61: ! Since we initialized MPI, we must call MPI_Finalize()
63: call MPI_Finalize(ierr)
64: end
66: !
67: !/*TEST
68: !
69: ! test:
70: !
71: !TEST*/