2 !-----------------------------------------------------------------------------
10 use geometry, only:int_bounds
18 !-----------------------------------------------------------------------------
21 ! integer :: modecalc,iscode,indpdb,indback,indphi,iranconf,&
22 ! icheckgrad,iprint,i2ndstr,mucadyn,constr_dist,symetr
23 ! logical :: minim,refstr,pdbref,outpdb,outmol2,overlapsc,&
24 ! energy_dec,sideadd,lsecondary,read_cart,unres_pdb,&
25 ! vdisulf,searchsc,lmuca,dccart,extconf,out1file,&
26 ! gnorm_check,gradout,split_ene
27 !... minim = .true. means DO minimization.
28 !... energy_dec = .true. means print energy decomposition matrix
29 !-----------------------------------------------------------------------------
31 ! FOUND_NAN - set by calcf to stop sumsl via stopx
33 real(kind=8) :: STIME,BATIME,PREVTIM,RSTIME
34 !el real(kind=8) :: TIMLIM,SAFETY
35 !el real(kind=8) :: WALLTIME
41 real(kind=8) :: t_init
42 ! time_bcast,time_reduce,time_gather,&
43 ! time_sendrecv,time_barrier_e,time_barrier_g,time_scatter,&
46 ! time_lagrangian,time_cartgrad,&
47 ! time_sumgradient,time_intcartderiv,time_inttocart,time_intfcart,&
48 ! time_mat,time_fricmatmult,&
49 ! time_scatter_fmat,time_scatter_ginv,&
50 ! time_scatter_fmatmult,time_scatter_ginvmult,&
51 ! t_eshort,t_elong,t_etotal
52 !-----------------------------------------------------------------------------
54 !-----------------------------------------------------------------------------
56 ! integer,parameter :: MaxMoveType = 4
57 ! character(len=14),dimension(-1:MaxMoveType+1) :: MovTypID=(/'pool','chain regrow',&
58 ! character :: MovTypID(-1:MaxMoveType+1)=(/'pool','chain regrow',&
59 ! 'multi-bond','phi','theta','side chain','total'/)
60 ! Conversion from poises to molecular unit and the gas constant
61 !el real(kind=8) :: cPoise=2.9361d0, Rb=0.001986d0
62 !-----------------------------------------------------------------------------
63 ! common /przechowalnia/ subroutines: init_int_table,add_int,add_int_from
64 integer,dimension(:),allocatable :: iturn3_start_all,&
65 iturn3_end_all,iturn4_start_all,iturn4_end_all,iatel_s_all,&
66 iatel_e_all !(0:max_fg_procs)
67 integer,dimension(:,:),allocatable :: ielstart_all,&
68 ielend_all !(maxres,0:max_fg_procs-1)
70 ! common /przechowalnia/ subroutine: init_int_table
71 integer,dimension(:),allocatable :: ntask_cont_from_all,&
72 ntask_cont_to_all !(0:max_fg_procs-1)
73 integer,dimension(:,:),allocatable :: itask_cont_from_all,&
74 itask_cont_to_all !(0:max_fg_procs-1,0:max_fg_procs-1)
75 !-----------------------------------------------------------------------------
78 !-----------------------------------------------------------------------------
80 !-----------------------------------------------------------------------------
82 !-----------------------------------------------------------------------------
85 ! Define constants and zero out tables.
89 use MCM_data, only: MovTypID
90 ! implicit real*8 (a-h,o-z)
91 ! include 'DIMENSIONS'
98 !MS$ATTRIBUTES C :: proc_proc
101 ! include 'COMMON.IOUNITS'
102 ! include 'COMMON.CHAIN'
103 ! include 'COMMON.INTERACT'
104 ! include 'COMMON.GEO'
105 ! include 'COMMON.LOCAL'
106 ! include 'COMMON.TORSION'
107 ! include 'COMMON.FFIELD'
108 ! include 'COMMON.SBRIDGE'
109 ! include 'COMMON.MCM'
110 ! include 'COMMON.MINIM'
111 ! include 'COMMON.DERIV'
112 ! include 'COMMON.SPLITELE'
114 ! Common blocks from the diagonalization routines
115 !el integer :: IR,IW,IP,IJK,IPK,IDAF,NAV,IODA(400)
116 !el integer :: KDIAG,ICORFL,IXDR
117 !el COMMON /IOFILE/ IR,IW,IP,IJK,IPK,IDAF,NAV,IODA
118 !el COMMON /MACHSW/ KDIAG,ICORFL,IXDR
120 ! real*8 text1 /'initial_i'/
124 integer :: i,j,k,l,ichir1,ichir2,iblock,m,maxit
126 #if .not. defined(WHAM_RUN) && .not. defined(CLUSTER)
129 ! NaNQ initialization
133 idumm=proc_proc(rr,i)
134 #elif defined(WHAM_RUN)
143 allocate(MovTypID(-1:MaxMoveType+1))
144 MovTypID=(/'pool ','chain regrow ',&
145 'multi-bond ','phi ','theta ',&
146 'side chain ','total '/)
149 ! The following is just to define auxiliary variables used in angle conversion
151 pi=4.0D0*datan(1.0D0)
156 rad2deg=1.0D0/deg2rad
157 angmin=10.0D0*deg2rad
184 !rc for write_rmsbank1
186 !dr include secondary structure prediction bias
197 #if defined(WHAM_RUN) || defined(CLUSTER)
201 ! CSA I/O units (separated from others especially for Jooyoung)
212 icsa_bank_reminimized=38
215 !rc for ifc error 118
234 #if defined(WHAM_RUN) || defined(CLUSTER)
236 ! setting the mpi variables for WHAM
243 ! Set default weights of the energy terms.
245 wsc=1.0D0 ! in wham: wlong=1.0D0
254 ! print '(a,$)','Inside initialize'
255 ! call memmon_print_usage()
289 ! athet(j,i,ichir1,ichir2)=0.0D0
290 ! bthet(j,i,ichir1,ichir2)=0.0D0
310 ! gaussc(l,k,j,i)=0.0D0
318 ! do i=-maxtor,maxtor
320 !c write (iout,*) "TU DOCHODZE",i,itortyp(i)
322 ! do j=-maxtor,maxtor
324 ! v1(k,j,i,iblock)=0.0D0
325 ! v2(k,j,i,iblock)=0.0D0
331 ! do i=-maxtor,maxtor
332 ! do j=-maxtor,maxtor
333 ! do k=-maxtor,maxtor
335 ! v1c(1,l,i,j,k,iblock)=0.0D0
336 ! v1s(1,l,i,j,k,iblock)=0.0D0
337 ! v1c(2,l,i,j,k,iblock)=0.0D0
338 ! v1s(2,l,i,j,k,iblock)=0.0D0
342 ! v2c(m,l,i,j,k,iblock)=0.0D0
343 ! v2s(m,l,i,j,k,iblock)=0.0D0
355 ! Initialize the bridge arrays
374 ! Initialize variables used in minimization.
383 ! Initialize the variables responsible for the mode of gradient storage.
389 allocate(iww(max_eneW))
392 if (print_order(i).eq.j) then
393 iww(print_order(i))=j
401 #if defined(WHAM_RUN) || defined(CLUSTER)
404 ! allocate(ww0(max_eneW))
405 ! ww0 = reshape((/1.0d0,1.0d0,1.0d0,1.0d0,1.0d0,1.0d0,1.0d0,1.0d0,&
406 ! 1.0d0,1.0d0,1.0d0,1.0d0,1.0d0,1.0d0,1.0d0,1.0d0,0.4d0,1.0d0,&
407 ! 1.0d0,0.0d0,0.0/), shape(ww0))
410 ! Set timers and counters for the respective routines
430 ! Initialize constants used to split the energy into long- and short-range
436 nprint_ene=nprint_ene-1
439 end subroutine initialize
440 !-----------------------------------------------------------------------------
441 subroutine init_int_table
443 use geometry, only:int_bounds1
446 ! implicit real*8 (a-h,o-z)
447 ! include 'DIMENSIONS'
450 integer,dimension(15) :: blocklengths,displs
452 ! include 'COMMON.CONTROL'
453 ! include 'COMMON.SETUP'
454 ! include 'COMMON.CHAIN'
455 ! include 'COMMON.INTERACT'
456 ! include 'COMMON.LOCAL'
457 ! include 'COMMON.SBRIDGE'
458 ! include 'COMMON.TORCNSTR'
459 ! include 'COMMON.IOUNITS'
460 ! include 'COMMON.DERIV'
461 ! include 'COMMON.CONTACTS'
462 !el integer,dimension(0:nfgtasks) :: iturn3_start_all,iturn3_end_all,&
463 !el iturn4_start_all,iturn4_end_all,iatel_s_all,iatel_e_all !(0:max_fg_procs)
464 !el integer,dimension(nres,0:nfgtasks) :: ielstart_all,&
465 !el ielend_all !(maxres,0:max_fg_procs-1)
466 !el integer,dimension(0:nfgtasks-1) :: ntask_cont_from_all,&
467 !el ntask_cont_to_all !(0:max_fg_procs-1),
468 !el integer,dimension(0:nfgtasks-1,0:nfgtasks-1) :: itask_cont_from_all,&
469 !el itask_cont_to_all !(0:max_fg_procs-1,0:max_fg_procs-1)
471 !el common /przechowalnia/ iturn3_start_all,iturn3_end_all,&
472 !el iturn4_start_all,iturn4_end_all,iatel_s_all,iatel_e_all,&
473 !el ielstart_all,ielend_all,ntask_cont_from_all,itask_cont_from_all,&
474 !el ntask_cont_to_all,itask_cont_to_all
476 integer :: FG_GROUP,CONT_FROM_GROUP,CONT_TO_GROUP
477 logical :: scheck,lprint,flag
480 integer :: ind_scint=0,ind_scint_old,ii,jj,i,j,iint
483 integer :: my_sc_int(0:nfgtasks-1),my_ele_int(0:nfgtasks-1)
484 integer :: my_sc_intt(0:nfgtasks),my_ele_intt(0:nfgtasks)
485 integer :: n_sc_int_tot,my_sc_inde,my_sc_inds,ind_sctint,npept
486 integer :: nele_int_tot,my_ele_inds,my_ele_inde,ind_eleint_old,&
487 ind_eleint,ijunk,nele_int_tot_vdw,my_ele_inds_vdw,&
488 my_ele_inde_vdw,ind_eleint_vdw,ind_eleint_vdw_old,&
489 nscp_int_tot,my_scp_inds,my_scp_inde,ind_scpint,&
490 ind_scpint_old,nsumgrad,nlen,ngrad_start,ngrad_end,&
491 ierror,k,ierr,iaux,ncheck_to,ncheck_from,ind_typ,&
493 integer,dimension(5) :: nct_molec
494 !el allocate(itask_cont_from(0:nfgtasks-1)) !(0:max_fg_procs-1)
495 !el allocate(itask_cont_to(0:nfgtasks-1)) !(0:max_fg_procs-1)
497 !... Determine the numbers of start and end SC-SC interaction
498 !... to deal with by current processor.
499 !write (iout,*) '******INIT_INT_TABLE nres=',nres,' nnt=',nnt,' nct=',nct
501 itask_cont_from(i)=fg_rank
502 itask_cont_to(i)=fg_rank
507 write (iout,*)'INIT_INT_TABLE nres=',nres,' nnt=',nnt,' nct=',nct
508 n_sc_int_tot=(nct-nnt+1)*(nct-nnt)/2-nss
509 call int_bounds(n_sc_int_tot,my_sc_inds,my_sc_inde)
510 !write (iout,*) 'INIT_INT_TABLE nres=',nres,' nnt=',nnt,' nct=',nct
512 write (iout,*) 'Processor',fg_rank,' CG group',kolor,&
513 ' absolute rank',MyRank,&
514 ' n_sc_int_tot',n_sc_int_tot,' my_sc_inds=',my_sc_inds,&
515 ' my_sc_inde',my_sc_inde
520 !el common /przechowalnia/
521 allocate(iturn3_start_all(0:nfgtasks))
522 allocate(iturn3_end_all(0:nfgtasks))
523 allocate(iturn4_start_all(0:nfgtasks))
524 allocate(iturn4_end_all(0:nfgtasks))
525 allocate(iatel_s_all(0:nfgtasks))
526 allocate(iatel_e_all(0:nfgtasks))
527 allocate(ielstart_all(nres,0:nfgtasks-1))
528 allocate(ielend_all(nres,0:nfgtasks-1))
530 allocate(ntask_cont_from_all(0:nfgtasks-1))
531 allocate(ntask_cont_to_all(0:nfgtasks-1))
532 allocate(itask_cont_from_all(0:nfgtasks-1,0:nfgtasks-1))
533 allocate(itask_cont_to_all(0:nfgtasks-1,0:nfgtasks-1))
536 do i=1,nres !el !maxres
550 !d write (iout,*) 'ns=',ns,' nss=',nss,' ihpb,jhpb',
551 !d & (ihpb(i),jhpb(i),i=1,nss)
556 if (ihpb(ii).eq.i+nres) then
563 !d write (iout,*) 'i=',i,' scheck=',scheck,' jj=',jj
567 ! write (iout,*) 'jj=i+1'
568 call int_partition(ind_scint,my_sc_inds,my_sc_inde,i,&
569 iatsc_s,iatsc_e,i+2,nct,nint_gr(i),istart(i,1),iend(i,1),*12)
575 else if (jj.eq.nct) then
577 ! write (iout,*) 'jj=nct'
578 call int_partition(ind_scint,my_sc_inds,my_sc_inde,i,&
579 iatsc_s,iatsc_e,i+1,nct-1,nint_gr(i),istart(i,1),iend(i,1),*12)
587 call int_partition(ind_scint,my_sc_inds,my_sc_inde,i,&
588 iatsc_s,iatsc_e,i+1,jj-1,nint_gr(i),istart(i,1),iend(i,1),*12)
590 call int_partition(ind_scint,my_sc_inds,my_sc_inde,i,&
591 iatsc_s,iatsc_e,jj+1,nct,nint_gr(i),istart(i,ii),iend(i,ii),*12)
602 call int_partition(ind_scint,my_sc_inds,my_sc_inde,i,&
603 iatsc_s,iatsc_e,i+1,nct,nint_gr(i),istart(i,1),iend(i,1),*12)
608 ind_scint=ind_scint+nct-i
612 ind_scint_old=ind_scint
620 if (iatsc_s.eq.0) iatsc_s=1
622 if (lprint) write (*,*) 'Processor',fg_rank,' CG Group',kolor,&
623 ' absolute rank',myrank,' iatsc_s=',iatsc_s,' iatsc_e=',iatsc_e
626 write (iout,'(a)') 'Interaction array:'
628 write (iout,'(i3,2(2x,2i3))') &
629 i,(istart(i,iint),iend(i,iint),iint=1,nint_gr(i))
632 ispp=4 !?? wham ispp=2
634 ! Now partition the electrostatic-interaction array
635 if (itype(nres_molec(1),1).eq.ntyp1_molec(1)) then
636 npept=nres_molec(1)-nnt-1
638 npept=nres_molec(1)-nnt
640 nele_int_tot=(npept-ispp)*(npept-ispp+1)/2
641 call int_bounds(nele_int_tot,my_ele_inds,my_ele_inde)
643 write (*,*) 'Processor',fg_rank,' CG group',kolor,&
644 ' absolute rank',MyRank,&
645 ' nele_int_tot',nele_int_tot,' my_ele_inds=',my_ele_inds,&
646 ' my_ele_inde',my_ele_inde
651 if (itype(nres_molec(1),1).eq.ntyp_molec(1)) then
652 nct_molec(1)=nres_molec(1)-1
654 nct_molec(1)=nres_molec(1)
657 do i=nnt,nct_molec(1)-3
659 call int_partition(ind_eleint,my_ele_inds,my_ele_inde,i,&
660 iatel_s,iatel_e,i+ispp,nct-1,ijunk,ielstart(i),ielend(i),*13)
663 if (iatel_s.eq.0) iatel_s=1
664 nele_int_tot_vdw=(npept-2)*(npept-2+1)/2
665 ! write (iout,*) "nele_int_tot_vdw",nele_int_tot_vdw
666 call int_bounds(nele_int_tot_vdw,my_ele_inds_vdw,my_ele_inde_vdw)
667 ! write (iout,*) "my_ele_inds_vdw",my_ele_inds_vdw,
668 ! & " my_ele_inde_vdw",my_ele_inde_vdw
673 do i=nnt,nct_molec(1)-3
675 call int_partition(ind_eleint_vdw,my_ele_inds_vdw,&
677 iatel_s_vdw,iatel_e_vdw,i+2,nct-1,ijunk,ielstart_vdw(i),&
679 ! write (iout,*) i," ielstart_vdw",ielstart_vdw(i),
680 ! & " ielend_vdw",ielend_vdw(i)
682 if (iatel_s_vdw.eq.0) iatel_s_vdw=1
686 iatel_e=nct_molec(1)-5 ! ?? wham iatel_e=nct-3
688 ielstart(i)=i+4 ! ?? wham +2
689 ielend(i)=nct_molec(1)-1
692 iatel_e_vdw=nct_molec(1)-3
693 do i=iatel_s_vdw,iatel_e_vdw
695 ielend_vdw(i)=nct_molec(1)-1
699 write (*,'(a)') 'Processor',fg_rank,' CG group',kolor,&
700 ' absolute rank',MyRank
701 write (iout,*) 'Electrostatic interaction array:'
703 write (iout,'(i3,2(2x,2i3))') i,ielstart(i),ielend(i)
708 ! Partition the SC-p interaction array
710 nscp_int_tot=(npept-iscp+1)*(npept-iscp+1)
711 call int_bounds(nscp_int_tot,my_scp_inds,my_scp_inde)
712 if (lprint) write (iout,*) 'Processor',fg_rank,' CG group',kolor,&
713 ' absolute rank',myrank,&
714 ' nscp_int_tot',nscp_int_tot,' my_scp_inds=',my_scp_inds,&
715 ' my_scp_inde',my_scp_inde
720 do i=nnt,nct_molec(1)-1
721 if (i.lt.nnt+iscp) then
722 !d write (iout,*) 'i.le.nnt+iscp'
723 call int_partition(ind_scpint,my_scp_inds,my_scp_inde,i,&
724 iatscp_s,iatscp_e,i+iscp,nct,nscp_gr(i),iscpstart(i,1),&
726 else if (i.gt.nct-iscp) then
727 !d write (iout,*) 'i.gt.nct-iscp'
728 call int_partition(ind_scpint,my_scp_inds,my_scp_inde,i,&
729 iatscp_s,iatscp_e,nnt,i-iscp,nscp_gr(i),iscpstart(i,1),&
732 call int_partition(ind_scpint,my_scp_inds,my_scp_inde,i,&
733 iatscp_s,iatscp_e,nnt,i-iscp,nscp_gr(i),iscpstart(i,1),&
736 call int_partition(ind_scpint,my_scp_inds,my_scp_inde,i,&
737 iatscp_s,iatscp_e,i+iscp,nct,nscp_gr(i),iscpstart(i,ii),&
744 iatscp_e=nct_molec(1)-1
745 do i=nnt,nct_molec(1)-1
746 if (i.lt.nnt+iscp) then
748 iscpstart(i,1)=i+iscp
749 iscpend(i,1)=nct_molec(1)
750 elseif (i.gt.nct-iscp) then
758 iscpstart(i,2)=i+iscp
759 iscpend(i,2)=nct_molec(1)
763 if (iatscp_s.eq.0) iatscp_s=1
765 write (iout,'(a)') 'SC-p interaction array:'
766 do i=iatscp_s,iatscp_e
767 write (iout,'(i3,2(2x,2i3))') &
768 i,(iscpstart(i,j),iscpend(i,j),j=1,nscp_gr(i))
771 ! Partition local interactions
773 call int_bounds(nres_molec(1)-2,loc_start,loc_end)
774 loc_start=loc_start+1
776 call int_bounds(nres_molec(1)-2,ithet_start,ithet_end)
777 ithet_start=ithet_start+2
778 ithet_end=ithet_end+2
779 call int_bounds(nct_molec(1)-nnt-2,iturn3_start,iturn3_end)
780 iturn3_start=iturn3_start+nnt
781 iphi_start=iturn3_start+2
782 iturn3_end=iturn3_end+nnt
783 iphi_end=iturn3_end+2
784 iturn3_start=iturn3_start-1
785 iturn3_end=iturn3_end-1
786 call int_bounds(nres_molec(1)-3,itau_start,itau_end)
787 itau_start=itau_start+3
789 call int_bounds(nres_molec(1)-3,iphi1_start,iphi1_end)
790 iphi1_start=iphi1_start+3
791 iphi1_end=iphi1_end+3
792 call int_bounds(nct_molec(1)-nnt-3,iturn4_start,iturn4_end)
793 iturn4_start=iturn4_start+nnt
794 iphid_start=iturn4_start+2
795 iturn4_end=iturn4_end+nnt
796 iphid_end=iturn4_end+2
797 iturn4_start=iturn4_start-1
798 iturn4_end=iturn4_end-1
799 print *,"TUTUTU",nres_molec(1),nres
800 call int_bounds(nres-2,ibond_start,ibond_end)
801 ibond_start=ibond_start+1
802 ibond_end=ibond_end+1
803 call int_bounds(nct_molec(1)-nnt,ibondp_start,ibondp_end)
804 ibondp_start=ibondp_start+nnt
805 ibondp_end=ibondp_end+nnt
806 call int_bounds1(nres_molec(1)-1,ivec_start,ivec_end)
807 ! print *,"Processor",myrank,fg_rank,fg_rank1,
808 ! & " ivec_start",ivec_start," ivec_end",ivec_end
809 iset_start=loc_start+2
811 call int_bounds(nres_molec(1),ilip_start,ilip_end)
812 ilip_start=ilip_start
814 call int_bounds(nres_molec(1)-1,itube_start,itube_end)
815 itube_start=itube_start
817 if (ndih_constr.eq.0) then
821 call int_bounds(ndih_constr,idihconstr_start,idihconstr_end)
823 if (ntheta_constr.eq.0) then
828 (ntheta_constr,ithetaconstr_start,ithetaconstr_end)
831 ! nsumgrad=(nres-nnt)*(nres-nnt+1)/2
833 nsumgrad=(nres-nnt)*(nres-nnt+1)/2
835 call int_bounds(nsumgrad,ngrad_start,ngrad_end)
836 igrad_start=((2*nlen+1) &
837 -sqrt(float((2*nlen-1)**2-8*(ngrad_start-1))))/2
838 igrad_end=((2*nlen+1) &
839 -sqrt(float((2*nlen-1)**2-8*(ngrad_end-1))))/2
840 !el allocate(jgrad_start(igrad_start:igrad_end))
841 !el allocate(jgrad_end(igrad_start:igrad_end)) !(maxres)
842 jgrad_start(igrad_start)= &
843 ngrad_start-(2*nlen-igrad_start)*(igrad_start-1)/2 &
845 jgrad_end(igrad_start)=nres
846 if (igrad_end.gt.igrad_start) jgrad_start(igrad_end)=igrad_end+1
847 jgrad_end(igrad_end)=ngrad_end-(2*nlen-igrad_end)*(igrad_end-1)/2 &
849 do i=igrad_start+1,igrad_end-1
854 write (*,*) 'Processor:',fg_rank,' CG group',kolor,&
855 ' absolute rank',myrank,&
856 ' loc_start',loc_start,' loc_end',loc_end,&
857 ' ithet_start',ithet_start,' ithet_end',ithet_end,&
858 ' iphi_start',iphi_start,' iphi_end',iphi_end,&
859 ' iphid_start',iphid_start,' iphid_end',iphid_end,&
860 ' ibond_start',ibond_start,' ibond_end',ibond_end,&
861 ' ibondp_start',ibondp_start,' ibondp_end',ibondp_end,&
862 ' iturn3_start',iturn3_start,' iturn3_end',iturn3_end,&
863 ' iturn4_start',iturn4_start,' iturn4_end',iturn4_end,&
864 ' ivec_start',ivec_start,' ivec_end',ivec_end,&
865 ' iset_start',iset_start,' iset_end',iset_end,&
866 ' idihconstr_start',idihconstr_start,' idihconstr_end',&
868 write (*,*) 'Processor:',fg_rank,myrank,' igrad_start',&
869 igrad_start,' igrad_end',igrad_end,' ngrad_start',ngrad_start,&
870 ' ngrad_end',ngrad_end
871 do i=igrad_start,igrad_end
872 write(*,*) 'Processor:',fg_rank,myrank,i,&
873 jgrad_start(i),jgrad_end(i)
876 if (nfgtasks.gt.1) then
877 call MPI_Allgather(ivec_start,1,MPI_INTEGER,ivec_displ(0),1,&
878 MPI_INTEGER,FG_COMM1,IERROR)
879 iaux=ivec_end-ivec_start+1
880 call MPI_Allgather(iaux,1,MPI_INTEGER,ivec_count(0),1,&
881 MPI_INTEGER,FG_COMM1,IERROR)
882 call MPI_Allgather(iset_start-2,1,MPI_INTEGER,iset_displ(0),1,&
883 MPI_INTEGER,FG_COMM,IERROR)
884 iaux=iset_end-iset_start+1
885 call MPI_Allgather(iaux,1,MPI_INTEGER,iset_count(0),1,&
886 MPI_INTEGER,FG_COMM,IERROR)
887 call MPI_Allgather(ibond_start,1,MPI_INTEGER,ibond_displ(0),1,&
888 MPI_INTEGER,FG_COMM,IERROR)
889 iaux=ibond_end-ibond_start+1
890 call MPI_Allgather(iaux,1,MPI_INTEGER,ibond_count(0),1,&
891 MPI_INTEGER,FG_COMM,IERROR)
892 call MPI_Allgather(ithet_start,1,MPI_INTEGER,ithet_displ(0),1,&
893 MPI_INTEGER,FG_COMM,IERROR)
894 iaux=ithet_end-ithet_start+1
895 call MPI_Allgather(iaux,1,MPI_INTEGER,ithet_count(0),1,&
896 MPI_INTEGER,FG_COMM,IERROR)
897 call MPI_Allgather(iphi_start,1,MPI_INTEGER,iphi_displ(0),1,&
898 MPI_INTEGER,FG_COMM,IERROR)
899 iaux=iphi_end-iphi_start+1
900 call MPI_Allgather(iaux,1,MPI_INTEGER,iphi_count(0),1,&
901 MPI_INTEGER,FG_COMM,IERROR)
902 call MPI_Allgather(iphi1_start,1,MPI_INTEGER,iphi1_displ(0),1,&
903 MPI_INTEGER,FG_COMM,IERROR)
904 iaux=iphi1_end-iphi1_start+1
905 call MPI_Allgather(iaux,1,MPI_INTEGER,iphi1_count(0),1,&
906 MPI_INTEGER,FG_COMM,IERROR)
913 call MPI_Allgather(iturn3_start,1,MPI_INTEGER,&
914 iturn3_start_all(0),1,MPI_INTEGER,FG_COMM,IERROR)
915 call MPI_Allgather(iturn4_start,1,MPI_INTEGER,&
916 iturn4_start_all(0),1,MPI_INTEGER,FG_COMM,IERROR)
917 call MPI_Allgather(iturn3_end,1,MPI_INTEGER,&
918 iturn3_end_all(0),1,MPI_INTEGER,FG_COMM,IERROR)
919 call MPI_Allgather(iturn4_end,1,MPI_INTEGER,&
920 iturn4_end_all(0),1,MPI_INTEGER,FG_COMM,IERROR)
921 call MPI_Allgather(iatel_s,1,MPI_INTEGER,&
922 iatel_s_all(0),1,MPI_INTEGER,FG_COMM,IERROR)
923 call MPI_Allgather(iatel_e,1,MPI_INTEGER,&
924 iatel_e_all(0),1,MPI_INTEGER,FG_COMM,IERROR)
925 call MPI_Allgather(ielstart(1),nres,MPI_INTEGER,&
926 ielstart_all(1,0),nres,MPI_INTEGER,FG_COMM,IERROR)
927 call MPI_Allgather(ielend(1),nres,MPI_INTEGER,&
928 ielend_all(1,0),nres,MPI_INTEGER,FG_COMM,IERROR)
930 write (iout,*) "iatel_s_all",(iatel_s_all(i),i=0,nfgtasks)
931 write (iout,*) "iatel_e_all",(iatel_e_all(i),i=0,nfgtasks)
932 write (iout,*) "iturn3_start_all",&
933 (iturn3_start_all(i),i=0,nfgtasks-1)
934 write (iout,*) "iturn3_end_all",&
935 (iturn3_end_all(i),i=0,nfgtasks-1)
936 write (iout,*) "iturn4_start_all",&
937 (iturn4_start_all(i),i=0,nfgtasks-1)
938 write (iout,*) "iturn4_end_all",&
939 (iturn4_end_all(i),i=0,nfgtasks-1)
940 write (iout,*) "The ielstart_all array"
942 write (iout,'(20i4)') i,(ielstart_all(i,j),j=0,nfgtasks-1)
944 write (iout,*) "The ielend_all array"
946 write (iout,'(20i4)') i,(ielend_all(i,j),j=0,nfgtasks-1)
952 itask_cont_from(0)=fg_rank
953 itask_cont_to(0)=fg_rank
955 !el allocate(iturn3_sent(4,iturn3_start:iturn3_end))
956 !el allocate(iturn4_sent(4,iturn4_start:iturn4_end)) !(4,maxres)
957 do ii=iturn3_start,iturn3_end
958 call add_int(ii,ii+2,iturn3_sent(1,ii),&
959 ntask_cont_to,itask_cont_to,flag)
961 do ii=iturn4_start,iturn4_end
962 call add_int(ii,ii+3,iturn4_sent(1,ii),&
963 ntask_cont_to,itask_cont_to,flag)
965 do ii=iturn3_start,iturn3_end
966 call add_int_from(ii,ii+2,ntask_cont_from,itask_cont_from)
968 do ii=iturn4_start,iturn4_end
969 call add_int_from(ii,ii+3,ntask_cont_from,itask_cont_from)
972 write (iout,*) "After turn3 ntask_cont_from",ntask_cont_from,&
973 " ntask_cont_to",ntask_cont_to
974 write (iout,*) "itask_cont_from",&
975 (itask_cont_from(i),i=1,ntask_cont_from)
976 write (iout,*) "itask_cont_to",&
977 (itask_cont_to(i),i=1,ntask_cont_to)
980 ! write (iout,*) "Loop forward"
983 ! write (iout,*) "from loop i=",i
985 do j=ielstart(i),ielend(i)
986 call add_int_from(i,j,ntask_cont_from,itask_cont_from)
989 ! write (iout,*) "Loop backward iatel_e-1",iatel_e-1,
990 ! & " iatel_e",iatel_e
994 ! write (iout,*) "i",i," ielstart",ielstart(i),
995 ! & " ielend",ielend(i)
998 do j=ielstart(i),ielend(i)
999 call add_int(i,j,iint_sent(1,j,nat_sent+1),ntask_cont_to,&
1004 iat_sent(nat_sent)=i
1008 write (iout,*)"After longrange ntask_cont_from",ntask_cont_from,&
1009 " ntask_cont_to",ntask_cont_to
1010 write (iout,*) "itask_cont_from",&
1011 (itask_cont_from(i),i=1,ntask_cont_from)
1012 write (iout,*) "itask_cont_to",&
1013 (itask_cont_to(i),i=1,ntask_cont_to)
1015 write (iout,*) "iint_sent"
1018 write (iout,'(20i4)') ii,(j,(iint_sent(k,j,i),k=1,4),&
1019 j=ielstart(ii),ielend(ii))
1021 write (iout,*) "iturn3_sent iturn3_start",iturn3_start,&
1022 " iturn3_end",iturn3_end
1023 write (iout,'(20i4)') (i,(iturn3_sent(j,i),j=1,4),&
1024 i=iturn3_start,iturn3_end)
1025 write (iout,*) "iturn4_sent iturn4_start",iturn4_start,&
1026 " iturn4_end",iturn4_end
1027 write (iout,'(20i4)') (i,(iturn4_sent(j,i),j=1,4),&
1028 i=iturn4_start,iturn4_end)
1031 call MPI_Gather(ntask_cont_from,1,MPI_INTEGER,&
1032 ntask_cont_from_all,1,MPI_INTEGER,king,FG_COMM,IERR)
1033 ! write (iout,*) "Gather ntask_cont_from ended"
1035 call MPI_Gather(itask_cont_from(0),nfgtasks,MPI_INTEGER,&
1036 itask_cont_from_all(0,0),nfgtasks,MPI_INTEGER,king,&
1038 ! write (iout,*) "Gather itask_cont_from ended"
1040 call MPI_Gather(ntask_cont_to,1,MPI_INTEGER,ntask_cont_to_all,&
1041 1,MPI_INTEGER,king,FG_COMM,IERR)
1042 ! write (iout,*) "Gather ntask_cont_to ended"
1044 call MPI_Gather(itask_cont_to,nfgtasks,MPI_INTEGER,&
1045 itask_cont_to_all,nfgtasks,MPI_INTEGER,king,FG_COMM,IERR)
1046 ! write (iout,*) "Gather itask_cont_to ended"
1048 if (fg_rank.eq.king) then
1049 write (iout,*)"Contact receive task map (proc, #tasks, tasks)"
1051 write (iout,'(20i4)') i,ntask_cont_from_all(i),&
1052 (itask_cont_from_all(j,i),j=1,ntask_cont_from_all(i))
1056 write (iout,*) "Contact send task map (proc, #tasks, tasks)"
1058 write (iout,'(20i4)') i,ntask_cont_to_all(i),&
1059 (itask_cont_to_all(j,i),j=1,ntask_cont_to_all(i))
1063 ! Check if every send will have a matching receive
1067 ncheck_to=ncheck_to+ntask_cont_to_all(i)
1068 ncheck_from=ncheck_from+ntask_cont_from_all(i)
1070 write (iout,*) "Control sums",ncheck_from,ncheck_to
1071 if (ncheck_from.ne.ncheck_to) then
1072 write (iout,*) "Error: #receive differs from #send."
1073 write (iout,*) "Terminating program...!"
1079 do j=1,ntask_cont_to_all(i)
1080 ii=itask_cont_to_all(j,i)
1081 do k=1,ntask_cont_from_all(ii)
1082 if (itask_cont_from_all(k,ii).eq.i) then
1083 if(lprint)write(iout,*)"Matching send/receive",i,ii
1087 if (k.eq.ntask_cont_from_all(ii)+1) then
1089 write (iout,*) "Error: send by",j," to",ii,&
1090 " would have no matching receive"
1096 write (iout,*) "Unmatched sends; terminating program"
1100 call MPI_Bcast(flag,1,MPI_LOGICAL,king,FG_COMM,IERROR)
1101 ! write (iout,*) "flag broadcast ended flag=",flag
1104 call MPI_Finalize(IERROR)
1105 stop "Error in INIT_INT_TABLE: unmatched send/receive."
1107 call MPI_Comm_group(FG_COMM,fg_group,IERR)
1108 ! write (iout,*) "MPI_Comm_group ended"
1110 call MPI_Group_incl(fg_group,ntask_cont_from+1,&
1111 itask_cont_from(0),CONT_FROM_GROUP,IERR)
1112 call MPI_Group_incl(fg_group,ntask_cont_to+1,itask_cont_to(0),&
1116 iaux=4*(ielend(ii)-ielstart(ii)+1)
1117 call MPI_Group_translate_ranks(fg_group,iaux,&
1118 iint_sent(1,ielstart(ii),i),CONT_TO_GROUP,&
1119 iint_sent_local(1,ielstart(ii),i),IERR )
1120 ! write (iout,*) "Ranks translated i=",i
1123 iaux=4*(iturn3_end-iturn3_start+1)
1124 call MPI_Group_translate_ranks(fg_group,iaux,&
1125 iturn3_sent(1,iturn3_start),CONT_TO_GROUP,&
1126 iturn3_sent_local(1,iturn3_start),IERR)
1127 iaux=4*(iturn4_end-iturn4_start+1)
1128 call MPI_Group_translate_ranks(fg_group,iaux,&
1129 iturn4_sent(1,iturn4_start),CONT_TO_GROUP,&
1130 iturn4_sent_local(1,iturn4_start),IERR)
1132 write (iout,*) "iint_sent_local"
1135 write (iout,'(20i4)') ii,(j,(iint_sent_local(k,j,i),k=1,4),&
1136 j=ielstart(ii),ielend(ii))
1139 write (iout,*) "iturn3_sent_local iturn3_start",iturn3_start,&
1140 " iturn3_end",iturn3_end
1141 write (iout,'(20i4)') (i,(iturn3_sent_local(j,i),j=1,4),&
1142 i=iturn3_start,iturn3_end)
1143 write (iout,*) "iturn4_sent_local iturn4_start",iturn4_start,&
1144 " iturn4_end",iturn4_end
1145 write (iout,'(20i4)') (i,(iturn4_sent_local(j,i),j=1,4),&
1146 i=iturn4_start,iturn4_end)
1149 call MPI_Group_free(fg_group,ierr)
1150 call MPI_Group_free(cont_from_group,ierr)
1151 call MPI_Group_free(cont_to_group,ierr)
1152 call MPI_Type_contiguous(3,MPI_DOUBLE_PRECISION,MPI_UYZ,IERROR)
1153 call MPI_Type_commit(MPI_UYZ,IERROR)
1154 call MPI_Type_contiguous(18,MPI_DOUBLE_PRECISION,MPI_UYZGRAD,&
1156 call MPI_Type_commit(MPI_UYZGRAD,IERROR)
1157 call MPI_Type_contiguous(2,MPI_DOUBLE_PRECISION,MPI_MU,IERROR)
1158 call MPI_Type_commit(MPI_MU,IERROR)
1159 call MPI_Type_contiguous(4,MPI_DOUBLE_PRECISION,MPI_MAT1,IERROR)
1160 call MPI_Type_commit(MPI_MAT1,IERROR)
1161 call MPI_Type_contiguous(8,MPI_DOUBLE_PRECISION,MPI_MAT2,IERROR)
1162 call MPI_Type_commit(MPI_MAT2,IERROR)
1163 call MPI_Type_contiguous(6,MPI_DOUBLE_PRECISION,MPI_THET,IERROR)
1164 call MPI_Type_commit(MPI_THET,IERROR)
1165 call MPI_Type_contiguous(9,MPI_DOUBLE_PRECISION,MPI_GAM,IERROR)
1166 call MPI_Type_commit(MPI_GAM,IERROR)
1168 !el allocate(lentyp(0:nfgtasks-1))
1170 ! 9/22/08 Derived types to send matrices which appear in correlation terms
1172 if (ivec_count(i).eq.ivec_count(0)) then
1178 do ind_typ=lentyp(0),lentyp(nfgtasks-1)
1179 if (ind_typ.eq.0) then
1180 ichunk=ivec_count(0)
1182 ichunk=ivec_count(1)
1189 ! displs(i)=displs(i-1)+blocklengths(i-1)*maxres
1192 ! blocklengths(i)=blocklengths(i)*ichunk
1194 ! write (iout,*) "blocklengths and displs"
1196 ! write (iout,*) i,blocklengths(i),displs(i)
1199 ! call MPI_Type_indexed(4,blocklengths(1),displs(1),
1200 ! & MPI_DOUBLE_PRECISION,MPI_ROTAT1(ind_typ),IERROR)
1201 ! call MPI_Type_commit(MPI_ROTAT1(ind_typ),IERROR)
1202 ! write (iout,*) "MPI_ROTAT1",MPI_ROTAT1
1208 ! displs(i)=displs(i-1)+blocklengths(i-1)*maxres
1211 ! blocklengths(i)=blocklengths(i)*ichunk
1213 ! write (iout,*) "blocklengths and displs"
1215 ! write (iout,*) i,blocklengths(i),displs(i)
1218 ! call MPI_Type_indexed(4,blocklengths(1),displs(1),
1219 ! & MPI_DOUBLE_PRECISION,MPI_ROTAT2(ind_typ),IERROR)
1220 ! call MPI_Type_commit(MPI_ROTAT2(ind_typ),IERROR)
1221 ! write (iout,*) "MPI_ROTAT2",MPI_ROTAT2
1227 displs(i)=displs(i-1)+blocklengths(i-1)*nres !maxres
1230 blocklengths(i)=blocklengths(i)*ichunk
1232 call MPI_Type_indexed(8,blocklengths,displs,&
1233 MPI_DOUBLE_PRECISION,MPI_PRECOMP11(ind_typ),IERROR)
1234 call MPI_Type_commit(MPI_PRECOMP11(ind_typ),IERROR)
1240 displs(i)=displs(i-1)+blocklengths(i-1)*nres !maxres
1243 blocklengths(i)=blocklengths(i)*ichunk
1245 call MPI_Type_indexed(8,blocklengths,displs,&
1246 MPI_DOUBLE_PRECISION,MPI_PRECOMP12(ind_typ),IERROR)
1247 call MPI_Type_commit(MPI_PRECOMP12(ind_typ),IERROR)
1253 displs(i)=displs(i-1)+blocklengths(i-1)*nres !maxres
1256 blocklengths(i)=blocklengths(i)*ichunk
1258 call MPI_Type_indexed(6,blocklengths,displs,&
1259 MPI_DOUBLE_PRECISION,MPI_PRECOMP22(ind_typ),IERROR)
1260 call MPI_Type_commit(MPI_PRECOMP22(ind_typ),IERROR)
1266 displs(i)=displs(i-1)+blocklengths(i-1)*nres !maxres
1269 blocklengths(i)=blocklengths(i)*ichunk
1271 call MPI_Type_indexed(2,blocklengths,displs,&
1272 MPI_DOUBLE_PRECISION,MPI_PRECOMP23(ind_typ),IERROR)
1273 call MPI_Type_commit(MPI_PRECOMP23(ind_typ),IERROR)
1279 displs(i)=displs(i-1)+blocklengths(i-1)*nres !maxres
1282 blocklengths(i)=blocklengths(i)*ichunk
1284 call MPI_Type_indexed(4,blocklengths,displs,&
1285 MPI_DOUBLE_PRECISION,MPI_ROTAT_OLD(ind_typ),IERROR)
1286 call MPI_Type_commit(MPI_ROTAT_OLD(ind_typ),IERROR)
1290 iint_start=ivec_start+1
1293 iint_count(i)=ivec_count(i)
1294 iint_displ(i)=ivec_displ(i)
1295 ivec_displ(i)=ivec_displ(i)-1
1296 iset_displ(i)=iset_displ(i)-1
1297 ithet_displ(i)=ithet_displ(i)-1
1298 iphi_displ(i)=iphi_displ(i)-1
1299 iphi1_displ(i)=iphi1_displ(i)-1
1300 ibond_displ(i)=ibond_displ(i)-1
1302 if (nfgtasks.gt.1 .and. fg_rank.eq.king &
1303 .and. (me.eq.0 .or. .not. out1file)) then
1304 write (iout,*) "IVEC_DISPL, IVEC_COUNT, ISET_START, ISET_COUNT"
1306 write (iout,*) i,ivec_displ(i),ivec_count(i),iset_displ(i),&
1309 write (iout,*) "iphi_start",iphi_start," iphi_end",iphi_end,&
1310 " iphi1_start",iphi1_start," iphi1_end",iphi1_end
1311 write (iout,*)"IPHI_COUNT, IPHI_DISPL, IPHI1_COUNT, IPHI1_DISPL"
1313 write (iout,*) i,iphi_count(i),iphi_displ(i),iphi1_count(i),&
1316 write(iout,'(i10,a,i10,a,i10,a/a,i3,a)') n_sc_int_tot,' SC-SC ',&
1317 nele_int_tot,' electrostatic and ',nscp_int_tot,&
1318 ' SC-p interactions','were distributed among',nfgtasks,&
1319 ' fine-grain processors.'
1323 loc_end=nres_molec(1)-1
1325 ithet_end=nres_molec(1)
1327 iturn3_end=nct_molec(1)-3
1329 iturn4_end=nct_molec(1)-4
1331 iphi_end=nct_molec(1)
1333 iphi1_end=nres_molec(1)
1335 idihconstr_end=ndih_constr
1336 ithetaconstr_start=1
1337 ithetaconstr_end=ntheta_constr
1338 iphid_start=iphi_start
1339 iphid_end=iphi_end-1
1341 itau_end=nres_molec(1)
1343 ibond_end=nres_molec(1)-1
1345 ibondp_end=nct_molec(1)-1
1347 ivec_end=nres_molec(1)-1
1349 iset_end=nres_molec(1)+1
1351 iint_end=nres_molec(1)-1
1353 ilip_end=nres_molec(1)
1355 itube_end=nres_molec(1)
1357 !el common /przechowalnia/
1358 ! deallocate(iturn3_start_all)
1359 ! deallocate(iturn3_end_all)
1360 ! deallocate(iturn4_start_all)
1361 ! deallocate(iturn4_end_all)
1362 ! deallocate(iatel_s_all)
1363 ! deallocate(iatel_e_all)
1364 ! deallocate(ielstart_all)
1365 ! deallocate(ielend_all)
1367 ! deallocate(ntask_cont_from_all)
1368 ! deallocate(ntask_cont_to_all)
1369 ! deallocate(itask_cont_from_all)
1370 ! deallocate(itask_cont_to_all)
1373 end subroutine init_int_table
1375 !-----------------------------------------------------------------------------
1376 subroutine add_int(ii,jj,itask,ntask_cont_to,itask_cont_to,flag)
1379 ! include "DIMENSIONS"
1380 ! include "COMMON.INTERACT"
1381 ! include "COMMON.SETUP"
1382 ! include "COMMON.IOUNITS"
1383 integer :: ii,jj,ntask_cont_to
1384 integer,dimension(4) :: itask
1385 integer :: itask_cont_to(0:nfgtasks-1) !(0:max_fg_procs-1)
1387 !el integer,dimension(0:nfgtasks) :: iturn3_start_all,iturn3_end_all,iturn4_start_all,&
1388 !el iturn4_end_all,iatel_s_all,iatel_e_all !(0:max_fg_procs)
1389 !el integer,dimension(nres,0:nfgtasks-1) :: ielstart_all,ielend_all !(maxres,0:max_fg_procs-1)
1390 !el common /przechowalnia/ iturn3_start_all,iturn3_end_all,iturn4_start_all,&
1391 !el iturn4_end_all,iatel_s_all,iatel_e_all,ielstart_all,ielend_all
1392 integer :: iproc,isent,k,l
1393 ! Determines whether to send interaction ii,jj to other processors; a given
1394 ! interaction can be sent to at most 2 processors.
1395 ! Sets flag=.true. if interaction ii,jj needs to be sent to at least
1396 ! one processor, otherwise flag is unchanged from the input value.
1402 ! write (iout,*) "ii",ii," jj",jj
1403 ! Loop over processors to check if anybody could need interaction ii,jj
1404 do iproc=0,fg_rank-1
1405 ! Check if the interaction matches any turn3 at iproc
1406 do k=iturn3_start_all(iproc),iturn3_end_all(iproc)
1408 if (k.eq.ii-1 .and. l.eq.jj-1 .or. k.eq.ii-1 .and. l.eq.jj+1 &
1409 .or. k.eq.ii+1 .and. l.eq.jj+1 .or. k.eq.ii+1 .and. l.eq.jj-1) &
1411 ! write (iout,*) "turn3 to iproc",iproc," ij",ii,jj,"kl",k,l
1414 if (iproc.ne.itask(1).and.iproc.ne.itask(2) &
1415 .and.iproc.ne.itask(3).and.iproc.ne.itask(4)) then
1418 call add_task(iproc,ntask_cont_to,itask_cont_to)
1422 ! Check if the interaction matches any turn4 at iproc
1423 do k=iturn4_start_all(iproc),iturn4_end_all(iproc)
1425 if (k.eq.ii-1 .and. l.eq.jj-1 .or. k.eq.ii-1 .and. l.eq.jj+1 &
1426 .or. k.eq.ii+1 .and. l.eq.jj+1 .or. k.eq.ii+1 .and. l.eq.jj-1) &
1428 ! write (iout,*) "turn3 to iproc",iproc," ij",ii,jj," kl",k,l
1431 if (iproc.ne.itask(1).and.iproc.ne.itask(2) &
1432 .and.iproc.ne.itask(3).and.iproc.ne.itask(4)) then
1435 call add_task(iproc,ntask_cont_to,itask_cont_to)
1439 if (iatel_s_all(iproc).gt.0 .and. iatel_e_all(iproc).gt.0 .and. &
1440 iatel_s_all(iproc).le.ii-1 .and. iatel_e_all(iproc).ge.ii-1)then
1441 if (ielstart_all(ii-1,iproc).le.jj-1.and. &
1442 ielend_all(ii-1,iproc).ge.jj-1) then
1444 if (iproc.ne.itask(1).and.iproc.ne.itask(2) &
1445 .and.iproc.ne.itask(3).and.iproc.ne.itask(4)) then
1448 call add_task(iproc,ntask_cont_to,itask_cont_to)
1451 if (ielstart_all(ii-1,iproc).le.jj+1.and. &
1452 ielend_all(ii-1,iproc).ge.jj+1) then
1454 if (iproc.ne.itask(1).and.iproc.ne.itask(2) &
1455 .and.iproc.ne.itask(3).and.iproc.ne.itask(4)) then
1458 call add_task(iproc,ntask_cont_to,itask_cont_to)
1464 end subroutine add_int
1465 !-----------------------------------------------------------------------------
1466 subroutine add_int_from(ii,jj,ntask_cont_from,itask_cont_from)
1470 ! include "DIMENSIONS"
1471 ! include "COMMON.INTERACT"
1472 ! include "COMMON.SETUP"
1473 ! include "COMMON.IOUNITS"
1474 integer :: ii,jj,itask(2),ntask_cont_from,&
1475 itask_cont_from(0:nfgtasks-1) !(0:max_fg_procs)
1477 !el integer,dimension(0:nfgtasks) :: iturn3_start_all,iturn3_end_all,&
1478 !el iturn4_start_all,iturn4_end_all,iatel_s_all,iatel_e_all !(0:max_fg_procs)
1479 !el integer,dimension(nres,0:nfgtasks-1) :: ielstart_all,ielend_all !(maxres,0:max_fg_procs-1)
1480 !el common /przechowalnia/ iturn3_start_all,iturn3_end_all,iturn4_start_all,&
1481 !el iturn4_end_all,iatel_s_all,iatel_e_all,ielstart_all,ielend_all
1482 integer :: iproc,k,l
1483 do iproc=fg_rank+1,nfgtasks-1
1484 do k=iturn3_start_all(iproc),iturn3_end_all(iproc)
1486 if (k.eq.ii+1 .and. l.eq.jj+1 .or. k.eq.ii+1.and.l.eq.jj-1 &
1487 .or. k.eq.ii-1 .and. l.eq.jj-1 .or. k.eq.ii-1 .and. l.eq.jj+1) &
1489 ! write (iout,*)"turn3 from iproc",iproc," ij",ii,jj," kl",k,l
1490 call add_task(iproc,ntask_cont_from,itask_cont_from)
1493 do k=iturn4_start_all(iproc),iturn4_end_all(iproc)
1495 if (k.eq.ii+1 .and. l.eq.jj+1 .or. k.eq.ii+1.and.l.eq.jj-1 &
1496 .or. k.eq.ii-1 .and. l.eq.jj-1 .or. k.eq.ii-1 .and. l.eq.jj+1) &
1498 ! write (iout,*)"turn4 from iproc",iproc," ij",ii,jj," kl",k,l
1499 call add_task(iproc,ntask_cont_from,itask_cont_from)
1502 if (iatel_s_all(iproc).gt.0 .and. iatel_e_all(iproc).gt.0) then
1503 if (ii+1.ge.iatel_s_all(iproc).and.ii+1.le.iatel_e_all(iproc)) &
1505 if (jj+1.ge.ielstart_all(ii+1,iproc).and. &
1506 jj+1.le.ielend_all(ii+1,iproc)) then
1507 call add_task(iproc,ntask_cont_from,itask_cont_from)
1509 if (jj-1.ge.ielstart_all(ii+1,iproc).and. &
1510 jj-1.le.ielend_all(ii+1,iproc)) then
1511 call add_task(iproc,ntask_cont_from,itask_cont_from)
1514 if (ii-1.ge.iatel_s_all(iproc).and.ii-1.le.iatel_e_all(iproc)) &
1516 if (jj-1.ge.ielstart_all(ii-1,iproc).and. &
1517 jj-1.le.ielend_all(ii-1,iproc)) then
1518 call add_task(iproc,ntask_cont_from,itask_cont_from)
1520 if (jj+1.ge.ielstart_all(ii-1,iproc).and. &
1521 jj+1.le.ielend_all(ii-1,iproc)) then
1522 call add_task(iproc,ntask_cont_from,itask_cont_from)
1528 end subroutine add_int_from
1529 !-----------------------------------------------------------------------------
1530 subroutine add_task(iproc,ntask_cont,itask_cont)
1534 ! include "DIMENSIONS"
1535 integer :: iproc,ntask_cont,itask_cont(0:nfgtasks-1) !(0:max_fg_procs-1)
1538 if (itask_cont(ii).eq.iproc) return
1540 ntask_cont=ntask_cont+1
1541 itask_cont(ntask_cont)=iproc
1543 end subroutine add_task
1545 !-----------------------------------------------------------------------------
1546 #if defined MPI || defined WHAM_RUN
1547 subroutine int_partition(int_index,lower_index,upper_index,atom,&
1548 at_start,at_end,first_atom,last_atom,int_gr,jat_start,jat_end,*)
1550 ! implicit real*8 (a-h,o-z)
1551 ! include 'DIMENSIONS'
1552 ! include 'COMMON.IOUNITS'
1553 integer :: int_index,lower_index,upper_index,atom,at_start,at_end,&
1554 first_atom,last_atom,int_gr,jat_start,jat_end,int_index_old
1557 if (lprn) write (iout,*) 'int_index=',int_index
1558 int_index_old=int_index
1559 int_index=int_index+last_atom-first_atom+1
1561 write (iout,*) 'int_index=',int_index,&
1562 ' int_index_old',int_index_old,&
1563 ' lower_index=',lower_index,&
1564 ' upper_index=',upper_index,&
1565 ' atom=',atom,' first_atom=',first_atom,&
1566 ' last_atom=',last_atom
1567 if (int_index.ge.lower_index) then
1569 if (at_start.eq.0) then
1571 jat_start=first_atom-1+lower_index-int_index_old
1573 jat_start=first_atom
1575 if (lprn) write (iout,*) 'jat_start',jat_start
1576 if (int_index.ge.upper_index) then
1578 jat_end=first_atom-1+upper_index-int_index_old
1583 if (lprn) write (iout,*) 'jat_end',jat_end
1586 end subroutine int_partition
1588 !-----------------------------------------------------------------------------
1590 subroutine hpb_partition
1592 ! implicit real*8 (a-h,o-z)
1593 ! include 'DIMENSIONS'
1597 ! include 'COMMON.SBRIDGE'
1598 ! include 'COMMON.IOUNITS'
1599 ! include 'COMMON.SETUP'
1601 call int_bounds(nhpb,link_start,link_end)
1602 write (iout,*) 'Processor',fg_rank,' CG group',kolor,&
1603 ' absolute rank',MyRank,&
1604 ' nhpb',nhpb,' link_start=',link_start,&
1605 ' link_end',link_end
1611 end subroutine hpb_partition
1613 !-----------------------------------------------------------------------------
1614 ! misc.f in module io_base
1615 !-----------------------------------------------------------------------------
1616 !-----------------------------------------------------------------------------
1618 !-----------------------------------------------------------------------------
1619 subroutine getenv_loc(var, val)
1621 character(*) :: var, val
1624 character(len=2000) :: line
1627 open (196,file='env',status='old',readonly,shared)
1629 ! write(*,*)'looking for ',var
1630 10 read(196,*,err=11,end=11)line
1631 iread=index(line,var)
1632 ! write(*,*)iread,' ',var,' ',line
1633 if (iread.eq.0) go to 10
1634 ! write(*,*)'---> ',line
1640 iread=iread+ilen(var)+1
1641 read (line(iread:),*,err=12,end=12) val
1642 ! write(*,*)'OK: ',var,' = ',val
1648 #elif (defined CRAY)
1649 integer :: lennam,lenval,ierror
1651 ! getenv using a POSIX call, useful on the T3D
1652 ! Sept 1996, comment out error check on advice of H. Pritchard
1655 if(lennam.le.0) stop '--error calling getenv--'
1656 call pxfgetenv(var,lennam,val,lenval,ierror)
1657 !-HP- if(ierror.ne.0) stop '--error returned by pxfgetenv--'
1659 call getenv(var,val)
1663 end subroutine getenv_loc
1664 !-----------------------------------------------------------------------------
1666 !-----------------------------------------------------------------------------
1667 subroutine setup_var
1670 ! implicit real*8 (a-h,o-z)
1671 ! include 'DIMENSIONS'
1672 ! include 'COMMON.IOUNITS'
1673 ! include 'COMMON.GEO'
1674 ! include 'COMMON.VAR'
1675 ! include 'COMMON.INTERACT'
1676 ! include 'COMMON.LOCAL'
1677 ! include 'COMMON.NAMES'
1678 ! include 'COMMON.CHAIN'
1679 ! include 'COMMON.FFIELD'
1680 ! include 'COMMON.SBRIDGE'
1681 ! include 'COMMON.HEADER'
1682 ! include 'COMMON.CONTROL'
1683 ! include 'COMMON.DBASE'
1684 ! include 'COMMON.THREAD'
1685 ! include 'COMMON.TIME1'
1686 ! Set up variable list.
1693 if (itype(i,1).ne.10) then
1695 if (itype(i,1).ne.10 .and. itype(i,1).ne.ntyp1) then
1698 ialph(i,1)=nvar+nside
1702 if (indphi.gt.0) then
1704 else if (indback.gt.0) then
1709 !d write (iout,'(3i4)') (i,ialph(i,1),ialph(i,2),i=2,nres-1)
1711 end subroutine setup_var
1712 !-----------------------------------------------------------------------------
1714 !-----------------------------------------------------------------------------
1715 integer function rescode(iseq,nam,itype,molecule)
1717 use io_base, only: ucase
1718 ! implicit real*8 (a-h,o-z)
1719 ! include 'DIMENSIONS'
1720 ! include 'COMMON.NAMES'
1721 ! include 'COMMON.IOUNITS'
1722 character(len=3) :: nam !,ucase
1723 integer :: iseq,itype,i
1725 print *,molecule,nam
1726 if (molecule.eq.1) then
1727 if (itype.eq.0) then
1729 do i=-ntyp1_molec(molecule),ntyp1_molec(molecule)
1730 if (ucase(nam).eq.restyp(i,molecule)) then
1738 do i=-ntyp1_molec(molecule),ntyp1_molec(molecule)
1739 if (nam(1:1).eq.onelet(i)) then
1746 else if (molecule.eq.2) then
1747 do i=1,ntyp1_molec(molecule)
1748 print *,nam(1:1),restyp(i,molecule)(1:1)
1749 if (nam(1:1).eq.restyp(i,molecule)(1:1)) then
1754 else if (molecule.eq.3) then
1755 write(iout,*) "SUGAR not yet implemented"
1757 else if (molecule.eq.4) then
1758 write(iout,*) "Explicit LIPID not yet implemented"
1760 else if (molecule.eq.5) then
1761 do i=1,ntyp1_molec(molecule)
1762 print *,i,restyp(i,molecule)
1763 if (ucase(nam).eq.restyp(i,molecule)) then
1769 write(iout,*) "molecule not defined"
1771 write (iout,10) iseq,nam
1773 10 format ('**** Error - residue',i4,' has an unresolved name ',a3)
1774 end function rescode
1775 integer function sugarcode(sugar,ires)
1778 if (sugar.eq.'D') then
1780 else if (sugar.eq.' ') then
1783 write (iout,*) 'UNKNOWN sugar type for residue',ires,' ',sugar
1787 end function sugarcode
1789 !-----------------------------------------------------------------------------
1791 !-----------------------------------------------------------------------------
1792 ! $Date: 1994/10/05 16:41:52 $
1795 subroutine set_timers
1798 !el real(kind=8) :: tcpu
1799 ! include 'COMMON.TIME1'
1804 ! Diminish the assigned time limit a little so that there is some time to
1806 ! timlim=batime-150.0
1807 ! Calculate the initial time, if it is not zero (e.g. for the SUN).
1809 #if .not. defined(WHAM_RUN) && .not. defined(CLUSTER)
1811 walltime=MPI_WTIME()
1813 time_allreduce=0.0d0
1818 time_scatter_fmat=0.0d0
1819 time_scatter_ginv=0.0d0
1820 time_scatter_fmatmult=0.0d0
1821 time_scatter_ginvmult=0.0d0
1822 time_barrier_e=0.0d0
1823 time_barrier_g=0.0d0
1826 time_lagrangian=0.0d0
1827 time_sumgradient=0.0d0
1828 time_intcartderiv=0.0d0
1829 time_inttocart=0.0d0
1831 time_fricmatmult=0.0d0
1841 time_fricmatmult=0.0d0
1845 !d print *,' in SET_TIMERS stime=',stime
1847 end subroutine set_timers
1848 !-----------------------------------------------------------------------------
1850 logical function stopx(nf)
1851 ! This function returns .true. if one of the following reasons to exit SUMSL
1852 ! occurs. The "reason" code is stored in WHATSUP passed thru a COMMON block:
1854 !... WHATSUP = 0 - go on, no reason to stop. Stopx will return .false.
1855 !... 1 - Time up in current node;
1856 !... 2 - STOP signal was received from another node because the
1857 !... node's task was accomplished (parallel only);
1858 !... -1 - STOP signal was received from another node because of error;
1859 !... -2 - STOP signal was received from another node, because
1860 !... the node's time was up.
1861 ! implicit real*8 (a-h,o-z)
1862 ! include 'DIMENSIONS'
1864 !el use control_data, only:WhatsUp
1867 !el use MPI_data !include 'COMMON.INFO'
1871 !el logical :: ovrtim
1873 ! include 'COMMON.IOUNITS'
1874 ! include 'COMMON.TIME1'
1877 !d print *,'Processor',MyID,' NF=',nf
1878 !d write (iout,*) "stopx: ",nf
1882 ! Finish if time is up.
1886 else if (mod(nf,100).eq.0) then
1887 ! Other processors might have finished. Check this every 100th function
1889 ! Master checks if any other processor has sent accepted conformation(s) to it.
1890 if (MyID.ne.MasterID) call receive_mcm_info
1891 if (MyID.eq.MasterID) call receive_conf
1892 !d print *,'Processor ',MyID,' is checking STOP: nf=',nf
1893 call recv_stop_sig(Kwita)
1894 if (Kwita.eq.-1) then
1895 write (iout,'(a,i4,a,i5)') 'Processor',&
1896 MyID,' has received STOP signal in STOPX; NF=',nf
1897 write (*,'(a,i4,a,i5)') 'Processor',&
1898 MyID,' has received STOP signal in STOPX; NF=',nf
1901 elseif (Kwita.eq.-2) then
1903 'Processor',MyID,' received TIMEUP-STOP signal in SUMSL.'
1905 'Processor',MyID,' received TIMEUP-STOP signal in SUMSL.'
1908 else if (Kwita.eq.-3) then
1910 'Processor',MyID,' received ERROR-STOP signal in SUMSL.'
1912 'Processor',MyID,' received ERROR-STOP signal in SUMSL.'
1926 !d write (iout,*) "stopx set at .false."
1930 ! Check for FOUND_NAN flag
1932 write(iout,*)" *** stopx : Found a NaN"
1938 ! Finish if time is up.
1941 else if (cutoffviol) then
1950 !-----------------------------------------------------------------------------
1952 logical function stopx(nf)
1954 ! ..................................................................
1957 ! THIS FUNCTION MAY SERVE AS THE STOPX (ASYNCHRONOUS INTERRUPTION)
1958 ! FUNCTION FOR THE NL2SOL (NONLINEAR LEAST-SQUARES) PACKAGE AT
1959 ! THOSE INSTALLATIONS WHICH DO NOT WISH TO IMPLEMENT A
1962 ! *****ALGORITHM NOTES...
1963 ! AT INSTALLATIONS WHERE THE NL2SOL SYSTEM IS USED
1964 ! INTERACTIVELY, THIS DUMMY STOPX SHOULD BE REPLACED BY A
1965 ! FUNCTION THAT RETURNS .TRUE. IF AND ONLY IF THE INTERRUPT
1966 ! (BREAK) KEY HAS BEEN PRESSED SINCE THE LAST CALL ON STOPX.
1968 ! $$$ MODIFIED FOR USE AS THE TIMER ROUTINE.
1969 ! $$$ WHEN THE TIME LIMIT HAS BEEN
1970 ! $$$ REACHED STOPX IS SET TO .TRUE AND INITIATES (IN ITSUM)
1971 ! $$$ AND ORDERLY EXIT OUT OF SUMSL. IF ARRAYS IV AND V ARE
1972 ! $$$ SAVED, THE SUMSL ROUTINES CAN BE RESTARTED AT THE SAME
1973 ! $$$ POINT AT WHICH THEY WERE INTERRUPTED.
1975 ! ..................................................................
1977 ! include 'DIMENSIONS'
1980 ! include 'COMMON.IOUNITS'
1981 ! include 'COMMON.TIME1'
1983 ! include 'COMMON.INFO'
1986 !d print *,'Processor',MyID,' NF=',nf
1989 ! Finish if time is up.
1992 else if (mod(nf,100).eq.0) then
1993 ! Other processors might have finished. Check this every 100th function
1995 !d print *,'Processor ',MyID,' is checking STOP: nf=',nf
1996 call recv_stop_sig(Kwita)
1997 if (Kwita.eq.-1) then
1998 write (iout,'(a,i4,a,i5)') 'Processor',&
1999 MyID,' has received STOP signal in STOPX; NF=',nf
2000 write (*,'(a,i4,a,i5)') 'Processor',&
2001 MyID,' has received STOP signal in STOPX; NF=',nf
2013 !-----------------------------------------------------------------------------
2014 logical function ovrtim()
2016 ! include 'DIMENSIONS'
2017 ! include 'COMMON.IOUNITS'
2018 ! include 'COMMON.TIME1'
2019 !el real(kind=8) :: tcpu
2020 real(kind=8) :: curtim
2023 curtim = MPI_Wtime()-walltime
2027 ! curtim is the current time in seconds.
2028 ! write (iout,*) "curtim",curtim," timlim",timlim," safety",safety
2030 if (curtim .ge. timlim - safety) then
2031 write (iout,'(a,f10.2,a,f10.2,a,f10.2,a)') &
2032 "***************** Elapsed time (",curtim,&
2033 " s) is within the safety limit (",safety,&
2034 " s) of the allocated time (",timlim," s). Terminating."
2042 !elwrite (iout,*) "ovrtim",ovrtim
2045 !-----------------------------------------------------------------------------
2046 real(kind=8) function tcpu()
2048 ! include 'COMMON.TIME1'
2049 real(kind=8) :: seconds
2051 !***************************
2052 ! Next definition for EAGLE (ibm-es9000)
2053 real(kind=8) :: micseconds
2055 tcpu=cputime(micseconds,rcode)
2056 tcpu=(micseconds/1.0E6) - stime
2057 !***************************
2060 !***************************
2061 ! Next definitions for sun
2062 REAL(kind=8) :: ECPU,ETIME,ETCPU
2063 real(kind=8),dimension(2) :: tarray
2066 !***************************
2069 !***************************
2070 ! Next definitions for ksr
2071 ! this function uses the ksr timer ALL_SECONDS from the PMON library to
2072 ! return the elapsed time in seconds
2073 tcpu= all_seconds() - stime
2074 !***************************
2077 !***************************
2078 ! Next definitions for sgi
2079 real(kind=4) :: timar(2), etime
2080 seconds = etime(timar)
2081 !d print *,'seconds=',seconds,' stime=',stime
2084 tcpu=seconds - stime
2085 !***************************
2089 !***************************
2090 ! Next definitions for sgi
2091 real(kind=4) :: timar(2), etime
2092 seconds = etime(timar)
2093 !d print *,'seconds=',seconds,' stime=',stime
2096 tcpu=seconds - stime
2097 !***************************
2102 !***************************
2103 ! Next definitions for Cray
2105 ! curdat=curdat(1:9)
2106 ! call clock(curtim)
2107 ! curtim=curtim(1:8)
2110 !***************************
2113 !***************************
2114 ! Next definitions for RS6000
2115 integer(kind=4) :: i1,mclock
2117 tcpu = (i1+0.0D0)/100.0D0
2120 !***************************
2121 ! next definitions for windows NT Digital fortran
2122 real(kind=4) :: time_real
2123 call cpu_time(time_real)
2127 !***************************
2128 ! next definitions for windows NT Digital fortran
2129 real(kind=4) :: time_real
2130 call cpu_time(time_real)
2136 !-----------------------------------------------------------------------------
2138 subroutine dajczas(rntime,hrtime,mintime,sectime)
2140 ! include 'COMMON.IOUNITS'
2141 integer :: ihr,imn,isc
2142 real(kind=8) :: rntime,hrtime,mintime,sectime
2143 hrtime=rntime/3600.0D0
2145 mintime=aint((rntime-3600.0D0*hrtime)/60.0D0)
2146 sectime=aint((rntime-3600.0D0*hrtime-60.0D0*mintime)+0.5D0)
2147 if (sectime.eq.60.0D0) then
2149 mintime=mintime+1.0D0
2154 write (iout,328) ihr,imn,isc
2155 328 FORMAT(//'***** Computation time: ',I4 ,' hours ',I2 ,&
2156 ' minutes ', I2 ,' seconds *****')
2158 end subroutine dajczas
2159 !-----------------------------------------------------------------------------
2160 subroutine print_detailed_timing
2163 ! implicit real*8 (a-h,o-z)
2164 ! include 'DIMENSIONS'
2168 ! include 'COMMON.IOUNITS'
2169 ! include 'COMMON.TIME1'
2170 ! include 'COMMON.SETUP'
2171 real(kind=8) :: time1,time_barrier
2172 time_barrier = 0.0d0
2176 write (iout,'(80(1h=)/a/(80(1h=)))') &
2177 "Details of FG communication time"
2178 write (*,'(7(a40,1pe15.5/),40(1h-)/a40,1pe15.5/80(1h=))') &
2179 "BROADCAST:",time_bcast,"REDUCE:",time_reduce,&
2180 "GATHER:",time_gather,&
2181 "SCATTER:",time_scatter,"SENDRECV:",time_sendrecv,&
2182 "BARRIER ene",time_barrier_e,&
2183 "BARRIER grad",time_barrier_g,&
2185 time_bcast+time_reduce+time_gather+time_scatter+time_sendrecv
2186 write (*,*) fg_rank,myrank,&
2187 ': Total wall clock time',time1-walltime,' sec'
2188 write (*,*) "Processor",fg_rank,myrank,&
2189 ": BROADCAST time",time_bcast," REDUCE time",&
2190 time_reduce," GATHER time",time_gather," SCATTER time",&
2192 " SCATTER fmatmult",time_scatter_fmatmult,&
2193 " SCATTER ginvmult",time_scatter_ginvmult,&
2194 " SCATTER fmat",time_scatter_fmat,&
2195 " SCATTER ginv",time_scatter_ginv,&
2196 " SENDRECV",time_sendrecv,&
2197 " BARRIER ene",time_barrier_e,&
2198 " BARRIER GRAD",time_barrier_g,&
2199 " BCAST7",time_bcast7," BCASTC",time_bcastc,&
2200 " BCASTW",time_bcastw," ALLREDUCE",time_allreduce,&
2202 time_bcast+time_reduce+time_gather+time_scatter+ &
2203 time_sendrecv+time_barrier+time_bcastc
2205 write (*,*) "Processor",fg_rank,myrank," enecalc",time_enecalc
2206 write (*,*) "Processor",fg_rank,myrank," sumene",time_sumene
2207 write (*,*) "Processor",fg_rank,myrank," intfromcart",&
2209 write (*,*) "Processor",fg_rank,myrank," vecandderiv",&
2211 write (*,*) "Processor",fg_rank,myrank," setmatrices",&
2213 write (*,*) "Processor",fg_rank,myrank," ginvmult",&
2215 write (*,*) "Processor",fg_rank,myrank," fricmatmult",&
2217 write (*,*) "Processor",fg_rank,myrank," inttocart",&
2219 write (*,*) "Processor",fg_rank,myrank," sumgradient",&
2221 write (*,*) "Processor",fg_rank,myrank," intcartderiv",&
2223 if (fg_rank.eq.0) then
2224 write (*,*) "Processor",fg_rank,myrank," lagrangian",&
2226 write (*,*) "Processor",fg_rank,myrank," cartgrad",&
2230 end subroutine print_detailed_timing
2232 !-----------------------------------------------------------------------------
2233 !-----------------------------------------------------------------------------