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)
139 #if !defined(WHAM_RUN) && !defined(CLUSTER)
144 allocate(MovTypID(-1:MaxMoveType+1))
145 MovTypID=(/'pool ','chain regrow ',&
146 'multi-bond ','phi ','theta ',&
147 'side chain ','total '/)
150 ! The following is just to define auxiliary variables used in angle conversion
152 pi=4.0D0*datan(1.0D0)
157 rad2deg=1.0D0/deg2rad
158 angmin=10.0D0*deg2rad
185 !rc for write_rmsbank1
187 !dr include secondary structure prediction bias
198 #if defined(WHAM_RUN) || defined(CLUSTER)
202 ! CSA I/O units (separated from others especially for Jooyoung)
213 icsa_bank_reminimized=38
216 !rc for ifc error 118
233 #if defined(WHAM_RUN) || defined(CLUSTER)
235 ! setting the mpi variables for WHAM
242 ! Set default weights of the energy terms.
244 wsc=1.0D0 ! in wham: wlong=1.0D0
253 ! print '(a,$)','Inside initialize'
254 ! call memmon_print_usage()
288 ! athet(j,i,ichir1,ichir2)=0.0D0
289 ! bthet(j,i,ichir1,ichir2)=0.0D0
309 ! gaussc(l,k,j,i)=0.0D0
317 ! do i=-maxtor,maxtor
319 !c write (iout,*) "TU DOCHODZE",i,itortyp(i)
321 ! do j=-maxtor,maxtor
323 ! v1(k,j,i,iblock)=0.0D0
324 ! v2(k,j,i,iblock)=0.0D0
330 ! do i=-maxtor,maxtor
331 ! do j=-maxtor,maxtor
332 ! do k=-maxtor,maxtor
334 ! v1c(1,l,i,j,k,iblock)=0.0D0
335 ! v1s(1,l,i,j,k,iblock)=0.0D0
336 ! v1c(2,l,i,j,k,iblock)=0.0D0
337 ! v1s(2,l,i,j,k,iblock)=0.0D0
341 ! v2c(m,l,i,j,k,iblock)=0.0D0
342 ! v2s(m,l,i,j,k,iblock)=0.0D0
354 ! Initialize the bridge arrays
373 ! Initialize variables used in minimization.
382 ! Initialize the variables responsible for the mode of gradient storage.
388 allocate(iww(max_eneW))
391 if (print_order(i).eq.j) then
392 iww(print_order(i))=j
400 #if defined(WHAM_RUN) || defined(CLUSTER)
403 ! allocate(ww0(max_eneW))
404 ! ww0 = reshape((/1.0d0,1.0d0,1.0d0,1.0d0,1.0d0,1.0d0,1.0d0,1.0d0,&
405 ! 1.0d0,1.0d0,1.0d0,1.0d0,1.0d0,1.0d0,1.0d0,1.0d0,0.4d0,1.0d0,&
406 ! 1.0d0,0.0d0,0.0/), shape(ww0))
409 ! Set timers and counters for the respective routines
429 ! Initialize constants used to split the energy into long- and short-range
435 nprint_ene=nprint_ene-1
438 end subroutine initialize
439 !-----------------------------------------------------------------------------
440 subroutine init_int_table
442 use geometry, only:int_bounds1
445 ! implicit real*8 (a-h,o-z)
446 ! include 'DIMENSIONS'
449 integer,dimension(15) :: blocklengths,displs
451 ! include 'COMMON.CONTROL'
452 ! include 'COMMON.SETUP'
453 ! include 'COMMON.CHAIN'
454 ! include 'COMMON.INTERACT'
455 ! include 'COMMON.LOCAL'
456 ! include 'COMMON.SBRIDGE'
457 ! include 'COMMON.TORCNSTR'
458 ! include 'COMMON.IOUNITS'
459 ! include 'COMMON.DERIV'
460 ! include 'COMMON.CONTACTS'
461 !el integer,dimension(0:nfgtasks) :: iturn3_start_all,iturn3_end_all,&
462 !el iturn4_start_all,iturn4_end_all,iatel_s_all,iatel_e_all !(0:max_fg_procs)
463 !el integer,dimension(nres,0:nfgtasks) :: ielstart_all,&
464 !el ielend_all !(maxres,0:max_fg_procs-1)
465 !el integer,dimension(0:nfgtasks-1) :: ntask_cont_from_all,&
466 !el ntask_cont_to_all !(0:max_fg_procs-1),
467 !el integer,dimension(0:nfgtasks-1,0:nfgtasks-1) :: itask_cont_from_all,&
468 !el itask_cont_to_all !(0:max_fg_procs-1,0:max_fg_procs-1)
470 !el common /przechowalnia/ iturn3_start_all,iturn3_end_all,&
471 !el iturn4_start_all,iturn4_end_all,iatel_s_all,iatel_e_all,&
472 !el ielstart_all,ielend_all,ntask_cont_from_all,itask_cont_from_all,&
473 !el ntask_cont_to_all,itask_cont_to_all
475 integer :: FG_GROUP,CONT_FROM_GROUP,CONT_TO_GROUP
476 logical :: scheck,lprint,flag
479 integer :: ind_scint=0,ind_scint_old,ii,jj,i,j,iint
482 integer :: my_sc_int(0:nfgtasks-1),my_ele_int(0:nfgtasks-1)
483 integer :: my_sc_intt(0:nfgtasks),my_ele_intt(0:nfgtasks)
484 integer :: n_sc_int_tot,my_sc_inde,my_sc_inds,ind_sctint,npept
485 integer :: nele_int_tot,my_ele_inds,my_ele_inde,ind_eleint_old,&
486 ind_eleint,ijunk,nele_int_tot_vdw,my_ele_inds_vdw,&
487 my_ele_inde_vdw,ind_eleint_vdw,ind_eleint_vdw_old,&
488 nscp_int_tot,my_scp_inds,my_scp_inde,ind_scpint,&
489 ind_scpint_old,nsumgrad,nlen,ngrad_start,ngrad_end,&
490 ierror,k,ierr,iaux,ncheck_to,ncheck_from,ind_typ,&
493 !el allocate(itask_cont_from(0:nfgtasks-1)) !(0:max_fg_procs-1)
494 !el allocate(itask_cont_to(0:nfgtasks-1)) !(0:max_fg_procs-1)
496 !... Determine the numbers of start and end SC-SC interaction
497 !... to deal with by current processor.
498 !write (iout,*) '******INIT_INT_TABLE nres=',nres,' nnt=',nnt,' nct=',nct
500 itask_cont_from(i)=fg_rank
501 itask_cont_to(i)=fg_rank
506 write (iout,*)'INIT_INT_TABLE nres=',nres,' nnt=',nnt,' nct=',nct
507 n_sc_int_tot=(nct-nnt+1)*(nct-nnt)/2-nss
508 call int_bounds(n_sc_int_tot,my_sc_inds,my_sc_inde)
509 !write (iout,*) 'INIT_INT_TABLE nres=',nres,' nnt=',nnt,' nct=',nct
511 write (iout,*) 'Processor',fg_rank,' CG group',kolor,&
512 ' absolute rank',MyRank,&
513 ' n_sc_int_tot',n_sc_int_tot,' my_sc_inds=',my_sc_inds,&
514 ' my_sc_inde',my_sc_inde
519 !el common /przechowalnia/
520 allocate(iturn3_start_all(0:nfgtasks))
521 allocate(iturn3_end_all(0:nfgtasks))
522 allocate(iturn4_start_all(0:nfgtasks))
523 allocate(iturn4_end_all(0:nfgtasks))
524 allocate(iatel_s_all(0:nfgtasks))
525 allocate(iatel_e_all(0:nfgtasks))
526 allocate(ielstart_all(nres,0:nfgtasks-1))
527 allocate(ielend_all(nres,0:nfgtasks-1))
529 allocate(ntask_cont_from_all(0:nfgtasks-1))
530 allocate(ntask_cont_to_all(0:nfgtasks-1))
531 allocate(itask_cont_from_all(0:nfgtasks-1,0:nfgtasks-1))
532 allocate(itask_cont_to_all(0:nfgtasks-1,0:nfgtasks-1))
535 do i=1,nres !el !maxres
549 !d write (iout,*) 'ns=',ns,' nss=',nss,' ihpb,jhpb',
550 !d & (ihpb(i),jhpb(i),i=1,nss)
555 if (ihpb(ii).eq.i+nres) then
562 !d write (iout,*) 'i=',i,' scheck=',scheck,' jj=',jj
566 ! write (iout,*) 'jj=i+1'
567 call int_partition(ind_scint,my_sc_inds,my_sc_inde,i,&
568 iatsc_s,iatsc_e,i+2,nct,nint_gr(i),istart(i,1),iend(i,1),*12)
574 else if (jj.eq.nct) then
576 ! write (iout,*) 'jj=nct'
577 call int_partition(ind_scint,my_sc_inds,my_sc_inde,i,&
578 iatsc_s,iatsc_e,i+1,nct-1,nint_gr(i),istart(i,1),iend(i,1),*12)
586 call int_partition(ind_scint,my_sc_inds,my_sc_inde,i,&
587 iatsc_s,iatsc_e,i+1,jj-1,nint_gr(i),istart(i,1),iend(i,1),*12)
589 call int_partition(ind_scint,my_sc_inds,my_sc_inde,i,&
590 iatsc_s,iatsc_e,jj+1,nct,nint_gr(i),istart(i,ii),iend(i,ii),*12)
601 call int_partition(ind_scint,my_sc_inds,my_sc_inde,i,&
602 iatsc_s,iatsc_e,i+1,nct,nint_gr(i),istart(i,1),iend(i,1),*12)
607 ind_scint=ind_scint+nct-i
611 ind_scint_old=ind_scint
619 if (iatsc_s.eq.0) iatsc_s=1
621 if (lprint) write (*,*) 'Processor',fg_rank,' CG Group',kolor,&
622 ' absolute rank',myrank,' iatsc_s=',iatsc_s,' iatsc_e=',iatsc_e
625 write (iout,'(a)') 'Interaction array:'
627 write (iout,'(i3,2(2x,2i3))') &
628 i,(istart(i,iint),iend(i,iint),iint=1,nint_gr(i))
631 ispp=4 !?? wham ispp=2
633 ! Now partition the electrostatic-interaction array
635 nele_int_tot=(npept-ispp)*(npept-ispp+1)/2
636 call int_bounds(nele_int_tot,my_ele_inds,my_ele_inde)
638 write (*,*) 'Processor',fg_rank,' CG group',kolor,&
639 ' absolute rank',MyRank,&
640 ' nele_int_tot',nele_int_tot,' my_ele_inds=',my_ele_inds,&
641 ' my_ele_inde',my_ele_inde
648 call int_partition(ind_eleint,my_ele_inds,my_ele_inde,i,&
649 iatel_s,iatel_e,i+ispp,nct-1,ijunk,ielstart(i),ielend(i),*13)
652 if (iatel_s.eq.0) iatel_s=1
653 nele_int_tot_vdw=(npept-2)*(npept-2+1)/2
654 ! write (iout,*) "nele_int_tot_vdw",nele_int_tot_vdw
655 call int_bounds(nele_int_tot_vdw,my_ele_inds_vdw,my_ele_inde_vdw)
656 ! write (iout,*) "my_ele_inds_vdw",my_ele_inds_vdw,
657 ! & " my_ele_inde_vdw",my_ele_inde_vdw
664 call int_partition(ind_eleint_vdw,my_ele_inds_vdw,&
666 iatel_s_vdw,iatel_e_vdw,i+2,nct-1,ijunk,ielstart_vdw(i),&
668 ! write (iout,*) i," ielstart_vdw",ielstart_vdw(i),
669 ! & " ielend_vdw",ielend_vdw(i)
671 if (iatel_s_vdw.eq.0) iatel_s_vdw=1
675 iatel_e=nct-5 ! ?? wham iatel_e=nct-3
677 ielstart(i)=i+4 ! ?? wham +2
682 do i=iatel_s_vdw,iatel_e_vdw
688 write (*,'(a)') 'Processor',fg_rank,' CG group',kolor,&
689 ' absolute rank',MyRank
690 write (iout,*) 'Electrostatic interaction array:'
692 write (iout,'(i3,2(2x,2i3))') i,ielstart(i),ielend(i)
697 ! Partition the SC-p interaction array
699 nscp_int_tot=(npept-iscp+1)*(npept-iscp+1)
700 call int_bounds(nscp_int_tot,my_scp_inds,my_scp_inde)
701 if (lprint) write (iout,*) 'Processor',fg_rank,' CG group',kolor,&
702 ' absolute rank',myrank,&
703 ' nscp_int_tot',nscp_int_tot,' my_scp_inds=',my_scp_inds,&
704 ' my_scp_inde',my_scp_inde
710 if (i.lt.nnt+iscp) then
711 !d write (iout,*) 'i.le.nnt+iscp'
712 call int_partition(ind_scpint,my_scp_inds,my_scp_inde,i,&
713 iatscp_s,iatscp_e,i+iscp,nct,nscp_gr(i),iscpstart(i,1),&
715 else if (i.gt.nct-iscp) then
716 !d write (iout,*) 'i.gt.nct-iscp'
717 call int_partition(ind_scpint,my_scp_inds,my_scp_inde,i,&
718 iatscp_s,iatscp_e,nnt,i-iscp,nscp_gr(i),iscpstart(i,1),&
721 call int_partition(ind_scpint,my_scp_inds,my_scp_inde,i,&
722 iatscp_s,iatscp_e,nnt,i-iscp,nscp_gr(i),iscpstart(i,1),&
725 call int_partition(ind_scpint,my_scp_inds,my_scp_inde,i,&
726 iatscp_s,iatscp_e,i+iscp,nct,nscp_gr(i),iscpstart(i,ii),&
735 if (i.lt.nnt+iscp) then
737 iscpstart(i,1)=i+iscp
739 elseif (i.gt.nct-iscp) then
747 iscpstart(i,2)=i+iscp
752 if (iatscp_s.eq.0) iatscp_s=1
754 write (iout,'(a)') 'SC-p interaction array:'
755 do i=iatscp_s,iatscp_e
756 write (iout,'(i3,2(2x,2i3))') &
757 i,(iscpstart(i,j),iscpend(i,j),j=1,nscp_gr(i))
760 ! Partition local interactions
762 call int_bounds(nres-2,loc_start,loc_end)
763 loc_start=loc_start+1
765 call int_bounds(nres-2,ithet_start,ithet_end)
766 ithet_start=ithet_start+2
767 ithet_end=ithet_end+2
768 call int_bounds(nct-nnt-2,iturn3_start,iturn3_end)
769 iturn3_start=iturn3_start+nnt
770 iphi_start=iturn3_start+2
771 iturn3_end=iturn3_end+nnt
772 iphi_end=iturn3_end+2
773 iturn3_start=iturn3_start-1
774 iturn3_end=iturn3_end-1
775 call int_bounds(nres-3,itau_start,itau_end)
776 itau_start=itau_start+3
778 call int_bounds(nres-3,iphi1_start,iphi1_end)
779 iphi1_start=iphi1_start+3
780 iphi1_end=iphi1_end+3
781 call int_bounds(nct-nnt-3,iturn4_start,iturn4_end)
782 iturn4_start=iturn4_start+nnt
783 iphid_start=iturn4_start+2
784 iturn4_end=iturn4_end+nnt
785 iphid_end=iturn4_end+2
786 iturn4_start=iturn4_start-1
787 iturn4_end=iturn4_end-1
788 call int_bounds(nres-2,ibond_start,ibond_end)
789 ibond_start=ibond_start+1
790 ibond_end=ibond_end+1
791 call int_bounds(nct-nnt,ibondp_start,ibondp_end)
792 ibondp_start=ibondp_start+nnt
793 ibondp_end=ibondp_end+nnt
794 call int_bounds1(nres-1,ivec_start,ivec_end)
795 ! print *,"Processor",myrank,fg_rank,fg_rank1,
796 ! & " ivec_start",ivec_start," ivec_end",ivec_end
797 iset_start=loc_start+2
799 if (ndih_constr.eq.0) then
803 call int_bounds(ndih_constr,idihconstr_start,idihconstr_end)
805 ! nsumgrad=(nres-nnt)*(nres-nnt+1)/2
807 nsumgrad=(nres-nnt)*(nres-nnt+1)/2
809 call int_bounds(nsumgrad,ngrad_start,ngrad_end)
810 igrad_start=((2*nlen+1) &
811 -sqrt(float((2*nlen-1)**2-8*(ngrad_start-1))))/2
812 igrad_end=((2*nlen+1) &
813 -sqrt(float((2*nlen-1)**2-8*(ngrad_end-1))))/2
814 !el allocate(jgrad_start(igrad_start:igrad_end))
815 !el allocate(jgrad_end(igrad_start:igrad_end)) !(maxres)
816 jgrad_start(igrad_start)= &
817 ngrad_start-(2*nlen-igrad_start)*(igrad_start-1)/2 &
819 jgrad_end(igrad_start)=nres
820 if (igrad_end.gt.igrad_start) jgrad_start(igrad_end)=igrad_end+1
821 jgrad_end(igrad_end)=ngrad_end-(2*nlen-igrad_end)*(igrad_end-1)/2 &
823 do i=igrad_start+1,igrad_end-1
828 write (*,*) 'Processor:',fg_rank,' CG group',kolor,&
829 ' absolute rank',myrank,&
830 ' loc_start',loc_start,' loc_end',loc_end,&
831 ' ithet_start',ithet_start,' ithet_end',ithet_end,&
832 ' iphi_start',iphi_start,' iphi_end',iphi_end,&
833 ' iphid_start',iphid_start,' iphid_end',iphid_end,&
834 ' ibond_start',ibond_start,' ibond_end',ibond_end,&
835 ' ibondp_start',ibondp_start,' ibondp_end',ibondp_end,&
836 ' iturn3_start',iturn3_start,' iturn3_end',iturn3_end,&
837 ' iturn4_start',iturn4_start,' iturn4_end',iturn4_end,&
838 ' ivec_start',ivec_start,' ivec_end',ivec_end,&
839 ' iset_start',iset_start,' iset_end',iset_end,&
840 ' idihconstr_start',idihconstr_start,' idihconstr_end',&
842 write (*,*) 'Processor:',fg_rank,myrank,' igrad_start',&
843 igrad_start,' igrad_end',igrad_end,' ngrad_start',ngrad_start,&
844 ' ngrad_end',ngrad_end
845 do i=igrad_start,igrad_end
846 write(*,*) 'Processor:',fg_rank,myrank,i,&
847 jgrad_start(i),jgrad_end(i)
850 if (nfgtasks.gt.1) then
851 call MPI_Allgather(ivec_start,1,MPI_INTEGER,ivec_displ(0),1,&
852 MPI_INTEGER,FG_COMM1,IERROR)
853 iaux=ivec_end-ivec_start+1
854 call MPI_Allgather(iaux,1,MPI_INTEGER,ivec_count(0),1,&
855 MPI_INTEGER,FG_COMM1,IERROR)
856 call MPI_Allgather(iset_start-2,1,MPI_INTEGER,iset_displ(0),1,&
857 MPI_INTEGER,FG_COMM,IERROR)
858 iaux=iset_end-iset_start+1
859 call MPI_Allgather(iaux,1,MPI_INTEGER,iset_count(0),1,&
860 MPI_INTEGER,FG_COMM,IERROR)
861 call MPI_Allgather(ibond_start,1,MPI_INTEGER,ibond_displ(0),1,&
862 MPI_INTEGER,FG_COMM,IERROR)
863 iaux=ibond_end-ibond_start+1
864 call MPI_Allgather(iaux,1,MPI_INTEGER,ibond_count(0),1,&
865 MPI_INTEGER,FG_COMM,IERROR)
866 call MPI_Allgather(ithet_start,1,MPI_INTEGER,ithet_displ(0),1,&
867 MPI_INTEGER,FG_COMM,IERROR)
868 iaux=ithet_end-ithet_start+1
869 call MPI_Allgather(iaux,1,MPI_INTEGER,ithet_count(0),1,&
870 MPI_INTEGER,FG_COMM,IERROR)
871 call MPI_Allgather(iphi_start,1,MPI_INTEGER,iphi_displ(0),1,&
872 MPI_INTEGER,FG_COMM,IERROR)
873 iaux=iphi_end-iphi_start+1
874 call MPI_Allgather(iaux,1,MPI_INTEGER,iphi_count(0),1,&
875 MPI_INTEGER,FG_COMM,IERROR)
876 call MPI_Allgather(iphi1_start,1,MPI_INTEGER,iphi1_displ(0),1,&
877 MPI_INTEGER,FG_COMM,IERROR)
878 iaux=iphi1_end-iphi1_start+1
879 call MPI_Allgather(iaux,1,MPI_INTEGER,iphi1_count(0),1,&
880 MPI_INTEGER,FG_COMM,IERROR)
887 call MPI_Allgather(iturn3_start,1,MPI_INTEGER,&
888 iturn3_start_all(0),1,MPI_INTEGER,FG_COMM,IERROR)
889 call MPI_Allgather(iturn4_start,1,MPI_INTEGER,&
890 iturn4_start_all(0),1,MPI_INTEGER,FG_COMM,IERROR)
891 call MPI_Allgather(iturn3_end,1,MPI_INTEGER,&
892 iturn3_end_all(0),1,MPI_INTEGER,FG_COMM,IERROR)
893 call MPI_Allgather(iturn4_end,1,MPI_INTEGER,&
894 iturn4_end_all(0),1,MPI_INTEGER,FG_COMM,IERROR)
895 call MPI_Allgather(iatel_s,1,MPI_INTEGER,&
896 iatel_s_all(0),1,MPI_INTEGER,FG_COMM,IERROR)
897 call MPI_Allgather(iatel_e,1,MPI_INTEGER,&
898 iatel_e_all(0),1,MPI_INTEGER,FG_COMM,IERROR)
899 call MPI_Allgather(ielstart(1),nres,MPI_INTEGER,&
900 ielstart_all(1,0),nres,MPI_INTEGER,FG_COMM,IERROR)
901 call MPI_Allgather(ielend(1),nres,MPI_INTEGER,&
902 ielend_all(1,0),nres,MPI_INTEGER,FG_COMM,IERROR)
904 write (iout,*) "iatel_s_all",(iatel_s_all(i),i=0,nfgtasks)
905 write (iout,*) "iatel_e_all",(iatel_e_all(i),i=0,nfgtasks)
906 write (iout,*) "iturn3_start_all",&
907 (iturn3_start_all(i),i=0,nfgtasks-1)
908 write (iout,*) "iturn3_end_all",&
909 (iturn3_end_all(i),i=0,nfgtasks-1)
910 write (iout,*) "iturn4_start_all",&
911 (iturn4_start_all(i),i=0,nfgtasks-1)
912 write (iout,*) "iturn4_end_all",&
913 (iturn4_end_all(i),i=0,nfgtasks-1)
914 write (iout,*) "The ielstart_all array"
916 write (iout,'(20i4)') i,(ielstart_all(i,j),j=0,nfgtasks-1)
918 write (iout,*) "The ielend_all array"
920 write (iout,'(20i4)') i,(ielend_all(i,j),j=0,nfgtasks-1)
926 itask_cont_from(0)=fg_rank
927 itask_cont_to(0)=fg_rank
929 !el allocate(iturn3_sent(4,iturn3_start:iturn3_end))
930 !el allocate(iturn4_sent(4,iturn4_start:iturn4_end)) !(4,maxres)
931 do ii=iturn3_start,iturn3_end
932 call add_int(ii,ii+2,iturn3_sent(1,ii),&
933 ntask_cont_to,itask_cont_to,flag)
935 do ii=iturn4_start,iturn4_end
936 call add_int(ii,ii+3,iturn4_sent(1,ii),&
937 ntask_cont_to,itask_cont_to,flag)
939 do ii=iturn3_start,iturn3_end
940 call add_int_from(ii,ii+2,ntask_cont_from,itask_cont_from)
942 do ii=iturn4_start,iturn4_end
943 call add_int_from(ii,ii+3,ntask_cont_from,itask_cont_from)
946 write (iout,*) "After turn3 ntask_cont_from",ntask_cont_from,&
947 " ntask_cont_to",ntask_cont_to
948 write (iout,*) "itask_cont_from",&
949 (itask_cont_from(i),i=1,ntask_cont_from)
950 write (iout,*) "itask_cont_to",&
951 (itask_cont_to(i),i=1,ntask_cont_to)
954 ! write (iout,*) "Loop forward"
957 ! write (iout,*) "from loop i=",i
959 do j=ielstart(i),ielend(i)
960 call add_int_from(i,j,ntask_cont_from,itask_cont_from)
963 ! write (iout,*) "Loop backward iatel_e-1",iatel_e-1,
964 ! & " iatel_e",iatel_e
968 ! write (iout,*) "i",i," ielstart",ielstart(i),
969 ! & " ielend",ielend(i)
972 do j=ielstart(i),ielend(i)
973 call add_int(i,j,iint_sent(1,j,nat_sent+1),ntask_cont_to,&
982 write (iout,*)"After longrange ntask_cont_from",ntask_cont_from,&
983 " ntask_cont_to",ntask_cont_to
984 write (iout,*) "itask_cont_from",&
985 (itask_cont_from(i),i=1,ntask_cont_from)
986 write (iout,*) "itask_cont_to",&
987 (itask_cont_to(i),i=1,ntask_cont_to)
989 write (iout,*) "iint_sent"
992 write (iout,'(20i4)') ii,(j,(iint_sent(k,j,i),k=1,4),&
993 j=ielstart(ii),ielend(ii))
995 write (iout,*) "iturn3_sent iturn3_start",iturn3_start,&
996 " iturn3_end",iturn3_end
997 write (iout,'(20i4)') (i,(iturn3_sent(j,i),j=1,4),&
998 i=iturn3_start,iturn3_end)
999 write (iout,*) "iturn4_sent iturn4_start",iturn4_start,&
1000 " iturn4_end",iturn4_end
1001 write (iout,'(20i4)') (i,(iturn4_sent(j,i),j=1,4),&
1002 i=iturn4_start,iturn4_end)
1005 call MPI_Gather(ntask_cont_from,1,MPI_INTEGER,&
1006 ntask_cont_from_all,1,MPI_INTEGER,king,FG_COMM,IERR)
1007 ! write (iout,*) "Gather ntask_cont_from ended"
1009 call MPI_Gather(itask_cont_from(0),nfgtasks,MPI_INTEGER,&
1010 itask_cont_from_all(0,0),nfgtasks,MPI_INTEGER,king,&
1012 ! write (iout,*) "Gather itask_cont_from ended"
1014 call MPI_Gather(ntask_cont_to,1,MPI_INTEGER,ntask_cont_to_all,&
1015 1,MPI_INTEGER,king,FG_COMM,IERR)
1016 ! write (iout,*) "Gather ntask_cont_to ended"
1018 call MPI_Gather(itask_cont_to,nfgtasks,MPI_INTEGER,&
1019 itask_cont_to_all,nfgtasks,MPI_INTEGER,king,FG_COMM,IERR)
1020 ! write (iout,*) "Gather itask_cont_to ended"
1022 if (fg_rank.eq.king) then
1023 write (iout,*)"Contact receive task map (proc, #tasks, tasks)"
1025 write (iout,'(20i4)') i,ntask_cont_from_all(i),&
1026 (itask_cont_from_all(j,i),j=1,ntask_cont_from_all(i))
1030 write (iout,*) "Contact send task map (proc, #tasks, tasks)"
1032 write (iout,'(20i4)') i,ntask_cont_to_all(i),&
1033 (itask_cont_to_all(j,i),j=1,ntask_cont_to_all(i))
1037 ! Check if every send will have a matching receive
1041 ncheck_to=ncheck_to+ntask_cont_to_all(i)
1042 ncheck_from=ncheck_from+ntask_cont_from_all(i)
1044 write (iout,*) "Control sums",ncheck_from,ncheck_to
1045 if (ncheck_from.ne.ncheck_to) then
1046 write (iout,*) "Error: #receive differs from #send."
1047 write (iout,*) "Terminating program...!"
1053 do j=1,ntask_cont_to_all(i)
1054 ii=itask_cont_to_all(j,i)
1055 do k=1,ntask_cont_from_all(ii)
1056 if (itask_cont_from_all(k,ii).eq.i) then
1057 if(lprint)write(iout,*)"Matching send/receive",i,ii
1061 if (k.eq.ntask_cont_from_all(ii)+1) then
1063 write (iout,*) "Error: send by",j," to",ii,&
1064 " would have no matching receive"
1070 write (iout,*) "Unmatched sends; terminating program"
1074 call MPI_Bcast(flag,1,MPI_LOGICAL,king,FG_COMM,IERROR)
1075 ! write (iout,*) "flag broadcast ended flag=",flag
1078 call MPI_Finalize(IERROR)
1079 stop "Error in INIT_INT_TABLE: unmatched send/receive."
1081 call MPI_Comm_group(FG_COMM,fg_group,IERR)
1082 ! write (iout,*) "MPI_Comm_group ended"
1084 call MPI_Group_incl(fg_group,ntask_cont_from+1,&
1085 itask_cont_from(0),CONT_FROM_GROUP,IERR)
1086 call MPI_Group_incl(fg_group,ntask_cont_to+1,itask_cont_to(0),&
1090 iaux=4*(ielend(ii)-ielstart(ii)+1)
1091 call MPI_Group_translate_ranks(fg_group,iaux,&
1092 iint_sent(1,ielstart(ii),i),CONT_TO_GROUP,&
1093 iint_sent_local(1,ielstart(ii),i),IERR )
1094 ! write (iout,*) "Ranks translated i=",i
1097 iaux=4*(iturn3_end-iturn3_start+1)
1098 call MPI_Group_translate_ranks(fg_group,iaux,&
1099 iturn3_sent(1,iturn3_start),CONT_TO_GROUP,&
1100 iturn3_sent_local(1,iturn3_start),IERR)
1101 iaux=4*(iturn4_end-iturn4_start+1)
1102 call MPI_Group_translate_ranks(fg_group,iaux,&
1103 iturn4_sent(1,iturn4_start),CONT_TO_GROUP,&
1104 iturn4_sent_local(1,iturn4_start),IERR)
1106 write (iout,*) "iint_sent_local"
1109 write (iout,'(20i4)') ii,(j,(iint_sent_local(k,j,i),k=1,4),&
1110 j=ielstart(ii),ielend(ii))
1113 write (iout,*) "iturn3_sent_local iturn3_start",iturn3_start,&
1114 " iturn3_end",iturn3_end
1115 write (iout,'(20i4)') (i,(iturn3_sent_local(j,i),j=1,4),&
1116 i=iturn3_start,iturn3_end)
1117 write (iout,*) "iturn4_sent_local iturn4_start",iturn4_start,&
1118 " iturn4_end",iturn4_end
1119 write (iout,'(20i4)') (i,(iturn4_sent_local(j,i),j=1,4),&
1120 i=iturn4_start,iturn4_end)
1123 call MPI_Group_free(fg_group,ierr)
1124 call MPI_Group_free(cont_from_group,ierr)
1125 call MPI_Group_free(cont_to_group,ierr)
1126 call MPI_Type_contiguous(3,MPI_DOUBLE_PRECISION,MPI_UYZ,IERROR)
1127 call MPI_Type_commit(MPI_UYZ,IERROR)
1128 call MPI_Type_contiguous(18,MPI_DOUBLE_PRECISION,MPI_UYZGRAD,&
1130 call MPI_Type_commit(MPI_UYZGRAD,IERROR)
1131 call MPI_Type_contiguous(2,MPI_DOUBLE_PRECISION,MPI_MU,IERROR)
1132 call MPI_Type_commit(MPI_MU,IERROR)
1133 call MPI_Type_contiguous(4,MPI_DOUBLE_PRECISION,MPI_MAT1,IERROR)
1134 call MPI_Type_commit(MPI_MAT1,IERROR)
1135 call MPI_Type_contiguous(8,MPI_DOUBLE_PRECISION,MPI_MAT2,IERROR)
1136 call MPI_Type_commit(MPI_MAT2,IERROR)
1137 call MPI_Type_contiguous(6,MPI_DOUBLE_PRECISION,MPI_THET,IERROR)
1138 call MPI_Type_commit(MPI_THET,IERROR)
1139 call MPI_Type_contiguous(9,MPI_DOUBLE_PRECISION,MPI_GAM,IERROR)
1140 call MPI_Type_commit(MPI_GAM,IERROR)
1142 !el allocate(lentyp(0:nfgtasks-1))
1144 ! 9/22/08 Derived types to send matrices which appear in correlation terms
1146 if (ivec_count(i).eq.ivec_count(0)) then
1152 do ind_typ=lentyp(0),lentyp(nfgtasks-1)
1153 if (ind_typ.eq.0) then
1154 ichunk=ivec_count(0)
1156 ichunk=ivec_count(1)
1163 ! displs(i)=displs(i-1)+blocklengths(i-1)*maxres
1166 ! blocklengths(i)=blocklengths(i)*ichunk
1168 ! write (iout,*) "blocklengths and displs"
1170 ! write (iout,*) i,blocklengths(i),displs(i)
1173 ! call MPI_Type_indexed(4,blocklengths(1),displs(1),
1174 ! & MPI_DOUBLE_PRECISION,MPI_ROTAT1(ind_typ),IERROR)
1175 ! call MPI_Type_commit(MPI_ROTAT1(ind_typ),IERROR)
1176 ! write (iout,*) "MPI_ROTAT1",MPI_ROTAT1
1182 ! displs(i)=displs(i-1)+blocklengths(i-1)*maxres
1185 ! blocklengths(i)=blocklengths(i)*ichunk
1187 ! write (iout,*) "blocklengths and displs"
1189 ! write (iout,*) i,blocklengths(i),displs(i)
1192 ! call MPI_Type_indexed(4,blocklengths(1),displs(1),
1193 ! & MPI_DOUBLE_PRECISION,MPI_ROTAT2(ind_typ),IERROR)
1194 ! call MPI_Type_commit(MPI_ROTAT2(ind_typ),IERROR)
1195 ! write (iout,*) "MPI_ROTAT2",MPI_ROTAT2
1201 displs(i)=displs(i-1)+blocklengths(i-1)*nres !maxres
1204 blocklengths(i)=blocklengths(i)*ichunk
1206 call MPI_Type_indexed(8,blocklengths,displs,&
1207 MPI_DOUBLE_PRECISION,MPI_PRECOMP11(ind_typ),IERROR)
1208 call MPI_Type_commit(MPI_PRECOMP11(ind_typ),IERROR)
1214 displs(i)=displs(i-1)+blocklengths(i-1)*nres !maxres
1217 blocklengths(i)=blocklengths(i)*ichunk
1219 call MPI_Type_indexed(8,blocklengths,displs,&
1220 MPI_DOUBLE_PRECISION,MPI_PRECOMP12(ind_typ),IERROR)
1221 call MPI_Type_commit(MPI_PRECOMP12(ind_typ),IERROR)
1227 displs(i)=displs(i-1)+blocklengths(i-1)*nres !maxres
1230 blocklengths(i)=blocklengths(i)*ichunk
1232 call MPI_Type_indexed(6,blocklengths,displs,&
1233 MPI_DOUBLE_PRECISION,MPI_PRECOMP22(ind_typ),IERROR)
1234 call MPI_Type_commit(MPI_PRECOMP22(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(2,blocklengths,displs,&
1246 MPI_DOUBLE_PRECISION,MPI_PRECOMP23(ind_typ),IERROR)
1247 call MPI_Type_commit(MPI_PRECOMP23(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(4,blocklengths,displs,&
1259 MPI_DOUBLE_PRECISION,MPI_ROTAT_OLD(ind_typ),IERROR)
1260 call MPI_Type_commit(MPI_ROTAT_OLD(ind_typ),IERROR)
1264 iint_start=ivec_start+1
1267 iint_count(i)=ivec_count(i)
1268 iint_displ(i)=ivec_displ(i)
1269 ivec_displ(i)=ivec_displ(i)-1
1270 iset_displ(i)=iset_displ(i)-1
1271 ithet_displ(i)=ithet_displ(i)-1
1272 iphi_displ(i)=iphi_displ(i)-1
1273 iphi1_displ(i)=iphi1_displ(i)-1
1274 ibond_displ(i)=ibond_displ(i)-1
1276 if (nfgtasks.gt.1 .and. fg_rank.eq.king &
1277 .and. (me.eq.0 .or. .not. out1file)) then
1278 write (iout,*) "IVEC_DISPL, IVEC_COUNT, ISET_START, ISET_COUNT"
1280 write (iout,*) i,ivec_displ(i),ivec_count(i),iset_displ(i),&
1283 write (iout,*) "iphi_start",iphi_start," iphi_end",iphi_end,&
1284 " iphi1_start",iphi1_start," iphi1_end",iphi1_end
1285 write (iout,*)"IPHI_COUNT, IPHI_DISPL, IPHI1_COUNT, IPHI1_DISPL"
1287 write (iout,*) i,iphi_count(i),iphi_displ(i),iphi1_count(i),&
1290 write(iout,'(i10,a,i10,a,i10,a/a,i3,a)') n_sc_int_tot,' SC-SC ',&
1291 nele_int_tot,' electrostatic and ',nscp_int_tot,&
1292 ' SC-p interactions','were distributed among',nfgtasks,&
1293 ' fine-grain processors.'
1309 idihconstr_end=ndih_constr
1310 iphid_start=iphi_start
1311 iphid_end=iphi_end-1
1325 !el common /przechowalnia/
1326 ! deallocate(iturn3_start_all)
1327 ! deallocate(iturn3_end_all)
1328 ! deallocate(iturn4_start_all)
1329 ! deallocate(iturn4_end_all)
1330 ! deallocate(iatel_s_all)
1331 ! deallocate(iatel_e_all)
1332 ! deallocate(ielstart_all)
1333 ! deallocate(ielend_all)
1335 ! deallocate(ntask_cont_from_all)
1336 ! deallocate(ntask_cont_to_all)
1337 ! deallocate(itask_cont_from_all)
1338 ! deallocate(itask_cont_to_all)
1341 end subroutine init_int_table
1343 !-----------------------------------------------------------------------------
1344 subroutine add_int(ii,jj,itask,ntask_cont_to,itask_cont_to,flag)
1347 ! include "DIMENSIONS"
1348 ! include "COMMON.INTERACT"
1349 ! include "COMMON.SETUP"
1350 ! include "COMMON.IOUNITS"
1351 integer :: ii,jj,ntask_cont_to
1352 integer,dimension(4) :: itask
1353 integer :: itask_cont_to(0:nfgtasks-1) !(0:max_fg_procs-1)
1355 !el integer,dimension(0:nfgtasks) :: iturn3_start_all,iturn3_end_all,iturn4_start_all,&
1356 !el iturn4_end_all,iatel_s_all,iatel_e_all !(0:max_fg_procs)
1357 !el integer,dimension(nres,0:nfgtasks-1) :: ielstart_all,ielend_all !(maxres,0:max_fg_procs-1)
1358 !el common /przechowalnia/ iturn3_start_all,iturn3_end_all,iturn4_start_all,&
1359 !el iturn4_end_all,iatel_s_all,iatel_e_all,ielstart_all,ielend_all
1360 integer :: iproc,isent,k,l
1361 ! Determines whether to send interaction ii,jj to other processors; a given
1362 ! interaction can be sent to at most 2 processors.
1363 ! Sets flag=.true. if interaction ii,jj needs to be sent to at least
1364 ! one processor, otherwise flag is unchanged from the input value.
1370 ! write (iout,*) "ii",ii," jj",jj
1371 ! Loop over processors to check if anybody could need interaction ii,jj
1372 do iproc=0,fg_rank-1
1373 ! Check if the interaction matches any turn3 at iproc
1374 do k=iturn3_start_all(iproc),iturn3_end_all(iproc)
1376 if (k.eq.ii-1 .and. l.eq.jj-1 .or. k.eq.ii-1 .and. l.eq.jj+1 &
1377 .or. k.eq.ii+1 .and. l.eq.jj+1 .or. k.eq.ii+1 .and. l.eq.jj-1) &
1379 ! write (iout,*) "turn3 to iproc",iproc," ij",ii,jj,"kl",k,l
1382 if (iproc.ne.itask(1).and.iproc.ne.itask(2) &
1383 .and.iproc.ne.itask(3).and.iproc.ne.itask(4)) then
1386 call add_task(iproc,ntask_cont_to,itask_cont_to)
1390 ! Check if the interaction matches any turn4 at iproc
1391 do k=iturn4_start_all(iproc),iturn4_end_all(iproc)
1393 if (k.eq.ii-1 .and. l.eq.jj-1 .or. k.eq.ii-1 .and. l.eq.jj+1 &
1394 .or. k.eq.ii+1 .and. l.eq.jj+1 .or. k.eq.ii+1 .and. l.eq.jj-1) &
1396 ! write (iout,*) "turn3 to iproc",iproc," ij",ii,jj," kl",k,l
1399 if (iproc.ne.itask(1).and.iproc.ne.itask(2) &
1400 .and.iproc.ne.itask(3).and.iproc.ne.itask(4)) then
1403 call add_task(iproc,ntask_cont_to,itask_cont_to)
1407 if (iatel_s_all(iproc).gt.0 .and. iatel_e_all(iproc).gt.0 .and. &
1408 iatel_s_all(iproc).le.ii-1 .and. iatel_e_all(iproc).ge.ii-1)then
1409 if (ielstart_all(ii-1,iproc).le.jj-1.and. &
1410 ielend_all(ii-1,iproc).ge.jj-1) then
1412 if (iproc.ne.itask(1).and.iproc.ne.itask(2) &
1413 .and.iproc.ne.itask(3).and.iproc.ne.itask(4)) then
1416 call add_task(iproc,ntask_cont_to,itask_cont_to)
1419 if (ielstart_all(ii-1,iproc).le.jj+1.and. &
1420 ielend_all(ii-1,iproc).ge.jj+1) then
1422 if (iproc.ne.itask(1).and.iproc.ne.itask(2) &
1423 .and.iproc.ne.itask(3).and.iproc.ne.itask(4)) then
1426 call add_task(iproc,ntask_cont_to,itask_cont_to)
1432 end subroutine add_int
1433 !-----------------------------------------------------------------------------
1434 subroutine add_int_from(ii,jj,ntask_cont_from,itask_cont_from)
1438 ! include "DIMENSIONS"
1439 ! include "COMMON.INTERACT"
1440 ! include "COMMON.SETUP"
1441 ! include "COMMON.IOUNITS"
1442 integer :: ii,jj,itask(2),ntask_cont_from,&
1443 itask_cont_from(0:nfgtasks-1) !(0:max_fg_procs)
1445 !el integer,dimension(0:nfgtasks) :: iturn3_start_all,iturn3_end_all,&
1446 !el iturn4_start_all,iturn4_end_all,iatel_s_all,iatel_e_all !(0:max_fg_procs)
1447 !el integer,dimension(nres,0:nfgtasks-1) :: ielstart_all,ielend_all !(maxres,0:max_fg_procs-1)
1448 !el common /przechowalnia/ iturn3_start_all,iturn3_end_all,iturn4_start_all,&
1449 !el iturn4_end_all,iatel_s_all,iatel_e_all,ielstart_all,ielend_all
1450 integer :: iproc,k,l
1451 do iproc=fg_rank+1,nfgtasks-1
1452 do k=iturn3_start_all(iproc),iturn3_end_all(iproc)
1454 if (k.eq.ii+1 .and. l.eq.jj+1 .or. k.eq.ii+1.and.l.eq.jj-1 &
1455 .or. k.eq.ii-1 .and. l.eq.jj-1 .or. k.eq.ii-1 .and. l.eq.jj+1) &
1457 ! write (iout,*)"turn3 from iproc",iproc," ij",ii,jj," kl",k,l
1458 call add_task(iproc,ntask_cont_from,itask_cont_from)
1461 do k=iturn4_start_all(iproc),iturn4_end_all(iproc)
1463 if (k.eq.ii+1 .and. l.eq.jj+1 .or. k.eq.ii+1.and.l.eq.jj-1 &
1464 .or. k.eq.ii-1 .and. l.eq.jj-1 .or. k.eq.ii-1 .and. l.eq.jj+1) &
1466 ! write (iout,*)"turn4 from iproc",iproc," ij",ii,jj," kl",k,l
1467 call add_task(iproc,ntask_cont_from,itask_cont_from)
1470 if (iatel_s_all(iproc).gt.0 .and. iatel_e_all(iproc).gt.0) then
1471 if (ii+1.ge.iatel_s_all(iproc).and.ii+1.le.iatel_e_all(iproc)) &
1473 if (jj+1.ge.ielstart_all(ii+1,iproc).and. &
1474 jj+1.le.ielend_all(ii+1,iproc)) then
1475 call add_task(iproc,ntask_cont_from,itask_cont_from)
1477 if (jj-1.ge.ielstart_all(ii+1,iproc).and. &
1478 jj-1.le.ielend_all(ii+1,iproc)) then
1479 call add_task(iproc,ntask_cont_from,itask_cont_from)
1482 if (ii-1.ge.iatel_s_all(iproc).and.ii-1.le.iatel_e_all(iproc)) &
1484 if (jj-1.ge.ielstart_all(ii-1,iproc).and. &
1485 jj-1.le.ielend_all(ii-1,iproc)) then
1486 call add_task(iproc,ntask_cont_from,itask_cont_from)
1488 if (jj+1.ge.ielstart_all(ii-1,iproc).and. &
1489 jj+1.le.ielend_all(ii-1,iproc)) then
1490 call add_task(iproc,ntask_cont_from,itask_cont_from)
1496 end subroutine add_int_from
1497 !-----------------------------------------------------------------------------
1498 subroutine add_task(iproc,ntask_cont,itask_cont)
1502 ! include "DIMENSIONS"
1503 integer :: iproc,ntask_cont,itask_cont(0:nfgtasks-1) !(0:max_fg_procs-1)
1506 if (itask_cont(ii).eq.iproc) return
1508 ntask_cont=ntask_cont+1
1509 itask_cont(ntask_cont)=iproc
1511 end subroutine add_task
1513 !-----------------------------------------------------------------------------
1514 #if defined MPI || defined WHAM_RUN
1515 subroutine int_partition(int_index,lower_index,upper_index,atom,&
1516 at_start,at_end,first_atom,last_atom,int_gr,jat_start,jat_end,*)
1518 ! implicit real*8 (a-h,o-z)
1519 ! include 'DIMENSIONS'
1520 ! include 'COMMON.IOUNITS'
1521 integer :: int_index,lower_index,upper_index,atom,at_start,at_end,&
1522 first_atom,last_atom,int_gr,jat_start,jat_end,int_index_old
1525 if (lprn) write (iout,*) 'int_index=',int_index
1526 int_index_old=int_index
1527 int_index=int_index+last_atom-first_atom+1
1529 write (iout,*) 'int_index=',int_index,&
1530 ' int_index_old',int_index_old,&
1531 ' lower_index=',lower_index,&
1532 ' upper_index=',upper_index,&
1533 ' atom=',atom,' first_atom=',first_atom,&
1534 ' last_atom=',last_atom
1535 if (int_index.ge.lower_index) then
1537 if (at_start.eq.0) then
1539 jat_start=first_atom-1+lower_index-int_index_old
1541 jat_start=first_atom
1543 if (lprn) write (iout,*) 'jat_start',jat_start
1544 if (int_index.ge.upper_index) then
1546 jat_end=first_atom-1+upper_index-int_index_old
1551 if (lprn) write (iout,*) 'jat_end',jat_end
1554 end subroutine int_partition
1556 !-----------------------------------------------------------------------------
1558 subroutine hpb_partition
1560 ! implicit real*8 (a-h,o-z)
1561 ! include 'DIMENSIONS'
1565 ! include 'COMMON.SBRIDGE'
1566 ! include 'COMMON.IOUNITS'
1567 ! include 'COMMON.SETUP'
1569 call int_bounds(nhpb,link_start,link_end)
1570 write (iout,*) 'Processor',fg_rank,' CG group',kolor,&
1571 ' absolute rank',MyRank,&
1572 ' nhpb',nhpb,' link_start=',link_start,&
1573 ' link_end',link_end
1579 end subroutine hpb_partition
1581 !-----------------------------------------------------------------------------
1582 ! misc.f in module io_base
1583 !-----------------------------------------------------------------------------
1584 !-----------------------------------------------------------------------------
1586 !-----------------------------------------------------------------------------
1587 subroutine getenv_loc(var, val)
1589 character(*) :: var, val
1592 character(len=2000) :: line
1595 open (196,file='env',status='old',readonly,shared)
1597 ! write(*,*)'looking for ',var
1598 10 read(196,*,err=11,end=11)line
1599 iread=index(line,var)
1600 ! write(*,*)iread,' ',var,' ',line
1601 if (iread.eq.0) go to 10
1602 ! write(*,*)'---> ',line
1608 iread=iread+ilen(var)+1
1609 read (line(iread:),*,err=12,end=12) val
1610 ! write(*,*)'OK: ',var,' = ',val
1616 #elif (defined CRAY)
1617 integer :: lennam,lenval,ierror
1619 ! getenv using a POSIX call, useful on the T3D
1620 ! Sept 1996, comment out error check on advice of H. Pritchard
1623 if(lennam.le.0) stop '--error calling getenv--'
1624 call pxfgetenv(var,lennam,val,lenval,ierror)
1625 !-HP- if(ierror.ne.0) stop '--error returned by pxfgetenv--'
1627 call getenv(var,val)
1631 end subroutine getenv_loc
1632 !-----------------------------------------------------------------------------
1634 !-----------------------------------------------------------------------------
1635 subroutine setup_var
1638 ! implicit real*8 (a-h,o-z)
1639 ! include 'DIMENSIONS'
1640 ! include 'COMMON.IOUNITS'
1641 ! include 'COMMON.GEO'
1642 ! include 'COMMON.VAR'
1643 ! include 'COMMON.INTERACT'
1644 ! include 'COMMON.LOCAL'
1645 ! include 'COMMON.NAMES'
1646 ! include 'COMMON.CHAIN'
1647 ! include 'COMMON.FFIELD'
1648 ! include 'COMMON.SBRIDGE'
1649 ! include 'COMMON.HEADER'
1650 ! include 'COMMON.CONTROL'
1651 ! include 'COMMON.DBASE'
1652 ! include 'COMMON.THREAD'
1653 ! include 'COMMON.TIME1'
1654 ! Set up variable list.
1661 if (itype(i).ne.10) then
1663 if (itype(i).ne.10 .and. itype(i).ne.ntyp1) then
1666 ialph(i,1)=nvar+nside
1670 if (indphi.gt.0) then
1672 else if (indback.gt.0) then
1677 !d write (iout,'(3i4)') (i,ialph(i,1),ialph(i,2),i=2,nres-1)
1679 end subroutine setup_var
1680 !-----------------------------------------------------------------------------
1682 !-----------------------------------------------------------------------------
1683 integer function rescode(iseq,nam,itype)
1685 use io_base, only: ucase
1686 ! implicit real*8 (a-h,o-z)
1687 ! include 'DIMENSIONS'
1688 ! include 'COMMON.NAMES'
1689 ! include 'COMMON.IOUNITS'
1690 character(len=3) :: nam !,ucase
1691 integer :: iseq,itype,i
1693 if (itype.eq.0) then
1696 if (ucase(nam).eq.restyp(i)) then
1705 if (nam(1:1).eq.onelet(i)) then
1712 write (iout,10) iseq,nam
1714 10 format ('**** Error - residue',i4,' has an unresolved name ',a3)
1715 end function rescode
1716 !-----------------------------------------------------------------------------
1718 !-----------------------------------------------------------------------------
1719 ! $Date: 1994/10/05 16:41:52 $
1722 subroutine set_timers
1725 !el real(kind=8) :: tcpu
1726 ! include 'COMMON.TIME1'
1731 ! Diminish the assigned time limit a little so that there is some time to
1733 ! timlim=batime-150.0
1734 ! Calculate the initial time, if it is not zero (e.g. for the SUN).
1736 #if !defined(WHAM_RUN) && !defined(CLUSTER)
1738 walltime=MPI_WTIME()
1740 time_allreduce=0.0d0
1745 time_scatter_fmat=0.0d0
1746 time_scatter_ginv=0.0d0
1747 time_scatter_fmatmult=0.0d0
1748 time_scatter_ginvmult=0.0d0
1749 time_barrier_e=0.0d0
1750 time_barrier_g=0.0d0
1753 time_lagrangian=0.0d0
1754 time_sumgradient=0.0d0
1755 time_intcartderiv=0.0d0
1756 time_inttocart=0.0d0
1758 time_fricmatmult=0.0d0
1768 time_fricmatmult=0.0d0
1772 !d print *,' in SET_TIMERS stime=',stime
1774 end subroutine set_timers
1775 !-----------------------------------------------------------------------------
1777 logical function stopx(nf)
1778 ! This function returns .true. if one of the following reasons to exit SUMSL
1779 ! occurs. The "reason" code is stored in WHATSUP passed thru a COMMON block:
1781 !... WHATSUP = 0 - go on, no reason to stop. Stopx will return .false.
1782 !... 1 - Time up in current node;
1783 !... 2 - STOP signal was received from another node because the
1784 !... node's task was accomplished (parallel only);
1785 !... -1 - STOP signal was received from another node because of error;
1786 !... -2 - STOP signal was received from another node, because
1787 !... the node's time was up.
1788 ! implicit real*8 (a-h,o-z)
1789 ! include 'DIMENSIONS'
1791 !el use control_data, only:WhatsUp
1794 !el use MPI_data !include 'COMMON.INFO'
1798 !el logical :: ovrtim
1800 ! include 'COMMON.IOUNITS'
1801 ! include 'COMMON.TIME1'
1804 !d print *,'Processor',MyID,' NF=',nf
1805 !d write (iout,*) "stopx: ",nf
1809 ! Finish if time is up.
1813 else if (mod(nf,100).eq.0) then
1814 ! Other processors might have finished. Check this every 100th function
1816 ! Master checks if any other processor has sent accepted conformation(s) to it.
1817 if (MyID.ne.MasterID) call receive_mcm_info
1818 if (MyID.eq.MasterID) call receive_conf
1819 !d print *,'Processor ',MyID,' is checking STOP: nf=',nf
1820 call recv_stop_sig(Kwita)
1821 if (Kwita.eq.-1) then
1822 write (iout,'(a,i4,a,i5)') 'Processor',&
1823 MyID,' has received STOP signal in STOPX; NF=',nf
1824 write (*,'(a,i4,a,i5)') 'Processor',&
1825 MyID,' has received STOP signal in STOPX; NF=',nf
1828 elseif (Kwita.eq.-2) then
1830 'Processor',MyID,' received TIMEUP-STOP signal in SUMSL.'
1832 'Processor',MyID,' received TIMEUP-STOP signal in SUMSL.'
1835 else if (Kwita.eq.-3) then
1837 'Processor',MyID,' received ERROR-STOP signal in SUMSL.'
1839 'Processor',MyID,' received ERROR-STOP signal in SUMSL.'
1853 !d write (iout,*) "stopx set at .false."
1857 ! Check for FOUND_NAN flag
1859 write(iout,*)" *** stopx : Found a NaN"
1865 ! Finish if time is up.
1868 else if (cutoffviol) then
1877 !-----------------------------------------------------------------------------
1879 logical function stopx(nf)
1881 ! ..................................................................
1884 ! THIS FUNCTION MAY SERVE AS THE STOPX (ASYNCHRONOUS INTERRUPTION)
1885 ! FUNCTION FOR THE NL2SOL (NONLINEAR LEAST-SQUARES) PACKAGE AT
1886 ! THOSE INSTALLATIONS WHICH DO NOT WISH TO IMPLEMENT A
1889 ! *****ALGORITHM NOTES...
1890 ! AT INSTALLATIONS WHERE THE NL2SOL SYSTEM IS USED
1891 ! INTERACTIVELY, THIS DUMMY STOPX SHOULD BE REPLACED BY A
1892 ! FUNCTION THAT RETURNS .TRUE. IF AND ONLY IF THE INTERRUPT
1893 ! (BREAK) KEY HAS BEEN PRESSED SINCE THE LAST CALL ON STOPX.
1895 ! $$$ MODIFIED FOR USE AS THE TIMER ROUTINE.
1896 ! $$$ WHEN THE TIME LIMIT HAS BEEN
1897 ! $$$ REACHED STOPX IS SET TO .TRUE AND INITIATES (IN ITSUM)
1898 ! $$$ AND ORDERLY EXIT OUT OF SUMSL. IF ARRAYS IV AND V ARE
1899 ! $$$ SAVED, THE SUMSL ROUTINES CAN BE RESTARTED AT THE SAME
1900 ! $$$ POINT AT WHICH THEY WERE INTERRUPTED.
1902 ! ..................................................................
1904 ! include 'DIMENSIONS'
1907 ! include 'COMMON.IOUNITS'
1908 ! include 'COMMON.TIME1'
1910 ! include 'COMMON.INFO'
1913 !d print *,'Processor',MyID,' NF=',nf
1916 ! Finish if time is up.
1919 else if (mod(nf,100).eq.0) then
1920 ! Other processors might have finished. Check this every 100th function
1922 !d print *,'Processor ',MyID,' is checking STOP: nf=',nf
1923 call recv_stop_sig(Kwita)
1924 if (Kwita.eq.-1) then
1925 write (iout,'(a,i4,a,i5)') 'Processor',&
1926 MyID,' has received STOP signal in STOPX; NF=',nf
1927 write (*,'(a,i4,a,i5)') 'Processor',&
1928 MyID,' has received STOP signal in STOPX; NF=',nf
1940 !-----------------------------------------------------------------------------
1941 logical function ovrtim()
1943 ! include 'DIMENSIONS'
1944 ! include 'COMMON.IOUNITS'
1945 ! include 'COMMON.TIME1'
1946 !el real(kind=8) :: tcpu
1947 real(kind=8) :: curtim
1950 curtim = MPI_Wtime()-walltime
1954 ! curtim is the current time in seconds.
1955 ! write (iout,*) "curtim",curtim," timlim",timlim," safety",safety
1957 if (curtim .ge. timlim - safety) then
1958 write (iout,'(a,f10.2,a,f10.2,a,f10.2,a)') &
1959 "***************** Elapsed time (",curtim,&
1960 " s) is within the safety limit (",safety,&
1961 " s) of the allocated time (",timlim," s). Terminating."
1969 !elwrite (iout,*) "ovrtim",ovrtim
1972 !-----------------------------------------------------------------------------
1973 real(kind=8) function tcpu()
1975 ! include 'COMMON.TIME1'
1976 real(kind=8) :: seconds
1978 !***************************
1979 ! Next definition for EAGLE (ibm-es9000)
1980 real(kind=8) :: micseconds
1982 tcpu=cputime(micseconds,rcode)
1983 tcpu=(micseconds/1.0E6) - stime
1984 !***************************
1987 !***************************
1988 ! Next definitions for sun
1989 REAL(kind=8) :: ECPU,ETIME,ETCPU
1990 real(kind=8),dimension(2) :: tarray
1993 !***************************
1996 !***************************
1997 ! Next definitions for ksr
1998 ! this function uses the ksr timer ALL_SECONDS from the PMON library to
1999 ! return the elapsed time in seconds
2000 tcpu= all_seconds() - stime
2001 !***************************
2004 !***************************
2005 ! Next definitions for sgi
2006 real(kind=4) :: timar(2), etime
2007 seconds = etime(timar)
2008 !d print *,'seconds=',seconds,' stime=',stime
2011 tcpu=seconds - stime
2012 !***************************
2016 !***************************
2017 ! Next definitions for sgi
2018 real(kind=4) :: timar(2), etime
2019 seconds = etime(timar)
2020 !d print *,'seconds=',seconds,' stime=',stime
2023 tcpu=seconds - stime
2024 !***************************
2029 !***************************
2030 ! Next definitions for Cray
2032 ! curdat=curdat(1:9)
2033 ! call clock(curtim)
2034 ! curtim=curtim(1:8)
2037 !***************************
2040 !***************************
2041 ! Next definitions for RS6000
2042 integer(kind=4) :: i1,mclock
2044 tcpu = (i1+0.0D0)/100.0D0
2047 !***************************
2048 ! next definitions for windows NT Digital fortran
2049 real(kind=4) :: time_real
2050 call cpu_time(time_real)
2054 !***************************
2055 ! next definitions for windows NT Digital fortran
2056 real(kind=4) :: time_real
2057 call cpu_time(time_real)
2063 !-----------------------------------------------------------------------------
2065 subroutine dajczas(rntime,hrtime,mintime,sectime)
2067 ! include 'COMMON.IOUNITS'
2068 integer :: ihr,imn,isc
2069 real(kind=8) :: rntime,hrtime,mintime,sectime
2070 hrtime=rntime/3600.0D0
2072 mintime=aint((rntime-3600.0D0*hrtime)/60.0D0)
2073 sectime=aint((rntime-3600.0D0*hrtime-60.0D0*mintime)+0.5D0)
2074 if (sectime.eq.60.0D0) then
2076 mintime=mintime+1.0D0
2081 write (iout,328) ihr,imn,isc
2082 328 FORMAT(//'***** Computation time: ',I4 ,' hours ',I2 ,&
2083 ' minutes ', I2 ,' seconds *****')
2085 end subroutine dajczas
2086 !-----------------------------------------------------------------------------
2087 subroutine print_detailed_timing
2090 ! implicit real*8 (a-h,o-z)
2091 ! include 'DIMENSIONS'
2095 ! include 'COMMON.IOUNITS'
2096 ! include 'COMMON.TIME1'
2097 ! include 'COMMON.SETUP'
2098 real(kind=8) :: time1,time_barrier
2099 time_barrier = 0.0d0
2103 write (iout,'(80(1h=)/a/(80(1h=)))') &
2104 "Details of FG communication time"
2105 write (*,'(7(a40,1pe15.5/),40(1h-)/a40,1pe15.5/80(1h=))') &
2106 "BROADCAST:",time_bcast,"REDUCE:",time_reduce,&
2107 "GATHER:",time_gather,&
2108 "SCATTER:",time_scatter,"SENDRECV:",time_sendrecv,&
2109 "BARRIER ene",time_barrier_e,&
2110 "BARRIER grad",time_barrier_g,&
2112 time_bcast+time_reduce+time_gather+time_scatter+time_sendrecv
2113 write (*,*) fg_rank,myrank,&
2114 ': Total wall clock time',time1-walltime,' sec'
2115 write (*,*) "Processor",fg_rank,myrank,&
2116 ": BROADCAST time",time_bcast," REDUCE time",&
2117 time_reduce," GATHER time",time_gather," SCATTER time",&
2119 " SCATTER fmatmult",time_scatter_fmatmult,&
2120 " SCATTER ginvmult",time_scatter_ginvmult,&
2121 " SCATTER fmat",time_scatter_fmat,&
2122 " SCATTER ginv",time_scatter_ginv,&
2123 " SENDRECV",time_sendrecv,&
2124 " BARRIER ene",time_barrier_e,&
2125 " BARRIER GRAD",time_barrier_g,&
2126 " BCAST7",time_bcast7," BCASTC",time_bcastc,&
2127 " BCASTW",time_bcastw," ALLREDUCE",time_allreduce,&
2129 time_bcast+time_reduce+time_gather+time_scatter+ &
2130 time_sendrecv+time_barrier+time_bcastc
2132 write (*,*) "Processor",fg_rank,myrank," enecalc",time_enecalc
2133 write (*,*) "Processor",fg_rank,myrank," sumene",time_sumene
2134 write (*,*) "Processor",fg_rank,myrank," intfromcart",&
2136 write (*,*) "Processor",fg_rank,myrank," vecandderiv",&
2138 write (*,*) "Processor",fg_rank,myrank," setmatrices",&
2140 write (*,*) "Processor",fg_rank,myrank," ginvmult",&
2142 write (*,*) "Processor",fg_rank,myrank," fricmatmult",&
2144 write (*,*) "Processor",fg_rank,myrank," inttocart",&
2146 write (*,*) "Processor",fg_rank,myrank," sumgradient",&
2148 write (*,*) "Processor",fg_rank,myrank," intcartderiv",&
2150 if (fg_rank.eq.0) then
2151 write (*,*) "Processor",fg_rank,myrank," lagrangian",&
2153 write (*,*) "Processor",fg_rank,myrank," cartgrad",&
2157 end subroutine print_detailed_timing
2159 !-----------------------------------------------------------------------------
2160 !-----------------------------------------------------------------------------