64 |
|
|
65 |
|
subroutine SimulationSetup(setThisSim, CnGlobal, CnLocal, c_idents, & |
66 |
|
CnLocalExcludes, CexcludesLocal, CnGlobalExcludes, CexcludesGlobal, & |
67 |
< |
CmolMembership, Cmfact, CnGroups, CgroupList, CgroupStart, & |
67 |
> |
CmolMembership, Cmfact, CnGroups, CglobalGroupMembership, & |
68 |
|
status) |
69 |
|
|
70 |
|
type (simtype) :: setThisSim |
84 |
|
!! mass factors used for molecular cutoffs |
85 |
|
real ( kind = dp ), dimension(CnLocal) :: Cmfact |
86 |
|
integer, intent(in):: CnGroups |
87 |
< |
integer, dimension(CnLocal),intent(in) :: CgroupList |
88 |
< |
integer, dimension(CnGroups),intent(in) :: CgroupStart |
89 |
< |
integer :: maxSkipsForAtom |
87 |
> |
integer, dimension(CnGlobal), intent(in):: CglobalGroupMembership |
88 |
> |
integer :: maxSkipsForAtom, glPointer |
89 |
|
|
90 |
|
#ifdef IS_MPI |
91 |
|
integer, allocatable, dimension(:) :: c_idents_Row |
92 |
|
integer, allocatable, dimension(:) :: c_idents_Col |
93 |
< |
integer :: nAtomsInRow, nGroupsInRow |
94 |
< |
integer :: nAtomsInCol, nGroupsInCol |
93 |
> |
integer :: nAtomsInRow, nGroupsInRow, aid |
94 |
> |
integer :: nAtomsInCol, nGroupsInCol, gid |
95 |
|
#endif |
96 |
|
|
97 |
|
simulation_setup_complete = .false. |
201 |
|
status = -1 |
202 |
|
return |
203 |
|
endif |
204 |
< |
allocate(groupStartLocal(nGroups), stat=alloc_stat) |
204 |
> |
allocate(mfactLocal(nLocal),stat=alloc_stat) |
205 |
|
if (alloc_stat /= 0 ) then |
206 |
|
status = -1 |
207 |
|
return |
208 |
|
endif |
209 |
< |
allocate(groupListLocal(nLocal), stat=alloc_stat) |
210 |
< |
if (alloc_stat /= 0 ) then |
212 |
< |
status = -1 |
213 |
< |
return |
214 |
< |
endif |
215 |
< |
allocate(mfactLocal(nLocal), stat=alloc_stat) |
216 |
< |
if (alloc_stat /= 0 ) then |
217 |
< |
status = -1 |
218 |
< |
return |
219 |
< |
endif |
220 |
< |
|
221 |
< |
groupStartLocal = CgroupStart |
222 |
< |
groupListLocal = CgroupList |
223 |
< |
mfactLocal = Cmfact |
224 |
< |
|
225 |
< |
call gather(groupStartLocal, groupStartRow, plan_group_row) |
226 |
< |
call gather(groupStartLocal, groupStartCol, plan_group_col) |
227 |
< |
groupStartRow(nGroupsInRow+1) = nAtomsInRow + 1 |
228 |
< |
groupStartCol(nGroupsInCol+1) = nAtomsInCol + 1 |
229 |
< |
call gather(groupListLocal, groupListRow, plan_atom_row) |
230 |
< |
call gather(groupListLocal, groupListCol, plan_atom_col) |
209 |
> |
|
210 |
> |
glPointer = 1 |
211 |
|
|
212 |
< |
! C passes us groupList as globalID numbers for the atoms |
233 |
< |
! we need to remap these onto the row and column ids on this |
234 |
< |
! processor. This is a linear search, but is only done once |
235 |
< |
! (we hope) |
212 |
> |
do i = 1, nGroupsInRow |
213 |
|
|
214 |
< |
do i = 1, nAtomsInRow |
214 |
> |
gid = GroupRowToGlobal(i) |
215 |
> |
groupStartRow(i) = glPointer |
216 |
> |
|
217 |
|
do j = 1, nAtomsInRow |
218 |
< |
if (AtomRowToGlobal(j) .eq. groupListRow(i)) then |
219 |
< |
groupListRow(i) = j |
218 |
> |
aid = AtomRowToGlobal(j) |
219 |
> |
if (CglobalGroupMembership(aid) .eq. gid) then |
220 |
> |
groupListRow(glPointer) = j |
221 |
> |
glPointer = glPointer + 1 |
222 |
|
endif |
223 |
|
enddo |
224 |
|
enddo |
225 |
< |
do i = 1, nAtomsInCol |
225 |
> |
groupStartRow(nGroupsInRow+1) = nAtomsInRow + 1 |
226 |
> |
|
227 |
> |
glPointer = 1 |
228 |
> |
|
229 |
> |
do i = 1, nGroupsInCol |
230 |
> |
|
231 |
> |
gid = GroupColToGlobal(i) |
232 |
> |
groupStartCol(i) = glPointer |
233 |
> |
|
234 |
|
do j = 1, nAtomsInCol |
235 |
< |
if (AtomColToGlobal(j) .eq. groupListCol(i)) then |
236 |
< |
groupListCol(i) = j |
235 |
> |
aid = AtomColToGlobal(j) |
236 |
> |
if (CglobalGroupMembership(aid) .eq. gid) then |
237 |
> |
groupListCol(glPointer) = j |
238 |
> |
glPointer = glPointer + 1 |
239 |
|
endif |
240 |
|
enddo |
241 |
|
enddo |
242 |
+ |
groupStartCol(nGroupsInCol+1) = nAtomsInCol + 1 |
243 |
+ |
|
244 |
+ |
mfactLocal = Cmfact |
245 |
+ |
|
246 |
|
call gather(mfactLocal, mfactRow, plan_atom_row) |
247 |
|
call gather(mfactLocal, mfactCol, plan_atom_col) |
248 |
|
|
249 |
|
if (allocated(mfactLocal)) then |
250 |
|
deallocate(mfactLocal) |
251 |
|
end if |
257 |
– |
if (allocated(groupListLocal)) then |
258 |
– |
deallocate(groupListLocal) |
259 |
– |
endif |
260 |
– |
if (allocated(groupStartLocal)) then |
261 |
– |
deallocate(groupStartLocal) |
262 |
– |
endif |
252 |
|
#else |
253 |
|
allocate(groupStartRow(nGroups+1),stat=alloc_stat) |
254 |
|
if (alloc_stat /= 0 ) then |
280 |
|
status = -1 |
281 |
|
return |
282 |
|
endif |
283 |
+ |
allocate(mfactLocal(nLocal),stat=alloc_stat) |
284 |
+ |
if (alloc_stat /= 0 ) then |
285 |
+ |
status = -1 |
286 |
+ |
return |
287 |
+ |
endif |
288 |
+ |
|
289 |
+ |
glPointer = 1 |
290 |
|
do i = 1, nGroups |
291 |
< |
groupStartRow(i) = CgroupStart(i) |
292 |
< |
groupStartCol(i) = CgroupStart(i) |
293 |
< |
end do |
291 |
> |
groupStartRow(i) = glPointer |
292 |
> |
groupStartCol(i) = glPointer |
293 |
> |
do j = 1, nLocal |
294 |
> |
if (CglobalGroupMembership(j) .eq. i) then |
295 |
> |
groupListRow(glPointer) = j |
296 |
> |
groupListCol(glPointer) = j |
297 |
> |
glPointer = glPointer + 1 |
298 |
> |
endif |
299 |
> |
enddo |
300 |
> |
enddo |
301 |
|
groupStartRow(nGroups+1) = nLocal + 1 |
302 |
|
groupStartCol(nGroups+1) = nLocal + 1 |
303 |
+ |
|
304 |
|
do i = 1, nLocal |
301 |
– |
groupListRow(i) = CgroupList(i) |
302 |
– |
groupListCol(i) = CgroupList(i) |
305 |
|
mfactRow(i) = Cmfact(i) |
306 |
|
mfactCol(i) = Cmfact(i) |
307 |
|
end do |
322 |
|
excludesLocal(2,i) = CexcludesLocal(2,i) |
323 |
|
enddo |
324 |
|
|
325 |
+ |
#ifdef IS_MPI |
326 |
+ |
allocate(nSkipsForAtom(nAtomsInRow), stat=alloc_stat) |
327 |
+ |
#else |
328 |
+ |
allocate(nSkipsForAtom(nLocal), stat=alloc_stat) |
329 |
+ |
#endif |
330 |
+ |
if (alloc_stat /= 0 ) then |
331 |
+ |
thisStat = -1 |
332 |
+ |
write(*,*) 'Could not allocate nSkipsForAtom array' |
333 |
+ |
return |
334 |
+ |
endif |
335 |
+ |
|
336 |
|
maxSkipsForAtom = 0 |
337 |
+ |
#ifdef IS_MPI |
338 |
+ |
do j = 1, nAtomsInRow |
339 |
+ |
#else |
340 |
|
do j = 1, nLocal |
341 |
+ |
#endif |
342 |
|
nSkipsForAtom(j) = 0 |
343 |
|
#ifdef IS_MPI |
344 |
|
id1 = AtomRowToGlobal(j) |
363 |
|
end do |
364 |
|
enddo |
365 |
|
|
366 |
+ |
#ifdef IS_MPI |
367 |
+ |
allocate(skipsForAtom(nAtomsInRow, maxSkipsForAtom), stat=alloc_stat) |
368 |
+ |
#else |
369 |
|
allocate(skipsForAtom(nLocal, maxSkipsForAtom), stat=alloc_stat) |
370 |
+ |
#endif |
371 |
|
if (alloc_stat /= 0 ) then |
372 |
|
write(*,*) 'Could not allocate skipsForAtom array' |
373 |
|
return |
374 |
|
endif |
375 |
|
|
376 |
+ |
#ifdef IS_MPI |
377 |
+ |
do j = 1, nAtomsInRow |
378 |
+ |
#else |
379 |
|
do j = 1, nLocal |
380 |
+ |
#endif |
381 |
|
nSkipsForAtom(j) = 0 |
382 |
|
#ifdef IS_MPI |
383 |
|
id1 = AtomRowToGlobal(j) |
387 |
|
do i = 1, nExcludes_Local |
388 |
|
if (excludesLocal(1,i) .eq. id1 ) then |
389 |
|
nSkipsForAtom(j) = nSkipsForAtom(j) + 1 |
390 |
< |
#ifdef IS_MPI |
391 |
< |
id2 = AtomColToGlobal(excludesLocal(2,i)) |
367 |
< |
#else |
390 |
> |
! exclude lists have global ID's so this line is |
391 |
> |
! the same in MPI and non-MPI |
392 |
|
id2 = excludesLocal(2,i) |
369 |
– |
#endif |
393 |
|
skipsForAtom(j, nSkipsForAtom(j)) = id2 |
394 |
|
endif |
395 |
< |
if (excludesLocal(2, i) .eq. id2 ) then |
395 |
> |
if (excludesLocal(2, i) .eq. id1 ) then |
396 |
|
nSkipsForAtom(j) = nSkipsForAtom(j) + 1 |
397 |
< |
#ifdef IS_MPI |
398 |
< |
id2 = AtomColToGlobal(excludesLocal(1,i)) |
376 |
< |
#else |
397 |
> |
! exclude lists have global ID's so this line is |
398 |
> |
! the same in MPI and non-MPI |
399 |
|
id2 = excludesLocal(1,i) |
378 |
– |
#endif |
400 |
|
skipsForAtom(j, nSkipsForAtom(j)) = id2 |
401 |
|
endif |
402 |
|
end do |
498 |
|
thisStat = 0 |
499 |
|
|
500 |
|
call FreeSimGlobals() |
480 |
– |
|
481 |
– |
allocate(nSkipsForAtom(nLocal), stat=alloc_stat) |
482 |
– |
if (alloc_stat /= 0 ) then |
483 |
– |
thisStat = -1 |
484 |
– |
return |
485 |
– |
endif |
501 |
|
|
502 |
|
allocate(excludesLocal(2,nExcludes_Local), stat=alloc_stat) |
503 |
|
if (alloc_stat /= 0 ) then |
524 |
|
!We free in the opposite order in which we allocate in. |
525 |
|
|
526 |
|
if (allocated(skipsForAtom)) deallocate(skipsForAtom) |
527 |
+ |
if (allocated(nSkipsForAtom)) deallocate(nSkipsForAtom) |
528 |
+ |
if (allocated(mfactLocal)) deallocate(mfactLocal) |
529 |
|
if (allocated(mfactCol)) deallocate(mfactCol) |
530 |
|
if (allocated(mfactRow)) deallocate(mfactRow) |
531 |
|
if (allocated(groupListCol)) deallocate(groupListCol) |