respa cleaning (my bug) and shielding MPI and previous bug cleaning
[unres.git] / source / unres / src_MD-M / energy_split-sep.F
index 43f9baa..e15ab61 100644 (file)
@@ -26,6 +26,7 @@ cMS$ATTRIBUTES C ::  proc_proc
       include 'COMMON.LOCAL'
       include 'COMMON.MD'
       include 'COMMON.CONTROL'
+      include 'COMMON.SHIELD'
 c      write(iout,'(a,i2)')'Calling etotal_long ipot=',ipot
       if (modecalc.eq.12.or.modecalc.eq.14) then
 #ifdef MPI
@@ -133,10 +134,60 @@ C Calculate electrostatic (H-bonding) energy of the main chain.
 C
   107 continue
       call vec_and_deriv
-      if (shield_mode.gt.0) then
+      if (shield_mode.eq.1) then
        call set_shield_fac
+      else if  (shield_mode.eq.2) then
+       call set_shield_fac2
+      if (nfgtasks.gt.1) then
+C#define DEBUG
+#ifdef DEBUG
+       write(iout,*) "befor reduce fac_shield reduce"
+       do i=1,nres
+        write(2,*) "fac",itype(i),fac_shield(i),grad_shield(1,i)
+        write(2,*) "list", shield_list(1,i),ishield_list(i),
+     &  grad_shield_side(1,1,i),grad_shield_loc(1,1,i)
+       enddo
+#endif
+       call MPI_Allgatherv(fac_shield(ivec_start),ivec_count(fg_rank1),
+     &  MPI_DOUBLE_PRECISION,fac_shield(1),ivec_count(0),ivec_displ(0),
+     &  MPI_DOUBLE_PRECISION,FG_COMM,IERR)
+       call MPI_Allgatherv(shield_list(1,ivec_start),
+     &  ivec_count(fg_rank1),
+     &  MPI_I50,shield_list(1,1),ivec_count(0),
+     &  ivec_displ(0),
+     &  MPI_I50,FG_COMM,IERR)
+       call MPI_Allgatherv(ishield_list(ivec_start),
+     &  ivec_count(fg_rank1),
+     &  MPI_INTEGER,ishield_list(1),ivec_count(0),
+     &  ivec_displ(0),
+     &  MPI_INTEGER,FG_COMM,IERR)
+       call MPI_Allgatherv(grad_shield(1,ivec_start),
+     &  ivec_count(fg_rank1),
+     &  MPI_UYZ,grad_shield(1,1),ivec_count(0),
+     &  ivec_displ(0),
+     &  MPI_UYZ,FG_COMM,IERR)
+       call MPI_Allgatherv(grad_shield_side(1,1,ivec_start),
+     &  ivec_count(fg_rank1),
+     &  MPI_SHI,grad_shield_side(1,1,1),ivec_count(0),
+     &  ivec_displ(0),
+     &  MPI_SHI,FG_COMM,IERR)
+       call MPI_Allgatherv(grad_shield_loc(1,1,ivec_start),
+     &  ivec_count(fg_rank1),
+     &  MPI_SHI,grad_shield_loc(1,1,1),ivec_count(0),
+     &  ivec_displ(0),
+     &  MPI_SHI,FG_COMM,IERR)
+#ifdef DEBUG
+       write(iout,*) "after reduce fac_shield reduce"
+       do i=1,nres
+        write(2,*) "fac",itype(i),fac_shield(i),grad_shield(1,i)
+        write(2,*) "list", shield_list(1,i),ishield_list(i),
+     &  grad_shield_side(1,1,i),grad_shield_loc(1,1,i)
+       enddo
+#endif
+C#undef DEBUG
       endif
 
+      endif
       if (ipot.lt.6) then
 #ifdef SPLITELE
          if (welec.gt.0d0.or.wvdwpp.gt.0d0.or.wel_loc.gt.0d0.or.
@@ -235,7 +286,8 @@ C
       energia(10)=eturn6
       energia(20)=Uconst+Uconst_back
       call sum_energy(energia,.true.)
-c      write (iout,*) "Exit ETOTAL_LONG"
+C      call enerprint
+      write (iout,*) "Exit ETOTAL_LONG"
       call flush(iout)
       return
       end
@@ -267,7 +319,7 @@ cMS$ATTRIBUTES C ::  proc_proc
       include 'COMMON.VAR'
       include 'COMMON.LOCAL'
       include 'COMMON.CONTROL'
-
+      include 'COMMON.SHIELD'
 c      write(iout,'(a,i2)')'Calling etotal_short ipot=',ipot
 c      call flush(iout)
       if (modecalc.eq.12.or.modecalc.eq.14) then
@@ -399,36 +451,86 @@ C
 C Calculate electrostatic (H-bonding) energy of the main chain.
 C
   107 continue
-      call vec_and_deriv
-      if (shield_mode.gt.0) then
-       call set_shield_fac
-      endif
-
-      if (ipot.lt.6) then
-#ifdef SPLITELE
-         if (welec.gt.0d0.or.wvdwpp.gt.0d0.or.wel_loc.gt.0d0.or.
-     &       wturn3.gt.0d0.or.wturn4.gt.0d0 .or. wcorr.gt.0.0d0
-     &       .or. wcorr4.gt.0.0d0 .or. wcorr5.gt.0.d0
-     &       .or. wcorr6.gt.0.0d0 .or. wturn6.gt.0.0d0 ) then
-#else
-         if (welec.gt.0d0.or.wel_loc.gt.0d0.or.
-     &       wturn3.gt.0d0.or.wturn4.gt.0d0 .or. wcorr.gt.0.0d0
-     &       .or. wcorr4.gt.0.0d0 .or. wcorr5.gt.0.d0
-     &       .or. wcorr6.gt.0.0d0 .or. wturn6.gt.0.0d0 ) then
-#endif
-           call eelec_scale(ees,evdw1,eel_loc,eello_turn3,eello_turn4)
-         else
-            ees=0
-            evdw1=0
-            eel_loc=0
-            eello_turn3=0
-            eello_turn4=0
-         endif
-      else
+C     call vec_and_deriv
+C     if (shield_mode.eq.1) then
+C       call set_shield_fac
+C      else if  (shield_mode.eq.2) then
+C       call set_shield_fac2
+C      if (nfgtasks.gt.1) then
+C#define DEBUG
+C#ifdef DEBUG
+C       write(iout,*) "befor reduce fac_shield reduce"
+C       do i=1,nres
+C        write(2,*) "fac",itype(i),fac_shield(i),grad_shield(1,i)
+C        write(2,*) "list", shield_list(1,i),ishield_list(i),
+C     &  grad_shield_side(1,1,i),grad_shield_loc(1,1,i)
+C       enddo
+C#endif
+C       call MPI_Allgatherv(fac_shield(ivec_start),ivec_count(fg_rank1),
+C     &  MPI_DOUBLE_PRECISION,fac_shield(1),ivec_count(0),ivec_displ(0),
+C     &  MPI_DOUBLE_PRECISION,FG_COMM,IERR)
+C       call MPI_Allgatherv(shield_list(1,ivec_start),
+C     &  ivec_count(fg_rank1),
+C     &  MPI_I50,shield_list(1,1),ivec_count(0),
+C     &  ivec_displ(0),
+C     &  MPI_I50,FG_COMM,IERR)
+C       call MPI_Allgatherv(ishield_list(ivec_start),
+C     &  ivec_count(fg_rank1),
+C     &  MPI_INTEGER,ishield_list(1),ivec_count(0),
+C     &  ivec_displ(0),
+C     &  MPI_INTEGER,FG_COMM,IERR)
+C       call MPI_Allgatherv(grad_shield(1,ivec_start),
+C     &  ivec_count(fg_rank1),
+C     &  MPI_UYZ,grad_shield(1,1),ivec_count(0),
+C     &  ivec_displ(0),
+C     &  MPI_UYZ,FG_COMM,IERR)
+C       call MPI_Allgatherv(grad_shield_side(1,1,ivec_start),
+C     &  ivec_count(fg_rank1),
+C     &  MPI_SHI,grad_shield_side(1,1,1),ivec_count(0),
+C     &  ivec_displ(0),
+C     &  MPI_SHI,FG_COMM,IERR)
+C       call MPI_Allgatherv(grad_shield_loc(1,1,ivec_start),
+C     &  ivec_count(fg_rank1),
+C     &  MPI_SHI,grad_shield_loc(1,1,1),ivec_count(0),
+C     &  ivec_displ(0),
+C     &  MPI_SHI,FG_COMM,IERR)
+C#ifdef DEBUG
+C       write(iout,*) "after reduce fac_shield reduce"
+C       do i=1,nres
+C        write(2,*) "fac",itype(i),fac_shield(i),grad_shield(1,i)
+C        write(2,*) "list", shield_list(1,i),ishield_list(i),
+C     &  grad_shield_side(1,1,i),grad_shield_loc(1,1,i)
+C       enddo
+C#endif
+C#undef DEBUG
+C      endif
+C
+C      endif
+C      if (ipot.lt.6) then
+C#ifdef SPLITELE
+C         if (welec.gt.0d0.or.wvdwpp.gt.0d0.or.wel_loc.gt.0d0.or.
+C     &       wturn3.gt.0d0.or.wturn4.gt.0d0 .or. wcorr.gt.0.0d0
+C     &       .or. wcorr4.gt.0.0d0 .or. wcorr5.gt.0.d0
+C     &       .or. wcorr6.gt.0.0d0 .or. wturn6.gt.0.0d0 ) then
+C#else
+C         if (welec.gt.0d0.or.wel_loc.gt.0d0.or.
+C     &       wturn3.gt.0d0.or.wturn4.gt.0d0 .or. wcorr.gt.0.0d0
+C     &       .or. wcorr4.gt.0.0d0 .or. wcorr5.gt.0.d0
+C     &       .or. wcorr6.gt.0.0d0 .or. wturn6.gt.0.0d0 ) then
+C#endif
+C           call eelec_scale(ees,evdw1,eel_loc,eello_turn3,eello_turn4)
+C         else
+C            ees=0
+C            evdw1=0
+C            eel_loc=0
+C            eello_turn3=0
+C            eello_turn4=0
+C         endif
+C      else
 c        write (iout,*) "Soft-spheer ELEC potential"
-        call eelec_soft_sphere(ees,evdw1,eel_loc,eello_turn3,
-     &   eello_turn4)
-      endif
+C        call eelec_soft_sphere(ees,evdw1,eel_loc,eello_turn3,
+C     &   eello_turn4)
+C      endif
 
 c
 c Calculate the short-range part of Evdwpp
@@ -509,10 +611,10 @@ C
       energia(17)=estr
       energia(19)=edihcnstr
       energia(21)=esccor
-c      write (iout,*) "ETOTAL_SHORT before SUM_ENERGY"
+      write (iout,*) "ETOTAL_SHORT before SUM_ENERGY"
       call flush(iout)
       call sum_energy(energia,.true.)
-c      write (iout,*) "Exit ETOTAL_SHORT"
+      write (iout,*) "Exit ETOTAL_SHORT"
       call flush(iout)
       return
       end