1 | ! *********************************************************************
|
---|
2 | ! This file contains distributeWorkLoad, fileNameMP
|
---|
3 | !
|
---|
4 | ! Copyright 2007 Frank Eisenmenger, U.H.E. Hansmann,
|
---|
5 | ! Jan H. Meinke, Sandipan Mohanty
|
---|
6 | !
|
---|
7 | ! *********************************************************************
|
---|
8 |
|
---|
9 | !! Calculate the best way to distribute the work load across processors.
|
---|
10 | ! It calculates the average number of interactions and then tries to
|
---|
11 | ! assign a number of interactions to each processor that is as close
|
---|
12 | ! as possible to the average. The routine should be called once for
|
---|
13 | ! every molecule in the system.
|
---|
14 | !
|
---|
15 | ! @param num_ppr Number of processors per replica
|
---|
16 | ! @param nml index of molecule or zero.
|
---|
17 | !
|
---|
18 | ! @author Jan H. Meinke
|
---|
19 | subroutine distributeWorkLoad(num_ppr,nml)
|
---|
20 |
|
---|
21 | include 'INCL.H'
|
---|
22 |
|
---|
23 | integer i1ms, io, iv, i2ms, ms
|
---|
24 |
|
---|
25 | integer num_ppr, nml
|
---|
26 | integer idxOfFirstVariable, idxOfLastVariable
|
---|
27 | integer at, atct, ivw, i, j, isum, i14
|
---|
28 | integer totalct, irank, itarget
|
---|
29 | double precision ipps
|
---|
30 |
|
---|
31 | if (nml.eq.0) then
|
---|
32 | idxOfFirstVariable = ivrml1(1)
|
---|
33 | idxOfLastVariable = ivrml1(ntlml) + nvrml(ntlml) -1
|
---|
34 | i1ms = imsml1(ntlml)+ nmsml(ntlml)
|
---|
35 | do i = 0, MAX_PROC
|
---|
36 | do j = 1, mxml
|
---|
37 | workPerProcessor(j, i) = 0
|
---|
38 | end do
|
---|
39 | end do
|
---|
40 | else
|
---|
41 | idxOfFirstVariable = ivrml1(nml)
|
---|
42 | idxOfLastVariable = ivrml1(nml) + nvrml(nml) - 1
|
---|
43 | i1ms = imsml1(nml)+ nmsml(nml)
|
---|
44 | do i = 0, MAX_PROC
|
---|
45 | workPerProcessor(nml, i) = 0
|
---|
46 | end do
|
---|
47 | end if
|
---|
48 |
|
---|
49 | isum = 0
|
---|
50 | do io = idxOfLastVariable, idxOfFirstVariable, - 1
|
---|
51 | iv = iorvr(io)
|
---|
52 | i2ms = i1ms - 1
|
---|
53 | i1ms = imsvr1(iv)
|
---|
54 | do ms = i1ms, i2ms
|
---|
55 | do at = latms1(ms), latms2(ms)
|
---|
56 | do ivw=ivwat1(at),ivwat2(at)
|
---|
57 | do j=lvwat1(ivw),lvwat2(ivw)
|
---|
58 | isum = isum + 1
|
---|
59 | end do
|
---|
60 | end do
|
---|
61 | do i14=i14at1(at),i14at2(at)
|
---|
62 | isum = isum + 1
|
---|
63 | end do
|
---|
64 | end do
|
---|
65 | end do
|
---|
66 | end do
|
---|
67 | ipps = isum / num_ppr
|
---|
68 | write (logString, *) "Total number of interactions:", isum
|
---|
69 | write (logString, *) "Average # of interactions per processor",
|
---|
70 | & ipps
|
---|
71 |
|
---|
72 | totalct = 0
|
---|
73 | irank = 1
|
---|
74 | itarget = int(irank * ipps)
|
---|
75 | if (nml.eq.0) then
|
---|
76 | i1ms = imsml1(ntlml)+ nmsml(ntlml)
|
---|
77 | else
|
---|
78 | i1ms = imsml1(nml)+ nmsml(nml)
|
---|
79 | end if
|
---|
80 | do io = idxOfLastVariable, idxOfFirstVariable, - 1
|
---|
81 | isum = 0
|
---|
82 | iv = iorvr(io)
|
---|
83 | i2ms = i1ms - 1
|
---|
84 | i1ms = imsvr1(iv)
|
---|
85 | do ms = i1ms, i2ms
|
---|
86 | do at = latms1(ms), latms2(ms)
|
---|
87 | atct = atct + 1
|
---|
88 | do ivw=ivwat1(at),ivwat2(at)
|
---|
89 | do j=lvwat1(ivw),lvwat2(ivw)
|
---|
90 | isum = isum + 1
|
---|
91 | end do
|
---|
92 | end do
|
---|
93 | do i14=i14at1(at),i14at2(at)
|
---|
94 | isum = isum + 1
|
---|
95 | end do
|
---|
96 | end do
|
---|
97 | end do
|
---|
98 | if ((totalct + isum).gt.itarget) then
|
---|
99 | if((.not.irank.eq.num_ppr)
|
---|
100 | & .and.
|
---|
101 | & (abs(totalct-itarget)
|
---|
102 | & .lt.abs(totalct + isum - itarget))) then
|
---|
103 | workPerProcessor(nml, irank) = io + 1
|
---|
104 | ! write (logString, *) io + 1, totalct, itarget
|
---|
105 | else
|
---|
106 | workPerProcessor(nml, irank) = io
|
---|
107 | ! write (logString, *) io, totalct + isum, itarget
|
---|
108 | end if
|
---|
109 | irank = irank + 1
|
---|
110 | itarget = int(irank * ipps)
|
---|
111 | end if
|
---|
112 | totalct = totalct + isum
|
---|
113 | end do
|
---|
114 | workPerProcessor(nml, 0) = idxOfLastVariable + 1
|
---|
115 | workPerProcessor(nml, num_ppr) = ivrml1(nml)
|
---|
116 |
|
---|
117 | end subroutine distributeWorkLoad
|
---|
118 |
|
---|
119 | !-----------------------------------------------------------------------
|
---|
120 | ! The function fileNameMP takes a template of a file name in the
|
---|
121 | ! variable base. The position of the first and last character that
|
---|
122 | ! may be replaced by rank in the string are given in i1 (first) and
|
---|
123 | ! i2 (last).
|
---|
124 | ! The function returns an empty string if the rank would need more
|
---|
125 | ! characters than is allowed by the template.
|
---|
126 | ! For example,
|
---|
127 | ! \code
|
---|
128 | ! rank = 11
|
---|
129 | ! fileName = fileNameMP('base_0000.dat', 6, 9, rank)
|
---|
130 | ! write (logString, *), fileName
|
---|
131 | ! \endcode
|
---|
132 | ! will output base_0011.dat.
|
---|
133 | !
|
---|
134 | ! @param base the base file name, e.g., base_0000.dat.
|
---|
135 | ! @param i1 index of the first character that may be replaced
|
---|
136 | ! @param i2 index of the last character that may be replaced
|
---|
137 | ! @param rank the number that should be inserted into the file name.
|
---|
138 | !
|
---|
139 | ! @return file name for rank
|
---|
140 | !-----------------------------------------------------------------------
|
---|
141 | character*80 function fileNameMP(base, i1, i2, rank)
|
---|
142 |
|
---|
143 | character*(*) base
|
---|
144 | ! i1, i2: Index of first and last character that can be replaced
|
---|
145 | ! rank: rank of node
|
---|
146 | integer i1, i2, rank
|
---|
147 |
|
---|
148 | fileNameMP = base
|
---|
149 | if ((i2 - i1 + 1).le.log10(1.0 * rank)) then
|
---|
150 | print *,'too few characters available to label '
|
---|
151 | print *,'filenames with rank = ',rank
|
---|
152 | stop
|
---|
153 | endif
|
---|
154 |
|
---|
155 | ! TODO: Allow arbitrary rank
|
---|
156 |
|
---|
157 | if (rank.lt.10) then
|
---|
158 | write(fileNameMP(i2:i2), '(i1)') rank
|
---|
159 | elseif (rank.lt.100) then
|
---|
160 | write(fileNameMP(i2-1:i2), '(i2)') rank
|
---|
161 | elseif (rank.lt.1000) then
|
---|
162 | write(fileNameMP(i2-2:i2), '(i3)') rank
|
---|
163 | elseif (rank.lt.10000) then
|
---|
164 | write(fileNameMP(i2-3:i2), '(i4)') rank
|
---|
165 | elseif (rank.lt.100000) then
|
---|
166 | write(fileNameMP(i2-4:i2), '(i5)') rank
|
---|
167 | elseif (rank.lt.1000000) then
|
---|
168 | write(fileNameMP(i2-5:i2), '(i6)') rank
|
---|
169 | endif
|
---|
170 | end function fileNameMP
|
---|
171 | ! End fileNameMP
|
---|
172 |
|
---|
173 |
|
---|
174 | !----------------------------------------------------------------------
|
---|
175 | ! Add messages to log. This routine takes the log (debugging) mes-
|
---|
176 | ! sages and writes them to the log file if the log level is less or
|
---|
177 | ! equal to the maximum log level given by the global variable
|
---|
178 | ! MAXLOGLEVEL.
|
---|
179 | !
|
---|
180 | ! @author Jan H. Meinke
|
---|
181 | !
|
---|
182 | ! @param loglevel level at which this message should be added to
|
---|
183 | ! the log.
|
---|
184 | ! @param message message to be written to the log.
|
---|
185 | ! @param rank global rank of this node if running an MPI job zero
|
---|
186 | ! otherwise.
|
---|
187 | !----------------------------------------------------------------------
|
---|
188 | subroutine addLogMessage(loglevel, message, rank)
|
---|
189 |
|
---|
190 | integer maxloglevel, logfileunit
|
---|
191 |
|
---|
192 | integer :: loglevel, rank
|
---|
193 | character(LEN=*) :: message
|
---|
194 |
|
---|
195 | if (loglevel <= MAXLOGLEVEL) then
|
---|
196 | write(LOGFILEUNIT, *) message
|
---|
197 | end if
|
---|
198 |
|
---|
199 | end subroutine addLogMessage
|
---|