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
124 C Lipidic input file for parameters range 60-79
126 C input file for transfer sidechain and peptide group inside the
127 C lipidic environment if lipid is implicite
129 C DNA input files for parameters range 80-99
130 C Suger input files for parameters range 100-119
131 C All-atom input files for parameters range 120-149
133 C Set default weights of the energy terms.
144 c print '(a,$)','Inside initialize'
145 c call memmon_print_usage()
180 athet(j,i,ichir1,ichir2)=0.0D0
181 bthet(j,i,ichir1,ichir2)=0.0D0
201 gaussc(l,k,j,i)=0.0D0
211 cc write (iout,*) "TU DOCHODZE",i,itortyp(i)
215 v1(k,j,i,iblock)=0.0D0
216 v2(k,j,i,iblock)=0.0D0
226 v1c(1,l,i,j,k,iblock)=0.0D0
227 v1s(1,l,i,j,k,iblock)=0.0D0
228 v1c(2,l,i,j,k,iblock)=0.0D0
229 v1s(2,l,i,j,k,iblock)=0.0D0
233 v2c(m,l,i,j,k,iblock)=0.0D0
234 v2s(m,l,i,j,k,iblock)=0.0D0
246 C Initialize the bridge arrays
260 C Initialize correlation arrays
291 C Initialize variables used in minimization.
300 C Initialize the variables responsible for the mode of gradient storage.
305 C Initialize constants used to split the energy into long- and short-range
311 nprint_ene=nprint_ene-1
315 c-------------------------------------------------------------------------
317 implicit real*8 (a-h,o-z)
319 include 'COMMON.NAMES'
320 include 'COMMON.FFIELD'
322 &'DD','DAU','DAI','DDB','DSM','DPR','DLY','DAR','DHI','DAS','DGL',
323 & 'DSG','DGN','DSN','DTH',
324 &'DYY','DAL','DTY','DTR','DVA','DLE','DIL','DPN','MED','DCY','ZER',
325 &'CYS','MET','PHE','ILE','LEU','VAL','TRP','TYR','ALA','GLY','THR',
326 &'SER','GLN','ASN','GLU','ASP','HIS','ARG','LYS','PRO','SME','DBZ',
329 &'z','z','z','z','z','p','k','r','h','d','e','n','q','s','t','g',
330 &'a','y','w','v','l','i','f','m','c','x',
331 &'C','M','F','I','L','V','W','Y','A','G','T',
332 &'S','Q','N','E','D','H','R','K','P','z','z','z','z','X'/
333 data potname /'LJ','LJK','BP','GB','GBV'/
335 & "EVDW SC-SC","EVDW2 SC-p","EES p-p","ECORR4 ","ECORR5 ",
336 & "ECORR6 ","EELLO ","ETURN3 ","ETURN4 ","ETURN6 ",
337 & "EBE bend","ESC SCloc","ETORS ","ETORSD ","EHPB ","EVDWPP ",
338 & "ESTR ","EVDW2_14 ","UCONST ", " ","ESCCOR",
339 & "ELIPTRAN", "EAFM", "ETHETCNSTR", " "/
341 & "WSC","WSCP","WELEC","WCORR","WCORR5","WCORR6","WEL_LOC",
342 & "WTURN3","WTURN4","WTURN6","WANG","WSCLOC","WTOR","WTORD",
343 & "WSTRAIN","WVDWPP","WBOND","SCAL14"," "," ","WSCCOR",
344 & "WLT", "WAFM", "WTHETCNSR", " "/
346 data print_order/1,2,3,11,12,13,14,4,5,6,7,8,9,10,19,18,15,17,16,
349 c---------------------------------------------------------------------------
350 subroutine init_int_table
351 implicit real*8 (a-h,o-z)
355 integer blocklengths(15),displs(15)
357 include 'COMMON.CONTROL'
358 include 'COMMON.SETUP'
359 include 'COMMON.CHAIN'
360 include 'COMMON.INTERACT'
361 include 'COMMON.LOCAL'
362 include 'COMMON.SBRIDGE'
363 include 'COMMON.TORCNSTR'
364 include 'COMMON.IOUNITS'
365 include 'COMMON.DERIV'
366 include 'COMMON.CONTACTS'
367 common /przechowalnia/ iturn3_start_all(0:max_fg_procs),
368 & iturn3_end_all(0:max_fg_procs),iturn4_start_all(0:max_fg_procs),
369 & iturn4_end_all(0:max_fg_procs),iatel_s_all(0:max_fg_procs),
370 &iatel_e_all(0:max_fg_procs),ielstart_all(maxres,0:max_fg_procs-1),
371 & ielend_all(maxres,0:max_fg_procs-1),
372 & ntask_cont_from_all(0:max_fg_procs-1),
373 & itask_cont_from_all(0:max_fg_procs-1,0:max_fg_procs-1),
374 & ntask_cont_to_all(0:max_fg_procs-1),
375 & itask_cont_to_all(0:max_fg_procs-1,0:max_fg_procs-1)
376 integer FG_GROUP,CONT_FROM_GROUP,CONT_TO_GROUP
377 logical scheck,lprint,flag
379 integer my_sc_int(0:max_fg_Procs-1),my_sc_intt(0:max_fg_Procs),
380 & my_ele_int(0:max_fg_Procs-1),my_ele_intt(0:max_fg_Procs)
381 C... Determine the numbers of start and end SC-SC interaction
382 C... to deal with by current processor.
384 itask_cont_from(i)=fg_rank
385 itask_cont_to(i)=fg_rank
389 &write (iout,*) 'INIT_INT_TABLE nres=',nres,' nnt=',nnt,' nct=',nct
390 n_sc_int_tot=(nct-nnt+1)*(nct-nnt)/2-nss
391 call int_bounds(n_sc_int_tot,my_sc_inds,my_sc_inde)
393 & write (iout,*) 'Processor',fg_rank,' CG group',kolor,
394 & ' absolute rank',MyRank,
395 & ' n_sc_int_tot',n_sc_int_tot,' my_sc_inds=',my_sc_inds,
396 & ' my_sc_inde',my_sc_inde
416 cd write (iout,*) 'ns=',ns,' nss=',nss,' ihpb,jhpb',
417 cd & (ihpb(i),jhpb(i),i=1,nss)
422 if (ihpb(ii).eq.i+nres) then
429 cd write (iout,*) 'i=',i,' scheck=',scheck,' jj=',jj
433 c write (iout,*) 'jj=i+1'
434 call int_partition(ind_scint,my_sc_inds,my_sc_inde,i,
435 & iatsc_s,iatsc_e,i+2,nct,nint_gr(i),istart(i,1),iend(i,1),*12)
441 else if (jj.eq.nct) then
443 c write (iout,*) 'jj=nct'
444 call int_partition(ind_scint,my_sc_inds,my_sc_inde,i,
445 & iatsc_s,iatsc_e,i+1,nct-1,nint_gr(i),istart(i,1),iend(i,1),*12)
453 call int_partition(ind_scint,my_sc_inds,my_sc_inde,i,
454 & iatsc_s,iatsc_e,i+1,jj-1,nint_gr(i),istart(i,1),iend(i,1),*12)
456 call int_partition(ind_scint,my_sc_inds,my_sc_inde,i,
457 & iatsc_s,iatsc_e,jj+1,nct,nint_gr(i),istart(i,ii),iend(i,ii),*12)
468 call int_partition(ind_scint,my_sc_inds,my_sc_inde,i,
469 & iatsc_s,iatsc_e,i+1,nct,nint_gr(i),istart(i,1),iend(i,1),*12)
474 ind_scint=ind_scint+nct-i
478 ind_scint_old=ind_scint
486 if (iatsc_s.eq.0) iatsc_s=1
488 if (lprint) write (*,*) 'Processor',fg_rank,' CG Group',kolor,
489 & ' absolute rank',myrank,' iatsc_s=',iatsc_s,' iatsc_e=',iatsc_e
492 write (iout,'(a)') 'Interaction array:'
494 write (iout,'(i3,2(2x,2i3))')
495 & i,(istart(i,iint),iend(i,iint),iint=1,nint_gr(i))
500 C Now partition the electrostatic-interaction array
502 nele_int_tot=(npept-ispp)*(npept-ispp+1)/2
503 call int_bounds(nele_int_tot,my_ele_inds,my_ele_inde)
505 & write (*,*) 'Processor',fg_rank,' CG group',kolor,
506 & ' absolute rank',MyRank,
507 & ' nele_int_tot',nele_int_tot,' my_ele_inds=',my_ele_inds,
508 & ' my_ele_inde',my_ele_inde
515 call int_partition(ind_eleint,my_ele_inds,my_ele_inde,i,
516 & iatel_s,iatel_e,i+ispp,nct-1,ijunk,ielstart(i),ielend(i),*13)
519 if (iatel_s.eq.0) iatel_s=1
520 nele_int_tot_vdw=(npept-2)*(npept-2+1)/2
521 c write (iout,*) "nele_int_tot_vdw",nele_int_tot_vdw
522 call int_bounds(nele_int_tot_vdw,my_ele_inds_vdw,my_ele_inde_vdw)
523 c write (iout,*) "my_ele_inds_vdw",my_ele_inds_vdw,
524 c & " my_ele_inde_vdw",my_ele_inde_vdw
531 call int_partition(ind_eleint_vdw,my_ele_inds_vdw,
533 & iatel_s_vdw,iatel_e_vdw,i+2,nct-1,ijunk,ielstart_vdw(i),
535 c write (iout,*) i," ielstart_vdw",ielstart_vdw(i),
536 c & " ielend_vdw",ielend_vdw(i)
538 if (iatel_s_vdw.eq.0) iatel_s_vdw=1
549 do i=iatel_s_vdw,iatel_e_vdw
555 write (*,'(a)') 'Processor',fg_rank,' CG group',kolor,
556 & ' absolute rank',MyRank
557 write (iout,*) 'Electrostatic interaction array:'
559 write (iout,'(i3,2(2x,2i3))') i,ielstart(i),ielend(i)
564 C Partition the SC-p interaction array
566 nscp_int_tot=(npept-iscp+1)*(npept-iscp+1)
567 call int_bounds(nscp_int_tot,my_scp_inds,my_scp_inde)
568 if (lprint) write (iout,*) 'Processor',fg_rank,' CG group',kolor,
569 & ' absolute rank',myrank,
570 & ' nscp_int_tot',nscp_int_tot,' my_scp_inds=',my_scp_inds,
571 & ' my_scp_inde',my_scp_inde
577 if (i.lt.nnt+iscp) then
578 cd write (iout,*) 'i.le.nnt+iscp'
579 call int_partition(ind_scpint,my_scp_inds,my_scp_inde,i,
580 & iatscp_s,iatscp_e,i+iscp,nct,nscp_gr(i),iscpstart(i,1),
582 else if (i.gt.nct-iscp) then
583 cd write (iout,*) 'i.gt.nct-iscp'
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,nnt,i-iscp,nscp_gr(i),iscpstart(i,1),
592 call int_partition(ind_scpint,my_scp_inds,my_scp_inde,i,
593 & iatscp_s,iatscp_e,i+iscp,nct,nscp_gr(i),iscpstart(i,ii),
602 if (i.lt.nnt+iscp) then
604 iscpstart(i,1)=i+iscp
606 elseif (i.gt.nct-iscp) then
614 iscpstart(i,2)=i+iscp
619 if (iatscp_s.eq.0) iatscp_s=1
621 write (iout,'(a)') 'SC-p interaction array:'
622 do i=iatscp_s,iatscp_e
623 write (iout,'(i3,2(2x,2i3))')
624 & i,(iscpstart(i,j),iscpend(i,j),j=1,nscp_gr(i))
627 C Partition local interactions
629 call int_bounds(nres-2,loc_start,loc_end)
630 loc_start=loc_start+1
632 call int_bounds(nres-2,ithet_start,ithet_end)
633 ithet_start=ithet_start+2
634 ithet_end=ithet_end+2
635 call int_bounds(nct-nnt-2,iturn3_start,iturn3_end)
636 iturn3_start=iturn3_start+nnt
637 iphi_start=iturn3_start+2
638 iturn3_end=iturn3_end+nnt
639 iphi_end=iturn3_end+2
640 iturn3_start=iturn3_start-1
641 iturn3_end=iturn3_end-1
642 call int_bounds(nres-3,itau_start,itau_end)
643 itau_start=itau_start+3
645 call int_bounds(nres-3,iphi1_start,iphi1_end)
646 iphi1_start=iphi1_start+3
647 iphi1_end=iphi1_end+3
648 call int_bounds(nct-nnt-3,iturn4_start,iturn4_end)
649 iturn4_start=iturn4_start+nnt
650 iphid_start=iturn4_start+2
651 iturn4_end=iturn4_end+nnt
652 iphid_end=iturn4_end+2
653 iturn4_start=iturn4_start-1
654 iturn4_end=iturn4_end-1
655 call int_bounds(nres-2,ibond_start,ibond_end)
656 ibond_start=ibond_start+1
657 ibond_end=ibond_end+1
658 call int_bounds(nct-nnt,ibondp_start,ibondp_end)
659 ibondp_start=ibondp_start+nnt
660 ibondp_end=ibondp_end+nnt
661 call int_bounds(nres,ilip_start,ilip_end)
662 ilip_start=ilip_start
663 call int_bounds1(nres-1,ivec_start,ivec_end)
664 c print *,"Processor",myrank,fg_rank,fg_rank1,
665 c & " ivec_start",ivec_start," ivec_end",ivec_end
666 iset_start=loc_start+2
668 if (ndih_constr.eq.0) then
672 call int_bounds(ndih_constr,idihconstr_start,idihconstr_end)
674 if (ntheta_constr.eq.0) then
679 & (ntheta_constr,ithetaconstr_start,ithetaconstr_end)
681 c nsumgrad=(nres-nnt)*(nres-nnt+1)/2
683 nsumgrad=(nres-nnt)*(nres-nnt+1)/2
685 call int_bounds(nsumgrad,ngrad_start,ngrad_end)
686 igrad_start=((2*nlen+1)
687 & -sqrt(float((2*nlen-1)**2-8*(ngrad_start-1))))/2
688 jgrad_start(igrad_start)=
689 & ngrad_start-(2*nlen-igrad_start)*(igrad_start-1)/2
691 jgrad_end(igrad_start)=nres
692 igrad_end=((2*nlen+1)
693 & -sqrt(float((2*nlen-1)**2-8*(ngrad_end-1))))/2
694 if (igrad_end.gt.igrad_start) jgrad_start(igrad_end)=igrad_end+1
695 jgrad_end(igrad_end)=ngrad_end-(2*nlen-igrad_end)*(igrad_end-1)/2
697 do i=igrad_start+1,igrad_end-1
702 write (*,*) 'Processor:',fg_rank,' CG group',kolor,
703 & ' absolute rank',myrank,
704 & ' loc_start',loc_start,' loc_end',loc_end,
705 & ' ithet_start',ithet_start,' ithet_end',ithet_end,
706 & ' iphi_start',iphi_start,' iphi_end',iphi_end,
707 & ' iphid_start',iphid_start,' iphid_end',iphid_end,
708 & ' ibond_start',ibond_start,' ibond_end',ibond_end,
709 & ' ibondp_start',ibondp_start,' ibondp_end',ibondp_end,
710 & ' iturn3_start',iturn3_start,' iturn3_end',iturn3_end,
711 & ' iturn4_start',iturn4_start,' iturn4_end',iturn4_end,
712 & ' ivec_start',ivec_start,' ivec_end',ivec_end,
713 & ' iset_start',iset_start,' iset_end',iset_end,
714 & ' idihconstr_start',idihconstr_start,' idihconstr_end',
716 & ' ithetaconstr_start',ithetaconstr_start,' ithetaconstr_end',
719 write (*,*) 'Processor:',fg_rank,myrank,' igrad_start',
720 & igrad_start,' igrad_end',igrad_end,' ngrad_start',ngrad_start,
721 & ' ngrad_end',ngrad_end
722 do i=igrad_start,igrad_end
723 write(*,*) 'Processor:',fg_rank,myrank,i,
724 & jgrad_start(i),jgrad_end(i)
727 if (nfgtasks.gt.1) then
728 call MPI_Allgather(ivec_start,1,MPI_INTEGER,ivec_displ(0),1,
729 & MPI_INTEGER,FG_COMM1,IERROR)
730 iaux=ivec_end-ivec_start+1
731 call MPI_Allgather(iaux,1,MPI_INTEGER,ivec_count(0),1,
732 & MPI_INTEGER,FG_COMM1,IERROR)
733 call MPI_Allgather(iset_start-2,1,MPI_INTEGER,iset_displ(0),1,
734 & MPI_INTEGER,FG_COMM,IERROR)
735 iaux=iset_end-iset_start+1
736 call MPI_Allgather(iaux,1,MPI_INTEGER,iset_count(0),1,
737 & MPI_INTEGER,FG_COMM,IERROR)
738 call MPI_Allgather(ibond_start,1,MPI_INTEGER,ibond_displ(0),1,
739 & MPI_INTEGER,FG_COMM,IERROR)
740 iaux=ibond_end-ibond_start+1
741 call MPI_Allgather(iaux,1,MPI_INTEGER,ibond_count(0),1,
742 & MPI_INTEGER,FG_COMM,IERROR)
743 call MPI_Allgather(ithet_start,1,MPI_INTEGER,ithet_displ(0),1,
744 & MPI_INTEGER,FG_COMM,IERROR)
745 iaux=ithet_end-ithet_start+1
746 call MPI_Allgather(iaux,1,MPI_INTEGER,ithet_count(0),1,
747 & MPI_INTEGER,FG_COMM,IERROR)
748 call MPI_Allgather(iphi_start,1,MPI_INTEGER,iphi_displ(0),1,
749 & MPI_INTEGER,FG_COMM,IERROR)
750 iaux=iphi_end-iphi_start+1
751 call MPI_Allgather(iaux,1,MPI_INTEGER,iphi_count(0),1,
752 & MPI_INTEGER,FG_COMM,IERROR)
753 call MPI_Allgather(iphi1_start,1,MPI_INTEGER,iphi1_displ(0),1,
754 & MPI_INTEGER,FG_COMM,IERROR)
755 iaux=iphi1_end-iphi1_start+1
756 call MPI_Allgather(iaux,1,MPI_INTEGER,iphi1_count(0),1,
757 & MPI_INTEGER,FG_COMM,IERROR)
764 call MPI_Allgather(iturn3_start,1,MPI_INTEGER,
765 & iturn3_start_all(0),1,MPI_INTEGER,FG_COMM,IERROR)
766 call MPI_Allgather(iturn4_start,1,MPI_INTEGER,
767 & iturn4_start_all(0),1,MPI_INTEGER,FG_COMM,IERROR)
768 call MPI_Allgather(iturn3_end,1,MPI_INTEGER,
769 & iturn3_end_all(0),1,MPI_INTEGER,FG_COMM,IERROR)
770 call MPI_Allgather(iturn4_end,1,MPI_INTEGER,
771 & iturn4_end_all(0),1,MPI_INTEGER,FG_COMM,IERROR)
772 call MPI_Allgather(iatel_s,1,MPI_INTEGER,
773 & iatel_s_all(0),1,MPI_INTEGER,FG_COMM,IERROR)
774 call MPI_Allgather(iatel_e,1,MPI_INTEGER,
775 & iatel_e_all(0),1,MPI_INTEGER,FG_COMM,IERROR)
776 call MPI_Allgather(ielstart(1),maxres,MPI_INTEGER,
777 & ielstart_all(1,0),maxres,MPI_INTEGER,FG_COMM,IERROR)
778 call MPI_Allgather(ielend(1),maxres,MPI_INTEGER,
779 & ielend_all(1,0),maxres,MPI_INTEGER,FG_COMM,IERROR)
781 write (iout,*) "iatel_s_all",(iatel_s_all(i),i=0,nfgtasks)
782 write (iout,*) "iatel_e_all",(iatel_e_all(i),i=0,nfgtasks)
783 write (iout,*) "iturn3_start_all",
784 & (iturn3_start_all(i),i=0,nfgtasks-1)
785 write (iout,*) "iturn3_end_all",
786 & (iturn3_end_all(i),i=0,nfgtasks-1)
787 write (iout,*) "iturn4_start_all",
788 & (iturn4_start_all(i),i=0,nfgtasks-1)
789 write (iout,*) "iturn4_end_all",
790 & (iturn4_end_all(i),i=0,nfgtasks-1)
791 write (iout,*) "The ielstart_all array"
793 write (iout,'(20i4)') i,(ielstart_all(i,j),j=0,nfgtasks-1)
795 write (iout,*) "The ielend_all array"
797 write (iout,'(20i4)') i,(ielend_all(i,j),j=0,nfgtasks-1)
803 itask_cont_from(0)=fg_rank
804 itask_cont_to(0)=fg_rank
806 do ii=iturn3_start,iturn3_end
807 call add_int(ii,ii+2,iturn3_sent(1,ii),
808 & ntask_cont_to,itask_cont_to,flag)
810 do ii=iturn4_start,iturn4_end
811 call add_int(ii,ii+3,iturn4_sent(1,ii),
812 & ntask_cont_to,itask_cont_to,flag)
814 do ii=iturn3_start,iturn3_end
815 call add_int_from(ii,ii+2,ntask_cont_from,itask_cont_from)
817 do ii=iturn4_start,iturn4_end
818 call add_int_from(ii,ii+3,ntask_cont_from,itask_cont_from)
821 write (iout,*) "After turn3 ntask_cont_from",ntask_cont_from,
822 & " ntask_cont_to",ntask_cont_to
823 write (iout,*) "itask_cont_from",
824 & (itask_cont_from(i),i=1,ntask_cont_from)
825 write (iout,*) "itask_cont_to",
826 & (itask_cont_to(i),i=1,ntask_cont_to)
829 c write (iout,*) "Loop forward"
832 c write (iout,*) "from loop i=",i
834 do j=ielstart(i),ielend(i)
835 call add_int_from(i,j,ntask_cont_from,itask_cont_from)
838 c write (iout,*) "Loop backward iatel_e-1",iatel_e-1,
839 c & " iatel_e",iatel_e
843 c write (iout,*) "i",i," ielstart",ielstart(i),
844 c & " ielend",ielend(i)
847 do j=ielstart(i),ielend(i)
848 call add_int(i,j,iint_sent(1,j,nat_sent+1),ntask_cont_to,
849 & itask_cont_to,flag)
857 write (iout,*)"After longrange ntask_cont_from",ntask_cont_from,
858 & " ntask_cont_to",ntask_cont_to
859 write (iout,*) "itask_cont_from",
860 & (itask_cont_from(i),i=1,ntask_cont_from)
861 write (iout,*) "itask_cont_to",
862 & (itask_cont_to(i),i=1,ntask_cont_to)
864 write (iout,*) "iint_sent"
867 write (iout,'(20i4)') ii,(j,(iint_sent(k,j,i),k=1,4),
868 & j=ielstart(ii),ielend(ii))
870 write (iout,*) "iturn3_sent iturn3_start",iturn3_start,
871 & " iturn3_end",iturn3_end
872 write (iout,'(20i4)') (i,(iturn3_sent(j,i),j=1,4),
873 & i=iturn3_start,iturn3_end)
874 write (iout,*) "iturn4_sent iturn4_start",iturn4_start,
875 & " iturn4_end",iturn4_end
876 write (iout,'(20i4)') (i,(iturn4_sent(j,i),j=1,4),
877 & i=iturn4_start,iturn4_end)
880 call MPI_Gather(ntask_cont_from,1,MPI_INTEGER,
881 & ntask_cont_from_all,1,MPI_INTEGER,king,FG_COMM,IERR)
882 c write (iout,*) "Gather ntask_cont_from ended"
884 call MPI_Gather(itask_cont_from(0),max_fg_procs,MPI_INTEGER,
885 & itask_cont_from_all(0,0),max_fg_procs,MPI_INTEGER,king,
887 c write (iout,*) "Gather itask_cont_from ended"
889 call MPI_Gather(ntask_cont_to,1,MPI_INTEGER,ntask_cont_to_all,
890 & 1,MPI_INTEGER,king,FG_COMM,IERR)
891 c write (iout,*) "Gather ntask_cont_to ended"
893 call MPI_Gather(itask_cont_to,max_fg_procs,MPI_INTEGER,
894 & itask_cont_to_all,max_fg_procs,MPI_INTEGER,king,FG_COMM,IERR)
895 c write (iout,*) "Gather itask_cont_to ended"
897 if (fg_rank.eq.king) then
898 write (iout,*)"Contact receive task map (proc, #tasks, tasks)"
900 write (iout,'(20i4)') i,ntask_cont_from_all(i),
901 & (itask_cont_from_all(j,i),j=1,ntask_cont_from_all(i))
905 write (iout,*) "Contact send task map (proc, #tasks, tasks)"
907 write (iout,'(20i4)') i,ntask_cont_to_all(i),
908 & (itask_cont_to_all(j,i),j=1,ntask_cont_to_all(i))
912 C Check if every send will have a matching receive
916 ncheck_to=ncheck_to+ntask_cont_to_all(i)
917 ncheck_from=ncheck_from+ntask_cont_from_all(i)
919 write (iout,*) "Control sums",ncheck_from,ncheck_to
920 if (ncheck_from.ne.ncheck_to) then
921 write (iout,*) "Error: #receive differs from #send."
922 write (iout,*) "Terminating program...!"
928 do j=1,ntask_cont_to_all(i)
929 ii=itask_cont_to_all(j,i)
930 do k=1,ntask_cont_from_all(ii)
931 if (itask_cont_from_all(k,ii).eq.i) then
932 if(lprint)write(iout,*)"Matching send/receive",i,ii
936 if (k.eq.ntask_cont_from_all(ii)+1) then
938 write (iout,*) "Error: send by",j," to",ii,
939 & " would have no matching receive"
945 write (iout,*) "Unmatched sends; terminating program"
949 call MPI_Bcast(flag,1,MPI_LOGICAL,king,FG_COMM,IERROR)
950 c write (iout,*) "flag broadcast ended flag=",flag
953 call MPI_Finalize(IERROR)
954 stop "Error in INIT_INT_TABLE: unmatched send/receive."
956 call MPI_Comm_group(FG_COMM,fg_group,IERR)
957 c write (iout,*) "MPI_Comm_group ended"
959 call MPI_Group_incl(fg_group,ntask_cont_from+1,
960 & itask_cont_from(0),CONT_FROM_GROUP,IERR)
961 call MPI_Group_incl(fg_group,ntask_cont_to+1,itask_cont_to(0),
962 & CONT_TO_GROUP,IERR)
965 iaux=4*(ielend(ii)-ielstart(ii)+1)
966 call MPI_Group_translate_ranks(fg_group,iaux,
967 & iint_sent(1,ielstart(ii),i),CONT_TO_GROUP,
968 & iint_sent_local(1,ielstart(ii),i),IERR )
969 c write (iout,*) "Ranks translated i=",i
972 iaux=4*(iturn3_end-iturn3_start+1)
973 call MPI_Group_translate_ranks(fg_group,iaux,
974 & iturn3_sent(1,iturn3_start),CONT_TO_GROUP,
975 & iturn3_sent_local(1,iturn3_start),IERR)
976 iaux=4*(iturn4_end-iturn4_start+1)
977 call MPI_Group_translate_ranks(fg_group,iaux,
978 & iturn4_sent(1,iturn4_start),CONT_TO_GROUP,
979 & iturn4_sent_local(1,iturn4_start),IERR)
981 write (iout,*) "iint_sent_local"
984 write (iout,'(20i4)') ii,(j,(iint_sent_local(k,j,i),k=1,4),
985 & j=ielstart(ii),ielend(ii))
988 write (iout,*) "iturn3_sent_local iturn3_start",iturn3_start,
989 & " iturn3_end",iturn3_end
990 write (iout,'(20i4)') (i,(iturn3_sent_local(j,i),j=1,4),
991 & i=iturn3_start,iturn3_end)
992 write (iout,*) "iturn4_sent_local iturn4_start",iturn4_start,
993 & " iturn4_end",iturn4_end
994 write (iout,'(20i4)') (i,(iturn4_sent_local(j,i),j=1,4),
995 & i=iturn4_start,iturn4_end)
998 call MPI_Group_free(fg_group,ierr)
999 call MPI_Group_free(cont_from_group,ierr)
1000 call MPI_Group_free(cont_to_group,ierr)
1001 call MPI_Type_contiguous(3,MPI_DOUBLE_PRECISION,MPI_UYZ,IERROR)
1002 call MPI_Type_commit(MPI_UYZ,IERROR)
1003 call MPI_Type_contiguous(18,MPI_DOUBLE_PRECISION,MPI_UYZGRAD,
1005 call MPI_Type_commit(MPI_UYZGRAD,IERROR)
1006 call MPI_Type_contiguous(2,MPI_DOUBLE_PRECISION,MPI_MU,IERROR)
1007 call MPI_Type_commit(MPI_MU,IERROR)
1008 call MPI_Type_contiguous(4,MPI_DOUBLE_PRECISION,MPI_MAT1,IERROR)
1009 call MPI_Type_commit(MPI_MAT1,IERROR)
1010 call MPI_Type_contiguous(8,MPI_DOUBLE_PRECISION,MPI_MAT2,IERROR)
1011 call MPI_Type_commit(MPI_MAT2,IERROR)
1012 call MPI_Type_contiguous(6,MPI_DOUBLE_PRECISION,MPI_THET,IERROR)
1013 call MPI_Type_commit(MPI_THET,IERROR)
1014 call MPI_Type_contiguous(9,MPI_DOUBLE_PRECISION,MPI_GAM,IERROR)
1015 call MPI_Type_commit(MPI_GAM,IERROR)
1017 c 9/22/08 Derived types to send matrices which appear in correlation terms
1019 if (ivec_count(i).eq.ivec_count(0)) then
1025 do ind_typ=lentyp(0),lentyp(nfgtasks-1)
1026 if (ind_typ.eq.0) then
1027 ichunk=ivec_count(0)
1029 ichunk=ivec_count(1)
1036 c displs(i)=displs(i-1)+blocklengths(i-1)*maxres
1039 c blocklengths(i)=blocklengths(i)*ichunk
1041 c write (iout,*) "blocklengths and displs"
1043 c write (iout,*) i,blocklengths(i),displs(i)
1046 c call MPI_Type_indexed(4,blocklengths(1),displs(1),
1047 c & MPI_DOUBLE_PRECISION,MPI_ROTAT1(ind_typ),IERROR)
1048 c call MPI_Type_commit(MPI_ROTAT1(ind_typ),IERROR)
1049 c write (iout,*) "MPI_ROTAT1",MPI_ROTAT1
1055 c displs(i)=displs(i-1)+blocklengths(i-1)*maxres
1058 c blocklengths(i)=blocklengths(i)*ichunk
1060 c write (iout,*) "blocklengths and displs"
1062 c write (iout,*) i,blocklengths(i),displs(i)
1065 c call MPI_Type_indexed(4,blocklengths(1),displs(1),
1066 c & MPI_DOUBLE_PRECISION,MPI_ROTAT2(ind_typ),IERROR)
1067 c call MPI_Type_commit(MPI_ROTAT2(ind_typ),IERROR)
1068 c write (iout,*) "MPI_ROTAT2",MPI_ROTAT2
1074 displs(i)=displs(i-1)+blocklengths(i-1)*maxres
1077 blocklengths(i)=blocklengths(i)*ichunk
1079 call MPI_Type_indexed(8,blocklengths,displs,
1080 & MPI_DOUBLE_PRECISION,MPI_PRECOMP11(ind_typ),IERROR)
1081 call MPI_Type_commit(MPI_PRECOMP11(ind_typ),IERROR)
1087 displs(i)=displs(i-1)+blocklengths(i-1)*maxres
1090 blocklengths(i)=blocklengths(i)*ichunk
1092 call MPI_Type_indexed(8,blocklengths,displs,
1093 & MPI_DOUBLE_PRECISION,MPI_PRECOMP12(ind_typ),IERROR)
1094 call MPI_Type_commit(MPI_PRECOMP12(ind_typ),IERROR)
1100 displs(i)=displs(i-1)+blocklengths(i-1)*maxres
1103 blocklengths(i)=blocklengths(i)*ichunk
1105 call MPI_Type_indexed(6,blocklengths,displs,
1106 & MPI_DOUBLE_PRECISION,MPI_PRECOMP22(ind_typ),IERROR)
1107 call MPI_Type_commit(MPI_PRECOMP22(ind_typ),IERROR)
1113 displs(i)=displs(i-1)+blocklengths(i-1)*maxres
1116 blocklengths(i)=blocklengths(i)*ichunk
1118 call MPI_Type_indexed(2,blocklengths,displs,
1119 & MPI_DOUBLE_PRECISION,MPI_PRECOMP23(ind_typ),IERROR)
1120 call MPI_Type_commit(MPI_PRECOMP23(ind_typ),IERROR)
1126 displs(i)=displs(i-1)+blocklengths(i-1)*maxres
1129 blocklengths(i)=blocklengths(i)*ichunk
1131 call MPI_Type_indexed(4,blocklengths,displs,
1132 & MPI_DOUBLE_PRECISION,MPI_ROTAT_OLD(ind_typ),IERROR)
1133 call MPI_Type_commit(MPI_ROTAT_OLD(ind_typ),IERROR)
1137 iint_start=ivec_start+1
1140 iint_count(i)=ivec_count(i)
1141 iint_displ(i)=ivec_displ(i)
1142 ivec_displ(i)=ivec_displ(i)-1
1143 iset_displ(i)=iset_displ(i)-1
1144 ithet_displ(i)=ithet_displ(i)-1
1145 iphi_displ(i)=iphi_displ(i)-1
1146 iphi1_displ(i)=iphi1_displ(i)-1
1147 ibond_displ(i)=ibond_displ(i)-1
1149 if (nfgtasks.gt.1 .and. fg_rank.eq.king
1150 & .and. (me.eq.0 .or. .not. out1file)) then
1151 write (iout,*) "IVEC_DISPL, IVEC_COUNT, ISET_START, ISET_COUNT"
1153 write (iout,*) i,ivec_displ(i),ivec_count(i),iset_displ(i),
1156 write (iout,*) "iphi_start",iphi_start," iphi_end",iphi_end,
1157 & " iphi1_start",iphi1_start," iphi1_end",iphi1_end
1158 write (iout,*)"IPHI_COUNT, IPHI_DISPL, IPHI1_COUNT, IPHI1_DISPL"
1160 write (iout,*) i,iphi_count(i),iphi_displ(i),iphi1_count(i),
1163 write(iout,'(i10,a,i10,a,i10,a/a,i3,a)') n_sc_int_tot,' SC-SC ',
1164 & nele_int_tot,' electrostatic and ',nscp_int_tot,
1165 & ' SC-p interactions','were distributed among',nfgtasks,
1166 & ' fine-grain processors.'
1182 idihconstr_end=ndih_constr
1183 ithetaconstr_start=1
1184 ithetaconstr_end=ntheta_constr
1185 iphid_start=iphi_start
1186 iphid_end=iphi_end-1
1206 c---------------------------------------------------------------------------
1207 subroutine add_int(ii,jj,itask,ntask_cont_to,itask_cont_to,flag)
1209 include "DIMENSIONS"
1210 include "COMMON.INTERACT"
1211 include "COMMON.SETUP"
1212 include "COMMON.IOUNITS"
1213 integer ii,jj,itask(4),ntask_cont_to,
1214 &itask_cont_to(0:max_fg_procs-1)
1216 integer iturn3_start_all,iturn3_end_all,iturn4_start_all,
1217 & iturn4_end_all,iatel_s_all,iatel_e_all,ielstart_all,ielend_all
1218 common /przechowalnia/ iturn3_start_all(0:max_fg_procs),
1219 & iturn3_end_all(0:max_fg_procs),iturn4_start_all(0:max_fg_procs),
1220 & iturn4_end_all(0:max_fg_procs),iatel_s_all(0:max_fg_procs),
1221 &iatel_e_all(0:max_fg_procs),ielstart_all(maxres,0:max_fg_procs-1),
1222 & ielend_all(maxres,0:max_fg_procs-1)
1223 integer iproc,isent,k,l
1224 c Determines whether to send interaction ii,jj to other processors; a given
1225 c interaction can be sent to at most 2 processors.
1226 c Sets flag=.true. if interaction ii,jj needs to be sent to at least
1227 c one processor, otherwise flag is unchanged from the input value.
1233 c write (iout,*) "ii",ii," jj",jj
1234 c Loop over processors to check if anybody could need interaction ii,jj
1235 do iproc=0,fg_rank-1
1236 c Check if the interaction matches any turn3 at iproc
1237 do k=iturn3_start_all(iproc),iturn3_end_all(iproc)
1239 if (k.eq.ii-1 .and. l.eq.jj-1 .or. k.eq.ii-1 .and. l.eq.jj+1
1240 & .or. k.eq.ii+1 .and. l.eq.jj+1 .or. k.eq.ii+1 .and. l.eq.jj-1)
1242 c write (iout,*) "turn3 to iproc",iproc," ij",ii,jj,"kl",k,l
1245 if (iproc.ne.itask(1).and.iproc.ne.itask(2)
1246 & .and.iproc.ne.itask(3).and.iproc.ne.itask(4)) then
1249 call add_task(iproc,ntask_cont_to,itask_cont_to)
1253 C Check if the interaction matches any turn4 at iproc
1254 do k=iturn4_start_all(iproc),iturn4_end_all(iproc)
1256 if (k.eq.ii-1 .and. l.eq.jj-1 .or. k.eq.ii-1 .and. l.eq.jj+1
1257 & .or. k.eq.ii+1 .and. l.eq.jj+1 .or. k.eq.ii+1 .and. l.eq.jj-1)
1259 c write (iout,*) "turn3 to iproc",iproc," ij",ii,jj," kl",k,l
1262 if (iproc.ne.itask(1).and.iproc.ne.itask(2)
1263 & .and.iproc.ne.itask(3).and.iproc.ne.itask(4)) then
1266 call add_task(iproc,ntask_cont_to,itask_cont_to)
1270 if (iatel_s_all(iproc).gt.0 .and. iatel_e_all(iproc).gt.0 .and.
1271 & iatel_s_all(iproc).le.ii-1 .and. iatel_e_all(iproc).ge.ii-1)then
1272 if (ielstart_all(ii-1,iproc).le.jj-1.and.
1273 & ielend_all(ii-1,iproc).ge.jj-1) then
1275 if (iproc.ne.itask(1).and.iproc.ne.itask(2)
1276 & .and.iproc.ne.itask(3).and.iproc.ne.itask(4)) then
1279 call add_task(iproc,ntask_cont_to,itask_cont_to)
1282 if (ielstart_all(ii-1,iproc).le.jj+1.and.
1283 & ielend_all(ii-1,iproc).ge.jj+1) then
1285 if (iproc.ne.itask(1).and.iproc.ne.itask(2)
1286 & .and.iproc.ne.itask(3).and.iproc.ne.itask(4)) then
1289 call add_task(iproc,ntask_cont_to,itask_cont_to)
1296 c---------------------------------------------------------------------------
1297 subroutine add_int_from(ii,jj,ntask_cont_from,itask_cont_from)
1299 include "DIMENSIONS"
1300 include "COMMON.INTERACT"
1301 include "COMMON.SETUP"
1302 include "COMMON.IOUNITS"
1303 integer ii,jj,itask(2),ntask_cont_from,
1304 & itask_cont_from(0:max_fg_procs-1)
1306 integer iturn3_start_all,iturn3_end_all,iturn4_start_all,
1307 & iturn4_end_all,iatel_s_all,iatel_e_all,ielstart_all,ielend_all
1308 common /przechowalnia/ iturn3_start_all(0:max_fg_procs),
1309 & iturn3_end_all(0:max_fg_procs),iturn4_start_all(0:max_fg_procs),
1310 & iturn4_end_all(0:max_fg_procs),iatel_s_all(0:max_fg_procs),
1311 &iatel_e_all(0:max_fg_procs),ielstart_all(maxres,0:max_fg_procs-1),
1312 & ielend_all(maxres,0:max_fg_procs-1)
1314 do iproc=fg_rank+1,nfgtasks-1
1315 do k=iturn3_start_all(iproc),iturn3_end_all(iproc)
1317 if (k.eq.ii+1 .and. l.eq.jj+1 .or. k.eq.ii+1.and.l.eq.jj-1
1318 & .or. k.eq.ii-1 .and. l.eq.jj-1 .or. k.eq.ii-1 .and. l.eq.jj+1)
1320 c write (iout,*)"turn3 from iproc",iproc," ij",ii,jj," kl",k,l
1321 call add_task(iproc,ntask_cont_from,itask_cont_from)
1324 do k=iturn4_start_all(iproc),iturn4_end_all(iproc)
1326 if (k.eq.ii+1 .and. l.eq.jj+1 .or. k.eq.ii+1.and.l.eq.jj-1
1327 & .or. k.eq.ii-1 .and. l.eq.jj-1 .or. k.eq.ii-1 .and. l.eq.jj+1)
1329 c write (iout,*)"turn4 from iproc",iproc," ij",ii,jj," kl",k,l
1330 call add_task(iproc,ntask_cont_from,itask_cont_from)
1333 if (iatel_s_all(iproc).gt.0 .and. iatel_e_all(iproc).gt.0) then
1334 if (ii+1.ge.iatel_s_all(iproc).and.ii+1.le.iatel_e_all(iproc))
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)
1340 if (jj-1.ge.ielstart_all(ii+1,iproc).and.
1341 & jj-1.le.ielend_all(ii+1,iproc)) then
1342 call add_task(iproc,ntask_cont_from,itask_cont_from)
1345 if (ii-1.ge.iatel_s_all(iproc).and.ii-1.le.iatel_e_all(iproc))
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)
1351 if (jj+1.ge.ielstart_all(ii-1,iproc).and.
1352 & jj+1.le.ielend_all(ii-1,iproc)) then
1353 call add_task(iproc,ntask_cont_from,itask_cont_from)
1360 c---------------------------------------------------------------------------
1361 subroutine add_task(iproc,ntask_cont,itask_cont)
1363 include "DIMENSIONS"
1364 integer iproc,ntask_cont,itask_cont(0:max_fg_procs-1)
1367 if (itask_cont(ii).eq.iproc) return
1369 ntask_cont=ntask_cont+1
1370 itask_cont(ntask_cont)=iproc
1373 c---------------------------------------------------------------------------
1374 subroutine int_bounds(total_ints,lower_bound,upper_bound)
1375 implicit real*8 (a-h,o-z)
1376 include 'DIMENSIONS'
1378 include 'COMMON.SETUP'
1379 integer total_ints,lower_bound,upper_bound
1380 integer int4proc(0:max_fg_procs),sint4proc(0:max_fg_procs)
1381 nint=total_ints/nfgtasks
1385 nexcess=total_ints-nint*nfgtasks
1387 int4proc(nfgtasks-i)=int4proc(nfgtasks-i)+1
1391 lower_bound=lower_bound+int4proc(i)
1393 upper_bound=lower_bound+int4proc(fg_rank)
1394 lower_bound=lower_bound+1
1397 c---------------------------------------------------------------------------
1398 subroutine int_bounds1(total_ints,lower_bound,upper_bound)
1399 implicit real*8 (a-h,o-z)
1400 include 'DIMENSIONS'
1402 include 'COMMON.SETUP'
1403 integer total_ints,lower_bound,upper_bound
1404 integer int4proc(0:max_fg_procs),sint4proc(0:max_fg_procs)
1405 nint=total_ints/nfgtasks1
1409 nexcess=total_ints-nint*nfgtasks1
1411 int4proc(nfgtasks1-i)=int4proc(nfgtasks1-i)+1
1415 lower_bound=lower_bound+int4proc(i)
1417 upper_bound=lower_bound+int4proc(fg_rank1)
1418 lower_bound=lower_bound+1
1421 c---------------------------------------------------------------------------
1422 subroutine int_partition(int_index,lower_index,upper_index,atom,
1423 & at_start,at_end,first_atom,last_atom,int_gr,jat_start,jat_end,*)
1424 implicit real*8 (a-h,o-z)
1425 include 'DIMENSIONS'
1426 include 'COMMON.IOUNITS'
1427 integer int_index,lower_index,upper_index,atom,at_start,at_end,
1428 & first_atom,last_atom,int_gr,jat_start,jat_end
1431 if (lprn) write (iout,*) 'int_index=',int_index
1432 int_index_old=int_index
1433 int_index=int_index+last_atom-first_atom+1
1435 & write (iout,*) 'int_index=',int_index,
1436 & ' int_index_old',int_index_old,
1437 & ' lower_index=',lower_index,
1438 & ' upper_index=',upper_index,
1439 & ' atom=',atom,' first_atom=',first_atom,
1440 & ' last_atom=',last_atom
1441 if (int_index.ge.lower_index) then
1443 if (at_start.eq.0) then
1445 jat_start=first_atom-1+lower_index-int_index_old
1447 jat_start=first_atom
1449 if (lprn) write (iout,*) 'jat_start',jat_start
1450 if (int_index.ge.upper_index) then
1452 jat_end=first_atom-1+upper_index-int_index_old
1457 if (lprn) write (iout,*) 'jat_end',jat_end
1462 c------------------------------------------------------------------------------
1463 subroutine hpb_partition
1464 implicit real*8 (a-h,o-z)
1465 include 'DIMENSIONS'
1469 include 'COMMON.SBRIDGE'
1470 include 'COMMON.IOUNITS'
1471 include 'COMMON.SETUP'
1473 call int_bounds(nhpb,link_start,link_end)
1474 write (iout,*) 'Processor',fg_rank,' CG group',kolor,
1475 & ' absolute rank',MyRank,
1476 & ' nhpb',nhpb,' link_start=',link_start,
1477 & ' link_end',link_end