dynamic dissulfides with finegrain parallelization cont.
[unres.git] / source / unres / src_MD / ssMD.F
index b425056..bf1a9b3 100644 (file)
@@ -400,10 +400,10 @@ c-------END SECOND METHOD, CONTINUOUS SECOND DERIVATIVE
       if (havebond) then
 #ifndef CLUST
 #ifndef WHAM
-        if (dyn_ssbond_ij(i,j).eq.1.0d300) then
-          write(iout,'(a15,f12.2,f8.1,2i5)')
-     &         "SSBOND_E_FORM",totT,t_bath,i,j
-        endif
+c        if (dyn_ssbond_ij(i,j).eq.1.0d300) then
+c          write(iout,'(a15,f12.2,f8.1,2i5)')
+c     &         "SSBOND_E_FORM",totT,t_bath,i,j
+c        endif
 #endif
 #endif
         dyn_ssbond_ij(i,j)=eij
@@ -411,8 +411,8 @@ c-------END SECOND METHOD, CONTINUOUS SECOND DERIVATIVE
         dyn_ssbond_ij(i,j)=1.0d300
 #ifndef CLUST
 #ifndef WHAM
-        write(iout,'(a15,f12.2,f8.1,2i5)')
-     &       "SSBOND_E_BREAK",totT,t_bath,i,j
+c        write(iout,'(a15,f12.2,f8.1,2i5)')
+c     &       "SSBOND_E_BREAK",totT,t_bath,i,j
 #endif
 #endif
       endif
@@ -449,10 +449,15 @@ c-------END TESTING CODE
      &       +(eom12*(dc_norm(k,nres+i)-om12*dc_norm(k,nres+j))
      &       +eom2*(erij(k)-om2*dc_norm(k,nres+j)))*dscj_inv
       enddo
-      do k=i,j-1
-        do l=1,3
-          gvdwc(l,k)=gvdwc(l,k)+gg(l)
-        enddo
+cgrad      do k=i,j-1
+cgrad        do l=1,3
+cgrad          gvdwc(l,k)=gvdwc(l,k)+gg(l)
+cgrad        enddo
+cgrad      enddo
+
+      do l=1,3
+        gvdwc(l,i)=gvdwc(l,i)-gg(l)
+        gvdwc(l,j)=gvdwc(l,j)+gg(l)
       enddo
 
       return
@@ -507,9 +512,13 @@ c      implicit none
 
 c     Includes
       include 'DIMENSIONS'
+#ifdef MPI
+      include "mpif.h"
+#endif
       include 'COMMON.SBRIDGE'
       include 'COMMON.CHAIN'
       include 'COMMON.IOUNITS'
+      include 'COMMON.SETUP'
 #ifndef CLUST
 #ifndef WHAM
       include 'COMMON.MD'
@@ -523,7 +532,8 @@ c     Local variables
      &     allihpb(maxdim),alljhpb(maxdim),
      &     newnss,newihpb(maxdim),newjhpb(maxdim)
       logical found
-
+      integer i_newnss(max_fg_procs),displ(max_fg_procs)
+      integer g_newihpb(maxdim),g_newjhpb(maxdim),g_newnss
 
       allnss=0
       do i=1,nres-1
@@ -571,6 +581,35 @@ cmc      write(iout,*)"ALLNSS ",allnss,(allihpb(i),alljhpb(i),i=1,allnss)
           newjhpb(newnss)=alljhpb(i)
         endif
       enddo
+
+      if (nfgtasks.gt.1)then
+
+        call MPI_Reduce(newnss,g_newnss,1,
+     &    MPI_INTEGER,MPI_SUM,king,FG_COMM,IERR)
+        call MPI_Gather(newnss,1,MPI_INTEGER,
+     &                  i_newnss,1,MPI_INTEGER,king,FG_COMM,IERR)
+        displ(0)=0
+        do i=1,nfgtasks-1,1
+          displ(i)=i_newnss(i-1)+displ(i-1)
+        enddo
+        call MPI_Gatherv(newihpb,newnss,MPI_INTEGER,
+     &                   g_newihpb,i_newnss,displ,MPI_INTEGER,
+     &                   king,FG_COMM,IERR)     
+        call MPI_Gatherv(newjhpb,newnss,MPI_INTEGER,
+     &                   g_newjhpb,i_newnss,displ,MPI_INTEGER,
+     &                   king,FG_COMM,IERR)     
+        if(fg_rank.eq.0) then
+c         print *,'g_newnss',g_newnss
+c         print *,'g_newihpb',(g_newihpb(i),i=1,g_newnss)
+c         print *,'g_newjhpb',(g_newjhpb(i),i=1,g_newnss)
+         newnss=g_newnss  
+         do i=1,newnss
+          newihpb(i)=g_newihpb(i)
+          newjhpb(i)=g_newjhpb(i)
+         enddo
+        endif
+      endif
+
       diff=newnss-nss
 
 cmc      write(iout,*)"NEWNSS ",newnss,(newihpb(i),newjhpb(i),i=1,newnss)
@@ -578,13 +617,13 @@ cmc      write(iout,*)"NEWNSS ",newnss,(newihpb(i),newjhpb(i),i=1,newnss)
       do i=1,nss
         found=.false.
         do j=1,newnss
-          if (ihpb(i).eq.newihpb(j) .and.
-     &         jhpb(i).eq.newjhpb(j)) found=.true.
+          if (idssb(i).eq.newihpb(j) .and.
+     &         jdssb(i).eq.newjhpb(j)) found=.true.
         enddo
 #ifndef CLUST
 #ifndef WHAM
         if (.not.found) write(iout,'(a15,f12.2,f8.1,2i5)')
-     &       "SSBOND_BREAK",totT,t_bath,ihpb(i),jhpb(i)
+     &       "SSBOND_BREAK",totT,t_bath,idssb(i),jdssb(i)
 #endif
 #endif
       enddo
@@ -592,8 +631,8 @@ cmc      write(iout,*)"NEWNSS ",newnss,(newihpb(i),newjhpb(i),i=1,newnss)
       do i=1,newnss
         found=.false.
         do j=1,nss
-          if (newihpb(i).eq.ihpb(j) .and.
-     &         newjhpb(i).eq.jhpb(j)) found=.true.
+          if (newihpb(i).eq.idssb(j) .and.
+     &         newjhpb(i).eq.jdssb(j)) found=.true.
         enddo
 #ifndef CLUST
 #ifndef WHAM
@@ -603,27 +642,10 @@ cmc      write(iout,*)"NEWNSS ",newnss,(newihpb(i),newjhpb(i),i=1,newnss)
 #endif
       enddo
 
-      if (diff.gt.0) then
-        do i=1,diff
-          ihpb(nhpb+i)=ihpb(nss+i)
-          jhpb(nhpb+i)=jhpb(nss+i)
-          forcon(nhpb+i)=forcon(nss+i)
-          dhpb(nhpb+i)=dhpb(nss+i)
-        enddo
-      else if (diff.lt.0) then
-        do i=diff,-1
-          ihpb(nss+i)=ihpb(nhpb+i)
-          jhpb(nss+i)=jhpb(nhpb+i)
-          forcon(nss+i)=forcon(nhpb+i)
-          dhpb(nss+i)=dhpb(nhpb+i)
-        enddo
-      endif
-
-      nhpb=nhpb+diff
       nss=newnss
       do i=1,nss
-        ihpb(i)=newihpb(i)
-        jhpb(i)=newjhpb(i)
+        idssb(i)=newihpb(i)
+        jdssb(i)=newjhpb(i)
       enddo
 
       return