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