unres_package_Oct_2016 from emilial
[unres4.git] / source / unres / control.f90
index a8b0df6..8d22bf0 100644 (file)
@@ -7,13 +7,26 @@
       use energy_data
       use control_data
       use minim_data
-      use csa_data
       use geometry, only:int_bounds
+#ifndef CLUSTER
+      use csa_data
 #ifdef WHAM_RUN
       use wham_data
 #endif
+#endif
       implicit none
 !-----------------------------------------------------------------------------
+! commom.control
+!      common /cntrl/
+!      integer :: modecalc,iscode,indpdb,indback,indphi,iranconf,&
+!       icheckgrad,iprint,i2ndstr,mucadyn,constr_dist,symetr
+!      logical :: minim,refstr,pdbref,outpdb,outmol2,overlapsc,&
+!       energy_dec,sideadd,lsecondary,read_cart,unres_pdb,&
+!       vdisulf,searchsc,lmuca,dccart,extconf,out1file,&
+!       gnorm_check,gradout,split_ene
+!... minim = .true. means DO minimization.
+!... energy_dec = .true. means print energy decomposition matrix
+!-----------------------------------------------------------------------------
 ! common.time1
 !     FOUND_NAN - set by calcf to stop sumsl via stopx
 !      COMMON/TIME1/
       logical :: FOUND_NAN
 !      common /timing/
       real(kind=8) :: t_init
+!       time_bcast,time_reduce,time_gather,&
+!       time_sendrecv,time_barrier_e,time_barrier_g,time_scatter,&
+       !t_eelecij,
+!       time_allreduce,&
+!       time_lagrangian,time_cartgrad,&
+!       time_sumgradient,time_intcartderiv,time_inttocart,time_intfcart,&
+!       time_mat,time_fricmatmult,&
+!       time_scatter_fmat,time_scatter_ginv,&
+!       time_scatter_fmatmult,time_scatter_ginvmult,&
+!       t_eshort,t_elong,t_etotal
 !-----------------------------------------------------------------------------
 ! initialize_p.F
 !-----------------------------------------------------------------------------
@@ -38,8 +61,9 @@
 !el      real(kind=8) :: cPoise=2.9361d0, Rb=0.001986d0
 !-----------------------------------------------------------------------------
 !      common /przechowalnia/ subroutines: init_int_table,add_int,add_int_from
-      integer,dimension(:),allocatable :: iturn3_start_all,iturn3_end_all,&
-        iturn4_start_all,iturn4_end_all,iatel_s_all,iatel_e_all !(0:max_fg_procs)
+      integer,dimension(:),allocatable :: iturn3_start_all,&
+        iturn3_end_all,iturn4_start_all,iturn4_end_all,iatel_s_all,&
+        iatel_e_all !(0:max_fg_procs)
       integer,dimension(:,:),allocatable :: ielstart_all,&
         ielend_all !(maxres,0:max_fg_procs-1)
 
 !local variables el
       integer :: i,j,k,l,ichir1,ichir2,iblock,m,maxit
 
-#ifndef WHAM_RUN
+#if .not. defined(WHAM_RUN) && .not. defined(CLUSTER)
       mask_r=.false.
 #ifndef ISNAN
 ! NaNQ initialization
       rr=dacos(100.0d0)
 #ifdef WINPGI
       idumm=proc_proc(rr,i)
-#else
+#elif defined(WHAM_RUN)
       call proc_proc(rr,i)
 #endif
 #endif
       deg2rad=pi/180.0D0
       rad2deg=1.0D0/deg2rad
       angmin=10.0D0*deg2rad
+!el#ifdef CLUSTER
+!el      Rgas = 1.987D-3
+!el#endif
 !
 ! Define I/O units.
 !
       iout=   2
       ipdbin= 3
       ipdb=   7
+#ifdef CLUSTER
+      imol2= 18
+      jplot= 19
+!el      jstatin=10
+      imol2=  4
+      jrms=30
+#else
       icart = 30
       imol2=  4
+      ithep_pdb=51
+      irotam_pdb=52
+      irest1=55
+      irest2=56
+      iifrag=57
+      ientin=18
+      ientout=19
+!rc for write_rmsbank1  
+      izs1=21
+!dr  include secondary structure prediction bias
+      isecpred=27
+#endif
       igeom=  8
       intin=  9
       ithep= 11
-      ithep_pdb=51
       irotam=12
-      irotam_pdb=52
       itorp= 13
       itordp= 23
       ielep= 14
       isidep=15
-#ifdef WHAM_RUN
+#if defined(WHAM_RUN) || defined(CLUSTER)
       isidep1=22 !wham
+#else
+!
+! CSA I/O units (separated from others especially for Jooyoung)
+!
+      icsa_rbank=30
+      icsa_seed=31
+      icsa_history=32
+      icsa_bank=33
+      icsa_bank1=34
+      icsa_alpha=35
+      icsa_alpha1=36
+      icsa_bankt=37
+      icsa_int=39
+      icsa_bank_reminimized=38
+      icsa_native_int=41
+      icsa_in=40
+!rc for ifc error 118
+      icsa_pdb=42
 #endif
       iscpp=25
       icbase=16
       ifourier=20
       istat= 17
-      irest1=55
-      irest2=56
-      iifrag=57
-      ientin=18
-      ientout=19
       ibond = 28
       isccor = 29
-!rc for write_rmsbank1  
-      izs1=21
-!dr  include secondary structure prediction bias
-      isecpred=27
 #ifdef WHAM_RUN
 !
 ! WHAM files
       ihist=30
       iweight=31
       izsc=32
+#endif
+#if defined(WHAM_RUN) || defined(CLUSTER)
 !
 ! setting the mpi variables for WHAM
 !
       nfgtasks1=1
 #endif
 !
-! CSA I/O units (separated from others especially for Jooyoung)
-!
-      icsa_rbank=30
-      icsa_seed=31
-      icsa_history=32
-      icsa_bank=33
-      icsa_bank1=34
-      icsa_alpha=35
-      icsa_alpha1=36
-      icsa_bankt=37
-      icsa_int=39
-      icsa_bank_reminimized=38
-      icsa_native_int=41
-      icsa_in=40
-!rc for ifc error 118
-      icsa_pdb=42
-!
 ! Set default weights of the energy terms.
 !
       wsc=1.0D0 ! in wham:  wlong=1.0D0
       nfl=0
       icg=1
       
-!el      if (run_wham) then !el
 #ifdef WHAM_RUN
-      ndih_constr=0
-
-!      allocate(ww0(max_eneW))
-!      ww0 = reshape((/1.0d0,1.0d0,1.0d0,1.0d0,1.0d0,1.0d0,1.0d0,1.0d0,&
-!          1.0d0,1.0d0,1.0d0,1.0d0,1.0d0,1.0d0,1.0d0,1.0d0,0.4d0,1.0d0,&
-!          1.0d0,0.0d0,0.0/), shape(ww0))
-!
-!      allocate(iww(max_eneW))
+      allocate(iww(max_eneW))
       do i=1,14
         do j=1,14
           if (print_order(i).eq.j) then
         enddo
 1121    continue
       enddo
+#endif
+#if defined(WHAM_RUN) || defined(CLUSTER)
+      ndih_constr=0
+
+!      allocate(ww0(max_eneW))
+!      ww0 = reshape((/1.0d0,1.0d0,1.0d0,1.0d0,1.0d0,1.0d0,1.0d0,1.0d0,&
+!          1.0d0,1.0d0,1.0d0,1.0d0,1.0d0,1.0d0,1.0d0,1.0d0,0.4d0,1.0d0,&
+!          1.0d0,0.0d0,0.0/), shape(ww0))
+!
       calc_grad=.false.
 ! Set timers and counters for the respective routines
       t_func = 0.0d0
       subroutine init_int_table
 
       use geometry, only:int_bounds1
+!el      use MPI_data
 !el      implicit none
 !      implicit real*8 (a-h,o-z)
 !      include 'DIMENSIONS'
 
 !... Determine the numbers of start and end SC-SC interaction
 !... to deal with by current processor.
+!write (iout,*) '******INIT_INT_TABLE nres=',nres,' nnt=',nnt,' nct=',nct
       do i=0,nfgtasks-1
         itask_cont_from(i)=fg_rank
         itask_cont_to(i)=fg_rank
       enddo
       lprint=energy_dec
+!      lprint=.true.
       if (lprint) &
-       write (iout,*) 'INIT_INT_TABLE nres=',nres,' nnt=',nnt,' nct=',nct
+       write (iout,*)'INIT_INT_TABLE nres=',nres,' nnt=',nnt,' nct=',nct
       n_sc_int_tot=(nct-nnt+1)*(nct-nnt)/2-nss
       call int_bounds(n_sc_int_tot,my_sc_inds,my_sc_inde)
-write (iout,*) 'INIT_INT_TABLE nres=',nres,' nnt=',nnt,' nct=',nct
+!write (iout,*) 'INIT_INT_TABLE nres=',nres,' nnt=',nnt,' nct=',nct
       if (lprint) &
         write (iout,*) 'Processor',fg_rank,' CG group',kolor,&
         ' absolute rank',MyRank,&
@@ -1279,19 +1322,19 @@ write (iout,*) 'INIT_INT_TABLE nres=',nres,' nnt=',nnt,' nct=',nct
       iint_end=nres-1
 #endif
 !el       common /przechowalnia/
-      deallocate(iturn3_start_all)
-      deallocate(iturn3_end_all)
-      deallocate(iturn4_start_all)
-      deallocate(iturn4_end_all)
-      deallocate(iatel_s_all)
-      deallocate(iatel_e_all)
-      deallocate(ielstart_all)
-      deallocate(ielend_all)
+!      deallocate(iturn3_start_all)
+!      deallocate(iturn3_end_all)
+!      deallocate(iturn4_start_all)
+!      deallocate(iturn4_end_all)
+!      deallocate(iatel_s_all)
+!      deallocate(iatel_e_all)
+!      deallocate(ielstart_all)
+!      deallocate(ielend_all)
 
-      deallocate(ntask_cont_from_all)
-      deallocate(ntask_cont_to_all)
-      deallocate(itask_cont_from_all)
-      deallocate(itask_cont_to_all)
+!      deallocate(ntask_cont_from_all)
+!      deallocate(ntask_cont_to_all)
+!      deallocate(itask_cont_from_all)
+!      deallocate(itask_cont_to_all)
 !el----------
       return
       end subroutine init_int_table
@@ -1453,6 +1496,7 @@ write (iout,*) 'INIT_INT_TABLE nres=',nres,' nnt=',nnt,' nct=',nct
 !-----------------------------------------------------------------------------
       subroutine add_task(iproc,ntask_cont,itask_cont)
 
+!el      use MPI_data
 !el      implicit none
 !      include "DIMENSIONS"
       integer :: iproc,ntask_cont,itask_cont(0:nfgtasks-1)     !(0:max_fg_procs-1)
@@ -1509,6 +1553,7 @@ write (iout,*) 'INIT_INT_TABLE nres=',nres,' nnt=',nnt,' nct=',nct
       end subroutine int_partition
 #endif
 !-----------------------------------------------------------------------------
+#ifndef CLUSTER
       subroutine hpb_partition
 
 !      implicit real*8 (a-h,o-z)
@@ -1531,8 +1576,9 @@ write (iout,*) 'INIT_INT_TABLE nres=',nres,' nnt=',nnt,' nct=',nct
 #endif
       return
       end subroutine hpb_partition
+#endif
 !-----------------------------------------------------------------------------
-! misc.f in module io_common
+! misc.f in module io_base
 !-----------------------------------------------------------------------------
 !-----------------------------------------------------------------------------
 ! parmread.F
@@ -1686,7 +1732,7 @@ write (iout,*) 'INIT_INT_TABLE nres=',nres,' nnt=',nnt,' nct=',nct
 !     timlim=batime-150.0
 ! Calculate the initial time, if it is not zero (e.g. for the SUN).
       stime=tcpu()
-#ifndef WHAM_RUN
+#if .not. defined(WHAM_RUN) && .not. defined(CLUSTER)
 #ifdef MPI
       walltime=MPI_WTIME()
       time_reduce=0.0d0
@@ -1726,6 +1772,7 @@ write (iout,*) 'INIT_INT_TABLE nres=',nres,' nnt=',nnt,' nct=',nct
       return
       end subroutine set_timers
 !-----------------------------------------------------------------------------
+#ifndef CLUSTER
       logical function stopx(nf)
 ! This function returns .true. if one of the following reasons to exit SUMSL
 ! occurs. The "reason" code is stored in WHATSUP passed thru a COMMON block:
@@ -1827,6 +1874,69 @@ write (iout,*) 'INIT_INT_TABLE nres=',nres,' nnt=',nnt,' nct=',nct
       return
       end function stopx
 !-----------------------------------------------------------------------------
+#else
+      logical function stopx(nf)
+!
+!     ..................................................................
+!
+!     *****PURPOSE...
+!     THIS FUNCTION MAY SERVE AS THE STOPX (ASYNCHRONOUS INTERRUPTION)
+!     FUNCTION FOR THE NL2SOL (NONLINEAR LEAST-SQUARES) PACKAGE AT
+!     THOSE INSTALLATIONS WHICH DO NOT WISH TO IMPLEMENT A
+!     DYNAMIC STOPX.
+!
+!     *****ALGORITHM NOTES...
+!     AT INSTALLATIONS WHERE THE NL2SOL SYSTEM IS USED
+!     INTERACTIVELY, THIS DUMMY STOPX SHOULD BE REPLACED BY A
+!     FUNCTION THAT RETURNS .TRUE. IF AND ONLY IF THE INTERRUPT
+!     (BREAK) KEY HAS BEEN PRESSED SINCE THE LAST CALL ON STOPX.
+!
+!     $$$ MODIFIED FOR USE AS  THE TIMER ROUTINE.
+!     $$$                              WHEN THE TIME LIMIT HAS BEEN
+!     $$$ REACHED     STOPX IS SET TO .TRUE  AND INITIATES (IN ITSUM)
+!     $$$ AND ORDERLY EXIT OUT OF SUMSL.  IF ARRAYS IV AND V ARE
+!     $$$ SAVED, THE SUMSL ROUTINES CAN BE RESTARTED AT THE SAME
+!     $$$ POINT AT WHICH THEY WERE INTERRUPTED.
+!
+!     ..................................................................
+!
+!      include 'DIMENSIONS'
+      integer :: nf
+!      logical ovrtim
+!      include 'COMMON.IOUNITS'
+!      include 'COMMON.TIME1'
+#ifdef MPL
+!     include 'COMMON.INFO'
+      integer :: Kwita
+
+!d    print *,'Processor',MyID,' NF=',nf
+#endif
+      if (ovrtim()) then
+! Finish if time is up.
+         stopx = .true.
+#ifdef MPL
+      else if (mod(nf,100).eq.0) then
+! Other processors might have finished. Check this every 100th function 
+! evaluation.
+!d       print *,'Processor ',MyID,' is checking STOP: nf=',nf
+         call recv_stop_sig(Kwita)
+         if (Kwita.eq.-1) then
+           write (iout,'(a,i4,a,i5)') 'Processor',&
+           MyID,' has received STOP signal in STOPX; NF=',nf
+           write (*,'(a,i4,a,i5)') 'Processor',&
+           MyID,' has received STOP signal in STOPX; NF=',nf
+           stopx=.true.
+         else
+           stopx=.false.
+         endif
+#endif
+      else
+         stopx = .false.
+      endif
+      return
+      end function stopx
+#endif
+!-----------------------------------------------------------------------------
       logical function ovrtim()
 
 !      include 'DIMENSIONS'
@@ -1950,6 +2060,7 @@ write (iout,*) 'INIT_INT_TABLE nres=',nres,' nnt=',nnt,' nct=',nct
       return
       end function tcpu
 !-----------------------------------------------------------------------------
+#ifndef CLUSTER
       subroutine dajczas(rntime,hrtime,mintime,sectime)
 
 !      include 'COMMON.IOUNITS'
@@ -1974,6 +2085,7 @@ write (iout,*) 'INIT_INT_TABLE nres=',nres,' nnt=',nnt,' nct=',nct
 !-----------------------------------------------------------------------------
       subroutine print_detailed_timing
 
+!el      use MPI_data
 !      implicit real*8 (a-h,o-z)
 !      include 'DIMENSIONS'
 #ifdef MPI
@@ -2042,6 +2154,7 @@ write (iout,*) 'INIT_INT_TABLE nres=',nres,' nnt=',nnt,' nct=',nct
          endif
       return
       end subroutine print_detailed_timing
+#endif
 !-----------------------------------------------------------------------------
 !-----------------------------------------------------------------------------
       end module control