Statistics
| Branch: | Revision:

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

History | View | Annotate | Download (5.6 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), sizes(0:maxnod-1)
11
      Integer            :: glb, gub, lb
12
      Integer            :: comm, ierr, ityp, rtyp
13
! ---------------------------------------------------------------------
14
      Contains
15

    
16
      Subroutine bsaddr
17
! ----------------------------------------------------------------------
18
! --- Routine 'bsaddr' calculates the offsets that occur when local
19
!     data must be copied into a global one that combines all local
20
!     data. As the sizes of the local arrays need not be the same,
21
!     offsets cannot be generated with local knowledge only.
22
!
23
! --- Input:  - Integer nodes              (via Module mpi_module)
24
!             - Integer sizes(0:maxnod-1)  (via Module mpi_module)
25
! --- Output: - Integer offset(0:maxnod-1) (via Module mpi_module)
26
! ----------------------------------------------------------------------
27
      Implicit   None
28

    
29
      Integer :: i
30
! ----------------------------------------------------------------------
31
      offset(0) = 0
32
      Do i = 1, nodes - 1
33
         offset(i) = offset(i-1) + sizes(i-1)
34
      End Do
35
      glb = offset(me)
36
      lb  = glb + 1
37
      If ( me < nodes - 1 ) Then
38
         gub = offset(me+1)
39
      Else
40
         gub = offset(me) + sizes(me)
41
      End If
42
! ----------------------------------------------------------------------
43
      End Subroutine bsaddr
44

    
45
      Subroutine mpibye
46
! ----------------------------------------------------------------------
47
      Call MPI_Finalize( ierr )
48
! ----------------------------------------------------------------------
49
      End Subroutine mpibye
50

    
51
      Subroutine csetup
52
! ----------------------------------------------------------------------
53
! --- 'csetup' initializes the communication for MPI programs.
54
!
55
! --- Output parameters (in mpi_module):
56
!     Integer: me    --- Local node number (0 <= me <= nodes-1).
57
!     Integer: nodes --- Number of nodes as found in the MPI system.
58
! --- Initialize MPI also, initialize this processor and the set of
59
!     processors for this job. (In case of problems, report and stop).
60
! ----------------------------------------------------------------------
61
      Call Mpi_Init( ierr )
62
      If ( ierr /= Mpi_Success ) Then
63
         Print *, 'Could not initialize MPI, ierr = ', ierr
64
         Stop 'Csetup stage 1'
65
      End If
66
      Call Mpi_Comm_Rank( Mpi_Comm_World, me, ierr )
67
      If ( ierr /= Mpi_Success ) Then
68
         Print *, 'Could not find my process id, ierr = ', ierr
69
         Stop 'Csetup stage 2'
70
      End If
71
      Call Mpi_Comm_Size( Mpi_Comm_World, nodes, ierr )
72
      If ( ierr /= Mpi_Success ) Then
73
         Print *, 'Could not determine no. of nodes, ierr = ', ierr
74
         Stop 'Csetup stage 3'
75
      End If
76
! ----------------------------------------------------------------------
77
! --- Be sure that all processors start together.
78

    
79
      Call Mpi_Barrier( Mpi_Comm_World, ierr )
80
! ----------------------------------------------------------------------
81
      End Subroutine csetup
82

    
83

    
84
      Subroutine evdist( n )
85
! ---------------------------------------------------------------------
86
! --- Routine 'evdist' distributes 'n' elements as evenly as possible
87
!     over 'nodes' processors. The actual number of elements per
88
!     processor are returned in array 'sizes'.
89
! ---------------------------------------------------------------------
90
! --- Input:  - Integer n
91
!             - Integer nodes             (via Module mpi_module).
92
! --- Output: - Integer sizes(0:maxnod-1) (via Module mpi_module).
93
! ---------------------------------------------------------------------
94
      Implicit   None
95

    
96
      Integer :: n
97

    
98
      Integer :: i, non, nrest, rest
99
! ---------------------------------------------------------------------
100
! --- Set number of rows.
101

    
102
      non   = n/nodes
103
      rest  = Mod( n, nodes )
104
      nrest = nodes - rest - 1
105
      Do i = 0, nodes - 1
106
         sizes(i) = non
107
         If ( i > nrest ) sizes(i) = non + 1
108
      End Do
109
! ---------------------------------------------------------------------
110
      End Subroutine evdist
111

    
112
      Subroutine mpistart
113
! ---------------------------------------------------------------------
114
      Call csetup
115
      Call setnames
116
! ---------------------------------------------------------------------
117
      End Subroutine mpistart
118

    
119
      Integer Function part( n )
120
! ---------------------------------------------------------------------
121
! --- Routine 'part' partitions 'n' elements as evenly as possible
122
!     over 'nodes' processors.
123
! ---------------------------------------------------------------------
124
! --- Input:  - Integer n
125
!             - Integer nodes
126
! ---------------------------------------------------------------------
127
      Implicit   None
128
      Integer :: n
129

    
130
      Integer :: i, non, nrest, rest
131
! ---------------------------------------------------------------------
132
      non   = n/nodes
133
      rest  = Mod( n, nodes )
134
      nrest = nodes - rest - 1
135
      part  = non
136
      If ( me > nrest ) part = part + 1
137
! ---------------------------------------------------------------------
138
      End Function part
139

    
140
      Subroutine setnames
141
! ---------------------------------------------------------------------
142
      comm = MPI_Comm_World
143
      ityp = MPI_Integer8
144
      rtyp = MPI_Real8
145
! ---------------------------------------------------------------------
146
      End Subroutine
147

    
148
      End Module mpi_module