source: utilities.f@ 32289cd

Last change on this file since 32289cd was 32289cd, checked in by baerbaer <baerbaer@…>, 14 years ago

Explicitly declare variables.

git-svn-id: svn+ssh://svn.berlios.de/svnroot/repos/smmp/trunk@33 26dc1dd8-5c4e-0410-9ffe-d298b4865968

  • Property mode set to 100644
File size: 6.6 KB
Line 
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 (*,*) "Total number of interactions:", isum
69 write (*,*) "Average # of interactions per processor", ipps
70
71 totalct = 0
72 irank = 1
73 itarget = int(irank * ipps)
74 if (nml.eq.0) then
75 i1ms = imsml1(ntlml)+ nmsml(ntlml)
76 else
77 i1ms = imsml1(nml)+ nmsml(nml)
78 end if
79 do io = idxOfLastVariable, idxOfFirstVariable, - 1
80 isum = 0
81 iv = iorvr(io)
82 i2ms = i1ms - 1
83 i1ms = imsvr1(iv)
84 do ms = i1ms, i2ms
85 do at = latms1(ms), latms2(ms)
86 atct = atct + 1
87 do ivw=ivwat1(at),ivwat2(at)
88 do j=lvwat1(ivw),lvwat2(ivw)
89 isum = isum + 1
90 end do
91 end do
92 do i14=i14at1(at),i14at2(at)
93 isum = isum + 1
94 end do
95 end do
96 end do
97 if ((totalct + isum).gt.itarget) then
98 if((.not.irank.eq.num_ppr)
99 & .and.
100 & (abs(totalct-itarget)
101 & .lt.abs(totalct + isum - itarget))) then
102 workPerProcessor(nml, irank) = io + 1
103! write (*,*) io + 1, totalct, itarget
104 else
105 workPerProcessor(nml, irank) = io
106! write (*,*) io, totalct + isum, itarget
107 end if
108 irank = irank + 1
109 itarget = int(irank * ipps)
110 end if
111 totalct = totalct + isum
112 end do
113 workPerProcessor(nml, 0) = idxOfLastVariable + 1
114 workPerProcessor(nml, num_ppr) = ivrml1(nml)
115
116 end subroutine distributeWorkLoad
117
118!-----------------------------------------------------------------------
119! The function fileNameMP takes a template of a file name in the
120! variable base. The position of the first and last character that
121! may be replaced by rank in the string are given in i1 (first) and
122! i2 (last).
123! The function returns an empty string if the rank would need more
124! characters than is allowed by the template.
125! For example,
126! \code
127! rank = 11
128! fileName = fileNameMP('base_0000.dat', 6, 9, rank)
129! write (*,*), fileName
130! \endcode
131! will output base_0011.dat.
132!
133! @param base the base file name, e.g., base_0000.dat.
134! @param i1 index of the first character that may be replaced
135! @param i2 index of the last character that may be replaced
136! @param rank the number that should be inserted into the file name.
137!
138! @return file name for rank
139!-----------------------------------------------------------------------
140 character*80 function fileNameMP(base, i1, i2, rank)
141
142 character*(*) base
143! i1, i2: Index of first and last character that can be replaced
144! rank: rank of node
145 integer i1, i2, rank
146
147 fileNameMP = base
148 if ((i2 - i1 + 1).le.log10(1.0 * rank)) then
149 print *,'too few characters available to label '
150 print *,'filenames with rank = ',rank
151 stop
152 endif
153
154! TODO: Allow arbitrary rank
155
156 if (rank.lt.10) then
157 write(fileNameMP(i2:i2), '(i1)') rank
158 elseif (rank.lt.100) then
159 write(fileNameMP(i2-1:i2), '(i2)') rank
160 elseif (rank.lt.1000) then
161 write(fileNameMP(i2-2:i2), '(i3)') rank
162 elseif (rank.lt.10000) then
163 write(fileNameMP(i2-3:i2), '(i4)') rank
164 elseif (rank.lt.100000) then
165 write(fileNameMP(i2-4:i2), '(i5)') rank
166 elseif (rank.lt.1000000) then
167 write(fileNameMP(i2-5:i2), '(i6)') rank
168 endif
169 end function fileNameMP
170! End fileNameMP
171
172
173!----------------------------------------------------------------------
174! Add messages to log. This routine takes the log (debugging) mes-
175! sages and writes them to the log file if the log level is less or
176! equal to the maximum log level given by the global variable
177! MAXLOGLEVEL.
178!
179! @author Jan H. Meinke
180!
181! @param loglevel level at which this message should be added to
182! the log.
183! @param message message to be written to the log.
184! @param rank global rank of this node if running an MPI job zero
185! otherwise.
186!----------------------------------------------------------------------
187 subroutine addLogMessage(loglevel, message, rank)
188
189 integer maxloglevel, logfileunit
190
191 integer :: loglevel, rank
192 character(LEN=*) :: message
193
194 if (loglevel <= MAXLOGLEVEL) then
195 write(LOGFILEUNIT, *) message
196 end if
197
198 end subroutine addLogMessage
Note: See TracBrowser for help on using the repository browser.