Statistics
| Branch: | Revision:

root / synthbench / euroben-dm / mod2f / .svn / text-base / mpimod.f.svn-base @ 0:839f52ef7657

History | View | Annotate | Download (4 kB)

1
      Module mpi_module
2
! ---------------------------------------------------------------------
3
! --- This module contains information for communication and data 
4
!     distribution.
5
! ---------------------------------------------------------------------
6
      Include               'mpif.h'
7

    
8
      Integer            :: me, nodes
9
      Integer, Parameter :: maxnod = 2048
10
      Integer            :: offset(0:maxnod-1,2), sizes(0:maxnod-1,2)
11
      Integer            :: hsize, vsize
12
      Integer            :: comm, ierr, rtyp
13
! ---------------------------------------------------------------------
14
      Contains
15

    
16
      Subroutine mpi_bye
17
! ----------------------------------------------------------------------
18
      Call MPI_Finalize( ierr )
19
! ----------------------------------------------------------------------
20
      End Subroutine mpi_bye
21

    
22
      Subroutine csetup
23
! ----------------------------------------------------------------------
24
! --- 'csetup' initializes the communication for MPI programs.
25
!
26
! --- Output parameters (in mpi_module):
27
!     Integer: me    --- Local node number (0 <= me <= nodes-1).
28
!     Integer: nodes --- Number of nodes as found in the MPI system.
29
! --- Initialize MPI also, initialize this processor and the set of
30
!     processors for this job. (In case of problems, report and stop).
31
! ----------------------------------------------------------------------
32
      Call setnames
33
      Call MPI_Init( ierr )
34
      If ( ierr /= MPI_Success ) Then
35
         Print *, 'Could not initialize MPI, ierr = ', ierr
36
         Stop 'Csetup stage 1'
37
      End If
38
      Call MPI_Comm_Rank( comm, me, ierr )
39
      If ( ierr /= MPI_Success ) Then
40
         Print *, 'Could not find my process id, ierr = ', ierr
41
         Stop 'Csetup stage 2'
42
      End If
43
      Call MPI_Comm_Size( comm, nodes, ierr )
44
      If ( ierr /= MPI_Success ) Then
45
         Print *, 'Could not determine no. of nodes, ierr = ', ierr
46
         Stop 'Csetup stage 3'
47
      End If
48
! ----------------------------------------------------------------------
49
! --- Be sure that all processors start together.
50

    
51
      Call MPI_Barrier( comm, ierr )
52
! ----------------------------------------------------------------------
53
      End Subroutine csetup
54

    
55
      Subroutine mpistart
56
! ---------------------------------------------------------------------
57
      Call csetup
58
      Call setnames
59
! ---------------------------------------------------------------------
60
      End Subroutine mpistart
61

    
62
      Subroutine setnames
63
! ---------------------------------------------------------------------
64
      comm = MPI_Comm_World
65
      rtyp = MPI_Real8
66
! ---------------------------------------------------------------------
67
      End Subroutine
68

    
69
      Subroutine sizoff( n1, n2 )
70
! ---------------------------------------------------------------------
71
! --- Routine 'sizoff' determines the sizes and offsets of a 2-D
72
!     array with dimensions 'n1' and 'n2' with respect to a
73
!     distribution that is as even as possible on 'nodes' processors
74
!     Then the offsets for each local array with respect to the global
75
!     array are determined.
76
!     Entry 'sizes(i,1)' giving the size for the i-th slice and 1-st
77
!     dimension, etc.
78
! ---------------------------------------------------------------------
79
      Integer n1, n2
80

    
81
      Integer i, k, non, nrest, rest
82
! ---------------------------------------------------------------------
83
      non   = n1/nodes
84
      rest  = Mod( n1, nodes )
85
      nrest = nodes - rest - 1
86
      Do i = 0, nodes - 1
87
         sizes(i,1) = non
88
         If ( i > nrest ) sizes(i,1) = non + 1
89
      End Do
90
      non   = n2/nodes
91
      rest  = Mod( n2, nodes )
92
      nrest = nodes - rest - 1
93
      Do i = 0, nodes - 1
94
         sizes(i,2) = non
95
         If ( i > nrest ) sizes(i,2) = non + 1
96
      End Do
97
      Do k = 1, 2
98
         offset(0,k) = 0
99
         Do i = 1, nodes - 1
100
            offset(i,k) = offset(i-1,k) + sizes(i-1,k)
101
         End Do
102
      End Do
103
! ----------------------------------------------------------------------
104
      End Subroutine sizoff
105

    
106
      End Module mpi_module