Skip to content

Commit

Permalink
Merge branch 'kn_nompi'
Browse files Browse the repository at this point in the history
  • Loading branch information
KenichiNomura committed Apr 3, 2019
2 parents c335807 + d6600cd commit 81d1903
Show file tree
Hide file tree
Showing 9 changed files with 407 additions and 61 deletions.
9 changes: 6 additions & 3 deletions src/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ include ../make.inc
# suffix rules
.SUFFIXES: .o .F90 .cpp
.F90.o:
$(MPIF90) $(MPIF90_FLAGS) -c $<
$(MPIF90) $(MPIF90_FLAGS) $(LIBS) -c $<

%.o: %.mod

Expand All @@ -12,7 +12,6 @@ OBJS := $(SRCS:.F90=.o)

EXE := rxmd


../$(EXE): $(OBJS)
$(MPIF90) $(MPIF90_FLAGS) -o ../$(EXE) $(OBJS) module.o $(LIBS)

Expand All @@ -37,8 +36,12 @@ init.o : fileio.o

main.o : init.o

nompi: nompi.f90
$(FC) $(FC_FLAGS) -DNOMPI -c nompi.f90 module.F90
make MPIF90=$(FC) MPIF90_FLAGS="$(FC_FLAGS) -DNOMPI" OBJS="$(OBJS) nompi.o" $(EXE)

clean:
rm -f PI* *.o *.mod *.MOD mpif.h ../rxmd rxmd
rm -f PI* *.o *.mod *.MOD mpif.h ../rxmd

rebuild:
make clean
Expand Down
21 changes: 13 additions & 8 deletions src/cg.F90
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,8 @@ subroutine ConjugateGradient(atype,pos)
p(1:NATOMS,1:3)=gnew(1:NATOMS,1:3)

PE(0)=sum(PE(1:13))
call MPI_ALLREDUCE(PE, GPE, size(PE), MPI_DOUBLE_PRECISION, MPI_SUM, MPI_COMM_WORLD, ierr)
call MPI_ALLREDUCE(MPI_IN_PLACE, PE, size(PE), MPI_DOUBLE_PRECISION, MPI_SUM, MPI_COMM_WORLD, ierr)
GPE=PE
GPEnew=GPE(0)

!--- if no bracket range was found here, you are at the energy minimum already.
Expand All @@ -67,7 +68,8 @@ subroutine ConjugateGradient(atype,pos)

GPEold=GPEnew
PE(0)=sum(PE(1:13))
call MPI_ALLREDUCE(PE, GPE, size(PE), MPI_DOUBLE_PRECISION, MPI_SUM, MPI_COMM_WORLD, ierr)
call MPI_ALLREDUCE(MPI_IN_PLACE, PE, size(PE), MPI_DOUBLE_PRECISION, MPI_SUM, MPI_COMM_WORLD, ierr)
GPE=PE
GPEnew=GPE(0)

if(abs(GPEnew-GPEold)<=CG_tol*GNATOMS) then
Expand Down Expand Up @@ -162,7 +164,8 @@ subroutine WolfeConditions(atype,pos,p,stepl,isLowerEnergy,isArmijoRule,isCurvat
call FORCE(atype, pos, fbefore, qTmp)

PE(0)=sum(PE(1:13))
call MPI_ALLREDUCE(PE, GPE, size(PE), MPI_DOUBLE_PRECISION, MPI_SUM, MPI_COMM_WORLD, ierr)
call MPI_ALLREDUCE(MPI_IN_PLACE, PE, size(PE), MPI_DOUBLE_PRECISION, MPI_SUM, MPI_COMM_WORLD, ierr)
GPE=PE
GPEbefore=GPE(0)

! Evaluate df(x+alpha*p) and f(x+alpha*p)
Expand All @@ -178,7 +181,8 @@ subroutine WolfeConditions(atype,pos,p,stepl,isLowerEnergy,isArmijoRule,isCurvat
call FORCE(atypeTmp, posTmp, fafter, qTmp)

PE(0)=sum(PE(1:13))
call MPI_ALLREDUCE(PE, GPE, size(PE), MPI_DOUBLE_PRECISION, MPI_SUM, MPI_COMM_WORLD, ierr)
call MPI_ALLREDUCE(MPI_IN_PLACE, PE, size(PE), MPI_DOUBLE_PRECISION, MPI_SUM, MPI_COMM_WORLD, ierr)
GPE=PE
GPEafter=GPE(0)

isLowerEnergy = GPEafter < GPEbefore
Expand Down Expand Up @@ -311,20 +315,20 @@ end function MigrateVec3D


!---------------------------------------------------------------------------------
function DotProductVec3D(v1, v2, Nelems) result (ret)
function DotProductVec3D(v1, v2, Nelems) result (vsum)
!---------------------------------------------------------------------------------
implicit none
integer,intent(in) :: Nelems
real(8),intent(in) :: v1(Nelems,3), v2(Nelems,3)
integer :: i
real(8) :: vsum, ret
real(8) :: vsum

vsum = 0.d0
do i=1, Nelems
vsum = vsum + sum(v1(i,1:3)*v2(i,1:3))
enddo

call MPI_ALLREDUCE(vsum, ret, 1, MPI_DOUBLE_PRECISION, MPI_SUM, MPI_COMM_WORLD, ierr)
call MPI_ALLREDUCE(MPI_IN_PLACE, vsum, 1, MPI_DOUBLE_PRECISION, MPI_SUM, MPI_COMM_WORLD, ierr)

return
end function DotProductVec3D
Expand Down Expand Up @@ -376,7 +380,8 @@ function EvaluateEnergyWithStep(atype,pos,p,stepl) result(potentialEnergy)
NATOMS = NATOMSTmp

PE(0)=sum(PE(1:13))
call MPI_ALLREDUCE(PE, GPE, size(PE), MPI_DOUBLE_PRECISION, MPI_SUM, MPI_COMM_WORLD, ierr)
call MPI_ALLREDUCE(MPI_IN_PLACE, PE, size(PE), MPI_DOUBLE_PRECISION, MPI_SUM, MPI_COMM_WORLD, ierr)
GPE=PE
potentialEnergy=GPE(0)

end function EvaluateEnergyWithStep
Expand Down
3 changes: 2 additions & 1 deletion src/fileio.F90
Original file line number Diff line number Diff line change
Expand Up @@ -629,7 +629,8 @@ subroutine WriteBIN(atype, rreal, v, q, fileNameBase)
allocate(ldata(nmeta),gdata(nmeta))
ldata(:)=0
ldata(4+myid+1)=NATOMS
call MPI_ALLREDUCE(ldata,gdata,nmeta,MPI_INTEGER,MPI_SUM,MPI_COMM_WORLD,ierr)
call MPI_ALLREDUCE(MPI_IN_PLACE,ldata,nmeta,MPI_INTEGER,MPI_SUM,MPI_COMM_WORLD,ierr)
gdata = ldata
gdata(1)=nprocs
gdata(2:4)=vprocs
gdata(nmeta)=nstep+current_step
Expand Down
23 changes: 12 additions & 11 deletions src/init.F90
Original file line number Diff line number Diff line change
Expand Up @@ -136,16 +136,14 @@ SUBROUTINE INITSYSTEM(atype, pos, v, f, q)

!--- get total number of atoms per type. This will be used to determine
!--- subroutine cutofflength()
allocate(natoms_per_type(nso),ibuf8(nso)) ! NOTE 8byte int is not supported in MemoryAllocator
allocate(natoms_per_type(nso)) ! NOTE 8byte int is not supported in MemoryAllocator
natoms_per_type(:)=0
do i=1, NATOMS
ity=nint(atype(i))
natoms_per_type(ity)=natoms_per_type(ity)+1
enddo

call MPI_ALLREDUCE(natoms_per_type, ibuf8, nso, MPI_INTEGER8, MPI_SUM, MPI_COMM_WORLD, ierr)
natoms_per_type(1:nso)=ibuf8(1:nso)
deallocate(ibuf8)
call MPI_ALLREDUCE(MPI_IN_PLACE, natoms_per_type, nso, MPI_INTEGER8, MPI_SUM, MPI_COMM_WORLD, ierr)

!--- determine cutoff distances only for exsiting atom pairs
call CUTOFFLENGTH()
Expand All @@ -154,8 +152,8 @@ SUBROUTINE INITSYSTEM(atype, pos, v, f, q)
call UpdateBoxParams()

!--- get global number of atoms
i8=NATOMS ! Convert 4 byte to 8 byte
call MPI_ALLREDUCE(i8, GNATOMS, 1, MPI_INTEGER8, MPI_SUM, MPI_COMM_WORLD, ierr)
GNATOMS=NATOMS ! Convert 4 byte to 8 byte
call MPI_ALLREDUCE(MPI_IN_PLACE, GNATOMS, 1, MPI_INTEGER8, MPI_SUM, MPI_COMM_WORLD, ierr)

!--- Linked List & Near Neighb Parameters
call allocatori2d(nbrlist,1,NBUFFER,0,MAXNEIGHBS)
Expand Down Expand Up @@ -216,7 +214,8 @@ SUBROUTINE INITSYSTEM(atype, pos, v, f, q)
ity = nint(atype(i))
mm = mm + mass(ity)
enddo
call MPI_ALLREDUCE (mm, gmm, 1, MPI_DOUBLE_PRECISION, MPI_SUM, MPI_COMM_WORLD, ierr)
call MPI_ALLREDUCE(MPI_IN_PLACE, mm, 1, MPI_DOUBLE_PRECISION, MPI_SUM, MPI_COMM_WORLD, ierr)
gmm = mm
dns=gmm/MDBOX*UDENS

!--- allocate & initialize Array size Stat variables
Expand Down Expand Up @@ -330,8 +329,10 @@ SUBROUTINE INITVELOCITY(atype, v)
mm = mm + mass(ity)
enddo

call MPI_ALLREDUCE (vCM, GvCM, size(vCM), MPI_DOUBLE_PRECISION, MPI_SUM, MPI_COMM_WORLD, ierr)
call MPI_ALLREDUCE (mm, Gmm, 1, MPI_DOUBLE_PRECISION, MPI_SUM, MPI_COMM_WORLD, ierr)
call MPI_ALLREDUCE(MPI_IN_PLACE, vCM, size(vCM), MPI_DOUBLE_PRECISION, MPI_SUM, MPI_COMM_WORLD, ierr)
call MPI_ALLREDUCE(MPI_IN_PLACE, mm,1, MPI_DOUBLE_PRECISION, MPI_SUM, MPI_COMM_WORLD, ierr)
GvCM = vCM
Gmm = mm

!--- get the global momentum
GvCM(:)=GvCM(:)/Gmm
Expand All @@ -345,8 +346,8 @@ SUBROUTINE INITVELOCITY(atype, v)
KE = KE + hmas(ity)*sum( v(i,1:3)*v(i,1:3) )
enddo

call MPI_ALLREDUCE (KE, GKE, 1, MPI_DOUBLE_PRECISION, MPI_SUM, MPI_COMM_WORLD, ierr)
GKE = GKE/GNATOMS
call MPI_ALLREDUCE(MPI_IN_PLACE, KE, 1, MPI_DOUBLE_PRECISION, MPI_SUM, MPI_COMM_WORLD, ierr)
GKE = KE/GNATOMS

!--- scale the obtained velocity to get the initial temperature.
vfactor = sqrt(1.5d0*treq/GKE)
Expand Down
24 changes: 13 additions & 11 deletions src/main.F90
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,7 @@ program rxmd
integer :: i,ity,it1,it2,irt,provided
real(8) :: ctmp, dr(3)

!call MPI_INIT(ierr)
call MPI_INIT_THREAD(MPI_THREAD_SERIALIZED,provided,ierr)
call MPI_INIT(ierr)
call MPI_COMM_RANK(MPI_COMM_WORLD, myid, ierr)
call MPI_COMM_SIZE(MPI_COMM_WORLD, nprocs, ierr)

Expand Down Expand Up @@ -131,7 +130,7 @@ subroutine FinalizeMD(irt)
do i=1,nmaxas
ibuf(i)=maxval(maxas(:,i))
enddo
call MPI_ALLREDUCE (ibuf, ibuf1, nmaxas, MPI_INTEGER, MPI_MAX, MPI_COMM_WORLD, ierr)
call MPI_ALLREDUCE(ibuf, ibuf1, nmaxas, MPI_INTEGER, MPI_MAX, MPI_COMM_WORLD, ierr)

call MPI_ALLREDUCE(it_timer, it_timer_max, Ntimer, MPI_INTEGER, MPI_MAX, MPI_COMM_WORLD, ierr)
call MPI_ALLREDUCE(it_timer, it_timer_min, Ntimer, MPI_INTEGER, MPI_MIN, MPI_COMM_WORLD, ierr)
Expand Down Expand Up @@ -499,11 +498,12 @@ subroutine angular_momentum(atype, pos, v)
com(1:3) = mass(ity)*pos(i,1:3)
enddo

call MPI_ALLREDUCE(mm, Gmm, 1, MPI_DOUBLE_PRECISION, MPI_SUM, MPI_COMM_WORLD, ierr)
call MPI_ALLREDUCE(com, Gcom, 3, MPI_DOUBLE_PRECISION, MPI_SUM, MPI_COMM_WORLD, ierr)
call MPI_ALLREDUCE(MPI_IN_PLACE, mm, 1, MPI_DOUBLE_PRECISION, MPI_SUM, MPI_COMM_WORLD, ierr)
Gmm = mm
call MPI_ALLREDUCE(MPI_IN_PLACE, com, 3, MPI_DOUBLE_PRECISION, MPI_SUM, MPI_COMM_WORLD, ierr)
Gcom = com
Gcom(1:3) = Gcom(1:3)/Gmm


!--- get the angular momentum and inertia tensor from the com
angm(:)=0.d0; Gangm(:)=0.d0
intsr(:,:)=0.d0; Gintsr(:,:)=0.d0
Expand All @@ -528,8 +528,10 @@ subroutine angular_momentum(atype, pos, v)
intsr(3,2) = intsr(2,3)
enddo

call MPI_ALLREDUCE(angm, Gangm, 3, MPI_DOUBLE_PRECISION, MPI_SUM, MPI_COMM_WORLD, ierr)
call MPI_ALLREDUCE(intsr, Gintsr, 9, MPI_DOUBLE_PRECISION, MPI_SUM, MPI_COMM_WORLD, ierr)
call MPI_ALLREDUCE(MPI_IN_PLACE, angm, 3, MPI_DOUBLE_PRECISION, MPI_SUM, MPI_COMM_WORLD, ierr)
Gangm = angm
call MPI_ALLREDUCE(MPI_IN_PLACE, intsr, 9, MPI_DOUBLE_PRECISION, MPI_SUM, MPI_COMM_WORLD, ierr)
Gintsr = intsr

!--- get angular velocity
call matinv(Gintsr, intsr_i)
Expand Down Expand Up @@ -769,7 +771,7 @@ subroutine LinearMomentum(atype, v)
real(8) :: atype(NBUFFER), v(NBUFFER,3)

integer :: i,ity
real(8) :: mm,vCM(3),sbuf(4),rbuf(4)
real(8) :: mm,vCM(3),sbuf(4)

!--- get the local momentum and mass.
vCM(:)=0.d0; mm = 0.d0
Expand All @@ -780,8 +782,8 @@ subroutine LinearMomentum(atype, v)
enddo

sbuf(1)=mm; sbuf(2:4)=vCM(1:3)
call MPI_ALLREDUCE (sbuf, rbuf, size(sbuf), MPI_DOUBLE_PRECISION, MPI_SUM, MPI_COMM_WORLD, ierr)
mm=rbuf(1); vCM(1:3)=rbuf(2:4)
call MPI_ALLREDUCE (MPI_IN_PLACE, sbuf, size(sbuf), MPI_DOUBLE_PRECISION, MPI_SUM, MPI_COMM_WORLD, ierr)
mm=sbuf(1); vCM(1:3)=sbuf(2:4)

!--- get the global momentum
vCM(:)=vCM(:)/mm
Expand Down
8 changes: 6 additions & 2 deletions src/module.F90
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,16 @@ module base
! position, atom type, velocity, force & charge
real(8),allocatable,dimension(:),target :: atype, q
real(8),allocatable,dimension(:,:),target :: pos, v, f

end module

!-------------------------------------------------------------------------------------------
module atoms
!-------------------------------------------------------------------------------------------
include 'mpif.h'
#ifdef NOMPI
use nompi
#else
include 'mpif.h'
#endif

!--- For array size statistics
! 1-NATOMS, 2-nbrlist, 3-nbrlist for qeq, 4-NBUFFER for move, 5-NBUFFER for copy
Expand Down Expand Up @@ -890,3 +893,4 @@ integer(8) function GetTotalMemory()

end module MemoryAllocator
!-------------------------------------------------------------------------------------------

Loading

0 comments on commit 81d1903

Please sign in to comment.