--- trunk/OOPSE/libmdtools/simulation_module.F90 2004/05/21 15:58:48 1183 +++ trunk/OOPSE/libmdtools/simulation_module.F90 2004/05/27 00:48:12 1198 @@ -23,17 +23,23 @@ module simulation logical, save :: simulation_setup_complete = .false. integer, public, save :: nLocal, nGlobal - integer, public, save :: nGroup, nGroupGlobal + integer, public, save :: nGroups, nGroupGlobal integer, public, save :: nExcludes_Global = 0 integer, public, save :: nExcludes_Local = 0 integer, allocatable, dimension(:,:), public :: excludesLocal integer, allocatable, dimension(:), public :: excludesGlobal integer, allocatable, dimension(:), public :: molMembershipList - integer, allocatable, dimension(:), public :: groupList - integer, allocatable, dimension(:), public :: groupStart + integer, allocatable, dimension(:), public :: groupListRow + integer, allocatable, dimension(:), public :: groupStartRow + integer, allocatable, dimension(:), public :: groupListCol + integer, allocatable, dimension(:), public :: groupStartCol + integer, allocatable, dimension(:), public :: groupListLocal + integer, allocatable, dimension(:), public :: groupStartLocal integer, allocatable, dimension(:), public :: nSkipsForAtom integer, allocatable, dimension(:,:), public :: skipsForAtom - real(kind=dp), allocatable, dimension(:), public :: mfact + real(kind=dp), allocatable, dimension(:), public :: mfactRow + real(kind=dp), allocatable, dimension(:), public :: mfactCol + real(kind=dp), allocatable, dimension(:), public :: mfactLocal real(kind=dp), public, dimension(3,3), save :: Hmat, HmatInv logical, public, save :: boxIsOrthorhombic @@ -58,7 +64,7 @@ contains subroutine SimulationSetup(setThisSim, CnGlobal, CnLocal, c_idents, & CnLocalExcludes, CexcludesLocal, CnGlobalExcludes, CexcludesGlobal, & - CmolMembership, Cmfact, CnGroup, CgroupList, CgroupStart, & + CmolMembership, Cmfact, CnGroups, CgroupList, CgroupStart, & status) type (simtype) :: setThisSim @@ -73,20 +79,20 @@ contains !! Result status, success = 0, status = -1 integer, intent(out) :: status integer :: i, j, me, thisStat, alloc_stat, myNode, id1, id2 - integer :: gStart, gEnd, groupSize, biggestGroupSize, ia + integer :: ia !! mass factors used for molecular cutoffs real ( kind = dp ), dimension(CnLocal) :: Cmfact - integer, intent(in):: CnGroup + integer, intent(in):: CnGroups integer, dimension(CnLocal),intent(in) :: CgroupList - integer, dimension(CnGroup),intent(in) :: CgroupStart + integer, dimension(CnGroups),intent(in) :: CgroupStart integer :: maxSkipsForAtom #ifdef IS_MPI integer, allocatable, dimension(:) :: c_idents_Row integer, allocatable, dimension(:) :: c_idents_Col - integer :: nrow - integer :: ncol + integer :: nAtomsInRow, nGroupsInRow + integer :: nAtomsInCol, nGroupsInCol #endif simulation_setup_complete = .false. @@ -96,7 +102,7 @@ contains nLocal = CnLocal nGlobal = CnGlobal - nGroup = CnGroup + nGroups = CnGroups thisSim = setThisSim @@ -124,31 +130,33 @@ contains status = -1 return endif - nrow = getNrow(plan_row) - ncol = getNcol(plan_col) + nAtomsInRow = getNatomsInRow(plan_atom_row) + nAtomsInCol = getNatomsInCol(plan_atom_col) + nGroupsInRow = getNgroupsInRow(plan_group_row) + nGroupsInCol = getNgroupsInCol(plan_group_col) mynode = getMyNode() - allocate(c_idents_Row(nrow),stat=alloc_stat) + allocate(c_idents_Row(nAtomsInRow),stat=alloc_stat) if (alloc_stat /= 0 ) then status = -1 return endif - allocate(c_idents_Col(ncol),stat=alloc_stat) + allocate(c_idents_Col(nAtomsInCol),stat=alloc_stat) if (alloc_stat /= 0 ) then status = -1 return endif - call gather(c_idents, c_idents_Row, plan_row) - call gather(c_idents, c_idents_Col, plan_col) + call gather(c_idents, c_idents_Row, plan_atom_row) + call gather(c_idents, c_idents_Col, plan_atom_col) - do i = 1, nrow + do i = 1, nAtomsInRow me = getFirstMatchingElement(atypes, "c_ident", c_idents_Row(i)) atid_Row(i) = me enddo - do i = 1, ncol + do i = 1, nAtomsInCol me = getFirstMatchingElement(atypes, "c_ident", c_idents_Col(i)) atid_Col(i) = me enddo @@ -160,9 +168,125 @@ contains if (allocated(c_idents_Row)) then deallocate(c_idents_Row) endif + +#endif + +#ifdef IS_MPI + allocate(groupStartRow(nGroupsInRow+1),stat=alloc_stat) + if (alloc_stat /= 0 ) then + status = -1 + return + endif + allocate(groupStartCol(nGroupsInCol+1),stat=alloc_stat) + if (alloc_stat /= 0 ) then + status = -1 + return + endif + allocate(groupListRow(nAtomsInRow),stat=alloc_stat) + if (alloc_stat /= 0 ) then + status = -1 + return + endif + allocate(groupListCol(nAtomsInCol),stat=alloc_stat) + if (alloc_stat /= 0 ) then + status = -1 + return + endif + allocate(mfactRow(nAtomsInRow),stat=alloc_stat) + if (alloc_stat /= 0 ) then + status = -1 + return + endif + allocate(mfactCol(nAtomsInCol),stat=alloc_stat) + if (alloc_stat /= 0 ) then + status = -1 + return + endif + allocate(groupStartLocal(nGroups), stat=alloc_stat) + if (alloc_stat /= 0 ) then + status = -1 + return + endif + allocate(groupListLocal(nLocal), stat=alloc_stat) + if (alloc_stat /= 0 ) then + status = -1 + return + endif + allocate(mfactLocal(nLocal), stat=alloc_stat) + if (alloc_stat /= 0 ) then + status = -1 + return + endif + + groupStartLocal = CgroupStart + groupListLocal = CgroupList + mfactLocal = Cmfact + + call gather(groupStartLocal, groupStartRow, plan_group_row) + call gather(groupStartLocal, groupStartCol, plan_group_col) + groupStartRow(nGroupsInRow+1) = nAtomsInRow + groupStartCol(nGroupsInCol+1) = nAtomsInCol + call gather(groupListLocal, groupListRow, plan_atom_row) + call gather(groupListLocal, groupListCol, plan_atom_col) + call gather(mfactLocal, mfactRow, plan_atom_row) + call gather(mfactLocal, mfactCol, plan_atom_col) + if (allocated(mfactLocal)) then + deallocate(mfactLocal) + end if + if (allocated(groupListLocal)) then + deallocate(groupListLocal) + endif + if (allocated(groupStartLocal)) then + deallocate(groupStartLocal) + endif +#else + allocate(groupStartRow(nGroups+1),stat=alloc_stat) + if (alloc_stat /= 0 ) then + status = -1 + return + endif + allocate(groupStartCol(nGroups+1),stat=alloc_stat) + if (alloc_stat /= 0 ) then + status = -1 + return + endif + allocate(groupListRow(nLocal),stat=alloc_stat) + if (alloc_stat /= 0 ) then + status = -1 + return + endif + allocate(groupListCol(nLocal),stat=alloc_stat) + if (alloc_stat /= 0 ) then + status = -1 + return + endif + allocate(mfactRow(nLocal),stat=alloc_stat) + if (alloc_stat /= 0 ) then + status = -1 + return + endif + allocate(mfactCol(nLocal),stat=alloc_stat) + if (alloc_stat /= 0 ) then + status = -1 + return + endif + do i = 1, nGroups + groupStartRow(i) = CgroupStart(i) + groupStartCol(i) = CgroupStart(i) + end do + groupStartRow(nGroups+1) = nLocal + groupStartCol(nGroups+1) = nLocal + do i = 1, nLocal + groupListRow(i) = CgroupList(i) + groupListCol(i) = CgroupList(i) + mfactRow(i) = Cmfact(i) + mfactCol(i) = Cmfact(i) + end do + #endif + ! We build the local atid's for both mpi and nonmpi do i = 1, nLocal @@ -180,7 +304,7 @@ contains do j = 1, nLocal nSkipsForAtom(j) = 0 #ifdef IS_MPI - id1 = tagRow(j) + id1 = AtomRowToGlobal(j) #else id1 = j #endif @@ -211,7 +335,7 @@ contains do j = 1, nLocal nSkipsForAtom(j) = 0 #ifdef IS_MPI - id1 = tagRow(j) + id1 = AtomRowToGlobal(j) #else id1 = j #endif @@ -219,7 +343,7 @@ contains if (excludesLocal(1,i) .eq. id1 ) then nSkipsForAtom(j) = nSkipsForAtom(j) + 1 #ifdef IS_MPI - id2 = tagColumn(excludesLocal(2,i)) + id2 = AtomColToGlobal(excludesLocal(2,i)) #else id2 = excludesLocal(2,i) #endif @@ -228,7 +352,7 @@ contains if (excludesLocal(2, i) .eq. id2 ) then nSkipsForAtom(j) = nSkipsForAtom(j) + 1 #ifdef IS_MPI - id2 = tagColumn(excludesLocal(1,i)) + id2 = AtomColToGlobal(excludesLocal(1,i)) #else id2 = excludesLocal(1,i) #endif @@ -245,28 +369,6 @@ contains molMemberShipList(i) = CmolMembership(i) enddo - biggestGroupSize = 0 - do i = 1, nGroup - groupStart(i) = CgroupStart(i) - groupSize = 0 - gStart = groupStart(i) - if (i .eq. nGroup) then - gEnd = nLocal - else - gEnd = CgroupStart(i+1) - 1 - endif - do ia = gStart, gEnd - groupList(ia) = CgroupList(ia) - groupSize = groupSize + 1 - enddo - if (groupSize .gt. biggestGroupSize) biggestGroupSize = groupSize - enddo - groupStart(nGroup+1) = nLocal+1 - - do i = 1, nLocal - mfact(i) = Cmfact(i) - enddo - if (status == 0) simulation_setup_complete = .true. end subroutine SimulationSetup @@ -379,24 +481,6 @@ contains thisStat = -1 return endif - - allocate(groupStart(nGroup+1), stat=alloc_stat) - if (alloc_stat /= 0 ) then - thisStat = -1 - return - endif - - allocate(groupList(nLocal), stat=alloc_stat) - if (alloc_stat /= 0 ) then - thisStat = -1 - return - endif - - allocate(mfact(nLocal), stat=alloc_stat) - if (alloc_stat /= 0 ) then - thisStat = -1 - return - endif end subroutine InitializeSimGlobals @@ -405,9 +489,12 @@ contains !We free in the opposite order in which we allocate in. if (allocated(skipsForAtom)) deallocate(skipsForAtom) - if (allocated(mfact)) deallocate(mfact) - if (allocated(groupList)) deallocate(groupList) - if (allocated(groupStart)) deallocate(groupStart) + if (allocated(mfactCol)) deallocate(mfactCol) + if (allocated(mfactRow)) deallocate(mfactRow) + if (allocated(groupListCol)) deallocate(groupListCol) + if (allocated(groupListRow)) deallocate(groupListRow) + if (allocated(groupStartCol)) deallocate(groupStartCol) + if (allocated(groupStartRow)) deallocate(groupStartRow) if (allocated(molMembershipList)) deallocate(molMembershipList) if (allocated(excludesGlobal)) deallocate(excludesGlobal) if (allocated(excludesLocal)) deallocate(excludesLocal)