src_MIN sum_gradient from src_MD
authorCezary Czaplewski <czarek@cell.kias.re.kr>
Tue, 15 Mar 2016 04:35:16 +0000 (13:35 +0900)
committerCezary Czaplewski <czarek@cell.kias.re.kr>
Tue, 15 Mar 2016 04:35:16 +0000 (13:35 +0900)
source/unres/src_MIN/energy_p_new_barrier.F

index 072053a..8943726 100644 (file)
@@ -441,12 +441,9 @@ cMS$ATTRIBUTES C ::  proc_proc
 #endif
 #ifdef MPI
       include 'mpif.h'
-      double precision gradbufc(3,maxres),gradbufx(3,maxres),
-     &  glocbuf(4*maxres),gradbufc_sum(3,maxres)
-#else
-      double precision gradbufc(3,maxres),gradbufx(3,maxres),
-     &  glocbuf(4*maxres),gradbufc_sum(3,maxres)
 #endif
+      double precision gradbufc(3,maxres),gradbufx(3,maxres),
+     &  glocbuf(4*maxres),gradbufc_sum(3,maxres),gloc_scbuf(3,maxres)
       include 'COMMON.SETUP'
       include 'COMMON.IOUNITS'
       include 'COMMON.FFIELD'
@@ -458,8 +455,13 @@ cMS$ATTRIBUTES C ::  proc_proc
       include 'COMMON.CONTROL'
       include 'COMMON.TIME1'
       include 'COMMON.MAXGRAD'
+      include 'COMMON.SCCOR'
 #ifdef TIMING
+#ifdef MPI
       time01=MPI_Wtime()
+#else
+      time01=tcpu()
+#endif
 #endif
 #ifdef DEBUG
       write (iout,*) "sum_gradient gvdwc, gvdwx"
@@ -554,31 +556,61 @@ c      enddo
       enddo
       call flush(iout)
 #endif
-      call MPI_AllReduce(gradbufc(1,1),gradbufc_sum(1,1),3*nres,
-     &    MPI_DOUBLE_PRECISION,MPI_SUM,FG_COMM,IERR)
-      time_reduce=time_reduce+MPI_Wtime()-time00
-#ifdef DEBUG
-      write (iout,*) "gradbufc_sum after allreduce"
       do i=1,nres
-        write (iout,'(i3,3f10.5)') i,(gradbufc_sum(j,i),j=1,3)
+        do j=1,3
+          gradbufc_sum(j,i)=gradbufc(j,i)
+        enddo
       enddo
-      call flush(iout)
+c      call MPI_AllReduce(gradbufc(1,1),gradbufc_sum(1,1),3*nres,
+c     &    MPI_DOUBLE_PRECISION,MPI_SUM,FG_COMM,IERR)
+c      time_reduce=time_reduce+MPI_Wtime()-time00
+#ifdef DEBUG
+c      write (iout,*) "gradbufc_sum after allreduce"
+c      do i=1,nres
+c        write (iout,'(i3,3f10.5)') i,(gradbufc_sum(j,i),j=1,3)
+c      enddo
+c      call flush(iout)
 #endif
 #ifdef TIMING
-      time_allreduce=time_allreduce+MPI_Wtime()-time00
+c      time_allreduce=time_allreduce+MPI_Wtime()-time00
 #endif
       do i=nnt,nres
         do k=1,3
           gradbufc(k,i)=0.0d0
         enddo
       enddo
-      do i=igrad_start,igrad_end
-        do j=jgrad_start(i),jgrad_end(i)
-          do k=1,3
-            gradbufc(k,i)=gradbufc(k,i)+gradbufc_sum(k,j)
-          enddo
+#ifdef DEBUG
+      write (iout,*) "igrad_start",igrad_start," igrad_end",igrad_end
+      write (iout,*) (i," jgrad_start",jgrad_start(i),
+     &                  " jgrad_end  ",jgrad_end(i),
+     &                  i=igrad_start,igrad_end)
+#endif
+c
+c Obsolete and inefficient code; we can make the effort O(n) and, therefore,
+c do not parallelize this part.
+c
+c      do i=igrad_start,igrad_end
+c        do j=jgrad_start(i),jgrad_end(i)
+c          do k=1,3
+c            gradbufc(k,i)=gradbufc(k,i)+gradbufc_sum(k,j)
+c          enddo
+c        enddo
+c      enddo
+      do j=1,3
+        gradbufc(j,nres-1)=gradbufc_sum(j,nres)
+      enddo
+      do i=nres-2,nnt,-1
+        do j=1,3
+          gradbufc(j,i)=gradbufc(j,i+1)+gradbufc_sum(j,i+1)
         enddo
       enddo
+#ifdef DEBUG
+      write (iout,*) "gradbufc after summing"
+      do i=1,nres
+        write (iout,'(i3,3f10.5)') i,(gradbufc(j,i),j=1,3)
+      enddo
+      call flush(iout)
+#endif
       else
 #endif
 #ifdef DEBUG
@@ -588,16 +620,37 @@ c      enddo
       enddo
       call flush(iout)
 #endif
-      do i=nnt,nres-1
-        do k=1,3
-          gradbufc(k,i)=0.0d0
+      do i=1,nres
+        do j=1,3
+          gradbufc_sum(j,i)=gradbufc(j,i)
+          gradbufc(j,i)=0.0d0
         enddo
-        do j=i+1,nres
-          do k=1,3
-            gradbufc(k,i)=gradbufc(k,i)+gradbufc(k,j)
-          enddo
+      enddo
+      do j=1,3
+        gradbufc(j,nres-1)=gradbufc_sum(j,nres)
+      enddo
+      do i=nres-2,nnt,-1
+        do j=1,3
+          gradbufc(j,i)=gradbufc(j,i+1)+gradbufc_sum(j,i+1)
         enddo
       enddo
+c      do i=nnt,nres-1
+c        do k=1,3
+c          gradbufc(k,i)=0.0d0
+c        enddo
+c        do j=i+1,nres
+c          do k=1,3
+c            gradbufc(k,i)=gradbufc(k,i)+gradbufc(k,j)
+c          enddo
+c        enddo
+c      enddo
+#ifdef DEBUG
+      write (iout,*) "gradbufc after summing"
+      do i=1,nres
+        write (iout,'(i3,3f10.5)') i,(gradbufc(j,i),j=1,3)
+      enddo
+      call flush(iout)
+#endif
 #ifdef MPI
       endif
 #endif
@@ -675,7 +728,6 @@ c      enddo
      &   +wturn3*gel_loc_turn3(i)
      &   +wturn6*gel_loc_turn6(i)
      &   +wel_loc*gel_loc_loc(i)
-     &   +wsccor*gsccor_loc(i)
       enddo
 #ifdef DEBUG
       write (iout,*) "gloc after adding corr"
@@ -694,6 +746,19 @@ c      enddo
         do i=1,4*nres
           glocbuf(i)=gloc(i,icg)
         enddo
+#ifdef DEBUG
+      write (iout,*) "gloc_sc before reduce"
+      do i=1,nres
+       do j=1,3
+        write (iout,*) i,j,gloc_sc(j,i,icg)
+       enddo
+      enddo
+#endif
+        do i=1,nres
+         do j=1,3
+          gloc_scbuf(j,i)=gloc_sc(j,i,icg)
+         enddo
+        enddo
         time00=MPI_Wtime()
         call MPI_Barrier(FG_COMM,IERR)
         time_barrier_g=time_barrier_g+MPI_Wtime()-time00
@@ -704,8 +769,18 @@ c      enddo
      &    MPI_DOUBLE_PRECISION,MPI_SUM,king,FG_COMM,IERR)
         call MPI_Reduce(glocbuf(1),gloc(1,icg),4*nres,
      &    MPI_DOUBLE_PRECISION,MPI_SUM,king,FG_COMM,IERR)
+        call MPI_Reduce(gloc_scbuf(1,1),gloc_sc(1,1,icg),3*nres,
+     &    MPI_DOUBLE_PRECISION,MPI_SUM,king,FG_COMM,IERR)
         time_reduce=time_reduce+MPI_Wtime()-time00
 #ifdef DEBUG
+      write (iout,*) "gloc_sc after reduce"
+      do i=1,nres
+       do j=1,3
+        write (iout,*) i,j,gloc_sc(j,i,icg)
+       enddo
+      enddo
+#endif
+#ifdef DEBUG
       write (iout,*) "gloc after reduce"
       do i=1,4*nres
         write (iout,*) i,gloc(i,icg)
@@ -831,7 +906,11 @@ c
       enddo 
 #endif
 #ifdef TIMING
+#ifdef MPI
       time_sumgradient=time_sumgradient+MPI_Wtime()-time01
+#else
+      time_sumgradient=time_sumgradient+tcpu()-time01
+#endif
 #endif
       return
       end
@@ -945,25 +1024,25 @@ C------------------------------------------------------------------------
      &  edihcnstr,ebr*nss,
      &  Uconst,etot
    10 format (/'Virtual-chain energies:'//
-     & 'EVDW=  ',1pE16.6,' WEIGHT=',1pD16.6,' (SC-SC)'/
-     & 'EVDW2= ',1pE16.6,' WEIGHT=',1pD16.6,' (SC-p)'/
-     & 'EES=   ',1pE16.6,' WEIGHT=',1pD16.6,' (p-p)'/
-     & 'EVDWPP=',1pE16.6,' WEIGHT=',1pD16.6,' (p-p VDW)'/
-     & 'ESTR=  ',1pE16.6,' WEIGHT=',1pD16.6,' (stretching)'/
-     & 'EBE=   ',1pE16.6,' WEIGHT=',1pD16.6,' (bending)'/
-     & 'ESC=   ',1pE16.6,' WEIGHT=',1pD16.6,' (SC local)'/
-     & 'ETORS= ',1pE16.6,' WEIGHT=',1pD16.6,' (torsional)'/
-     & 'ETORSD=',1pE16.6,' WEIGHT=',1pD16.6,' (double torsional)'/
-     & 'EHBP=  ',1pE16.6,' WEIGHT=',1pD16.6,
+     & 'EVDW=  ',1pE16.6,' WEIGHT=',1pE16.6,' (SC-SC)'/
+     & 'EVDW2= ',1pE16.6,' WEIGHT=',1pE16.6,' (SC-p)'/
+     & 'EES=   ',1pE16.6,' WEIGHT=',1pE16.6,' (p-p)'/
+     & 'EVDWPP=',1pE16.6,' WEIGHT=',1pE16.6,' (p-p VDW)'/
+     & 'ESTR=  ',1pE16.6,' WEIGHT=',1pE16.6,' (stretching)'/
+     & 'EBE=   ',1pE16.6,' WEIGHT=',1pE16.6,' (bending)'/
+     & 'ESC=   ',1pE16.6,' WEIGHT=',1pE16.6,' (SC local)'/
+     & 'ETORS= ',1pE16.6,' WEIGHT=',1pE16.6,' (torsional)'/
+     & 'ETORSD=',1pE16.6,' WEIGHT=',1pE16.6,' (double torsional)'/
+     & 'EHPB=  ',1pE16.6,' WEIGHT=',1pE16.6,
      & ' (SS bridges & dist. cnstr.)'/
-     & 'ECORR4=',1pE16.6,' WEIGHT=',1pD16.6,' (multi-body)'/
-     & 'ECORR5=',1pE16.6,' WEIGHT=',1pD16.6,' (multi-body)'/
-     & 'ECORR6=',1pE16.6,' WEIGHT=',1pD16.6,' (multi-body)'/
-     & 'EELLO= ',1pE16.6,' WEIGHT=',1pD16.6,' (electrostatic-local)'/
-     & 'ETURN3=',1pE16.6,' WEIGHT=',1pD16.6,' (turns, 3rd order)'/
-     & 'ETURN4=',1pE16.6,' WEIGHT=',1pD16.6,' (turns, 4th order)'/
-     & 'ETURN6=',1pE16.6,' WEIGHT=',1pD16.6,' (turns, 6th order)'/
-     & 'ESCCOR=',1pE16.6,' WEIGHT=',1pD16.6,' (backbone-rotamer corr)'/
+     & 'ECORR4=',1pE16.6,' WEIGHT=',1pE16.6,' (multi-body)'/
+     & 'ECORR5=',1pE16.6,' WEIGHT=',1pE16.6,' (multi-body)'/
+     & 'ECORR6=',1pE16.6,' WEIGHT=',1pE16.6,' (multi-body)'/
+     & 'EELLO= ',1pE16.6,' WEIGHT=',1pE16.6,' (electrostatic-local)'/
+     & 'ETURN3=',1pE16.6,' WEIGHT=',1pE16.6,' (turns, 3rd order)'/
+     & 'ETURN4=',1pE16.6,' WEIGHT=',1pE16.6,' (turns, 4th order)'/
+     & 'ETURN6=',1pE16.6,' WEIGHT=',1pE16.6,' (turns, 6th order)'/
+     & 'ESCCOR=',1pE16.6,' WEIGHT=',1pE16.6,' (backbone-rotamer corr)'/
      & 'EDIHC= ',1pE16.6,' (dihedral angle constraints)'/
      & 'ESS=   ',1pE16.6,' (disulfide-bridge intrinsic energy)'/
      & 'UCONST= ',1pE16.6,' (Constraint energy)'/ 
@@ -4165,39 +4244,39 @@ cd          write (iout,*) "eij",eij
         else
 C Calculate the distance between the two points and its difference from the
 C target distance.
-        dd=dist(ii,jj)
-        rdis=dd-dhpb(i)
+          dd=dist(ii,jj)
+            rdis=dd-dhpb(i)
 C Get the force constant corresponding to this distance.
-        waga=forcon(i)
+            waga=forcon(i)
 C Calculate the contribution to energy.
-        ehpb=ehpb+waga*rdis*rdis
+            ehpb=ehpb+waga*rdis*rdis
 C
 C Evaluate gradient.
 C
-        fac=waga*rdis/dd
+            fac=waga*rdis/dd
 cd      print *,'i=',i,' ii=',ii,' jj=',jj,' dhpb=',dhpb(i),' dd=',dd,
 cd   &   ' waga=',waga,' fac=',fac
-        do j=1,3
-          ggg(j)=fac*(c(j,jj)-c(j,ii))
-        enddo
+            do j=1,3
+              ggg(j)=fac*(c(j,jj)-c(j,ii))
+            enddo
 cd      print '(i3,3(1pe14.5))',i,(ggg(j),j=1,3)
 C If this is a SC-SC distance, we need to calculate the contributions to the
 C Cartesian gradient in the SC vectors (ghpbx).
-        if (iii.lt.ii) then
+          if (iii.lt.ii) then
           do j=1,3
             ghpbx(j,iii)=ghpbx(j,iii)-ggg(j)
             ghpbx(j,jjj)=ghpbx(j,jjj)+ggg(j)
           enddo
-        endif
+          endif
 cgrad        do j=iii,jjj-1
 cgrad          do k=1,3
 cgrad            ghpbc(k,j)=ghpbc(k,j)+ggg(k)
 cgrad          enddo
 cgrad        enddo
-        do k=1,3
-          ghpbc(k,jjj)=ghpbc(k,jjj)+ggg(k)
-          ghpbc(k,iii)=ghpbc(k,iii)-ggg(k)
-        enddo
+          do k=1,3
+            ghpbc(k,jjj)=ghpbc(k,jjj)+ggg(k)
+            ghpbc(k,iii)=ghpbc(k,iii)-ggg(k)
+          enddo
         endif
       enddo
       ehpb=0.5D0*ehpb
@@ -5822,7 +5901,7 @@ cc Omicron is flat angle depending on the value of first digit
 c(see comment below)
 C        print *,i,tauangle(1,i)
         
-       do intertyp=1,3 !intertyp
+        do intertyp=1,3 !intertyp
 cc Added 09 May 2012 (Adasko)
 cc  Intertyp means interaction type of backbone mainchain correlation: 
 c   1 = SC...Ca...Ca...Ca
@@ -8076,12 +8155,12 @@ C                                                                              C
 C          o             o                                                     C
 C     \   /l\           /j\   /                                                C
 C      \ /   \         /   \ /                                                 C
-C       o| o |         | o |o                                                  C
+C       o| o |         | o |o                                                  C                
 C     \ j|/k\|      \  |/k\|l                                                  C
 C      \ /   \       \ /   \                                                   C
 C       o             o                                                        C
-C       i             i                                                        C
-C                                                                              C
+C       i             i                                                        C 
+C                                                                              C           
 CCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCC
 cd      write (2,*) 'eello6_graph2: i,',i,' j',j,' k',k,' l',l
 C AL 7/4/01 s1 would occur in the sixth-order moment, 
@@ -8252,11 +8331,11 @@ c----------------------------------------------------------------------------
       double precision vv(2),pizda(2,2),auxmat(2,2),auxvec(2)
       logical swap
 CCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCC
-C                                                                              C
+C                                                                              C 
 C      Parallel       Antiparallel                                             C
 C                                                                              C
 C          o             o                                                     C 
-C         /l\   /   \   /j\                                                    C
+C         /l\   /   \   /j\                                                    C 
 C        /   \ /     \ /   \                                                   C
 C       /| o |o       o| o |\                                                  C
 C       j|/k\|  /      |/k\|l /                                                C
@@ -8369,18 +8448,18 @@ c----------------------------------------------------------------------------
      & auxvec1(2),auxmat1(2,2)
       logical swap
 CCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCC
-C                                                                              C
+C                                                                              C                       
 C      Parallel       Antiparallel                                             C
 C                                                                              C
-C          o             o                                                     C 
+C          o             o                                                     C
 C         /l\   /   \   /j\                                                    C
 C        /   \ /     \ /   \                                                   C
-C       /| o |o       o| o |\                                                  C 
+C       /| o |o       o| o |\                                                  C
 C     \ j|/k\|      \  |/k\|l                                                  C
-C      \ /   \       \ /   \                                                   C
+C      \ /   \       \ /   \                                                   C 
 C       o     \       o     \                                                  C
 C       i             i                                                        C
-C                                                                              C
+C                                                                              C 
 CCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCC
 C
 C 4/7/01 AL Component s1 was removed, because it pertains to the respective