Actual source code: ex4f.F
petsc-3.3-p7 2013-05-11
1: !
2: ! Program usage: mpiexec -n 2 ex4f [-help] [all PETSc options]
3: !
4: ! This introductory example illustrates running PETSc on a subset
5: ! of processes
6: !
7: !/*T
8: ! Concepts: introduction to PETSc;
9: ! Concepts: process^subset set PETSC_COMM_WORLD
10: ! Processors: 2
11: !T*/
12: ! -----------------------------------------------------------------------
14: program main
15: implicit none
16: #include <finclude/petscsys.h>
17: PetscErrorCode ierr
18: PetscMPIInt rank, size
20: ! We must call MPI_Init() first, making us, not PETSc, responsible
21: ! for MPI
23: call MPI_Init(ierr)
25: ! We can now change the communicator universe for PETSc
27: call MPI_Comm_rank(MPI_COMM_WORLD,rank,ierr)
28: call MPI_Comm_split(MPI_COMM_WORLD,mod(rank,2),0, &
29: & PETSC_COMM_WORLD,ierr)
31: ! Every PETSc routine should begin with the PetscInitialize()
32: ! routine.
34: call PetscInitialize(PETSC_NULL_CHARACTER,ierr)
36: ! The following MPI calls return the number of processes being used
37: ! and the rank of this process in the group.
39: call MPI_Comm_size(PETSC_COMM_WORLD,size,ierr)
40: call MPI_Comm_rank(PETSC_COMM_WORLD,rank,ierr)
43: ! Here we would like to print only one message that represents all
44: ! the processes in the group.
45: if (rank .eq. 0) write(6,100) size,rank
46: 100 format("No of Procs = ",i4," rank = ",i4)
48: ! Always call PetscFinalize() before exiting a program. This
49: ! routine - finalizes the PETSc libraries as well as MPI - provides
50: ! summary and diagnostic information if certain runtime options are
51: ! chosen (e.g., -log_summary). See PetscFinalize() manpage for more
52: ! information.
54: call PetscFinalize(ierr)
56: ! Since we initialized MPI, we must call MPI_Finalize()
58: call MPI_Finalize(ierr)
59: end