2 !-----------------------------------------------------------------------------
11 use geometry, only:int_bounds
16 !-----------------------------------------------------------------------------
18 ! FOUND_NAN - set by calcf to stop sumsl via stopx
20 real(kind=8) :: STIME,BATIME,PREVTIM,RSTIME
21 !el real(kind=8) :: TIMLIM,SAFETY
22 !el real(kind=8) :: WALLTIME
28 real(kind=8) :: t_init
29 !-----------------------------------------------------------------------------
31 !-----------------------------------------------------------------------------
33 ! integer,parameter :: MaxMoveType = 4
34 ! character(len=14),dimension(-1:MaxMoveType+1) :: MovTypID=(/'pool','chain regrow',&
35 ! character :: MovTypID(-1:MaxMoveType+1)=(/'pool','chain regrow',&
36 ! 'multi-bond','phi','theta','side chain','total'/)
37 ! Conversion from poises to molecular unit and the gas constant
38 !el real(kind=8) :: cPoise=2.9361d0, Rb=0.001986d0
39 !-----------------------------------------------------------------------------
40 ! common /przechowalnia/ subroutines: init_int_table,add_int,add_int_from
41 integer,dimension(:),allocatable :: iturn3_start_all,iturn3_end_all,&
42 iturn4_start_all,iturn4_end_all,iatel_s_all,iatel_e_all !(0:max_fg_procs)
43 integer,dimension(:,:),allocatable :: ielstart_all,&
44 ielend_all !(maxres,0:max_fg_procs-1)
46 ! common /przechowalnia/ subroutine: init_int_table
47 integer,dimension(:),allocatable :: ntask_cont_from_all,&
48 ntask_cont_to_all !(0:max_fg_procs-1)
49 integer,dimension(:,:),allocatable :: itask_cont_from_all,&
50 itask_cont_to_all !(0:max_fg_procs-1,0:max_fg_procs-1)
51 !-----------------------------------------------------------------------------
54 !-----------------------------------------------------------------------------
56 !-----------------------------------------------------------------------------
58 !-----------------------------------------------------------------------------
61 ! Define constants and zero out tables.
65 use MCM_data, only: MovTypID
66 ! implicit real*8 (a-h,o-z)
67 ! include 'DIMENSIONS'
74 !MS$ATTRIBUTES C :: proc_proc
77 ! include 'COMMON.IOUNITS'
78 ! include 'COMMON.CHAIN'
79 ! include 'COMMON.INTERACT'
80 ! include 'COMMON.GEO'
81 ! include 'COMMON.LOCAL'
82 ! include 'COMMON.TORSION'
83 ! include 'COMMON.FFIELD'
84 ! include 'COMMON.SBRIDGE'
85 ! include 'COMMON.MCM'
86 ! include 'COMMON.MINIM'
87 ! include 'COMMON.DERIV'
88 ! include 'COMMON.SPLITELE'
90 ! Common blocks from the diagonalization routines
91 !el integer :: IR,IW,IP,IJK,IPK,IDAF,NAV,IODA(400)
92 !el integer :: KDIAG,ICORFL,IXDR
93 !el COMMON /IOFILE/ IR,IW,IP,IJK,IPK,IDAF,NAV,IODA
94 !el COMMON /MACHSW/ KDIAG,ICORFL,IXDR
96 ! real*8 text1 /'initial_i'/
100 integer :: i,j,k,l,ichir1,ichir2,iblock,m,maxit
105 ! NaNQ initialization
109 idumm=proc_proc(rr,i)
119 allocate(MovTypID(-1:MaxMoveType+1))
120 MovTypID=(/'pool ','chain regrow ',&
121 'multi-bond ','phi ','theta ',&
122 'side chain ','total '/)
125 ! The following is just to define auxiliary variables used in angle conversion
127 pi=4.0D0*datan(1.0D0)
132 rad2deg=1.0D0/deg2rad
133 angmin=10.0D0*deg2rad
167 !rc for write_rmsbank1
169 !dr include secondary structure prediction bias
179 ! setting the mpi variables for WHAM
186 ! CSA I/O units (separated from others especially for Jooyoung)
197 icsa_bank_reminimized=38
200 !rc for ifc error 118
203 ! Set default weights of the energy terms.
205 wsc=1.0D0 ! in wham: wlong=1.0D0
214 ! print '(a,$)','Inside initialize'
215 ! call memmon_print_usage()
249 ! athet(j,i,ichir1,ichir2)=0.0D0
250 ! bthet(j,i,ichir1,ichir2)=0.0D0
270 ! gaussc(l,k,j,i)=0.0D0
278 ! do i=-maxtor,maxtor
280 !c write (iout,*) "TU DOCHODZE",i,itortyp(i)
282 ! do j=-maxtor,maxtor
284 ! v1(k,j,i,iblock)=0.0D0
285 ! v2(k,j,i,iblock)=0.0D0
291 ! do i=-maxtor,maxtor
292 ! do j=-maxtor,maxtor
293 ! do k=-maxtor,maxtor
295 ! v1c(1,l,i,j,k,iblock)=0.0D0
296 ! v1s(1,l,i,j,k,iblock)=0.0D0
297 ! v1c(2,l,i,j,k,iblock)=0.0D0
298 ! v1s(2,l,i,j,k,iblock)=0.0D0
302 ! v2c(m,l,i,j,k,iblock)=0.0D0
303 ! v2s(m,l,i,j,k,iblock)=0.0D0
315 ! Initialize the bridge arrays
334 ! Initialize variables used in minimization.
343 ! Initialize the variables responsible for the mode of gradient storage.
348 !el if (run_wham) then !el
352 ! allocate(ww0(max_eneW))
353 ! ww0 = reshape((/1.0d0,1.0d0,1.0d0,1.0d0,1.0d0,1.0d0,1.0d0,1.0d0,&
354 ! 1.0d0,1.0d0,1.0d0,1.0d0,1.0d0,1.0d0,1.0d0,1.0d0,0.4d0,1.0d0,&
355 ! 1.0d0,0.0d0,0.0/), shape(ww0))
357 ! allocate(iww(max_eneW))
360 if (print_order(i).eq.j) then
361 iww(print_order(i))=j
368 ! Set timers and counters for the respective routines
388 ! Initialize constants used to split the energy into long- and short-range
394 nprint_ene=nprint_ene-1
397 end subroutine initialize
398 !-----------------------------------------------------------------------------
399 subroutine init_int_table
401 use geometry, only:int_bounds1
403 ! implicit real*8 (a-h,o-z)
404 ! include 'DIMENSIONS'
407 integer,dimension(15) :: blocklengths,displs
409 ! include 'COMMON.CONTROL'
410 ! include 'COMMON.SETUP'
411 ! include 'COMMON.CHAIN'
412 ! include 'COMMON.INTERACT'
413 ! include 'COMMON.LOCAL'
414 ! include 'COMMON.SBRIDGE'
415 ! include 'COMMON.TORCNSTR'
416 ! include 'COMMON.IOUNITS'
417 ! include 'COMMON.DERIV'
418 ! include 'COMMON.CONTACTS'
419 !el integer,dimension(0:nfgtasks) :: iturn3_start_all,iturn3_end_all,&
420 !el iturn4_start_all,iturn4_end_all,iatel_s_all,iatel_e_all !(0:max_fg_procs)
421 !el integer,dimension(nres,0:nfgtasks) :: ielstart_all,&
422 !el ielend_all !(maxres,0:max_fg_procs-1)
423 !el integer,dimension(0:nfgtasks-1) :: ntask_cont_from_all,&
424 !el ntask_cont_to_all !(0:max_fg_procs-1),
425 !el integer,dimension(0:nfgtasks-1,0:nfgtasks-1) :: itask_cont_from_all,&
426 !el itask_cont_to_all !(0:max_fg_procs-1,0:max_fg_procs-1)
428 !el common /przechowalnia/ iturn3_start_all,iturn3_end_all,&
429 !el iturn4_start_all,iturn4_end_all,iatel_s_all,iatel_e_all,&
430 !el ielstart_all,ielend_all,ntask_cont_from_all,itask_cont_from_all,&
431 !el ntask_cont_to_all,itask_cont_to_all
433 integer :: FG_GROUP,CONT_FROM_GROUP,CONT_TO_GROUP
434 logical :: scheck,lprint,flag
437 integer :: ind_scint=0,ind_scint_old,ii,jj,i,j,iint
440 integer :: my_sc_int(0:nfgtasks-1),my_ele_int(0:nfgtasks-1)
441 integer :: my_sc_intt(0:nfgtasks),my_ele_intt(0:nfgtasks)
442 integer :: n_sc_int_tot,my_sc_inde,my_sc_inds,ind_sctint,npept
443 integer :: nele_int_tot,my_ele_inds,my_ele_inde,ind_eleint_old,&
444 ind_eleint,ijunk,nele_int_tot_vdw,my_ele_inds_vdw,&
445 my_ele_inde_vdw,ind_eleint_vdw,ind_eleint_vdw_old,&
446 nscp_int_tot,my_scp_inds,my_scp_inde,ind_scpint,&
447 ind_scpint_old,nsumgrad,nlen,ngrad_start,ngrad_end,&
448 ierror,k,ierr,iaux,ncheck_to,ncheck_from,ind_typ,&
451 !el allocate(itask_cont_from(0:nfgtasks-1)) !(0:max_fg_procs-1)
452 !el allocate(itask_cont_to(0:nfgtasks-1)) !(0:max_fg_procs-1)
454 !... Determine the numbers of start and end SC-SC interaction
455 !... to deal with by current processor.
457 itask_cont_from(i)=fg_rank
458 itask_cont_to(i)=fg_rank
462 write (iout,*) 'INIT_INT_TABLE nres=',nres,' nnt=',nnt,' nct=',nct
463 n_sc_int_tot=(nct-nnt+1)*(nct-nnt)/2-nss
464 call int_bounds(n_sc_int_tot,my_sc_inds,my_sc_inde)
465 write (iout,*) 'INIT_INT_TABLE nres=',nres,' nnt=',nnt,' nct=',nct
467 write (iout,*) 'Processor',fg_rank,' CG group',kolor,&
468 ' absolute rank',MyRank,&
469 ' n_sc_int_tot',n_sc_int_tot,' my_sc_inds=',my_sc_inds,&
470 ' my_sc_inde',my_sc_inde
475 !el common /przechowalnia/
476 allocate(iturn3_start_all(0:nfgtasks))
477 allocate(iturn3_end_all(0:nfgtasks))
478 allocate(iturn4_start_all(0:nfgtasks))
479 allocate(iturn4_end_all(0:nfgtasks))
480 allocate(iatel_s_all(0:nfgtasks))
481 allocate(iatel_e_all(0:nfgtasks))
482 allocate(ielstart_all(nres,0:nfgtasks-1))
483 allocate(ielend_all(nres,0:nfgtasks-1))
485 allocate(ntask_cont_from_all(0:nfgtasks-1))
486 allocate(ntask_cont_to_all(0:nfgtasks-1))
487 allocate(itask_cont_from_all(0:nfgtasks-1,0:nfgtasks-1))
488 allocate(itask_cont_to_all(0:nfgtasks-1,0:nfgtasks-1))
491 do i=1,nres !el !maxres
505 !d write (iout,*) 'ns=',ns,' nss=',nss,' ihpb,jhpb',
506 !d & (ihpb(i),jhpb(i),i=1,nss)
511 if (ihpb(ii).eq.i+nres) then
518 !d write (iout,*) 'i=',i,' scheck=',scheck,' jj=',jj
522 ! write (iout,*) 'jj=i+1'
523 call int_partition(ind_scint,my_sc_inds,my_sc_inde,i,&
524 iatsc_s,iatsc_e,i+2,nct,nint_gr(i),istart(i,1),iend(i,1),*12)
530 else if (jj.eq.nct) then
532 ! write (iout,*) 'jj=nct'
533 call int_partition(ind_scint,my_sc_inds,my_sc_inde,i,&
534 iatsc_s,iatsc_e,i+1,nct-1,nint_gr(i),istart(i,1),iend(i,1),*12)
542 call int_partition(ind_scint,my_sc_inds,my_sc_inde,i,&
543 iatsc_s,iatsc_e,i+1,jj-1,nint_gr(i),istart(i,1),iend(i,1),*12)
545 call int_partition(ind_scint,my_sc_inds,my_sc_inde,i,&
546 iatsc_s,iatsc_e,jj+1,nct,nint_gr(i),istart(i,ii),iend(i,ii),*12)
557 call int_partition(ind_scint,my_sc_inds,my_sc_inde,i,&
558 iatsc_s,iatsc_e,i+1,nct,nint_gr(i),istart(i,1),iend(i,1),*12)
563 ind_scint=ind_scint+nct-i
567 ind_scint_old=ind_scint
575 if (iatsc_s.eq.0) iatsc_s=1
577 if (lprint) write (*,*) 'Processor',fg_rank,' CG Group',kolor,&
578 ' absolute rank',myrank,' iatsc_s=',iatsc_s,' iatsc_e=',iatsc_e
581 write (iout,'(a)') 'Interaction array:'
583 write (iout,'(i3,2(2x,2i3))') &
584 i,(istart(i,iint),iend(i,iint),iint=1,nint_gr(i))
587 ispp=4 !?? wham ispp=2
589 ! Now partition the electrostatic-interaction array
591 nele_int_tot=(npept-ispp)*(npept-ispp+1)/2
592 call int_bounds(nele_int_tot,my_ele_inds,my_ele_inde)
594 write (*,*) 'Processor',fg_rank,' CG group',kolor,&
595 ' absolute rank',MyRank,&
596 ' nele_int_tot',nele_int_tot,' my_ele_inds=',my_ele_inds,&
597 ' my_ele_inde',my_ele_inde
604 call int_partition(ind_eleint,my_ele_inds,my_ele_inde,i,&
605 iatel_s,iatel_e,i+ispp,nct-1,ijunk,ielstart(i),ielend(i),*13)
608 if (iatel_s.eq.0) iatel_s=1
609 nele_int_tot_vdw=(npept-2)*(npept-2+1)/2
610 ! write (iout,*) "nele_int_tot_vdw",nele_int_tot_vdw
611 call int_bounds(nele_int_tot_vdw,my_ele_inds_vdw,my_ele_inde_vdw)
612 ! write (iout,*) "my_ele_inds_vdw",my_ele_inds_vdw,
613 ! & " my_ele_inde_vdw",my_ele_inde_vdw
620 call int_partition(ind_eleint_vdw,my_ele_inds_vdw,&
622 iatel_s_vdw,iatel_e_vdw,i+2,nct-1,ijunk,ielstart_vdw(i),&
624 ! write (iout,*) i," ielstart_vdw",ielstart_vdw(i),
625 ! & " ielend_vdw",ielend_vdw(i)
627 if (iatel_s_vdw.eq.0) iatel_s_vdw=1
631 iatel_e=nct-5 ! ?? wham iatel_e=nct-3
633 ielstart(i)=i+4 ! ?? wham +2
638 do i=iatel_s_vdw,iatel_e_vdw
644 write (*,'(a)') 'Processor',fg_rank,' CG group',kolor,&
645 ' absolute rank',MyRank
646 write (iout,*) 'Electrostatic interaction array:'
648 write (iout,'(i3,2(2x,2i3))') i,ielstart(i),ielend(i)
653 ! Partition the SC-p interaction array
655 nscp_int_tot=(npept-iscp+1)*(npept-iscp+1)
656 call int_bounds(nscp_int_tot,my_scp_inds,my_scp_inde)
657 if (lprint) write (iout,*) 'Processor',fg_rank,' CG group',kolor,&
658 ' absolute rank',myrank,&
659 ' nscp_int_tot',nscp_int_tot,' my_scp_inds=',my_scp_inds,&
660 ' my_scp_inde',my_scp_inde
666 if (i.lt.nnt+iscp) then
667 !d write (iout,*) 'i.le.nnt+iscp'
668 call int_partition(ind_scpint,my_scp_inds,my_scp_inde,i,&
669 iatscp_s,iatscp_e,i+iscp,nct,nscp_gr(i),iscpstart(i,1),&
671 else if (i.gt.nct-iscp) then
672 !d write (iout,*) 'i.gt.nct-iscp'
673 call int_partition(ind_scpint,my_scp_inds,my_scp_inde,i,&
674 iatscp_s,iatscp_e,nnt,i-iscp,nscp_gr(i),iscpstart(i,1),&
677 call int_partition(ind_scpint,my_scp_inds,my_scp_inde,i,&
678 iatscp_s,iatscp_e,nnt,i-iscp,nscp_gr(i),iscpstart(i,1),&
681 call int_partition(ind_scpint,my_scp_inds,my_scp_inde,i,&
682 iatscp_s,iatscp_e,i+iscp,nct,nscp_gr(i),iscpstart(i,ii),&
691 if (i.lt.nnt+iscp) then
693 iscpstart(i,1)=i+iscp
695 elseif (i.gt.nct-iscp) then
703 iscpstart(i,2)=i+iscp
708 if (iatscp_s.eq.0) iatscp_s=1
710 write (iout,'(a)') 'SC-p interaction array:'
711 do i=iatscp_s,iatscp_e
712 write (iout,'(i3,2(2x,2i3))') &
713 i,(iscpstart(i,j),iscpend(i,j),j=1,nscp_gr(i))
716 ! Partition local interactions
718 call int_bounds(nres-2,loc_start,loc_end)
719 loc_start=loc_start+1
721 call int_bounds(nres-2,ithet_start,ithet_end)
722 ithet_start=ithet_start+2
723 ithet_end=ithet_end+2
724 call int_bounds(nct-nnt-2,iturn3_start,iturn3_end)
725 iturn3_start=iturn3_start+nnt
726 iphi_start=iturn3_start+2
727 iturn3_end=iturn3_end+nnt
728 iphi_end=iturn3_end+2
729 iturn3_start=iturn3_start-1
730 iturn3_end=iturn3_end-1
731 call int_bounds(nres-3,itau_start,itau_end)
732 itau_start=itau_start+3
734 call int_bounds(nres-3,iphi1_start,iphi1_end)
735 iphi1_start=iphi1_start+3
736 iphi1_end=iphi1_end+3
737 call int_bounds(nct-nnt-3,iturn4_start,iturn4_end)
738 iturn4_start=iturn4_start+nnt
739 iphid_start=iturn4_start+2
740 iturn4_end=iturn4_end+nnt
741 iphid_end=iturn4_end+2
742 iturn4_start=iturn4_start-1
743 iturn4_end=iturn4_end-1
744 call int_bounds(nres-2,ibond_start,ibond_end)
745 ibond_start=ibond_start+1
746 ibond_end=ibond_end+1
747 call int_bounds(nct-nnt,ibondp_start,ibondp_end)
748 ibondp_start=ibondp_start+nnt
749 ibondp_end=ibondp_end+nnt
750 call int_bounds1(nres-1,ivec_start,ivec_end)
751 ! print *,"Processor",myrank,fg_rank,fg_rank1,
752 ! & " ivec_start",ivec_start," ivec_end",ivec_end
753 iset_start=loc_start+2
755 if (ndih_constr.eq.0) then
759 call int_bounds(ndih_constr,idihconstr_start,idihconstr_end)
761 ! nsumgrad=(nres-nnt)*(nres-nnt+1)/2
763 nsumgrad=(nres-nnt)*(nres-nnt+1)/2
765 call int_bounds(nsumgrad,ngrad_start,ngrad_end)
766 igrad_start=((2*nlen+1) &
767 -sqrt(float((2*nlen-1)**2-8*(ngrad_start-1))))/2
768 igrad_end=((2*nlen+1) &
769 -sqrt(float((2*nlen-1)**2-8*(ngrad_end-1))))/2
770 !el allocate(jgrad_start(igrad_start:igrad_end))
771 !el allocate(jgrad_end(igrad_start:igrad_end)) !(maxres)
772 jgrad_start(igrad_start)= &
773 ngrad_start-(2*nlen-igrad_start)*(igrad_start-1)/2 &
775 jgrad_end(igrad_start)=nres
776 if (igrad_end.gt.igrad_start) jgrad_start(igrad_end)=igrad_end+1
777 jgrad_end(igrad_end)=ngrad_end-(2*nlen-igrad_end)*(igrad_end-1)/2 &
779 do i=igrad_start+1,igrad_end-1
784 write (*,*) 'Processor:',fg_rank,' CG group',kolor,&
785 ' absolute rank',myrank,&
786 ' loc_start',loc_start,' loc_end',loc_end,&
787 ' ithet_start',ithet_start,' ithet_end',ithet_end,&
788 ' iphi_start',iphi_start,' iphi_end',iphi_end,&
789 ' iphid_start',iphid_start,' iphid_end',iphid_end,&
790 ' ibond_start',ibond_start,' ibond_end',ibond_end,&
791 ' ibondp_start',ibondp_start,' ibondp_end',ibondp_end,&
792 ' iturn3_start',iturn3_start,' iturn3_end',iturn3_end,&
793 ' iturn4_start',iturn4_start,' iturn4_end',iturn4_end,&
794 ' ivec_start',ivec_start,' ivec_end',ivec_end,&
795 ' iset_start',iset_start,' iset_end',iset_end,&
796 ' idihconstr_start',idihconstr_start,' idihconstr_end',&
798 write (*,*) 'Processor:',fg_rank,myrank,' igrad_start',&
799 igrad_start,' igrad_end',igrad_end,' ngrad_start',ngrad_start,&
800 ' ngrad_end',ngrad_end
801 do i=igrad_start,igrad_end
802 write(*,*) 'Processor:',fg_rank,myrank,i,&
803 jgrad_start(i),jgrad_end(i)
806 if (nfgtasks.gt.1) then
807 call MPI_Allgather(ivec_start,1,MPI_INTEGER,ivec_displ(0),1,&
808 MPI_INTEGER,FG_COMM1,IERROR)
809 iaux=ivec_end-ivec_start+1
810 call MPI_Allgather(iaux,1,MPI_INTEGER,ivec_count(0),1,&
811 MPI_INTEGER,FG_COMM1,IERROR)
812 call MPI_Allgather(iset_start-2,1,MPI_INTEGER,iset_displ(0),1,&
813 MPI_INTEGER,FG_COMM,IERROR)
814 iaux=iset_end-iset_start+1
815 call MPI_Allgather(iaux,1,MPI_INTEGER,iset_count(0),1,&
816 MPI_INTEGER,FG_COMM,IERROR)
817 call MPI_Allgather(ibond_start,1,MPI_INTEGER,ibond_displ(0),1,&
818 MPI_INTEGER,FG_COMM,IERROR)
819 iaux=ibond_end-ibond_start+1
820 call MPI_Allgather(iaux,1,MPI_INTEGER,ibond_count(0),1,&
821 MPI_INTEGER,FG_COMM,IERROR)
822 call MPI_Allgather(ithet_start,1,MPI_INTEGER,ithet_displ(0),1,&
823 MPI_INTEGER,FG_COMM,IERROR)
824 iaux=ithet_end-ithet_start+1
825 call MPI_Allgather(iaux,1,MPI_INTEGER,ithet_count(0),1,&
826 MPI_INTEGER,FG_COMM,IERROR)
827 call MPI_Allgather(iphi_start,1,MPI_INTEGER,iphi_displ(0),1,&
828 MPI_INTEGER,FG_COMM,IERROR)
829 iaux=iphi_end-iphi_start+1
830 call MPI_Allgather(iaux,1,MPI_INTEGER,iphi_count(0),1,&
831 MPI_INTEGER,FG_COMM,IERROR)
832 call MPI_Allgather(iphi1_start,1,MPI_INTEGER,iphi1_displ(0),1,&
833 MPI_INTEGER,FG_COMM,IERROR)
834 iaux=iphi1_end-iphi1_start+1
835 call MPI_Allgather(iaux,1,MPI_INTEGER,iphi1_count(0),1,&
836 MPI_INTEGER,FG_COMM,IERROR)
843 call MPI_Allgather(iturn3_start,1,MPI_INTEGER,&
844 iturn3_start_all(0),1,MPI_INTEGER,FG_COMM,IERROR)
845 call MPI_Allgather(iturn4_start,1,MPI_INTEGER,&
846 iturn4_start_all(0),1,MPI_INTEGER,FG_COMM,IERROR)
847 call MPI_Allgather(iturn3_end,1,MPI_INTEGER,&
848 iturn3_end_all(0),1,MPI_INTEGER,FG_COMM,IERROR)
849 call MPI_Allgather(iturn4_end,1,MPI_INTEGER,&
850 iturn4_end_all(0),1,MPI_INTEGER,FG_COMM,IERROR)
851 call MPI_Allgather(iatel_s,1,MPI_INTEGER,&
852 iatel_s_all(0),1,MPI_INTEGER,FG_COMM,IERROR)
853 call MPI_Allgather(iatel_e,1,MPI_INTEGER,&
854 iatel_e_all(0),1,MPI_INTEGER,FG_COMM,IERROR)
855 call MPI_Allgather(ielstart(1),nres,MPI_INTEGER,&
856 ielstart_all(1,0),nres,MPI_INTEGER,FG_COMM,IERROR)
857 call MPI_Allgather(ielend(1),nres,MPI_INTEGER,&
858 ielend_all(1,0),nres,MPI_INTEGER,FG_COMM,IERROR)
860 write (iout,*) "iatel_s_all",(iatel_s_all(i),i=0,nfgtasks)
861 write (iout,*) "iatel_e_all",(iatel_e_all(i),i=0,nfgtasks)
862 write (iout,*) "iturn3_start_all",&
863 (iturn3_start_all(i),i=0,nfgtasks-1)
864 write (iout,*) "iturn3_end_all",&
865 (iturn3_end_all(i),i=0,nfgtasks-1)
866 write (iout,*) "iturn4_start_all",&
867 (iturn4_start_all(i),i=0,nfgtasks-1)
868 write (iout,*) "iturn4_end_all",&
869 (iturn4_end_all(i),i=0,nfgtasks-1)
870 write (iout,*) "The ielstart_all array"
872 write (iout,'(20i4)') i,(ielstart_all(i,j),j=0,nfgtasks-1)
874 write (iout,*) "The ielend_all array"
876 write (iout,'(20i4)') i,(ielend_all(i,j),j=0,nfgtasks-1)
882 itask_cont_from(0)=fg_rank
883 itask_cont_to(0)=fg_rank
885 !el allocate(iturn3_sent(4,iturn3_start:iturn3_end))
886 !el allocate(iturn4_sent(4,iturn4_start:iturn4_end)) !(4,maxres)
887 do ii=iturn3_start,iturn3_end
888 call add_int(ii,ii+2,iturn3_sent(1,ii),&
889 ntask_cont_to,itask_cont_to,flag)
891 do ii=iturn4_start,iturn4_end
892 call add_int(ii,ii+3,iturn4_sent(1,ii),&
893 ntask_cont_to,itask_cont_to,flag)
895 do ii=iturn3_start,iturn3_end
896 call add_int_from(ii,ii+2,ntask_cont_from,itask_cont_from)
898 do ii=iturn4_start,iturn4_end
899 call add_int_from(ii,ii+3,ntask_cont_from,itask_cont_from)
902 write (iout,*) "After turn3 ntask_cont_from",ntask_cont_from,&
903 " ntask_cont_to",ntask_cont_to
904 write (iout,*) "itask_cont_from",&
905 (itask_cont_from(i),i=1,ntask_cont_from)
906 write (iout,*) "itask_cont_to",&
907 (itask_cont_to(i),i=1,ntask_cont_to)
910 ! write (iout,*) "Loop forward"
913 ! write (iout,*) "from loop i=",i
915 do j=ielstart(i),ielend(i)
916 call add_int_from(i,j,ntask_cont_from,itask_cont_from)
919 ! write (iout,*) "Loop backward iatel_e-1",iatel_e-1,
920 ! & " iatel_e",iatel_e
924 ! write (iout,*) "i",i," ielstart",ielstart(i),
925 ! & " ielend",ielend(i)
928 do j=ielstart(i),ielend(i)
929 call add_int(i,j,iint_sent(1,j,nat_sent+1),ntask_cont_to,&
938 write (iout,*)"After longrange ntask_cont_from",ntask_cont_from,&
939 " ntask_cont_to",ntask_cont_to
940 write (iout,*) "itask_cont_from",&
941 (itask_cont_from(i),i=1,ntask_cont_from)
942 write (iout,*) "itask_cont_to",&
943 (itask_cont_to(i),i=1,ntask_cont_to)
945 write (iout,*) "iint_sent"
948 write (iout,'(20i4)') ii,(j,(iint_sent(k,j,i),k=1,4),&
949 j=ielstart(ii),ielend(ii))
951 write (iout,*) "iturn3_sent iturn3_start",iturn3_start,&
952 " iturn3_end",iturn3_end
953 write (iout,'(20i4)') (i,(iturn3_sent(j,i),j=1,4),&
954 i=iturn3_start,iturn3_end)
955 write (iout,*) "iturn4_sent iturn4_start",iturn4_start,&
956 " iturn4_end",iturn4_end
957 write (iout,'(20i4)') (i,(iturn4_sent(j,i),j=1,4),&
958 i=iturn4_start,iturn4_end)
961 call MPI_Gather(ntask_cont_from,1,MPI_INTEGER,&
962 ntask_cont_from_all,1,MPI_INTEGER,king,FG_COMM,IERR)
963 ! write (iout,*) "Gather ntask_cont_from ended"
965 call MPI_Gather(itask_cont_from(0),nfgtasks,MPI_INTEGER,&
966 itask_cont_from_all(0,0),nfgtasks,MPI_INTEGER,king,&
968 ! write (iout,*) "Gather itask_cont_from ended"
970 call MPI_Gather(ntask_cont_to,1,MPI_INTEGER,ntask_cont_to_all,&
971 1,MPI_INTEGER,king,FG_COMM,IERR)
972 ! write (iout,*) "Gather ntask_cont_to ended"
974 call MPI_Gather(itask_cont_to,nfgtasks,MPI_INTEGER,&
975 itask_cont_to_all,nfgtasks,MPI_INTEGER,king,FG_COMM,IERR)
976 ! write (iout,*) "Gather itask_cont_to ended"
978 if (fg_rank.eq.king) then
979 write (iout,*)"Contact receive task map (proc, #tasks, tasks)"
981 write (iout,'(20i4)') i,ntask_cont_from_all(i),&
982 (itask_cont_from_all(j,i),j=1,ntask_cont_from_all(i))
986 write (iout,*) "Contact send task map (proc, #tasks, tasks)"
988 write (iout,'(20i4)') i,ntask_cont_to_all(i),&
989 (itask_cont_to_all(j,i),j=1,ntask_cont_to_all(i))
993 ! Check if every send will have a matching receive
997 ncheck_to=ncheck_to+ntask_cont_to_all(i)
998 ncheck_from=ncheck_from+ntask_cont_from_all(i)
1000 write (iout,*) "Control sums",ncheck_from,ncheck_to
1001 if (ncheck_from.ne.ncheck_to) then
1002 write (iout,*) "Error: #receive differs from #send."
1003 write (iout,*) "Terminating program...!"
1009 do j=1,ntask_cont_to_all(i)
1010 ii=itask_cont_to_all(j,i)
1011 do k=1,ntask_cont_from_all(ii)
1012 if (itask_cont_from_all(k,ii).eq.i) then
1013 if(lprint)write(iout,*)"Matching send/receive",i,ii
1017 if (k.eq.ntask_cont_from_all(ii)+1) then
1019 write (iout,*) "Error: send by",j," to",ii,&
1020 " would have no matching receive"
1026 write (iout,*) "Unmatched sends; terminating program"
1030 call MPI_Bcast(flag,1,MPI_LOGICAL,king,FG_COMM,IERROR)
1031 ! write (iout,*) "flag broadcast ended flag=",flag
1034 call MPI_Finalize(IERROR)
1035 stop "Error in INIT_INT_TABLE: unmatched send/receive."
1037 call MPI_Comm_group(FG_COMM,fg_group,IERR)
1038 ! write (iout,*) "MPI_Comm_group ended"
1040 call MPI_Group_incl(fg_group,ntask_cont_from+1,&
1041 itask_cont_from(0),CONT_FROM_GROUP,IERR)
1042 call MPI_Group_incl(fg_group,ntask_cont_to+1,itask_cont_to(0),&
1046 iaux=4*(ielend(ii)-ielstart(ii)+1)
1047 call MPI_Group_translate_ranks(fg_group,iaux,&
1048 iint_sent(1,ielstart(ii),i),CONT_TO_GROUP,&
1049 iint_sent_local(1,ielstart(ii),i),IERR )
1050 ! write (iout,*) "Ranks translated i=",i
1053 iaux=4*(iturn3_end-iturn3_start+1)
1054 call MPI_Group_translate_ranks(fg_group,iaux,&
1055 iturn3_sent(1,iturn3_start),CONT_TO_GROUP,&
1056 iturn3_sent_local(1,iturn3_start),IERR)
1057 iaux=4*(iturn4_end-iturn4_start+1)
1058 call MPI_Group_translate_ranks(fg_group,iaux,&
1059 iturn4_sent(1,iturn4_start),CONT_TO_GROUP,&
1060 iturn4_sent_local(1,iturn4_start),IERR)
1062 write (iout,*) "iint_sent_local"
1065 write (iout,'(20i4)') ii,(j,(iint_sent_local(k,j,i),k=1,4),&
1066 j=ielstart(ii),ielend(ii))
1069 write (iout,*) "iturn3_sent_local iturn3_start",iturn3_start,&
1070 " iturn3_end",iturn3_end
1071 write (iout,'(20i4)') (i,(iturn3_sent_local(j,i),j=1,4),&
1072 i=iturn3_start,iturn3_end)
1073 write (iout,*) "iturn4_sent_local iturn4_start",iturn4_start,&
1074 " iturn4_end",iturn4_end
1075 write (iout,'(20i4)') (i,(iturn4_sent_local(j,i),j=1,4),&
1076 i=iturn4_start,iturn4_end)
1079 call MPI_Group_free(fg_group,ierr)
1080 call MPI_Group_free(cont_from_group,ierr)
1081 call MPI_Group_free(cont_to_group,ierr)
1082 call MPI_Type_contiguous(3,MPI_DOUBLE_PRECISION,MPI_UYZ,IERROR)
1083 call MPI_Type_commit(MPI_UYZ,IERROR)
1084 call MPI_Type_contiguous(18,MPI_DOUBLE_PRECISION,MPI_UYZGRAD,&
1086 call MPI_Type_commit(MPI_UYZGRAD,IERROR)
1087 call MPI_Type_contiguous(2,MPI_DOUBLE_PRECISION,MPI_MU,IERROR)
1088 call MPI_Type_commit(MPI_MU,IERROR)
1089 call MPI_Type_contiguous(4,MPI_DOUBLE_PRECISION,MPI_MAT1,IERROR)
1090 call MPI_Type_commit(MPI_MAT1,IERROR)
1091 call MPI_Type_contiguous(8,MPI_DOUBLE_PRECISION,MPI_MAT2,IERROR)
1092 call MPI_Type_commit(MPI_MAT2,IERROR)
1093 call MPI_Type_contiguous(6,MPI_DOUBLE_PRECISION,MPI_THET,IERROR)
1094 call MPI_Type_commit(MPI_THET,IERROR)
1095 call MPI_Type_contiguous(9,MPI_DOUBLE_PRECISION,MPI_GAM,IERROR)
1096 call MPI_Type_commit(MPI_GAM,IERROR)
1098 !el allocate(lentyp(0:nfgtasks-1))
1100 ! 9/22/08 Derived types to send matrices which appear in correlation terms
1102 if (ivec_count(i).eq.ivec_count(0)) then
1108 do ind_typ=lentyp(0),lentyp(nfgtasks-1)
1109 if (ind_typ.eq.0) then
1110 ichunk=ivec_count(0)
1112 ichunk=ivec_count(1)
1119 ! displs(i)=displs(i-1)+blocklengths(i-1)*maxres
1122 ! blocklengths(i)=blocklengths(i)*ichunk
1124 ! write (iout,*) "blocklengths and displs"
1126 ! write (iout,*) i,blocklengths(i),displs(i)
1129 ! call MPI_Type_indexed(4,blocklengths(1),displs(1),
1130 ! & MPI_DOUBLE_PRECISION,MPI_ROTAT1(ind_typ),IERROR)
1131 ! call MPI_Type_commit(MPI_ROTAT1(ind_typ),IERROR)
1132 ! write (iout,*) "MPI_ROTAT1",MPI_ROTAT1
1138 ! displs(i)=displs(i-1)+blocklengths(i-1)*maxres
1141 ! blocklengths(i)=blocklengths(i)*ichunk
1143 ! write (iout,*) "blocklengths and displs"
1145 ! write (iout,*) i,blocklengths(i),displs(i)
1148 ! call MPI_Type_indexed(4,blocklengths(1),displs(1),
1149 ! & MPI_DOUBLE_PRECISION,MPI_ROTAT2(ind_typ),IERROR)
1150 ! call MPI_Type_commit(MPI_ROTAT2(ind_typ),IERROR)
1151 ! write (iout,*) "MPI_ROTAT2",MPI_ROTAT2
1157 displs(i)=displs(i-1)+blocklengths(i-1)*nres !maxres
1160 blocklengths(i)=blocklengths(i)*ichunk
1162 call MPI_Type_indexed(8,blocklengths,displs,&
1163 MPI_DOUBLE_PRECISION,MPI_PRECOMP11(ind_typ),IERROR)
1164 call MPI_Type_commit(MPI_PRECOMP11(ind_typ),IERROR)
1170 displs(i)=displs(i-1)+blocklengths(i-1)*nres !maxres
1173 blocklengths(i)=blocklengths(i)*ichunk
1175 call MPI_Type_indexed(8,blocklengths,displs,&
1176 MPI_DOUBLE_PRECISION,MPI_PRECOMP12(ind_typ),IERROR)
1177 call MPI_Type_commit(MPI_PRECOMP12(ind_typ),IERROR)
1183 displs(i)=displs(i-1)+blocklengths(i-1)*nres !maxres
1186 blocklengths(i)=blocklengths(i)*ichunk
1188 call MPI_Type_indexed(6,blocklengths,displs,&
1189 MPI_DOUBLE_PRECISION,MPI_PRECOMP22(ind_typ),IERROR)
1190 call MPI_Type_commit(MPI_PRECOMP22(ind_typ),IERROR)
1196 displs(i)=displs(i-1)+blocklengths(i-1)*nres !maxres
1199 blocklengths(i)=blocklengths(i)*ichunk
1201 call MPI_Type_indexed(2,blocklengths,displs,&
1202 MPI_DOUBLE_PRECISION,MPI_PRECOMP23(ind_typ),IERROR)
1203 call MPI_Type_commit(MPI_PRECOMP23(ind_typ),IERROR)
1209 displs(i)=displs(i-1)+blocklengths(i-1)*nres !maxres
1212 blocklengths(i)=blocklengths(i)*ichunk
1214 call MPI_Type_indexed(4,blocklengths,displs,&
1215 MPI_DOUBLE_PRECISION,MPI_ROTAT_OLD(ind_typ),IERROR)
1216 call MPI_Type_commit(MPI_ROTAT_OLD(ind_typ),IERROR)
1220 iint_start=ivec_start+1
1223 iint_count(i)=ivec_count(i)
1224 iint_displ(i)=ivec_displ(i)
1225 ivec_displ(i)=ivec_displ(i)-1
1226 iset_displ(i)=iset_displ(i)-1
1227 ithet_displ(i)=ithet_displ(i)-1
1228 iphi_displ(i)=iphi_displ(i)-1
1229 iphi1_displ(i)=iphi1_displ(i)-1
1230 ibond_displ(i)=ibond_displ(i)-1
1232 if (nfgtasks.gt.1 .and. fg_rank.eq.king &
1233 .and. (me.eq.0 .or. .not. out1file)) then
1234 write (iout,*) "IVEC_DISPL, IVEC_COUNT, ISET_START, ISET_COUNT"
1236 write (iout,*) i,ivec_displ(i),ivec_count(i),iset_displ(i),&
1239 write (iout,*) "iphi_start",iphi_start," iphi_end",iphi_end,&
1240 " iphi1_start",iphi1_start," iphi1_end",iphi1_end
1241 write (iout,*)"IPHI_COUNT, IPHI_DISPL, IPHI1_COUNT, IPHI1_DISPL"
1243 write (iout,*) i,iphi_count(i),iphi_displ(i),iphi1_count(i),&
1246 write(iout,'(i10,a,i10,a,i10,a/a,i3,a)') n_sc_int_tot,' SC-SC ',&
1247 nele_int_tot,' electrostatic and ',nscp_int_tot,&
1248 ' SC-p interactions','were distributed among',nfgtasks,&
1249 ' fine-grain processors.'
1265 idihconstr_end=ndih_constr
1266 iphid_start=iphi_start
1267 iphid_end=iphi_end-1
1281 !el common /przechowalnia/
1282 deallocate(iturn3_start_all)
1283 deallocate(iturn3_end_all)
1284 deallocate(iturn4_start_all)
1285 deallocate(iturn4_end_all)
1286 deallocate(iatel_s_all)
1287 deallocate(iatel_e_all)
1288 deallocate(ielstart_all)
1289 deallocate(ielend_all)
1291 deallocate(ntask_cont_from_all)
1292 deallocate(ntask_cont_to_all)
1293 deallocate(itask_cont_from_all)
1294 deallocate(itask_cont_to_all)
1297 end subroutine init_int_table
1299 !-----------------------------------------------------------------------------
1300 subroutine add_int(ii,jj,itask,ntask_cont_to,itask_cont_to,flag)
1303 ! include "DIMENSIONS"
1304 ! include "COMMON.INTERACT"
1305 ! include "COMMON.SETUP"
1306 ! include "COMMON.IOUNITS"
1307 integer :: ii,jj,ntask_cont_to
1308 integer,dimension(4) :: itask
1309 integer :: itask_cont_to(0:nfgtasks-1) !(0:max_fg_procs-1)
1311 !el integer,dimension(0:nfgtasks) :: iturn3_start_all,iturn3_end_all,iturn4_start_all,&
1312 !el iturn4_end_all,iatel_s_all,iatel_e_all !(0:max_fg_procs)
1313 !el integer,dimension(nres,0:nfgtasks-1) :: ielstart_all,ielend_all !(maxres,0:max_fg_procs-1)
1314 !el common /przechowalnia/ iturn3_start_all,iturn3_end_all,iturn4_start_all,&
1315 !el iturn4_end_all,iatel_s_all,iatel_e_all,ielstart_all,ielend_all
1316 integer :: iproc,isent,k,l
1317 ! Determines whether to send interaction ii,jj to other processors; a given
1318 ! interaction can be sent to at most 2 processors.
1319 ! Sets flag=.true. if interaction ii,jj needs to be sent to at least
1320 ! one processor, otherwise flag is unchanged from the input value.
1326 ! write (iout,*) "ii",ii," jj",jj
1327 ! Loop over processors to check if anybody could need interaction ii,jj
1328 do iproc=0,fg_rank-1
1329 ! Check if the interaction matches any turn3 at iproc
1330 do k=iturn3_start_all(iproc),iturn3_end_all(iproc)
1332 if (k.eq.ii-1 .and. l.eq.jj-1 .or. k.eq.ii-1 .and. l.eq.jj+1 &
1333 .or. k.eq.ii+1 .and. l.eq.jj+1 .or. k.eq.ii+1 .and. l.eq.jj-1) &
1335 ! write (iout,*) "turn3 to iproc",iproc," ij",ii,jj,"kl",k,l
1338 if (iproc.ne.itask(1).and.iproc.ne.itask(2) &
1339 .and.iproc.ne.itask(3).and.iproc.ne.itask(4)) then
1342 call add_task(iproc,ntask_cont_to,itask_cont_to)
1346 ! Check if the interaction matches any turn4 at iproc
1347 do k=iturn4_start_all(iproc),iturn4_end_all(iproc)
1349 if (k.eq.ii-1 .and. l.eq.jj-1 .or. k.eq.ii-1 .and. l.eq.jj+1 &
1350 .or. k.eq.ii+1 .and. l.eq.jj+1 .or. k.eq.ii+1 .and. l.eq.jj-1) &
1352 ! write (iout,*) "turn3 to iproc",iproc," ij",ii,jj," kl",k,l
1355 if (iproc.ne.itask(1).and.iproc.ne.itask(2) &
1356 .and.iproc.ne.itask(3).and.iproc.ne.itask(4)) then
1359 call add_task(iproc,ntask_cont_to,itask_cont_to)
1363 if (iatel_s_all(iproc).gt.0 .and. iatel_e_all(iproc).gt.0 .and. &
1364 iatel_s_all(iproc).le.ii-1 .and. iatel_e_all(iproc).ge.ii-1)then
1365 if (ielstart_all(ii-1,iproc).le.jj-1.and. &
1366 ielend_all(ii-1,iproc).ge.jj-1) then
1368 if (iproc.ne.itask(1).and.iproc.ne.itask(2) &
1369 .and.iproc.ne.itask(3).and.iproc.ne.itask(4)) then
1372 call add_task(iproc,ntask_cont_to,itask_cont_to)
1375 if (ielstart_all(ii-1,iproc).le.jj+1.and. &
1376 ielend_all(ii-1,iproc).ge.jj+1) then
1378 if (iproc.ne.itask(1).and.iproc.ne.itask(2) &
1379 .and.iproc.ne.itask(3).and.iproc.ne.itask(4)) then
1382 call add_task(iproc,ntask_cont_to,itask_cont_to)
1388 end subroutine add_int
1389 !-----------------------------------------------------------------------------
1390 subroutine add_int_from(ii,jj,ntask_cont_from,itask_cont_from)
1394 ! include "DIMENSIONS"
1395 ! include "COMMON.INTERACT"
1396 ! include "COMMON.SETUP"
1397 ! include "COMMON.IOUNITS"
1398 integer :: ii,jj,itask(2),ntask_cont_from,&
1399 itask_cont_from(0:nfgtasks-1) !(0:max_fg_procs)
1401 !el integer,dimension(0:nfgtasks) :: iturn3_start_all,iturn3_end_all,&
1402 !el iturn4_start_all,iturn4_end_all,iatel_s_all,iatel_e_all !(0:max_fg_procs)
1403 !el integer,dimension(nres,0:nfgtasks-1) :: ielstart_all,ielend_all !(maxres,0:max_fg_procs-1)
1404 !el common /przechowalnia/ iturn3_start_all,iturn3_end_all,iturn4_start_all,&
1405 !el iturn4_end_all,iatel_s_all,iatel_e_all,ielstart_all,ielend_all
1406 integer :: iproc,k,l
1407 do iproc=fg_rank+1,nfgtasks-1
1408 do k=iturn3_start_all(iproc),iturn3_end_all(iproc)
1410 if (k.eq.ii+1 .and. l.eq.jj+1 .or. k.eq.ii+1.and.l.eq.jj-1 &
1411 .or. k.eq.ii-1 .and. l.eq.jj-1 .or. k.eq.ii-1 .and. l.eq.jj+1) &
1413 ! write (iout,*)"turn3 from iproc",iproc," ij",ii,jj," kl",k,l
1414 call add_task(iproc,ntask_cont_from,itask_cont_from)
1417 do k=iturn4_start_all(iproc),iturn4_end_all(iproc)
1419 if (k.eq.ii+1 .and. l.eq.jj+1 .or. k.eq.ii+1.and.l.eq.jj-1 &
1420 .or. k.eq.ii-1 .and. l.eq.jj-1 .or. k.eq.ii-1 .and. l.eq.jj+1) &
1422 ! write (iout,*)"turn4 from iproc",iproc," ij",ii,jj," kl",k,l
1423 call add_task(iproc,ntask_cont_from,itask_cont_from)
1426 if (iatel_s_all(iproc).gt.0 .and. iatel_e_all(iproc).gt.0) then
1427 if (ii+1.ge.iatel_s_all(iproc).and.ii+1.le.iatel_e_all(iproc)) &
1429 if (jj+1.ge.ielstart_all(ii+1,iproc).and. &
1430 jj+1.le.ielend_all(ii+1,iproc)) then
1431 call add_task(iproc,ntask_cont_from,itask_cont_from)
1433 if (jj-1.ge.ielstart_all(ii+1,iproc).and. &
1434 jj-1.le.ielend_all(ii+1,iproc)) then
1435 call add_task(iproc,ntask_cont_from,itask_cont_from)
1438 if (ii-1.ge.iatel_s_all(iproc).and.ii-1.le.iatel_e_all(iproc)) &
1440 if (jj-1.ge.ielstart_all(ii-1,iproc).and. &
1441 jj-1.le.ielend_all(ii-1,iproc)) then
1442 call add_task(iproc,ntask_cont_from,itask_cont_from)
1444 if (jj+1.ge.ielstart_all(ii-1,iproc).and. &
1445 jj+1.le.ielend_all(ii-1,iproc)) then
1446 call add_task(iproc,ntask_cont_from,itask_cont_from)
1452 end subroutine add_int_from
1453 !-----------------------------------------------------------------------------
1454 subroutine add_task(iproc,ntask_cont,itask_cont)
1457 ! include "DIMENSIONS"
1458 integer :: iproc,ntask_cont,itask_cont(0:nfgtasks-1) !(0:max_fg_procs-1)
1461 if (itask_cont(ii).eq.iproc) return
1463 ntask_cont=ntask_cont+1
1464 itask_cont(ntask_cont)=iproc
1466 end subroutine add_task
1468 !-----------------------------------------------------------------------------
1469 #if defined MPI || defined WHAM_RUN
1470 subroutine int_partition(int_index,lower_index,upper_index,atom,&
1471 at_start,at_end,first_atom,last_atom,int_gr,jat_start,jat_end,*)
1473 ! implicit real*8 (a-h,o-z)
1474 ! include 'DIMENSIONS'
1475 ! include 'COMMON.IOUNITS'
1476 integer :: int_index,lower_index,upper_index,atom,at_start,at_end,&
1477 first_atom,last_atom,int_gr,jat_start,jat_end,int_index_old
1480 if (lprn) write (iout,*) 'int_index=',int_index
1481 int_index_old=int_index
1482 int_index=int_index+last_atom-first_atom+1
1484 write (iout,*) 'int_index=',int_index,&
1485 ' int_index_old',int_index_old,&
1486 ' lower_index=',lower_index,&
1487 ' upper_index=',upper_index,&
1488 ' atom=',atom,' first_atom=',first_atom,&
1489 ' last_atom=',last_atom
1490 if (int_index.ge.lower_index) then
1492 if (at_start.eq.0) then
1494 jat_start=first_atom-1+lower_index-int_index_old
1496 jat_start=first_atom
1498 if (lprn) write (iout,*) 'jat_start',jat_start
1499 if (int_index.ge.upper_index) then
1501 jat_end=first_atom-1+upper_index-int_index_old
1506 if (lprn) write (iout,*) 'jat_end',jat_end
1509 end subroutine int_partition
1511 !-----------------------------------------------------------------------------
1512 subroutine hpb_partition
1514 ! implicit real*8 (a-h,o-z)
1515 ! include 'DIMENSIONS'
1519 ! include 'COMMON.SBRIDGE'
1520 ! include 'COMMON.IOUNITS'
1521 ! include 'COMMON.SETUP'
1523 call int_bounds(nhpb,link_start,link_end)
1524 write (iout,*) 'Processor',fg_rank,' CG group',kolor,&
1525 ' absolute rank',MyRank,&
1526 ' nhpb',nhpb,' link_start=',link_start,&
1527 ' link_end',link_end
1533 end subroutine hpb_partition
1534 !-----------------------------------------------------------------------------
1535 ! misc.f in module io_common
1536 !-----------------------------------------------------------------------------
1537 !-----------------------------------------------------------------------------
1539 !-----------------------------------------------------------------------------
1540 subroutine getenv_loc(var, val)
1542 character(*) :: var, val
1545 character(len=2000) :: line
1548 open (196,file='env',status='old',readonly,shared)
1550 ! write(*,*)'looking for ',var
1551 10 read(196,*,err=11,end=11)line
1552 iread=index(line,var)
1553 ! write(*,*)iread,' ',var,' ',line
1554 if (iread.eq.0) go to 10
1555 ! write(*,*)'---> ',line
1561 iread=iread+ilen(var)+1
1562 read (line(iread:),*,err=12,end=12) val
1563 ! write(*,*)'OK: ',var,' = ',val
1569 #elif (defined CRAY)
1570 integer :: lennam,lenval,ierror
1572 ! getenv using a POSIX call, useful on the T3D
1573 ! Sept 1996, comment out error check on advice of H. Pritchard
1576 if(lennam.le.0) stop '--error calling getenv--'
1577 call pxfgetenv(var,lennam,val,lenval,ierror)
1578 !-HP- if(ierror.ne.0) stop '--error returned by pxfgetenv--'
1580 call getenv(var,val)
1584 end subroutine getenv_loc
1585 !-----------------------------------------------------------------------------
1587 !-----------------------------------------------------------------------------
1588 subroutine setup_var
1591 ! implicit real*8 (a-h,o-z)
1592 ! include 'DIMENSIONS'
1593 ! include 'COMMON.IOUNITS'
1594 ! include 'COMMON.GEO'
1595 ! include 'COMMON.VAR'
1596 ! include 'COMMON.INTERACT'
1597 ! include 'COMMON.LOCAL'
1598 ! include 'COMMON.NAMES'
1599 ! include 'COMMON.CHAIN'
1600 ! include 'COMMON.FFIELD'
1601 ! include 'COMMON.SBRIDGE'
1602 ! include 'COMMON.HEADER'
1603 ! include 'COMMON.CONTROL'
1604 ! include 'COMMON.DBASE'
1605 ! include 'COMMON.THREAD'
1606 ! include 'COMMON.TIME1'
1607 ! Set up variable list.
1614 if (itype(i).ne.10) then
1616 if (itype(i).ne.10 .and. itype(i).ne.ntyp1) then
1619 ialph(i,1)=nvar+nside
1623 if (indphi.gt.0) then
1625 else if (indback.gt.0) then
1630 !d write (iout,'(3i4)') (i,ialph(i,1),ialph(i,2),i=2,nres-1)
1632 end subroutine setup_var
1633 !-----------------------------------------------------------------------------
1635 !-----------------------------------------------------------------------------
1636 integer function rescode(iseq,nam,itype)
1638 use io_base, only: ucase
1639 ! implicit real*8 (a-h,o-z)
1640 ! include 'DIMENSIONS'
1641 ! include 'COMMON.NAMES'
1642 ! include 'COMMON.IOUNITS'
1643 character(len=3) :: nam !,ucase
1644 integer :: iseq,itype,i
1646 if (itype.eq.0) then
1649 if (ucase(nam).eq.restyp(i)) then
1658 if (nam(1:1).eq.onelet(i)) then
1665 write (iout,10) iseq,nam
1667 10 format ('**** Error - residue',i4,' has an unresolved name ',a3)
1668 end function rescode
1669 !-----------------------------------------------------------------------------
1671 !-----------------------------------------------------------------------------
1672 ! $Date: 1994/10/05 16:41:52 $
1675 subroutine set_timers
1678 !el real(kind=8) :: tcpu
1679 ! include 'COMMON.TIME1'
1684 ! Diminish the assigned time limit a little so that there is some time to
1686 ! timlim=batime-150.0
1687 ! Calculate the initial time, if it is not zero (e.g. for the SUN).
1691 walltime=MPI_WTIME()
1693 time_allreduce=0.0d0
1698 time_scatter_fmat=0.0d0
1699 time_scatter_ginv=0.0d0
1700 time_scatter_fmatmult=0.0d0
1701 time_scatter_ginvmult=0.0d0
1702 time_barrier_e=0.0d0
1703 time_barrier_g=0.0d0
1706 time_lagrangian=0.0d0
1707 time_sumgradient=0.0d0
1708 time_intcartderiv=0.0d0
1709 time_inttocart=0.0d0
1711 time_fricmatmult=0.0d0
1721 time_fricmatmult=0.0d0
1725 !d print *,' in SET_TIMERS stime=',stime
1727 end subroutine set_timers
1728 !-----------------------------------------------------------------------------
1729 logical function stopx(nf)
1730 ! This function returns .true. if one of the following reasons to exit SUMSL
1731 ! occurs. The "reason" code is stored in WHATSUP passed thru a COMMON block:
1733 !... WHATSUP = 0 - go on, no reason to stop. Stopx will return .false.
1734 !... 1 - Time up in current node;
1735 !... 2 - STOP signal was received from another node because the
1736 !... node's task was accomplished (parallel only);
1737 !... -1 - STOP signal was received from another node because of error;
1738 !... -2 - STOP signal was received from another node, because
1739 !... the node's time was up.
1740 ! implicit real*8 (a-h,o-z)
1741 ! include 'DIMENSIONS'
1743 !el use control_data, only:WhatsUp
1746 !el use MPI_data !include 'COMMON.INFO'
1750 !el logical :: ovrtim
1752 ! include 'COMMON.IOUNITS'
1753 ! include 'COMMON.TIME1'
1756 !d print *,'Processor',MyID,' NF=',nf
1757 !d write (iout,*) "stopx: ",nf
1761 ! Finish if time is up.
1765 else if (mod(nf,100).eq.0) then
1766 ! Other processors might have finished. Check this every 100th function
1768 ! Master checks if any other processor has sent accepted conformation(s) to it.
1769 if (MyID.ne.MasterID) call receive_mcm_info
1770 if (MyID.eq.MasterID) call receive_conf
1771 !d print *,'Processor ',MyID,' is checking STOP: nf=',nf
1772 call recv_stop_sig(Kwita)
1773 if (Kwita.eq.-1) then
1774 write (iout,'(a,i4,a,i5)') 'Processor',&
1775 MyID,' has received STOP signal in STOPX; NF=',nf
1776 write (*,'(a,i4,a,i5)') 'Processor',&
1777 MyID,' has received STOP signal in STOPX; NF=',nf
1780 elseif (Kwita.eq.-2) then
1782 'Processor',MyID,' received TIMEUP-STOP signal in SUMSL.'
1784 'Processor',MyID,' received TIMEUP-STOP signal in SUMSL.'
1787 else if (Kwita.eq.-3) then
1789 'Processor',MyID,' received ERROR-STOP signal in SUMSL.'
1791 'Processor',MyID,' received ERROR-STOP signal in SUMSL.'
1805 !d write (iout,*) "stopx set at .false."
1809 ! Check for FOUND_NAN flag
1811 write(iout,*)" *** stopx : Found a NaN"
1817 ! Finish if time is up.
1820 else if (cutoffviol) then
1829 !-----------------------------------------------------------------------------
1830 logical function ovrtim()
1832 ! include 'DIMENSIONS'
1833 ! include 'COMMON.IOUNITS'
1834 ! include 'COMMON.TIME1'
1835 !el real(kind=8) :: tcpu
1836 real(kind=8) :: curtim
1839 curtim = MPI_Wtime()-walltime
1843 ! curtim is the current time in seconds.
1844 ! write (iout,*) "curtim",curtim," timlim",timlim," safety",safety
1846 if (curtim .ge. timlim - safety) then
1847 write (iout,'(a,f10.2,a,f10.2,a,f10.2,a)') &
1848 "***************** Elapsed time (",curtim,&
1849 " s) is within the safety limit (",safety,&
1850 " s) of the allocated time (",timlim," s). Terminating."
1858 !elwrite (iout,*) "ovrtim",ovrtim
1861 !-----------------------------------------------------------------------------
1862 real(kind=8) function tcpu()
1864 ! include 'COMMON.TIME1'
1865 real(kind=8) :: seconds
1867 !***************************
1868 ! Next definition for EAGLE (ibm-es9000)
1869 real(kind=8) :: micseconds
1871 tcpu=cputime(micseconds,rcode)
1872 tcpu=(micseconds/1.0E6) - stime
1873 !***************************
1876 !***************************
1877 ! Next definitions for sun
1878 REAL(kind=8) :: ECPU,ETIME,ETCPU
1879 real(kind=8),dimension(2) :: tarray
1882 !***************************
1885 !***************************
1886 ! Next definitions for ksr
1887 ! this function uses the ksr timer ALL_SECONDS from the PMON library to
1888 ! return the elapsed time in seconds
1889 tcpu= all_seconds() - stime
1890 !***************************
1893 !***************************
1894 ! Next definitions for sgi
1895 real(kind=4) :: timar(2), etime
1896 seconds = etime(timar)
1897 !d print *,'seconds=',seconds,' stime=',stime
1900 tcpu=seconds - stime
1901 !***************************
1905 !***************************
1906 ! Next definitions for sgi
1907 real(kind=4) :: timar(2), etime
1908 seconds = etime(timar)
1909 !d print *,'seconds=',seconds,' stime=',stime
1912 tcpu=seconds - stime
1913 !***************************
1918 !***************************
1919 ! Next definitions for Cray
1921 ! curdat=curdat(1:9)
1922 ! call clock(curtim)
1923 ! curtim=curtim(1:8)
1926 !***************************
1929 !***************************
1930 ! Next definitions for RS6000
1931 integer(kind=4) :: i1,mclock
1933 tcpu = (i1+0.0D0)/100.0D0
1936 !***************************
1937 ! next definitions for windows NT Digital fortran
1938 real(kind=4) :: time_real
1939 call cpu_time(time_real)
1943 !***************************
1944 ! next definitions for windows NT Digital fortran
1945 real(kind=4) :: time_real
1946 call cpu_time(time_real)
1952 !-----------------------------------------------------------------------------
1953 subroutine dajczas(rntime,hrtime,mintime,sectime)
1955 ! include 'COMMON.IOUNITS'
1956 integer :: ihr,imn,isc
1957 real(kind=8) :: rntime,hrtime,mintime,sectime
1958 hrtime=rntime/3600.0D0
1960 mintime=aint((rntime-3600.0D0*hrtime)/60.0D0)
1961 sectime=aint((rntime-3600.0D0*hrtime-60.0D0*mintime)+0.5D0)
1962 if (sectime.eq.60.0D0) then
1964 mintime=mintime+1.0D0
1969 write (iout,328) ihr,imn,isc
1970 328 FORMAT(//'***** Computation time: ',I4 ,' hours ',I2 ,&
1971 ' minutes ', I2 ,' seconds *****')
1973 end subroutine dajczas
1974 !-----------------------------------------------------------------------------
1975 subroutine print_detailed_timing
1977 ! implicit real*8 (a-h,o-z)
1978 ! include 'DIMENSIONS'
1982 ! include 'COMMON.IOUNITS'
1983 ! include 'COMMON.TIME1'
1984 ! include 'COMMON.SETUP'
1985 real(kind=8) :: time1,time_barrier
1986 time_barrier = 0.0d0
1990 write (iout,'(80(1h=)/a/(80(1h=)))') &
1991 "Details of FG communication time"
1992 write (*,'(7(a40,1pe15.5/),40(1h-)/a40,1pe15.5/80(1h=))') &
1993 "BROADCAST:",time_bcast,"REDUCE:",time_reduce,&
1994 "GATHER:",time_gather,&
1995 "SCATTER:",time_scatter,"SENDRECV:",time_sendrecv,&
1996 "BARRIER ene",time_barrier_e,&
1997 "BARRIER grad",time_barrier_g,&
1999 time_bcast+time_reduce+time_gather+time_scatter+time_sendrecv
2000 write (*,*) fg_rank,myrank,&
2001 ': Total wall clock time',time1-walltime,' sec'
2002 write (*,*) "Processor",fg_rank,myrank,&
2003 ": BROADCAST time",time_bcast," REDUCE time",&
2004 time_reduce," GATHER time",time_gather," SCATTER time",&
2006 " SCATTER fmatmult",time_scatter_fmatmult,&
2007 " SCATTER ginvmult",time_scatter_ginvmult,&
2008 " SCATTER fmat",time_scatter_fmat,&
2009 " SCATTER ginv",time_scatter_ginv,&
2010 " SENDRECV",time_sendrecv,&
2011 " BARRIER ene",time_barrier_e,&
2012 " BARRIER GRAD",time_barrier_g,&
2013 " BCAST7",time_bcast7," BCASTC",time_bcastc,&
2014 " BCASTW",time_bcastw," ALLREDUCE",time_allreduce,&
2016 time_bcast+time_reduce+time_gather+time_scatter+ &
2017 time_sendrecv+time_barrier+time_bcastc
2019 write (*,*) "Processor",fg_rank,myrank," enecalc",time_enecalc
2020 write (*,*) "Processor",fg_rank,myrank," sumene",time_sumene
2021 write (*,*) "Processor",fg_rank,myrank," intfromcart",&
2023 write (*,*) "Processor",fg_rank,myrank," vecandderiv",&
2025 write (*,*) "Processor",fg_rank,myrank," setmatrices",&
2027 write (*,*) "Processor",fg_rank,myrank," ginvmult",&
2029 write (*,*) "Processor",fg_rank,myrank," fricmatmult",&
2031 write (*,*) "Processor",fg_rank,myrank," inttocart",&
2033 write (*,*) "Processor",fg_rank,myrank," sumgradient",&
2035 write (*,*) "Processor",fg_rank,myrank," intcartderiv",&
2037 if (fg_rank.eq.0) then
2038 write (*,*) "Processor",fg_rank,myrank," lagrangian",&
2040 write (*,*) "Processor",fg_rank,myrank," cartgrad",&
2044 end subroutine print_detailed_timing
2045 !-----------------------------------------------------------------------------
2046 !-----------------------------------------------------------------------------