2 implicit real*8 (a-h,o-z)
7 & /'pool','chain regrow','multi-bond','phi','theta','side chain',
9 c Conversion from poises to molecular unit and the gas constant
10 data cPoise /2.9361d0/, Rb /0.001986d0/
12 c--------------------------------------------------------------------------
15 C Define constants and zero out tables.
17 implicit real*8 (a-h,o-z)
25 cMS$ATTRIBUTES C :: proc_proc
28 include 'COMMON.IOUNITS'
29 include 'COMMON.CHAIN'
30 include 'COMMON.INTERACT'
32 include 'COMMON.LOCAL'
33 include 'COMMON.TORSION'
34 include 'COMMON.FFIELD'
35 include 'COMMON.SBRIDGE'
37 include 'COMMON.MINIM'
38 include 'COMMON.DERIV'
39 include 'COMMON.SPLITELE'
40 c Common blocks from the diagonalization routines
41 COMMON /IOFILE/ IR,IW,IP,IJK,IPK,IDAF,NAV,IODA(400)
42 COMMON /MACHSW/ KDIAG,ICORFL,IXDR
44 c real*8 text1 /'initial_i'/
62 C The following is just to define auxiliary variables used in angle conversion
101 crc for write_rmsbank1
103 cdr include secondary structure prediction bias
106 C CSA I/O units (separated from others especially for Jooyoung)
117 icsa_bank_reminimized=38
120 crc for ifc error 118
122 C Lipidic input file for parameters range 60-79
124 C input file for transfer sidechain and peptide group inside the
125 C lipidic environment if lipid is implicite
127 C DNA input files for parameters range 80-99
128 C Suger input files for parameters range 100-119
129 C All-atom input files for parameters range 120-149
131 C Set default weights of the energy terms.
142 c print '(a,$)','Inside initialize'
143 c call memmon_print_usage()
178 athet(j,i,ichir1,ichir2)=0.0D0
179 bthet(j,i,ichir1,ichir2)=0.0D0
199 gaussc(l,k,j,i)=0.0D0
209 cc write (iout,*) "TU DOCHODZE",i,itortyp(i)
213 v1(k,j,i,iblock)=0.0D0
214 v2(k,j,i,iblock)=0.0D0
224 v1c(1,l,i,j,k,iblock)=0.0D0
225 v1s(1,l,i,j,k,iblock)=0.0D0
226 v1c(2,l,i,j,k,iblock)=0.0D0
227 v1s(2,l,i,j,k,iblock)=0.0D0
231 v2c(m,l,i,j,k,iblock)=0.0D0
232 v2s(m,l,i,j,k,iblock)=0.0D0
244 C Initialize the bridge arrays
258 C Initialize correlation arrays
289 C Initialize variables used in minimization.
298 C Initialize the variables responsible for the mode of gradient storage.
303 C Initialize constants used to split the energy into long- and short-range
309 nprint_ene=nprint_ene-1
313 c-------------------------------------------------------------------------
315 implicit real*8 (a-h,o-z)
317 include 'COMMON.NAMES'
318 include 'COMMON.FFIELD'
320 &'DD','DAU','DAI','DDB','DSM','DPR','DLY','DAR','DHI','DAS','DGL',
321 & 'DSG','DGN','DSN','DTH',
322 &'DYY','DAL','DTY','DTR','DVA','DLE','DIL','DPN','MED','DCY','ZER',
323 &'CYS','MET','PHE','ILE','LEU','VAL','TRP','TYR','ALA','GLY','THR',
324 &'SER','GLN','ASN','GLU','ASP','HIS','ARG','LYS','PRO','SME','DBZ',
327 &'z','z','z','z','z','p','k','r','h','d','e','n','q','s','t','g',
328 &'a','y','w','v','l','i','f','m','c','x',
329 &'C','M','F','I','L','V','W','Y','A','G','T',
330 &'S','Q','N','E','D','H','R','K','P','z','z','z','z','X'/
331 data potname /'LJ','LJK','BP','GB','GBV'/
333 & "EVDW SC-SC","EVDW2 SC-p","EES p-p","ECORR4 ","ECORR5 ",
334 & "ECORR6 ","EELLO ","ETURN3 ","ETURN4 ","ETURN6 ",
335 & "EBE bend","ESC SCloc","ETORS ","ETORSD ","EHPB ","EVDWPP ",
336 & "ESTR ","EVDW2_14 ","UCONST ", " ","ESCCOR"/
338 & "WSC","WSCP","WELEC","WCORR","WCORR5","WCORR6","WEL_LOC",
339 & "WTURN3","WTURN4","WTURN6","WANG","WSCLOC","WTOR","WTORD",
340 & "WSTRAIN","WVDWPP","WBOND","SCAL14"," "," ","WSCCOR"/
342 data print_order/1,2,3,11,12,13,14,4,5,6,7,8,9,10,19,18,15,17,16,
345 c---------------------------------------------------------------------------
346 subroutine init_int_table
347 implicit real*8 (a-h,o-z)
351 integer blocklengths(15),displs(15)
353 include 'COMMON.CONTROL'
354 include 'COMMON.SETUP'
355 include 'COMMON.CHAIN'
356 include 'COMMON.INTERACT'
357 include 'COMMON.LOCAL'
358 include 'COMMON.SBRIDGE'
359 include 'COMMON.TORCNSTR'
360 include 'COMMON.IOUNITS'
361 include 'COMMON.DERIV'
362 include 'COMMON.CONTACTS'
363 common /przechowalnia/ iturn3_start_all(0:max_fg_procs),
364 & iturn3_end_all(0:max_fg_procs),iturn4_start_all(0:max_fg_procs),
365 & iturn4_end_all(0:max_fg_procs),iatel_s_all(0:max_fg_procs),
366 &iatel_e_all(0:max_fg_procs),ielstart_all(maxres,0:max_fg_procs-1),
367 & ielend_all(maxres,0:max_fg_procs-1),
368 & ntask_cont_from_all(0:max_fg_procs-1),
369 & itask_cont_from_all(0:max_fg_procs-1,0:max_fg_procs-1),
370 & ntask_cont_to_all(0:max_fg_procs-1),
371 & itask_cont_to_all(0:max_fg_procs-1,0:max_fg_procs-1)
372 integer FG_GROUP,CONT_FROM_GROUP,CONT_TO_GROUP
373 logical scheck,lprint,flag
375 integer my_sc_int(0:max_fg_Procs-1),my_sc_intt(0:max_fg_Procs),
376 & my_ele_int(0:max_fg_Procs-1),my_ele_intt(0:max_fg_Procs)
377 C... Determine the numbers of start and end SC-SC interaction
378 C... to deal with by current processor.
380 itask_cont_from(i)=fg_rank
381 itask_cont_to(i)=fg_rank
385 &write (iout,*) 'INIT_INT_TABLE nres=',nres,' nnt=',nnt,' nct=',nct
386 n_sc_int_tot=(nct-nnt+1)*(nct-nnt)/2-nss
387 call int_bounds(n_sc_int_tot,my_sc_inds,my_sc_inde)
389 & write (iout,*) 'Processor',fg_rank,' CG group',kolor,
390 & ' absolute rank',MyRank,
391 & ' n_sc_int_tot',n_sc_int_tot,' my_sc_inds=',my_sc_inds,
392 & ' my_sc_inde',my_sc_inde
412 cd write (iout,*) 'ns=',ns,' nss=',nss,' ihpb,jhpb',
413 cd & (ihpb(i),jhpb(i),i=1,nss)
418 if (ihpb(ii).eq.i+nres) then
425 cd write (iout,*) 'i=',i,' scheck=',scheck,' jj=',jj
429 c write (iout,*) 'jj=i+1'
430 call int_partition(ind_scint,my_sc_inds,my_sc_inde,i,
431 & iatsc_s,iatsc_e,i+2,nct,nint_gr(i),istart(i,1),iend(i,1),*12)
437 else if (jj.eq.nct) then
439 c write (iout,*) 'jj=nct'
440 call int_partition(ind_scint,my_sc_inds,my_sc_inde,i,
441 & iatsc_s,iatsc_e,i+1,nct-1,nint_gr(i),istart(i,1),iend(i,1),*12)
449 call int_partition(ind_scint,my_sc_inds,my_sc_inde,i,
450 & iatsc_s,iatsc_e,i+1,jj-1,nint_gr(i),istart(i,1),iend(i,1),*12)
452 call int_partition(ind_scint,my_sc_inds,my_sc_inde,i,
453 & iatsc_s,iatsc_e,jj+1,nct,nint_gr(i),istart(i,ii),iend(i,ii),*12)
464 call int_partition(ind_scint,my_sc_inds,my_sc_inde,i,
465 & iatsc_s,iatsc_e,i+1,nct,nint_gr(i),istart(i,1),iend(i,1),*12)
470 ind_scint=ind_scint+nct-i
474 ind_scint_old=ind_scint
482 if (iatsc_s.eq.0) iatsc_s=1
484 if (lprint) write (*,*) 'Processor',fg_rank,' CG Group',kolor,
485 & ' absolute rank',myrank,' iatsc_s=',iatsc_s,' iatsc_e=',iatsc_e
488 write (iout,'(a)') 'Interaction array:'
490 write (iout,'(i3,2(2x,2i3))')
491 & i,(istart(i,iint),iend(i,iint),iint=1,nint_gr(i))
496 C Now partition the electrostatic-interaction array
498 nele_int_tot=(npept-ispp)*(npept-ispp+1)/2
499 call int_bounds(nele_int_tot,my_ele_inds,my_ele_inde)
501 & write (*,*) 'Processor',fg_rank,' CG group',kolor,
502 & ' absolute rank',MyRank,
503 & ' nele_int_tot',nele_int_tot,' my_ele_inds=',my_ele_inds,
504 & ' my_ele_inde',my_ele_inde
511 call int_partition(ind_eleint,my_ele_inds,my_ele_inde,i,
512 & iatel_s,iatel_e,i+ispp,nct-1,ijunk,ielstart(i),ielend(i),*13)
515 if (iatel_s.eq.0) iatel_s=1
516 nele_int_tot_vdw=(npept-2)*(npept-2+1)/2
517 c write (iout,*) "nele_int_tot_vdw",nele_int_tot_vdw
518 call int_bounds(nele_int_tot_vdw,my_ele_inds_vdw,my_ele_inde_vdw)
519 c write (iout,*) "my_ele_inds_vdw",my_ele_inds_vdw,
520 c & " my_ele_inde_vdw",my_ele_inde_vdw
527 call int_partition(ind_eleint_vdw,my_ele_inds_vdw,
529 & iatel_s_vdw,iatel_e_vdw,i+2,nct-1,ijunk,ielstart_vdw(i),
531 c write (iout,*) i," ielstart_vdw",ielstart_vdw(i),
532 c & " ielend_vdw",ielend_vdw(i)
534 if (iatel_s_vdw.eq.0) iatel_s_vdw=1
545 do i=iatel_s_vdw,iatel_e_vdw
551 write (*,'(a)') 'Processor',fg_rank,' CG group',kolor,
552 & ' absolute rank',MyRank
553 write (iout,*) 'Electrostatic interaction array:'
555 write (iout,'(i3,2(2x,2i3))') i,ielstart(i),ielend(i)
560 C Partition the SC-p interaction array
562 nscp_int_tot=(npept-iscp+1)*(npept-iscp+1)
563 call int_bounds(nscp_int_tot,my_scp_inds,my_scp_inde)
564 if (lprint) write (iout,*) 'Processor',fg_rank,' CG group',kolor,
565 & ' absolute rank',myrank,
566 & ' nscp_int_tot',nscp_int_tot,' my_scp_inds=',my_scp_inds,
567 & ' my_scp_inde',my_scp_inde
573 if (i.lt.nnt+iscp) then
574 cd write (iout,*) 'i.le.nnt+iscp'
575 call int_partition(ind_scpint,my_scp_inds,my_scp_inde,i,
576 & iatscp_s,iatscp_e,i+iscp,nct,nscp_gr(i),iscpstart(i,1),
578 else if (i.gt.nct-iscp) then
579 cd write (iout,*) 'i.gt.nct-iscp'
580 call int_partition(ind_scpint,my_scp_inds,my_scp_inde,i,
581 & iatscp_s,iatscp_e,nnt,i-iscp,nscp_gr(i),iscpstart(i,1),
584 call int_partition(ind_scpint,my_scp_inds,my_scp_inde,i,
585 & iatscp_s,iatscp_e,nnt,i-iscp,nscp_gr(i),iscpstart(i,1),
588 call int_partition(ind_scpint,my_scp_inds,my_scp_inde,i,
589 & iatscp_s,iatscp_e,i+iscp,nct,nscp_gr(i),iscpstart(i,ii),
598 if (i.lt.nnt+iscp) then
600 iscpstart(i,1)=i+iscp
602 elseif (i.gt.nct-iscp) then
610 iscpstart(i,2)=i+iscp
615 if (iatscp_s.eq.0) iatscp_s=1
617 write (iout,'(a)') 'SC-p interaction array:'
618 do i=iatscp_s,iatscp_e
619 write (iout,'(i3,2(2x,2i3))')
620 & i,(iscpstart(i,j),iscpend(i,j),j=1,nscp_gr(i))
623 C Partition local interactions
625 call int_bounds(nres-2,loc_start,loc_end)
626 loc_start=loc_start+1
628 call int_bounds(nres-2,ithet_start,ithet_end)
629 ithet_start=ithet_start+2
630 ithet_end=ithet_end+2
631 call int_bounds(nct-nnt-2,iturn3_start,iturn3_end)
632 iturn3_start=iturn3_start+nnt
633 iphi_start=iturn3_start+2
634 iturn3_end=iturn3_end+nnt
635 iphi_end=iturn3_end+2
636 iturn3_start=iturn3_start-1
637 iturn3_end=iturn3_end-1
638 call int_bounds(nres-3,itau_start,itau_end)
639 itau_start=itau_start+3
641 call int_bounds(nres-3,iphi1_start,iphi1_end)
642 iphi1_start=iphi1_start+3
643 iphi1_end=iphi1_end+3
644 call int_bounds(nct-nnt-3,iturn4_start,iturn4_end)
645 iturn4_start=iturn4_start+nnt
646 iphid_start=iturn4_start+2
647 iturn4_end=iturn4_end+nnt
648 iphid_end=iturn4_end+2
649 iturn4_start=iturn4_start-1
650 iturn4_end=iturn4_end-1
651 call int_bounds(nres-2,ibond_start,ibond_end)
652 ibond_start=ibond_start+1
653 ibond_end=ibond_end+1
654 call int_bounds(nct-nnt,ibondp_start,ibondp_end)
655 ibondp_start=ibondp_start+nnt
656 ibondp_end=ibondp_end+nnt
657 call int_bounds(nres,ilip_start,ilip_end)
658 ilip_start=ilip_start
659 call int_bounds1(nres-1,ivec_start,ivec_end)
660 c print *,"Processor",myrank,fg_rank,fg_rank1,
661 c & " ivec_start",ivec_start," ivec_end",ivec_end
662 iset_start=loc_start+2
664 if (ndih_constr.eq.0) then
668 call int_bounds(ndih_constr,idihconstr_start,idihconstr_end)
670 if (ntheta_constr.eq.0) then
675 & (ntheta_constr,ithetaconstr_start,ithetaconstr_end)
677 c nsumgrad=(nres-nnt)*(nres-nnt+1)/2
679 nsumgrad=(nres-nnt)*(nres-nnt+1)/2
681 call int_bounds(nsumgrad,ngrad_start,ngrad_end)
682 igrad_start=((2*nlen+1)
683 & -sqrt(float((2*nlen-1)**2-8*(ngrad_start-1))))/2
684 jgrad_start(igrad_start)=
685 & ngrad_start-(2*nlen-igrad_start)*(igrad_start-1)/2
687 jgrad_end(igrad_start)=nres
688 igrad_end=((2*nlen+1)
689 & -sqrt(float((2*nlen-1)**2-8*(ngrad_end-1))))/2
690 if (igrad_end.gt.igrad_start) jgrad_start(igrad_end)=igrad_end+1
691 jgrad_end(igrad_end)=ngrad_end-(2*nlen-igrad_end)*(igrad_end-1)/2
693 do i=igrad_start+1,igrad_end-1
698 write (*,*) 'Processor:',fg_rank,' CG group',kolor,
699 & ' absolute rank',myrank,
700 & ' loc_start',loc_start,' loc_end',loc_end,
701 & ' ithet_start',ithet_start,' ithet_end',ithet_end,
702 & ' iphi_start',iphi_start,' iphi_end',iphi_end,
703 & ' iphid_start',iphid_start,' iphid_end',iphid_end,
704 & ' ibond_start',ibond_start,' ibond_end',ibond_end,
705 & ' ibondp_start',ibondp_start,' ibondp_end',ibondp_end,
706 & ' iturn3_start',iturn3_start,' iturn3_end',iturn3_end,
707 & ' iturn4_start',iturn4_start,' iturn4_end',iturn4_end,
708 & ' ivec_start',ivec_start,' ivec_end',ivec_end,
709 & ' iset_start',iset_start,' iset_end',iset_end,
710 & ' idihconstr_start',idihconstr_start,' idihconstr_end',
712 & ' ithetaconstr_start',ithetaconstr_start,' ithetaconstr_end',
715 write (*,*) 'Processor:',fg_rank,myrank,' igrad_start',
716 & igrad_start,' igrad_end',igrad_end,' ngrad_start',ngrad_start,
717 & ' ngrad_end',ngrad_end
718 do i=igrad_start,igrad_end
719 write(*,*) 'Processor:',fg_rank,myrank,i,
720 & jgrad_start(i),jgrad_end(i)
723 if (nfgtasks.gt.1) then
724 call MPI_Allgather(ivec_start,1,MPI_INTEGER,ivec_displ(0),1,
725 & MPI_INTEGER,FG_COMM1,IERROR)
726 iaux=ivec_end-ivec_start+1
727 call MPI_Allgather(iaux,1,MPI_INTEGER,ivec_count(0),1,
728 & MPI_INTEGER,FG_COMM1,IERROR)
729 call MPI_Allgather(iset_start-2,1,MPI_INTEGER,iset_displ(0),1,
730 & MPI_INTEGER,FG_COMM,IERROR)
731 iaux=iset_end-iset_start+1
732 call MPI_Allgather(iaux,1,MPI_INTEGER,iset_count(0),1,
733 & MPI_INTEGER,FG_COMM,IERROR)
734 call MPI_Allgather(ibond_start,1,MPI_INTEGER,ibond_displ(0),1,
735 & MPI_INTEGER,FG_COMM,IERROR)
736 iaux=ibond_end-ibond_start+1
737 call MPI_Allgather(iaux,1,MPI_INTEGER,ibond_count(0),1,
738 & MPI_INTEGER,FG_COMM,IERROR)
739 call MPI_Allgather(ithet_start,1,MPI_INTEGER,ithet_displ(0),1,
740 & MPI_INTEGER,FG_COMM,IERROR)
741 iaux=ithet_end-ithet_start+1
742 call MPI_Allgather(iaux,1,MPI_INTEGER,ithet_count(0),1,
743 & MPI_INTEGER,FG_COMM,IERROR)
744 call MPI_Allgather(iphi_start,1,MPI_INTEGER,iphi_displ(0),1,
745 & MPI_INTEGER,FG_COMM,IERROR)
746 iaux=iphi_end-iphi_start+1
747 call MPI_Allgather(iaux,1,MPI_INTEGER,iphi_count(0),1,
748 & MPI_INTEGER,FG_COMM,IERROR)
749 call MPI_Allgather(iphi1_start,1,MPI_INTEGER,iphi1_displ(0),1,
750 & MPI_INTEGER,FG_COMM,IERROR)
751 iaux=iphi1_end-iphi1_start+1
752 call MPI_Allgather(iaux,1,MPI_INTEGER,iphi1_count(0),1,
753 & MPI_INTEGER,FG_COMM,IERROR)
760 call MPI_Allgather(iturn3_start,1,MPI_INTEGER,
761 & iturn3_start_all(0),1,MPI_INTEGER,FG_COMM,IERROR)
762 call MPI_Allgather(iturn4_start,1,MPI_INTEGER,
763 & iturn4_start_all(0),1,MPI_INTEGER,FG_COMM,IERROR)
764 call MPI_Allgather(iturn3_end,1,MPI_INTEGER,
765 & iturn3_end_all(0),1,MPI_INTEGER,FG_COMM,IERROR)
766 call MPI_Allgather(iturn4_end,1,MPI_INTEGER,
767 & iturn4_end_all(0),1,MPI_INTEGER,FG_COMM,IERROR)
768 call MPI_Allgather(iatel_s,1,MPI_INTEGER,
769 & iatel_s_all(0),1,MPI_INTEGER,FG_COMM,IERROR)
770 call MPI_Allgather(iatel_e,1,MPI_INTEGER,
771 & iatel_e_all(0),1,MPI_INTEGER,FG_COMM,IERROR)
772 call MPI_Allgather(ielstart(1),maxres,MPI_INTEGER,
773 & ielstart_all(1,0),maxres,MPI_INTEGER,FG_COMM,IERROR)
774 call MPI_Allgather(ielend(1),maxres,MPI_INTEGER,
775 & ielend_all(1,0),maxres,MPI_INTEGER,FG_COMM,IERROR)
777 write (iout,*) "iatel_s_all",(iatel_s_all(i),i=0,nfgtasks)
778 write (iout,*) "iatel_e_all",(iatel_e_all(i),i=0,nfgtasks)
779 write (iout,*) "iturn3_start_all",
780 & (iturn3_start_all(i),i=0,nfgtasks-1)
781 write (iout,*) "iturn3_end_all",
782 & (iturn3_end_all(i),i=0,nfgtasks-1)
783 write (iout,*) "iturn4_start_all",
784 & (iturn4_start_all(i),i=0,nfgtasks-1)
785 write (iout,*) "iturn4_end_all",
786 & (iturn4_end_all(i),i=0,nfgtasks-1)
787 write (iout,*) "The ielstart_all array"
789 write (iout,'(20i4)') i,(ielstart_all(i,j),j=0,nfgtasks-1)
791 write (iout,*) "The ielend_all array"
793 write (iout,'(20i4)') i,(ielend_all(i,j),j=0,nfgtasks-1)
799 itask_cont_from(0)=fg_rank
800 itask_cont_to(0)=fg_rank
802 do ii=iturn3_start,iturn3_end
803 call add_int(ii,ii+2,iturn3_sent(1,ii),
804 & ntask_cont_to,itask_cont_to,flag)
806 do ii=iturn4_start,iturn4_end
807 call add_int(ii,ii+3,iturn4_sent(1,ii),
808 & ntask_cont_to,itask_cont_to,flag)
810 do ii=iturn3_start,iturn3_end
811 call add_int_from(ii,ii+2,ntask_cont_from,itask_cont_from)
813 do ii=iturn4_start,iturn4_end
814 call add_int_from(ii,ii+3,ntask_cont_from,itask_cont_from)
817 write (iout,*) "After turn3 ntask_cont_from",ntask_cont_from,
818 & " ntask_cont_to",ntask_cont_to
819 write (iout,*) "itask_cont_from",
820 & (itask_cont_from(i),i=1,ntask_cont_from)
821 write (iout,*) "itask_cont_to",
822 & (itask_cont_to(i),i=1,ntask_cont_to)
825 c write (iout,*) "Loop forward"
828 c write (iout,*) "from loop i=",i
830 do j=ielstart(i),ielend(i)
831 call add_int_from(i,j,ntask_cont_from,itask_cont_from)
834 c write (iout,*) "Loop backward iatel_e-1",iatel_e-1,
835 c & " iatel_e",iatel_e
839 c write (iout,*) "i",i," ielstart",ielstart(i),
840 c & " ielend",ielend(i)
843 do j=ielstart(i),ielend(i)
844 call add_int(i,j,iint_sent(1,j,nat_sent+1),ntask_cont_to,
845 & itask_cont_to,flag)
853 write (iout,*)"After longrange ntask_cont_from",ntask_cont_from,
854 & " ntask_cont_to",ntask_cont_to
855 write (iout,*) "itask_cont_from",
856 & (itask_cont_from(i),i=1,ntask_cont_from)
857 write (iout,*) "itask_cont_to",
858 & (itask_cont_to(i),i=1,ntask_cont_to)
860 write (iout,*) "iint_sent"
863 write (iout,'(20i4)') ii,(j,(iint_sent(k,j,i),k=1,4),
864 & j=ielstart(ii),ielend(ii))
866 write (iout,*) "iturn3_sent iturn3_start",iturn3_start,
867 & " iturn3_end",iturn3_end
868 write (iout,'(20i4)') (i,(iturn3_sent(j,i),j=1,4),
869 & i=iturn3_start,iturn3_end)
870 write (iout,*) "iturn4_sent iturn4_start",iturn4_start,
871 & " iturn4_end",iturn4_end
872 write (iout,'(20i4)') (i,(iturn4_sent(j,i),j=1,4),
873 & i=iturn4_start,iturn4_end)
876 call MPI_Gather(ntask_cont_from,1,MPI_INTEGER,
877 & ntask_cont_from_all,1,MPI_INTEGER,king,FG_COMM,IERR)
878 c write (iout,*) "Gather ntask_cont_from ended"
880 call MPI_Gather(itask_cont_from(0),max_fg_procs,MPI_INTEGER,
881 & itask_cont_from_all(0,0),max_fg_procs,MPI_INTEGER,king,
883 c write (iout,*) "Gather itask_cont_from ended"
885 call MPI_Gather(ntask_cont_to,1,MPI_INTEGER,ntask_cont_to_all,
886 & 1,MPI_INTEGER,king,FG_COMM,IERR)
887 c write (iout,*) "Gather ntask_cont_to ended"
889 call MPI_Gather(itask_cont_to,max_fg_procs,MPI_INTEGER,
890 & itask_cont_to_all,max_fg_procs,MPI_INTEGER,king,FG_COMM,IERR)
891 c write (iout,*) "Gather itask_cont_to ended"
893 if (fg_rank.eq.king) then
894 write (iout,*)"Contact receive task map (proc, #tasks, tasks)"
896 write (iout,'(20i4)') i,ntask_cont_from_all(i),
897 & (itask_cont_from_all(j,i),j=1,ntask_cont_from_all(i))
901 write (iout,*) "Contact send task map (proc, #tasks, tasks)"
903 write (iout,'(20i4)') i,ntask_cont_to_all(i),
904 & (itask_cont_to_all(j,i),j=1,ntask_cont_to_all(i))
908 C Check if every send will have a matching receive
912 ncheck_to=ncheck_to+ntask_cont_to_all(i)
913 ncheck_from=ncheck_from+ntask_cont_from_all(i)
915 write (iout,*) "Control sums",ncheck_from,ncheck_to
916 if (ncheck_from.ne.ncheck_to) then
917 write (iout,*) "Error: #receive differs from #send."
918 write (iout,*) "Terminating program...!"
924 do j=1,ntask_cont_to_all(i)
925 ii=itask_cont_to_all(j,i)
926 do k=1,ntask_cont_from_all(ii)
927 if (itask_cont_from_all(k,ii).eq.i) then
928 if(lprint)write(iout,*)"Matching send/receive",i,ii
932 if (k.eq.ntask_cont_from_all(ii)+1) then
934 write (iout,*) "Error: send by",j," to",ii,
935 & " would have no matching receive"
941 write (iout,*) "Unmatched sends; terminating program"
945 call MPI_Bcast(flag,1,MPI_LOGICAL,king,FG_COMM,IERROR)
946 c write (iout,*) "flag broadcast ended flag=",flag
949 call MPI_Finalize(IERROR)
950 stop "Error in INIT_INT_TABLE: unmatched send/receive."
952 call MPI_Comm_group(FG_COMM,fg_group,IERR)
953 c write (iout,*) "MPI_Comm_group ended"
955 call MPI_Group_incl(fg_group,ntask_cont_from+1,
956 & itask_cont_from(0),CONT_FROM_GROUP,IERR)
957 call MPI_Group_incl(fg_group,ntask_cont_to+1,itask_cont_to(0),
958 & CONT_TO_GROUP,IERR)
961 iaux=4*(ielend(ii)-ielstart(ii)+1)
962 call MPI_Group_translate_ranks(fg_group,iaux,
963 & iint_sent(1,ielstart(ii),i),CONT_TO_GROUP,
964 & iint_sent_local(1,ielstart(ii),i),IERR )
965 c write (iout,*) "Ranks translated i=",i
968 iaux=4*(iturn3_end-iturn3_start+1)
969 call MPI_Group_translate_ranks(fg_group,iaux,
970 & iturn3_sent(1,iturn3_start),CONT_TO_GROUP,
971 & iturn3_sent_local(1,iturn3_start),IERR)
972 iaux=4*(iturn4_end-iturn4_start+1)
973 call MPI_Group_translate_ranks(fg_group,iaux,
974 & iturn4_sent(1,iturn4_start),CONT_TO_GROUP,
975 & iturn4_sent_local(1,iturn4_start),IERR)
977 write (iout,*) "iint_sent_local"
980 write (iout,'(20i4)') ii,(j,(iint_sent_local(k,j,i),k=1,4),
981 & j=ielstart(ii),ielend(ii))
984 write (iout,*) "iturn3_sent_local iturn3_start",iturn3_start,
985 & " iturn3_end",iturn3_end
986 write (iout,'(20i4)') (i,(iturn3_sent_local(j,i),j=1,4),
987 & i=iturn3_start,iturn3_end)
988 write (iout,*) "iturn4_sent_local iturn4_start",iturn4_start,
989 & " iturn4_end",iturn4_end
990 write (iout,'(20i4)') (i,(iturn4_sent_local(j,i),j=1,4),
991 & i=iturn4_start,iturn4_end)
994 call MPI_Group_free(fg_group,ierr)
995 call MPI_Group_free(cont_from_group,ierr)
996 call MPI_Group_free(cont_to_group,ierr)
997 call MPI_Type_contiguous(3,MPI_DOUBLE_PRECISION,MPI_UYZ,IERROR)
998 call MPI_Type_commit(MPI_UYZ,IERROR)
999 call MPI_Type_contiguous(18,MPI_DOUBLE_PRECISION,MPI_UYZGRAD,
1001 call MPI_Type_commit(MPI_UYZGRAD,IERROR)
1002 call MPI_Type_contiguous(2,MPI_DOUBLE_PRECISION,MPI_MU,IERROR)
1003 call MPI_Type_commit(MPI_MU,IERROR)
1004 call MPI_Type_contiguous(4,MPI_DOUBLE_PRECISION,MPI_MAT1,IERROR)
1005 call MPI_Type_commit(MPI_MAT1,IERROR)
1006 call MPI_Type_contiguous(8,MPI_DOUBLE_PRECISION,MPI_MAT2,IERROR)
1007 call MPI_Type_commit(MPI_MAT2,IERROR)
1008 call MPI_Type_contiguous(6,MPI_DOUBLE_PRECISION,MPI_THET,IERROR)
1009 call MPI_Type_commit(MPI_THET,IERROR)
1010 call MPI_Type_contiguous(9,MPI_DOUBLE_PRECISION,MPI_GAM,IERROR)
1011 call MPI_Type_commit(MPI_GAM,IERROR)
1013 c 9/22/08 Derived types to send matrices which appear in correlation terms
1015 if (ivec_count(i).eq.ivec_count(0)) then
1021 do ind_typ=lentyp(0),lentyp(nfgtasks-1)
1022 if (ind_typ.eq.0) then
1023 ichunk=ivec_count(0)
1025 ichunk=ivec_count(1)
1032 c displs(i)=displs(i-1)+blocklengths(i-1)*maxres
1035 c blocklengths(i)=blocklengths(i)*ichunk
1037 c write (iout,*) "blocklengths and displs"
1039 c write (iout,*) i,blocklengths(i),displs(i)
1042 c call MPI_Type_indexed(4,blocklengths(1),displs(1),
1043 c & MPI_DOUBLE_PRECISION,MPI_ROTAT1(ind_typ),IERROR)
1044 c call MPI_Type_commit(MPI_ROTAT1(ind_typ),IERROR)
1045 c write (iout,*) "MPI_ROTAT1",MPI_ROTAT1
1051 c displs(i)=displs(i-1)+blocklengths(i-1)*maxres
1054 c blocklengths(i)=blocklengths(i)*ichunk
1056 c write (iout,*) "blocklengths and displs"
1058 c write (iout,*) i,blocklengths(i),displs(i)
1061 c call MPI_Type_indexed(4,blocklengths(1),displs(1),
1062 c & MPI_DOUBLE_PRECISION,MPI_ROTAT2(ind_typ),IERROR)
1063 c call MPI_Type_commit(MPI_ROTAT2(ind_typ),IERROR)
1064 c write (iout,*) "MPI_ROTAT2",MPI_ROTAT2
1070 displs(i)=displs(i-1)+blocklengths(i-1)*maxres
1073 blocklengths(i)=blocklengths(i)*ichunk
1075 call MPI_Type_indexed(8,blocklengths,displs,
1076 & MPI_DOUBLE_PRECISION,MPI_PRECOMP11(ind_typ),IERROR)
1077 call MPI_Type_commit(MPI_PRECOMP11(ind_typ),IERROR)
1083 displs(i)=displs(i-1)+blocklengths(i-1)*maxres
1086 blocklengths(i)=blocklengths(i)*ichunk
1088 call MPI_Type_indexed(8,blocklengths,displs,
1089 & MPI_DOUBLE_PRECISION,MPI_PRECOMP12(ind_typ),IERROR)
1090 call MPI_Type_commit(MPI_PRECOMP12(ind_typ),IERROR)
1096 displs(i)=displs(i-1)+blocklengths(i-1)*maxres
1099 blocklengths(i)=blocklengths(i)*ichunk
1101 call MPI_Type_indexed(6,blocklengths,displs,
1102 & MPI_DOUBLE_PRECISION,MPI_PRECOMP22(ind_typ),IERROR)
1103 call MPI_Type_commit(MPI_PRECOMP22(ind_typ),IERROR)
1109 displs(i)=displs(i-1)+blocklengths(i-1)*maxres
1112 blocklengths(i)=blocklengths(i)*ichunk
1114 call MPI_Type_indexed(2,blocklengths,displs,
1115 & MPI_DOUBLE_PRECISION,MPI_PRECOMP23(ind_typ),IERROR)
1116 call MPI_Type_commit(MPI_PRECOMP23(ind_typ),IERROR)
1122 displs(i)=displs(i-1)+blocklengths(i-1)*maxres
1125 blocklengths(i)=blocklengths(i)*ichunk
1127 call MPI_Type_indexed(4,blocklengths,displs,
1128 & MPI_DOUBLE_PRECISION,MPI_ROTAT_OLD(ind_typ),IERROR)
1129 call MPI_Type_commit(MPI_ROTAT_OLD(ind_typ),IERROR)
1133 iint_start=ivec_start+1
1136 iint_count(i)=ivec_count(i)
1137 iint_displ(i)=ivec_displ(i)
1138 ivec_displ(i)=ivec_displ(i)-1
1139 iset_displ(i)=iset_displ(i)-1
1140 ithet_displ(i)=ithet_displ(i)-1
1141 iphi_displ(i)=iphi_displ(i)-1
1142 iphi1_displ(i)=iphi1_displ(i)-1
1143 ibond_displ(i)=ibond_displ(i)-1
1145 if (nfgtasks.gt.1 .and. fg_rank.eq.king
1146 & .and. (me.eq.0 .or. .not. out1file)) then
1147 write (iout,*) "IVEC_DISPL, IVEC_COUNT, ISET_START, ISET_COUNT"
1149 write (iout,*) i,ivec_displ(i),ivec_count(i),iset_displ(i),
1152 write (iout,*) "iphi_start",iphi_start," iphi_end",iphi_end,
1153 & " iphi1_start",iphi1_start," iphi1_end",iphi1_end
1154 write (iout,*)"IPHI_COUNT, IPHI_DISPL, IPHI1_COUNT, IPHI1_DISPL"
1156 write (iout,*) i,iphi_count(i),iphi_displ(i),iphi1_count(i),
1159 write(iout,'(i10,a,i10,a,i10,a/a,i3,a)') n_sc_int_tot,' SC-SC ',
1160 & nele_int_tot,' electrostatic and ',nscp_int_tot,
1161 & ' SC-p interactions','were distributed among',nfgtasks,
1162 & ' fine-grain processors.'
1178 idihconstr_end=ndih_constr
1179 ithetaconstr_start=1
1180 ithetaconstr_end=ntheta_constr
1181 iphid_start=iphi_start
1182 iphid_end=iphi_end-1
1202 c---------------------------------------------------------------------------
1203 subroutine add_int(ii,jj,itask,ntask_cont_to,itask_cont_to,flag)
1205 include "DIMENSIONS"
1206 include "COMMON.INTERACT"
1207 include "COMMON.SETUP"
1208 include "COMMON.IOUNITS"
1209 integer ii,jj,itask(4),ntask_cont_to,
1210 &itask_cont_to(0:max_fg_procs-1)
1212 integer iturn3_start_all,iturn3_end_all,iturn4_start_all,
1213 & iturn4_end_all,iatel_s_all,iatel_e_all,ielstart_all,ielend_all
1214 common /przechowalnia/ iturn3_start_all(0:max_fg_procs),
1215 & iturn3_end_all(0:max_fg_procs),iturn4_start_all(0:max_fg_procs),
1216 & iturn4_end_all(0:max_fg_procs),iatel_s_all(0:max_fg_procs),
1217 &iatel_e_all(0:max_fg_procs),ielstart_all(maxres,0:max_fg_procs-1),
1218 & ielend_all(maxres,0:max_fg_procs-1)
1219 integer iproc,isent,k,l
1220 c Determines whether to send interaction ii,jj to other processors; a given
1221 c interaction can be sent to at most 2 processors.
1222 c Sets flag=.true. if interaction ii,jj needs to be sent to at least
1223 c one processor, otherwise flag is unchanged from the input value.
1229 c write (iout,*) "ii",ii," jj",jj
1230 c Loop over processors to check if anybody could need interaction ii,jj
1231 do iproc=0,fg_rank-1
1232 c Check if the interaction matches any turn3 at iproc
1233 do k=iturn3_start_all(iproc),iturn3_end_all(iproc)
1235 if (k.eq.ii-1 .and. l.eq.jj-1 .or. k.eq.ii-1 .and. l.eq.jj+1
1236 & .or. k.eq.ii+1 .and. l.eq.jj+1 .or. k.eq.ii+1 .and. l.eq.jj-1)
1238 c write (iout,*) "turn3 to iproc",iproc," ij",ii,jj,"kl",k,l
1241 if (iproc.ne.itask(1).and.iproc.ne.itask(2)
1242 & .and.iproc.ne.itask(3).and.iproc.ne.itask(4)) then
1245 call add_task(iproc,ntask_cont_to,itask_cont_to)
1249 C Check if the interaction matches any turn4 at iproc
1250 do k=iturn4_start_all(iproc),iturn4_end_all(iproc)
1252 if (k.eq.ii-1 .and. l.eq.jj-1 .or. k.eq.ii-1 .and. l.eq.jj+1
1253 & .or. k.eq.ii+1 .and. l.eq.jj+1 .or. k.eq.ii+1 .and. l.eq.jj-1)
1255 c write (iout,*) "turn3 to iproc",iproc," ij",ii,jj," kl",k,l
1258 if (iproc.ne.itask(1).and.iproc.ne.itask(2)
1259 & .and.iproc.ne.itask(3).and.iproc.ne.itask(4)) then
1262 call add_task(iproc,ntask_cont_to,itask_cont_to)
1266 if (iatel_s_all(iproc).gt.0 .and. iatel_e_all(iproc).gt.0 .and.
1267 & iatel_s_all(iproc).le.ii-1 .and. iatel_e_all(iproc).ge.ii-1)then
1268 if (ielstart_all(ii-1,iproc).le.jj-1.and.
1269 & ielend_all(ii-1,iproc).ge.jj-1) then
1271 if (iproc.ne.itask(1).and.iproc.ne.itask(2)
1272 & .and.iproc.ne.itask(3).and.iproc.ne.itask(4)) then
1275 call add_task(iproc,ntask_cont_to,itask_cont_to)
1278 if (ielstart_all(ii-1,iproc).le.jj+1.and.
1279 & ielend_all(ii-1,iproc).ge.jj+1) then
1281 if (iproc.ne.itask(1).and.iproc.ne.itask(2)
1282 & .and.iproc.ne.itask(3).and.iproc.ne.itask(4)) then
1285 call add_task(iproc,ntask_cont_to,itask_cont_to)
1292 c---------------------------------------------------------------------------
1293 subroutine add_int_from(ii,jj,ntask_cont_from,itask_cont_from)
1295 include "DIMENSIONS"
1296 include "COMMON.INTERACT"
1297 include "COMMON.SETUP"
1298 include "COMMON.IOUNITS"
1299 integer ii,jj,itask(2),ntask_cont_from,
1300 & itask_cont_from(0:max_fg_procs-1)
1302 integer iturn3_start_all,iturn3_end_all,iturn4_start_all,
1303 & iturn4_end_all,iatel_s_all,iatel_e_all,ielstart_all,ielend_all
1304 common /przechowalnia/ iturn3_start_all(0:max_fg_procs),
1305 & iturn3_end_all(0:max_fg_procs),iturn4_start_all(0:max_fg_procs),
1306 & iturn4_end_all(0:max_fg_procs),iatel_s_all(0:max_fg_procs),
1307 &iatel_e_all(0:max_fg_procs),ielstart_all(maxres,0:max_fg_procs-1),
1308 & ielend_all(maxres,0:max_fg_procs-1)
1310 do iproc=fg_rank+1,nfgtasks-1
1311 do k=iturn3_start_all(iproc),iturn3_end_all(iproc)
1313 if (k.eq.ii+1 .and. l.eq.jj+1 .or. k.eq.ii+1.and.l.eq.jj-1
1314 & .or. k.eq.ii-1 .and. l.eq.jj-1 .or. k.eq.ii-1 .and. l.eq.jj+1)
1316 c write (iout,*)"turn3 from iproc",iproc," ij",ii,jj," kl",k,l
1317 call add_task(iproc,ntask_cont_from,itask_cont_from)
1320 do k=iturn4_start_all(iproc),iturn4_end_all(iproc)
1322 if (k.eq.ii+1 .and. l.eq.jj+1 .or. k.eq.ii+1.and.l.eq.jj-1
1323 & .or. k.eq.ii-1 .and. l.eq.jj-1 .or. k.eq.ii-1 .and. l.eq.jj+1)
1325 c write (iout,*)"turn4 from iproc",iproc," ij",ii,jj," kl",k,l
1326 call add_task(iproc,ntask_cont_from,itask_cont_from)
1329 if (iatel_s_all(iproc).gt.0 .and. iatel_e_all(iproc).gt.0) then
1330 if (ii+1.ge.iatel_s_all(iproc).and.ii+1.le.iatel_e_all(iproc))
1332 if (jj+1.ge.ielstart_all(ii+1,iproc).and.
1333 & jj+1.le.ielend_all(ii+1,iproc)) then
1334 call add_task(iproc,ntask_cont_from,itask_cont_from)
1336 if (jj-1.ge.ielstart_all(ii+1,iproc).and.
1337 & jj-1.le.ielend_all(ii+1,iproc)) then
1338 call add_task(iproc,ntask_cont_from,itask_cont_from)
1341 if (ii-1.ge.iatel_s_all(iproc).and.ii-1.le.iatel_e_all(iproc))
1343 if (jj-1.ge.ielstart_all(ii-1,iproc).and.
1344 & jj-1.le.ielend_all(ii-1,iproc)) then
1345 call add_task(iproc,ntask_cont_from,itask_cont_from)
1347 if (jj+1.ge.ielstart_all(ii-1,iproc).and.
1348 & jj+1.le.ielend_all(ii-1,iproc)) then
1349 call add_task(iproc,ntask_cont_from,itask_cont_from)
1356 c---------------------------------------------------------------------------
1357 subroutine add_task(iproc,ntask_cont,itask_cont)
1359 include "DIMENSIONS"
1360 integer iproc,ntask_cont,itask_cont(0:max_fg_procs-1)
1363 if (itask_cont(ii).eq.iproc) return
1365 ntask_cont=ntask_cont+1
1366 itask_cont(ntask_cont)=iproc
1369 c---------------------------------------------------------------------------
1370 subroutine int_bounds(total_ints,lower_bound,upper_bound)
1371 implicit real*8 (a-h,o-z)
1372 include 'DIMENSIONS'
1374 include 'COMMON.SETUP'
1375 integer total_ints,lower_bound,upper_bound
1376 integer int4proc(0:max_fg_procs),sint4proc(0:max_fg_procs)
1377 nint=total_ints/nfgtasks
1381 nexcess=total_ints-nint*nfgtasks
1383 int4proc(nfgtasks-i)=int4proc(nfgtasks-i)+1
1387 lower_bound=lower_bound+int4proc(i)
1389 upper_bound=lower_bound+int4proc(fg_rank)
1390 lower_bound=lower_bound+1
1393 c---------------------------------------------------------------------------
1394 subroutine int_bounds1(total_ints,lower_bound,upper_bound)
1395 implicit real*8 (a-h,o-z)
1396 include 'DIMENSIONS'
1398 include 'COMMON.SETUP'
1399 integer total_ints,lower_bound,upper_bound
1400 integer int4proc(0:max_fg_procs),sint4proc(0:max_fg_procs)
1401 nint=total_ints/nfgtasks1
1405 nexcess=total_ints-nint*nfgtasks1
1407 int4proc(nfgtasks1-i)=int4proc(nfgtasks1-i)+1
1411 lower_bound=lower_bound+int4proc(i)
1413 upper_bound=lower_bound+int4proc(fg_rank1)
1414 lower_bound=lower_bound+1
1417 c---------------------------------------------------------------------------
1418 subroutine int_partition(int_index,lower_index,upper_index,atom,
1419 & at_start,at_end,first_atom,last_atom,int_gr,jat_start,jat_end,*)
1420 implicit real*8 (a-h,o-z)
1421 include 'DIMENSIONS'
1422 include 'COMMON.IOUNITS'
1423 integer int_index,lower_index,upper_index,atom,at_start,at_end,
1424 & first_atom,last_atom,int_gr,jat_start,jat_end
1427 if (lprn) write (iout,*) 'int_index=',int_index
1428 int_index_old=int_index
1429 int_index=int_index+last_atom-first_atom+1
1431 & write (iout,*) 'int_index=',int_index,
1432 & ' int_index_old',int_index_old,
1433 & ' lower_index=',lower_index,
1434 & ' upper_index=',upper_index,
1435 & ' atom=',atom,' first_atom=',first_atom,
1436 & ' last_atom=',last_atom
1437 if (int_index.ge.lower_index) then
1439 if (at_start.eq.0) then
1441 jat_start=first_atom-1+lower_index-int_index_old
1443 jat_start=first_atom
1445 if (lprn) write (iout,*) 'jat_start',jat_start
1446 if (int_index.ge.upper_index) then
1448 jat_end=first_atom-1+upper_index-int_index_old
1453 if (lprn) write (iout,*) 'jat_end',jat_end
1458 c------------------------------------------------------------------------------
1459 subroutine hpb_partition
1460 implicit real*8 (a-h,o-z)
1461 include 'DIMENSIONS'
1465 include 'COMMON.SBRIDGE'
1466 include 'COMMON.IOUNITS'
1467 include 'COMMON.SETUP'
1469 call int_bounds(nhpb,link_start,link_end)
1470 write (iout,*) 'Processor',fg_rank,' CG group',kolor,
1471 & ' absolute rank',MyRank,
1472 & ' nhpb',nhpb,' link_start=',link_start,
1473 & ' link_end',link_end