repo_name
stringlengths
7
81
path
stringlengths
4
224
copies
stringclasses
221 values
size
stringlengths
4
7
content
stringlengths
975
1.04M
license
stringclasses
15 values
SamKChang/abinit-7.10.5_multipole
src/42_libpaw/m_pawdij.F90
1
170132
!{\src2tex{textfont=tt}} !!****m* ABINIT/m_pawdij !! NAME !! m_pawdij !! !! FUNCTION !! This module contains several routines used to compute the PAW pseudopotential !! strengths Dij. The Dijs define the non-local PAW operator: !! VNL = Sum_ij [ Dij |pi><pj| ], with pi, pj= projectors !! !! COPYRIGHT !! Copyright (C) 2013-2014 ABINIT group (MT) !! This file is distributed under the terms of the !! GNU General Public License, see ~abinit/COPYING !! or http://www.gnu.org/copyleft/gpl.txt . !! For the initials of contributors, see ~abinit/doc/developers/contributors.txt. !! !! INPUTS !! !! OUTPUT !! !! PARENTS !! !! CHILDREN !! !! SOURCE #if defined HAVE_CONFIG_H #include "config.h" #endif #include "abi_common.h" MODULE m_pawdij use defs_basis use m_profiling_abi use m_errors use m_paral_atom, only : get_my_atmtab, free_my_atmtab use m_xmpi, only : xcomm_size, xmpi_sum, xmpi_allgatherv, xmpi_self use m_pawio, only : pawio_print_ij use m_pawang, only : pawang_type use m_pawrad, only : pawrad_type, pawrad_deducer0, simp_gen, nderiv_gen use m_pawtab, only : pawtab_type use m_paw_an, only : paw_an_type use m_paw_ij, only : paw_ij_type, paw_ij_print use m_pawfgrtab, only : pawfgrtab_type use m_pawrhoij, only : pawrhoij_type use m_paw_finegrid, only : pawgylm, pawexpiqr implicit none private !public procedures. public :: pawdij ! Dij total public :: pawdijhartree ! Dij Hartree public :: pawdijxc ! Dij eXchange-Correlation (using (l,m) moments) public :: pawdijxcm ! Dij eXchange-Correlation (using (r,theta,phi) grid) public :: pawdijhat ! Dij^hat (compensation charge contribution) public :: pawdiju ! Dij LDA+U public :: pawdijso ! Dij spin-orbit public :: pawdijexxc ! Dij local exact-exchange public :: pawdijfr ! 1st-order frozen Dij public :: pawpupot ! On-site LDA+U potential public :: pawxpot ! On-site local exact-exchange potential public :: symdij ! Symmetrize total Dij or one part of it public :: symdij_all ! Symmetrize all contributions to Dij !!*** CONTAINS !=========================================================== !!*** !---------------------------------------------------------------------- !!****f* m_pawdij/pawdij !! NAME !! pawdij !! !! FUNCTION !! Compute the pseudopotential strengths Dij of the PAW non local operator as sum of !! several contributions. Can compute first-order strenghts Dij for RF calculations. !! This routine is a driver calling, for each contribution to Dij, a specific !! routines. !! Within standard PAW formalism, Dij can be decomposd as follows: !! Dij = Dij_atomic + Dij_Hartree + Dij_XC + Dij^hat !! In case of additional approximations, several other terms can appear: !! Dij_LDA+U, Dij_spin-orbit, Dij_exact-exchange, ... !! !! COPYRIGHT !! Copyright (C) 1998-2014 ABINIT group (MT, FJ) !! This file is distributed under the terms of the !! GNU General Public License, see ~abinit/COPYING !! or http://www.gnu.org/copyleft/gpl.txt . !! For the initials of contributors, see ~abinit/doc/developers/contributors.txt. !! !! INPUTS !! cplex=(RF calculations only) - 1 if RF 1st-order quantities are REAL, 2 if COMPLEX !! gprimd(3,3)=dimensional primitive translations for reciprocal space !! enunit=choice for units of output Dij !! ipert=index of perturbation (used only for RF calculation ; set ipert<=0 for GS calculations. !! my_natom=number of atoms treated by current processor !! natom=total number of atoms in cell !! nfft=number of real space grid points (for current proc) !! nfftot=total number of real space grid points !! nspden=number of spin-density components !! ntypat=number of types of atoms in unit cell. !! paw_an(my_natom) <type(paw_an_type)>=paw arrays given on angular mesh !! paw_ij(my_natom) <type(paw_ij_type)>=paw arrays given on (i,j) channels !! pawang <type(pawang_type)>=paw angular mesh and related data !! pawfgrtab(my_natom) <type(pawfgrtab_type)>=atomic data given on fine rectangular grid !! pawprtvol=control print volume and debugging output for PAW !! pawrad(ntypat) <type(pawrad_type)>=paw radial mesh and related data !! pawrhoij(my_natom) <type(pawrhoij_type)>= paw rhoij occupancies and related data !! pawspnorb=flag: 1 if spin-orbit coupling is activated !! pawtab(ntypat) <type(pawtab_type)>=paw tabulated starting data !! pawxcdev=Choice of XC development (0=no dev. (use of angular mesh) ; 1 or 2=dev. on moments) !! qphon(3)=wavevector of the phonon !! spnorbscl=scaling factor for spin-orbit coupling !! ucvol=unit cell volume !! vtrial(cplex*nfft,nspden)=GS potential on real space grid !! vxc(cplex*nfft,nspden)=XC potential (Hartree) on real space grid !! xred(3,my_natom)= reduced atomic coordinates !! ======== Optional arguments ============== !! Parallelism over atomic sites: !! mpi_atmtab(:)=indexes of the atoms treated by current proc !! mpi_comm_atom=MPI communicator over atoms !! mpi_comm_grid=MPI communicator over real space grid points !! Application of a potential energy shift on atomic sites: !! natvshift=number of atomic potential energy shifts (per atom) ; default=0 !! atvshift(natvshift,nsppol,natom)=potential energy shift for lm channel & spin & atom !! fatvshift=factor that multiplies atvshift !! Electrons-positron 2-component DFT: !! electronpositron_calctype=type of calculation for electron-positron 2component-DFT: !! 0: standard DFT (no positron) ; default value !! 1: positron in the constant electrons potential !! 2: electrons in the constant positron potential !! electronpositron_pawrhoij(my_natom) <type(pawrhoij_type)>= !! PAW occupation matrix of the "constant" particle(s) !! (electrons if calctype=1, positron if calctype=2) !! electronpositron_lmselect(lmmax,my_natom)= !! Flags selecting the non-zero LM-moments of on-site densities !! for the "constant" particle(s) !! (electrons if calctype=1, positron if calctype=2) !! !! OUTPUT !! paw_ij(iatom)%dij(cplex_dij*lmn2_size,ndij)= total Dij terms (GS calculation, ipert=0) !! total 1st-order Dij terms (RF ccalc., ipert>0) !! May be complex if cplex_dij=2 !! dij(:,:,1) contains Dij^up-up !! dij(:,:,2) contains Dij^dn-dn !! dij(:,:,3) contains Dij^up-dn (only if nspinor=2) !! dij(:,:,4) contains Dij^dn-up (only if nspinor=2) !! May also compute paw_ij(iatom)%dij0,paw_ij(iatom)%dijhartree,paw_ij(iatom)%dijxc, !! paw_ij(iatom)%dijxc_hat,paw_ij(iatom)%dijxc_val, !! paw_ij(iatom)%dijhat,paw_ij(iatom)dijso, !! paw_ij(iatom)%dijU,paw_ij(iatom)%dijexxc !! !! NOTES !! Response function calculations: !! In order to compute first-order Dij, paw_an (resp. paw_ij) datastructures !! must contain first-order quantities, namely paw_an1 (resp. paw_ij1). !! !! PARENTS !! bethe_salpeter,respfn,scfcv,scfcv3,screening,sigma !! !! CHILDREN !! free_my_atmtab,get_my_atmtab !! !! SOURCE subroutine pawdij(cplex,enunit,gprimd,ipert,my_natom,natom,nfft,nfftot,nspden,ntypat,& & paw_an,paw_ij,pawang,pawfgrtab,pawprtvol,pawrad,pawrhoij,pawspnorb,pawtab,& & pawxcdev,qphon,spnorbscl,ucvol,charge,vtrial,vxc,xred,& & electronpositron_calctype,electronpositron_pawrhoij,electronpositron_lmselect,& & atvshift,fatvshift,natvshift,& & mpi_atmtab,mpi_comm_atom,mpi_comm_grid) !This section has been created automatically by the script Abilint (TD). !Do not modify the following lines by hand. #undef ABI_FUNC #define ABI_FUNC 'pawdij' !End of the abilint section implicit none !Arguments --------------------------------------------- !scalars integer,intent(in) :: cplex,enunit,ipert,my_natom,natom,nfft,nfftot integer,intent(in) :: nspden,ntypat,pawprtvol,pawspnorb,pawxcdev integer,optional,intent(in) :: electronpositron_calctype integer,optional,intent(in) :: mpi_comm_atom,mpi_comm_grid,natvshift real(dp),intent(in) :: spnorbscl,ucvol,charge real(dp),intent(in),optional ::fatvshift type(pawang_type),intent(in) :: pawang !arrays integer,optional,target,intent(in) :: mpi_atmtab(:) logical,optional,intent(in) :: electronpositron_lmselect(:,:) real(dp),intent(in) :: gprimd(3,3),qphon(3) real(dp),intent(in) :: vxc(:,:),xred(3,natom) real(dp),intent(in),target :: vtrial(cplex*nfft,nspden) real(dp),intent(in),optional :: atvshift(:,:,:) type(paw_an_type),intent(in) :: paw_an(my_natom) type(paw_ij_type),target,intent(inout) :: paw_ij(my_natom) type(pawfgrtab_type),intent(inout) :: pawfgrtab(my_natom) type(pawrad_type),intent(in) :: pawrad(ntypat) type(pawrhoij_type),intent(inout) :: pawrhoij(my_natom) type(pawrhoij_type),intent(in),optional :: electronpositron_pawrhoij(:) type(pawtab_type),intent(in) :: pawtab(ntypat) !Local variables --------------------------------------- !scalars integer :: cplex_dij,iatom,iatom_tot,idij,ipositron,itypat,klmn,klmn1,lm_size,lmn2_size integer :: lpawu,my_comm_atom,my_comm_grid,natvshift_,ndij,nsploop,nsppol,usexcnhat logical :: dij_available,dij_need,dij_prereq logical :: dij0_available,dij0_need,dij0_prereq logical :: dijexxc_available,dijexxc_need,dijexxc_prereq logical :: dijhartree_available,dijhartree_need,dijhartree_prereq logical :: dijhat_available,dijhat_need,dijhat_prereq logical :: dijhatfr_available,dijhatfr_need,dijhatfr_prereq logical :: dijso_available,dijso_need,dijso_prereq logical :: dijxc_available,dijxc_need,dijxc_prereq logical :: dijxchat_available,dijxchat_need,dijxchat_prereq logical :: dijxcval_available,dijxcval_need,dijxcval_prereq logical :: dijU_available,dijU_need,dijU_prereq logical :: my_atmtab_allocated logical :: need_to_print,paral_atom,v_dijhat_allocated character(len=500) :: msg !arrays integer,pointer :: my_atmtab(:) logical,allocatable :: lmselect(:) real(dp),allocatable :: dij0(:),dijhartree(:),dijhat(:,:),dijexxc(:,:),dijpawu(:,:) real(dp),allocatable :: dijso(:,:),dijxc(:,:),dij_ep(:),dijxchat(:,:),dijxcval(:,:) real(dp),pointer :: v_dijhat(:,:),vpawu(:,:,:,:),vpawx(:,:,:) ! ************************************************************************* DBG_ENTER("COLL") !------------------------------------------------------------------------ !----- Check consistency of arguments !------------------------------------------------------------------------ ! === Check optional arguments === natvshift_=0;if (present(natvshift)) natvshift_=natvshift if (natvshift_>0) then if ((.not.present(atvshift)).or.(.not.present(fatvshift))) then msg='when natvshift>0, atvshift and fatvshift arguments must be present!' MSG_BUG(msg) end if end if ipositron=0;if (present(electronpositron_calctype)) ipositron=electronpositron_calctype if (ipositron/=0) then if ((.not.present(electronpositron_pawrhoij)).or.& & (.not.present(electronpositron_lmselect))) then msg='ep_pawrhoij and ep_lmselect must be present for electron-positron calculations!' MSG_BUG(msg) end if end if ! === Check complex character of arguments === if (nspden==4.and.cplex==2) then msg='nspden=4 probably not compatible with cplex=2!' MSG_BUG(msg) end if if (my_natom>0) then if (paw_ij(1)%ndij==4.and.paw_ij(1)%cplex_dij/=2) then msg='invalid cplex size for Dij (4 Dij components)!' MSG_BUG(msg) end if if (paw_ij(1)%cplex/=paw_an(1)%cplex) then msg='paw_ij()%cplex and paw_an()%cplex must be equal!' MSG_BUG(msg) end if if (ipert<=0.and.paw_ij(1)%cplex/=1) then msg='cplex must be 1 for GS calculations!' MSG_BUG(msg) end if if (paw_ij(1)%cplex_dij<cplex) then msg='cplex_dij must be >= cplex!' MSG_BUG(msg) end if if (paw_ij(1)%cplex/=cplex) then msg='paw_ij()%cplex must be equal to cplex!' MSG_BUG(msg) end if end if !------------------------------------------------------------------------ !----- Initializations !------------------------------------------------------------------------ !Nothing to do for some perturbations (RF case) if (ipert==natom+1.or.ipert==natom+5) then do iatom=1,my_natom if (paw_ij(iatom)%has_dij==1) paw_ij(iatom)%dij=zero if (paw_ij(iatom)%has_dij0==1) paw_ij(iatom)%dij0=zero if (paw_ij(iatom)%has_dijhartree==1) paw_ij(iatom)%dijhartree=zero if (paw_ij(iatom)%has_dijxc==1) paw_ij(iatom)%dijxc=zero if (paw_ij(iatom)%has_dijhat==1) paw_ij(iatom)%dijhat=zero if (paw_ij(iatom)%has_dijso==1) paw_ij(iatom)%dijso=zero if (paw_ij(iatom)%has_dijU==1) paw_ij(iatom)%dijU=zero if (paw_ij(iatom)%has_dijexxc==1) paw_ij(iatom)%dijexxc=zero if (paw_ij(iatom)%has_dijxc_hat==1) paw_ij(iatom)%dijxc_hat=zero if (paw_ij(iatom)%has_dijxc_val==1) paw_ij(iatom)%dijxc_val=zero end do return end if !Set up parallelism over atoms paral_atom=(present(mpi_comm_atom).and.(my_natom/=natom)) nullify(my_atmtab);if (present(mpi_atmtab)) my_atmtab => mpi_atmtab my_comm_atom=xmpi_self;if (present(mpi_comm_atom)) my_comm_atom=mpi_comm_atom call get_my_atmtab(my_comm_atom,my_atmtab,my_atmtab_allocated,paral_atom,natom,my_natom_ref=my_natom) !----- Various initializations nsppol=1;nsploop=1 if (my_natom>0) then nsppol=paw_ij(1)%nsppol nsploop=nsppol;if (paw_ij(1)%ndij==4) nsploop=4 end if usexcnhat=maxval(pawtab(1:ntypat)%usexcnhat) my_comm_grid=xmpi_self;if (present(mpi_comm_grid)) my_comm_grid=mpi_comm_grid !------ Select potential for Dij^hat computation v_dijhat_allocated=.false. if (my_natom>0) then if ((paw_ij(1)%has_dij==1).or.(paw_ij(1)%has_dijhat==1).or. & & (paw_ij(1)%has_dijhat==0.and.pawprtvol/=0)) then if (usexcnhat==0) then if (size(vxc,1)/=cplex*nfft.or.size(vxc,2)/=nspden) then msg='invalid size for vxc!' MSG_BUG(msg) end if ABI_ALLOCATE(v_dijhat,(cplex*nfft,nspden)) v_dijhat_allocated=.true. !v_dijhat=vtrial-vxc do idij=1,nspden do klmn=1,cplex*nfft v_dijhat(klmn,idij)=vtrial(klmn,idij)-vxc(klmn,idij) end do end do else v_dijhat => vtrial end if end if end if !------------------------------------------------------------------------ !----- Loop over atoms !------------------------------------------------------------------------ do iatom=1,my_natom iatom_tot=iatom;if (paral_atom) iatom_tot=my_atmtab(iatom) ! === Atom-dependent data === itypat=paw_ij(iatom)%itypat cplex_dij=paw_ij(iatom)%cplex_dij lm_size=paw_an(iatom)%lm_size lmn2_size=paw_ij(iatom)%lmn2_size ndij=paw_ij(iatom)%ndij need_to_print=((abs(pawprtvol)>=1).and. & & (iatom_tot==1.or.iatom_tot==natom.or.pawprtvol<0)) ! === Determine which conditions and prerequesites are fulfilled for Dij === if (my_natom>0) then ! Total Dij: no condition ; no prerequesites dij_available=.true.;dij_prereq=.true. ! Dij0: not available for RF ; need kij for the positron dij0_available=(ipert<=0);dij0_prereq=(ipositron/=1.or.pawtab(itypat)%has_kij==2) ! DijHartree: no condition ; no prerequesites dijhartree_available=.true.;dijhartree_prereq=.true. ! DijXC: no condition ; Vxc needed dijxc_available=.true. dijxc_prereq=(paw_ij(iatom)%has_dijxc==2.or.paw_an(iatom)%has_vxc>0) ! Dij^hat: no condition ; no prerequesites dijhat_available=.true.;dijhat_prereq=.true. ! Dij^hat_FR: only for RF and when it was previously computed dijhatfr_available=(ipert>0.and.paw_ij(iatom)%has_dijfr==2) ; dijhatfr_prereq=.true. ! DijSO: not available for RF, positron; only for spin-orbit ; VHartree and Vxc needed dijso_available=(pawspnorb>0.and.ipert<=0.and.ipositron/=1) dijso_prereq=(paw_ij(iatom)%has_dijso==2.or.& & (paw_an(iatom)%has_vhartree>0.and.paw_an(iatom)%has_vxc>0)) ! DijU: not available for RF, positron; only for LDA+U dijU_available=(pawtab(itypat)%usepawu>0.and.ipert<=0.and.ipositron/=1) dijU_prereq=(paw_ij(iatom)%has_dijU==2.or.paw_ij(iatom)%has_pawu_occ>0) ! DijExxc: not available for RF, positron; only for local exact exch. ; Vxc_ex needed dijexxc_available=(pawtab(itypat)%useexexch>0.and.ipert<=0.and.ipositron/=1) dijexxc_prereq=(paw_ij(iatom)%has_dijexxc==2.or.paw_ij(iatom)%has_exexch_pot>0) ! DijXC^hat: no condition ; Vxc needed dijxchat_available=.true. dijxchat_prereq=(paw_ij(iatom)%has_dijxc_hat==2.or.paw_an(iatom)%has_vxc>0) ! DijXC_val: no condition ; Vxc_val needed dijxcval_available=.true. dijxcval_prereq=(paw_ij(iatom)%has_dijxc_val==2.or.paw_an(iatom)%has_vxcval>0) end if ! === Determine which parts of Dij have to be computed === dij_need=.false.;dij0_need=.false.;dijhartree_need=.false.;dijxc_need=.false. dijhat_need=.false.;dijhatfr_need=.false.;dijso_need=.false.;dijU_need=.false. dijexxc_need=.false.;dijxchat_need=.false.;dijxcval_need=.false. if (dij_available) then if (paw_ij(iatom)%has_dij==1) then dij_need=.true.;paw_ij(iatom)%dij(:,:)=zero else if (paw_ij(iatom)%has_dij==0.and.need_to_print) then ABI_ALLOCATE(paw_ij(iatom)%dij,(cplex_dij*lmn2_size,ndij)) dij_need=.true.;paw_ij(iatom)%dij(:,:)=zero paw_ij(iatom)%has_dij=-1 end if else if (paw_ij(iatom)%has_dij==1) then paw_ij(iatom)%dij=zero end if if (dij0_available) then if (paw_ij(iatom)%has_dij0==1) then dij0_need=.true.;paw_ij(iatom)%dij0(:)=zero else if (paw_ij(iatom)%has_dij0==0.and.need_to_print) then ABI_ALLOCATE(paw_ij(iatom)%dij0,(lmn2_size)) dij0_need=.true.;paw_ij(iatom)%dij0(:)=zero paw_ij(iatom)%has_dij0=-1 end if else if (paw_ij(iatom)%has_dij0==1) then paw_ij(iatom)%dij0=zero end if if (dijhartree_available) then if (paw_ij(iatom)%has_dijhartree==1) then dijhartree_need=.true.;paw_ij(iatom)%dijhartree(:)=zero else if (paw_ij(iatom)%has_dijhartree==0) then ABI_ALLOCATE(paw_ij(iatom)%dijhartree,(cplex*lmn2_size)) dijhartree_need=.true.;paw_ij(iatom)%dijhartree(:)=zero paw_ij(iatom)%has_dijhartree=-1 end if else if (paw_ij(iatom)%has_dijhartree==1) then paw_ij(iatom)%dijhartree=zero end if if (dijxc_available) then if (paw_ij(iatom)%has_dijxc==1) then dijxc_need=.true.;paw_ij(iatom)%dijxc(:,:)=zero else if (paw_ij(iatom)%has_dijxc==0.and.need_to_print) then ABI_ALLOCATE(paw_ij(iatom)%dijxc,(cplex_dij*lmn2_size,ndij)) dijxc_need=.true.;paw_ij(iatom)%dijxc(:,:)=zero paw_ij(iatom)%has_dijxc=-1 end if else if (paw_ij(iatom)%has_dijxc==1) then paw_ij(iatom)%dijxc=zero end if if (dijhat_available) then if (paw_ij(iatom)%has_dijhat==1) then dijhat_need=.true.;paw_ij(iatom)%dijhat(:,:)=zero else if (paw_ij(iatom)%has_dijhat==0.and.need_to_print) then ABI_ALLOCATE(paw_ij(iatom)%dijhat,(cplex_dij*lmn2_size,ndij)) dijhat_need=.true.;paw_ij(iatom)%dijhat(:,:)=zero paw_ij(iatom)%has_dijhat=-1 end if else if (paw_ij(iatom)%has_dijhat==1) then paw_ij(iatom)%dijhat=zero end if if (dijso_available) then if (paw_ij(iatom)%has_dijso==1) then dijso_need=.true.;paw_ij(iatom)%dijso(:,:)=zero else if (paw_ij(iatom)%has_dijso==0.and.need_to_print) then ABI_ALLOCATE(paw_ij(iatom)%dijso,(cplex_dij*lmn2_size,ndij)) dijso_need=.true.;paw_ij(iatom)%dijso(:,:)=zero paw_ij(iatom)%has_dijso=-1 end if else if (paw_ij(iatom)%has_dijso==1) then paw_ij(iatom)%dijso=zero end if if (dijU_available) then if (paw_ij(iatom)%has_dijU==1) then dijU_need=.true.;paw_ij(iatom)%dijU(:,:)=zero else if (paw_ij(iatom)%has_dijU==0.and.need_to_print) then ABI_ALLOCATE(paw_ij(iatom)%dijU,(cplex_dij*lmn2_size,ndij)) dijU_need=.true.;paw_ij(iatom)%dijU(:,:)=zero paw_ij(iatom)%has_dijU=-1 end if else if (paw_ij(iatom)%has_dijU==1) then paw_ij(iatom)%dijU=zero end if if (dijexxc_available.and.paw_ij(iatom)%has_dijexxc/=2) then if (paw_ij(iatom)%has_dijexxc==1) then dijexxc_need=.true.;paw_ij(iatom)%dijexxc(:,:)=zero else if (paw_ij(iatom)%has_dijexxc==0.and.need_to_print) then ABI_ALLOCATE(paw_ij(iatom)%dijexxc,(cplex_dij*lmn2_size,ndij)) dijexxc_need=.true.;paw_ij(iatom)%dijexxc(:,:)=zero paw_ij(iatom)%has_dijexxc=-1 end if else if (paw_ij(iatom)%has_dijexxc==1) then paw_ij(iatom)%dijexxc=zero end if if (dijxchat_available) then if (paw_ij(iatom)%has_dijxc_hat==1) then dijxchat_need=.true.;paw_ij(iatom)%dijxc_hat(:,:)=zero ! else if (paw_ij(iatom)%has_dijxc_hat==0.and.need_to_print) then ! ABI_ALLOCATE(paw_ij(iatom)%dijxc_hat,(cplex_dij*lmn2_size,ndij)) ! dijxchat_need=.true.;paw_ij(iatom)%dijxc_hat(:,:)=zero ! paw_ij(iatom)%has_dijxc_hat=-1 end if else if (paw_ij(iatom)%has_dijxc_hat==1) then paw_ij(iatom)%dijxc_hat=zero end if if (dijxcval_available) then if (paw_ij(iatom)%has_dijxc_val==1) then dijxcval_need=.true.;paw_ij(iatom)%dijxc_val(:,:)=zero ! else if (paw_ij(iatom)%has_dijxc_val==0.and.need_to_print) then ! ABI_ALLOCATE(paw_ij(iatom)%dijxc_val,(cplex_dij*lmn2_size,ndij)) ! dijxcval_need=.true.;paw_ij(iatom)%dijxc_val(:,:)=zero ! paw_ij(iatom)%has_dijxc_val=-1 end if else if (paw_ij(iatom)%has_dijxc_val==1) then paw_ij(iatom)%dijxc_val=zero end if ! === Print error messages if prerequesites are not fulfilled === if (dij_need.and.(.not.dij_prereq)) then MSG_BUG('Dij prerequesites missing!') end if if (dij0_need.and.(.not.dij0_prereq)) then MSG_BUG('Dij0 prerequesites missing!') end if if (dijhartree_need.and.(.not.dijhartree_prereq)) then MSG_BUG('DijHartree prerequesites missing!') end if if (dijxc_need.and.(.not.dijxc_prereq)) then MSG_BUG('Dij^XC prerequesites missing!') end if if (dijhat_need.and.(.not.dijhat_prereq)) then MSG_BUG('Dij^hat prerequesites missing!') end if if (dijhatfr_need.and.(.not.dijhatfr_prereq)) then MSG_BUG('DijFR^hat prerequesites missing!') end if if (dijso_need.and.(.not.dijso_prereq)) then MSG_BUG('DijSO prerequesites missing!') end if if (dijU_need.and.(.not.dijU_prereq)) then MSG_BUG('DijU prerequesites missing!') end if if (dijexxc_need.and.(.not.dijexxc_prereq)) then MSG_BUG('DijExcc prerequesites missing!') end if if (dijxchat_need.and.(.not.dijxchat_prereq)) then MSG_BUG('DijXC^hat prerequesites missing!') end if if (dijxcval_need.and.(.not.dijxcval_prereq)) then MSG_BUG('DijXC_val prerequesites missing!') end if ! ------------------------------------------------------------------------ ! ----------- Add atomic Dij0 to Dij ! ------------------------------------------------------------------------ if ((dij0_need.or.dij_need).and.dij0_available) then ABI_ALLOCATE(dij0,(lmn2_size)) ! ===== Dij0 already computed if (paw_ij(iatom)%has_dij0==2) then dij0(:)=paw_ij(iatom)%dij0(:) else ! ===== Need to compute Dij0 dij0(:)=pawtab(itypat)%dij0(:) if (ipositron==1) dij0(:)=two*pawtab(itypat)%kij(:)-dij0(:) if (dij0_need) paw_ij(iatom)%dij0(:)=dij0(:) end if if (dij_need) then do idij=1,min(nsploop,2) klmn1=1 do klmn=1,lmn2_size paw_ij(iatom)%dij(klmn1,idij)=paw_ij(iatom)%dij(klmn1,idij)+dij0(klmn) klmn1=klmn1+cplex_dij end do end do end if ABI_DEALLOCATE(dij0) end if ! ------------------------------------------------------------------------ ! ----------- Add Dij_Hartree to Dij ! ------------------------------------------------------------------------ if ((dijhartree_need.or.dij_need).and.dijhartree_available) then ABI_ALLOCATE(dijhartree,(cplex*lmn2_size)) ! ===== DijHartree already computed if (paw_ij(iatom)%has_dijhartree==2) then dijhartree(:)=paw_ij(iatom)%dijhartree(:) else ! ===== Need to compute DijHartree if (ipositron/=1) then call pawdijhartree(cplex,dijhartree,nspden,pawrhoij(iatom),pawtab(itypat)) else dijhartree(:)=zero end if if (ipositron/=0) then ABI_ALLOCATE(dij_ep,(cplex*lmn2_size)) call pawdijhartree(cplex,dij_ep,nspden,electronpositron_pawrhoij(iatom),pawtab(itypat)) dijhartree(:)=dijhartree(:)-dij_ep(:) ABI_DEALLOCATE(dij_ep) end if if (dijhartree_need) paw_ij(iatom)%dijhartree(:)=dijhartree(:) end if if (dij_need) then do idij=1,min(nsploop,2) if (cplex==1) then klmn1=1 do klmn=1,lmn2_size paw_ij(iatom)%dij(klmn1,idij)=paw_ij(iatom)%dij(klmn1,idij)+dijhartree(klmn) klmn1=klmn1+cplex_dij end do else paw_ij(iatom)%dij(:,idij)=paw_ij(iatom)%dij(:,idij)+dijhartree(:) end if end do end if ABI_DEALLOCATE(dijhartree) end if ! ------------------------------------------------------------------------ ! ----------- Add Dij_xc to Dij ! ------------------------------------------------------------------------ if ((dijxc_need.or.dij_need).and.dijxc_available) then ! ===== Dijxc already computed if (paw_ij(iatom)%has_dijxc==2) then if (dij_need) paw_ij(iatom)%dij(:,:)=paw_ij(iatom)%dij(:,:)+paw_ij(iatom)%dijxc(:,:) else ! ===== Need to compute DijXC ABI_ALLOCATE(dijxc,(cplex_dij*lmn2_size,ndij)) if (pawxcdev/=0) then ABI_ALLOCATE(lmselect,(lm_size)) lmselect(:)=paw_an(iatom)%lmselect(:) if (ipositron/=0) lmselect(:)=(lmselect(:).or.electronpositron_lmselect(:,iatom)) call pawdijxcm(cplex,cplex_dij,dijxc,lmselect,ndij,nspden,nsppol,pawang,& & pawrad(itypat),pawtab(itypat),paw_an(iatom)%vxc1,& & paw_an(iatom)%vxct1,usexcnhat) ABI_DEALLOCATE(lmselect) else call pawdijxc(cplex,cplex_dij,dijxc,ndij,nspden,nsppol,& & pawang,pawrad(itypat),pawtab(itypat),paw_an(iatom)%vxc1,& & paw_an(iatom)%vxct1,usexcnhat) end if if (dijxc_need) paw_ij(iatom)%dijxc(:,:)=dijxc(:,:) if (dij_need) paw_ij(iatom)%dij(:,:)=paw_ij(iatom)%dij(:,:)+dijxc(:,:) ABI_DEALLOCATE(dijxc) end if end if ! ------------------------------------------------------------------------ ! ----------- Add Dij_hat to Dij ! ------------------------------------------------------------------------ if ((dijhat_need.or.dij_need).and.dijhat_available) then ! ===== Dijhat already computed if (paw_ij(iatom)%has_dijhat==2) then if (dij_need) paw_ij(iatom)%dij(:,:)=paw_ij(iatom)%dij(:,:)+paw_ij(iatom)%dijhat(:,:) else ! ===== Need to compute Dijhat ABI_ALLOCATE(dijhat,(cplex_dij*lmn2_size,ndij)) call pawdijhat(cplex,cplex_dij,dijhat,gprimd,iatom_tot,ipert,& & natom,ndij,nfft,nfftot,nspden,nsppol,pawang,pawfgrtab(iatom),& & pawtab(itypat),v_dijhat,qphon,ucvol,xred,mpi_comm_grid=my_comm_grid) if (dijhat_need) paw_ij(iatom)%dijhat(:,:)=dijhat(:,:) if (dij_need) paw_ij(iatom)%dij(:,:)=paw_ij(iatom)%dij(:,:)+dijhat(:,:) ABI_DEALLOCATE(dijhat) end if ! ===== RF: add frozen part of 1st-order Dij if (dijhatfr_available) then do idij=1,nsploop if (dij_need) paw_ij(iatom)%dij(:,idij)=paw_ij(iatom)%dij(:,idij) & & +paw_ij(iatom)%dijfr(:,idij) if (dijhat_need) paw_ij(iatom)%dijhat(:,idij)=paw_ij(iatom)%dijhat(:,idij) & & +paw_ij(iatom)%dijfr(:,idij) end do end if end if ! ------------------------------------------------------------------------ ! ----------- Add Dij spin-orbit to Dij ! ------------------------------------------------------------------------ if ((dijso_need.or.dij_need).and.dijso_available) then ! ===== DijSO already computed if (paw_ij(iatom)%has_dijso==2) then if (dij_need) paw_ij(iatom)%dij(:,:)=paw_ij(iatom)%dij(:,:)+paw_ij(iatom)%dijso(:,:) else ! ===== Need to compute DijSO ABI_ALLOCATE(dijso,(cplex_dij*lmn2_size,ndij)) call pawdijso(cplex_dij,dijso,ndij,nspden,& & pawang,pawrad(itypat),pawtab(itypat),pawxcdev,spnorbscl,& & paw_an(iatom)%vh1,paw_an(iatom)%vxc1) if (dijso_need) paw_ij(iatom)%dijso(:,:)=dijso(:,:) if (dij_need) paw_ij(iatom)%dij(:,:)=paw_ij(iatom)%dij(:,:)+dijso(:,:) ABI_DEALLOCATE(dijso) end if end if ! ------------------------------------------------------------------------ ! ----------- Add Dij_{LDA+U} to Dij ! ------------------------------------------------------------------------ if ((dijU_need.or.dij_need).and.dijU_available) then ! ===== DijU already computed if (paw_ij(iatom)%has_dijU==2) then if (dij_need) paw_ij(iatom)%dij(:,:)=paw_ij(iatom)%dij(:,:)+paw_ij(iatom)%dijU(:,:) else ! ===== Need to compute DijU lpawu=pawtab(itypat)%lpawu ABI_ALLOCATE(dijpawu,(cplex_dij*lmn2_size,ndij)) ABI_ALLOCATE(vpawu,(cplex_dij,lpawu*2+1,lpawu*2+1,nspden)) if (pawtab(itypat)%usepawu>=10) vpawu=zero ! if dmft, do not apply U in LDA+U if (pawtab(itypat)%usepawu< 10) then call pawpupot(cplex_dij,ndij,paw_ij(iatom)%noccmmp,paw_ij(iatom)%nocctot,& & nspden,pawprtvol,pawtab(itypat),vpawu) end if if (natvshift_==0) then call pawdiju(cplex_dij,dijpawu,ndij,nspden,nsppol,pawtab(itypat),vpawu) else call pawdiju(cplex_dij,dijpawu,ndij,nspden,nsppol,pawtab(itypat),vpawu,& & natvshift=natvshift_,atvshift=atvshift(:,:,iatom_tot),& & fatvshift=fatvshift) end if ABI_DEALLOCATE(vpawu) if (dijU_need) paw_ij(iatom)%dijU(:,:)=dijpawu(:,:) if (dij_need) paw_ij(iatom)%dij(:,:)=paw_ij(iatom)%dij(:,:)+dijpawu(:,:) ABI_DEALLOCATE(dijpawu) end if end if ! ------------------------------------------------------------------------ ! ----------- Add Dij_{local exact-exchange} to Dij ! ------------------------------------------------------------------------ if ((dijexxc_need.or.dij_need).and.dijexxc_available) then ! ===== DijEXXC already computed if (paw_ij(iatom)%has_dijexxc==2) then if (dij_need) paw_ij(iatom)%dij(:,:)=paw_ij(iatom)%dij(:,:)+paw_ij(iatom)%dijexxc(:,:) else ! ===== Need to compute DijEXXC ABI_ALLOCATE(dijexxc,(cplex_dij*lmn2_size,ndij)) if (pawxcdev/=0) then if (paw_ij(iatom)%has_exexch_pot/=2) then ABI_ALLOCATE(vpawx,(1,lmn2_size,nspden)) call pawxpot(nspden,pawprtvol,pawrhoij(iatom),pawtab(itypat),vpawx) else vpawx=>paw_ij(iatom)%vpawx end if ABI_ALLOCATE(lmselect,(lm_size)) lmselect(:)=paw_an(iatom)%lmselect(:) if (ipositron/=0) lmselect(:)=(lmselect(:).or.electronpositron_lmselect(:,iatom)) call pawdijexxc(cplex,cplex_dij,dijexxc,lmselect,ndij,nspden,nsppol,& & pawang,pawrad(itypat),pawtab(itypat),vpawx,paw_an(iatom)%vxc_ex) ABI_DEALLOCATE(lmselect) if (paw_ij(iatom)%has_exexch_pot/=2) then ABI_DEALLOCATE(vpawx) end if if (dijexxc_need) paw_ij(iatom)%dijexxc(:,:)=dijexxc(:,:) if (dij_need) paw_ij(iatom)%dij(:,:)=paw_ij(iatom)%dij(:,:)+dijexxc(:,:) ABI_DEALLOCATE(dijexxc) end if end if end if ! ------------------------------------------------------------------------ ! ----------- Add Dij background contribution to the total Dij ! ------------------------------------------------------------------------ if (dij_need .AND. pawtab(itypat)%usepotzero==1 ) then do idij=1,min(nsploop,2) klmn1=1 do klmn=1,lmn2_size paw_ij(iatom)%dij(klmn1,idij)=paw_ij(iatom)%dij(klmn1,idij)+pawtab(itypat)%gammaij(klmn)*charge/ucvol klmn1=klmn1+cplex_dij end do end do end if ! ------------------------------------------------------------------------ ! ----------- Compute Dijxc_hat ! ------------------------------------------------------------------------ if (dijxchat_need) then if (usexcnhat/=0) then ABI_ALLOCATE(dijxchat,(cplex_dij*lmn2_size,ndij)) call pawdijhat(cplex,cplex_dij,dijxchat,gprimd,iatom_tot,ipert,& & natom,ndij,nfft,nfftot,nspden,nsppol,pawang,pawfgrtab(iatom),& & pawtab(itypat),vxc,qphon,ucvol,xred,mpi_comm_grid=my_comm_grid) paw_ij(iatom)%dijxc_hat(:,:)=dijxchat(:,:) ABI_DEALLOCATE(dijxchat) else ! usexcnhat=0 paw_ij(iatom)%dijxc_hat=zero end if end if ! ------------------------------------------------------------------------ ! ----------- Compute Dijxc_val ! ------------------------------------------------------------------------ if (dijxcval_need) then ABI_ALLOCATE(dijxcval,(cplex_dij*lmn2_size,ndij)) ! Note that usexcnhat=0 for this call (no compensation term) if (pawxcdev/=0) then ABI_ALLOCATE(lmselect,(lm_size)) lmselect(:)=paw_an(iatom)%lmselect(:) if (ipositron/=0) lmselect(:)=(lmselect(:).or.electronpositron_lmselect(:,iatom)) call pawdijxcm(cplex,cplex_dij,dijxcval,lmselect,ndij,nspden,nsppol,& & pawang,pawrad(itypat),pawtab(itypat),paw_an(iatom)%vxc1_val,& & paw_an(iatom)%vxct1_val,0) ABI_DEALLOCATE(lmselect) else call pawdijxc(cplex,cplex_dij,dijxcval,ndij,nspden,nsppol,& & pawang,pawrad(itypat),pawtab(itypat),paw_an(iatom)%vxc1_val,& & paw_an(iatom)%vxct1_val,0) end if paw_ij(iatom)%dijxc_val(:,:)=dijxcval(:,:) ABI_DEALLOCATE(dijxcval) end if ! ------------------------------------------------------------------------ ! Update some flags if (dij_need.and.paw_ij(iatom)%has_dij>=1) paw_ij(iatom)%has_dij=2 if (dij0_need.and.paw_ij(iatom)%has_dij0>=1) paw_ij(iatom)%has_dij0=2 if (dijhartree_need.and.paw_ij(iatom)%has_dijhartree>=1) paw_ij(iatom)%has_dijhartree=2 if (dijxc_need.and.paw_ij(iatom)%has_dijxc>=1) paw_ij(iatom)%has_dijxc=2 if (dijhat_need.and.paw_ij(iatom)%has_dijhat>=1) paw_ij(iatom)%has_dijhat=2 if (dijso_need.and.paw_ij(iatom)%has_dijso>=1) paw_ij(iatom)%has_dijso=2 if (dijU_need.and.paw_ij(iatom)%has_dijU>=1) paw_ij(iatom)%has_dijU=2 if (dijexxc_need.and.paw_ij(iatom)%has_dijexxc>=1) paw_ij(iatom)%has_dijexxc=2 if (dijxchat_need.and.paw_ij(iatom)%has_dijxc_hat>=1) paw_ij(iatom)%has_dijxc_hat=2 if (dijxcval_need.and.paw_ij(iatom)%has_dijxc_val>=1) paw_ij(iatom)%has_dijxc_val=2 !End loop over atoms end do ! iatom !------------------------------------------------------------------------ !Final printing if (paral_atom) then call paw_ij_print(paw_ij,unit=std_out,pawprtvol=pawprtvol,pawspnorb=pawspnorb,& & mpi_comm_atom=my_comm_atom,mpi_atmtab=my_atmtab,natom=natom,& & mode_paral='PERS',enunit=enunit,ipert=ipert) else call paw_ij_print(paw_ij,unit=std_out,pawprtvol=pawprtvol,pawspnorb=pawspnorb,& & mode_paral='COLL',enunit=enunit,ipert=ipert) end if !Free temporary storage if (v_dijhat_allocated) then ABI_DEALLOCATE(v_dijhat) end if do iatom=1,my_natom if (paw_ij(iatom)%has_dij0==-1) then ABI_DEALLOCATE(paw_ij(iatom)%dij0) paw_ij(iatom)%has_dij0=0 end if if (paw_ij(iatom)%has_dijhartree==-1) then ABI_DEALLOCATE(paw_ij(iatom)%dijhartree) paw_ij(iatom)%has_dijhartree=0 end if if (paw_ij(iatom)%has_dijxc==-1) then ABI_DEALLOCATE(paw_ij(iatom)%dijxc) paw_ij(iatom)%has_dijxc=0 end if if (paw_ij(iatom)%has_dijhat==-1) then ABI_DEALLOCATE(paw_ij(iatom)%dijhat) paw_ij(iatom)%has_dijhat=0 end if if (paw_ij(iatom)%has_dijfr==-1) then ABI_DEALLOCATE(paw_ij(iatom)%dijfr) paw_ij(iatom)%has_dijfr=0 end if if (paw_ij(iatom)%has_dijso==-1) then ABI_DEALLOCATE(paw_ij(iatom)%dijso) paw_ij(iatom)%has_dijso=0 end if if (paw_ij(iatom)%has_dijU==-1) then ABI_DEALLOCATE(paw_ij(iatom)%dijU) paw_ij(iatom)%has_dijU=0 end if if (paw_ij(iatom)%has_dijexxc==-1) then ABI_DEALLOCATE(paw_ij(iatom)%dijexxc) paw_ij(iatom)%has_dijexxc=0 end if if (paw_ij(iatom)%has_dijxc_hat==-1) then ABI_DEALLOCATE(paw_ij(iatom)%dijxc_hat) paw_ij(iatom)%has_dijxc_hat=0 end if if (paw_ij(iatom)%has_dijxc_val==-1) then ABI_DEALLOCATE(paw_ij(iatom)%dijxc_val) paw_ij(iatom)%has_dijxc_val=0 end if end do !Destroy atom table used for parallelism call free_my_atmtab(my_atmtab,my_atmtab_allocated) DBG_EXIT("COLL") end subroutine pawdij !!*** !---------------------------------------------------------------------- !!****f* m_pawdij/pawdijhartree !! NAME !! pawdijhartree !! !! FUNCTION !! Compute the Hartree contribution to the PAW pseudopotential strength Dij !! (for one atom only) !! !! COPYRIGHT !! Copyright (C) 1998-2014 ABINIT group (MT) !! This file is distributed under the terms of the !! GNU General Public License, see ~abinit/COPYING !! or http://www.gnu.org/copyleft/gpl.txt . !! For the initials of contributors, see ~abinit/doc/developers/contributors.txt. !! !! INPUTS !! cplex=(RF calculations only) - 1 if RF 1st-order quantities are REAL, 2 if COMPLEX !! nspden=number of spin density components !! pawrhoij <type(pawrhoij_type)>= paw rhoij occupancies (and related data) for current atom !! pawtab <type(pawtab_type)>=paw tabulated starting data, for current atom !! !! OUTPUT !! dijxc(cplex*lmn2_size)= D_ij^Hartree terms !! !! PARENTS !! m_pawdij,pawdenpot,pawenergy3 !! !! CHILDREN !! free_my_atmtab,get_my_atmtab !! !! SOURCE subroutine pawdijhartree(cplex,dijhartree,nspden,pawrhoij,pawtab) !This section has been created automatically by the script Abilint (TD). !Do not modify the following lines by hand. #undef ABI_FUNC #define ABI_FUNC 'pawdijhartree' !End of the abilint section implicit none !Arguments --------------------------------------------- !scalars integer,intent(in) :: cplex,nspden !arrays real(dp),intent(out) :: dijhartree(:) type(pawrhoij_type),intent(in) :: pawrhoij type(pawtab_type),intent(in) :: pawtab !Local variables --------------------------------------- !scalars integer :: irhoij,ispden,jrhoij,kklmn,kklmn1,klmn,klmn1,lmn2_size,nspdiag character(len=500) :: msg !arrays real(dp) :: ro(cplex) ! ************************************************************************* DBG_ENTER("COLL") !Useful data lmn2_size=pawtab%lmn2_size nspdiag=1;if (nspden==2) nspdiag=2 !Check data consistency if (size(dijhartree,1)/=cplex*lmn2_size) then msg='invalid size for DijHartree !' MSG_BUG(msg) end if if (pawrhoij%cplex<cplex) then msg=' pawrhoij%cplex must be >=cplex !' MSG_BUG(msg) end if !------------------------------------------------------------------------ !----------- Allocations and initializations !------------------------------------------------------------------------ dijhartree=zero !Real on-site quantities (ground-state calculation) if (cplex==1) then do ispden=1,nspdiag jrhoij=1 do irhoij=1,pawrhoij%nrhoijsel klmn=pawrhoij%rhoijselect(irhoij) ro(1)=pawrhoij%rhoijp(jrhoij,ispden)*pawtab%dltij(klmn) dijhartree(klmn)=dijhartree(klmn)& & +ro(1)*pawtab%eijkl(klmn,klmn) do klmn1=1,klmn-1 dijhartree(klmn1)=dijhartree(klmn1)& & +ro(1)*pawtab%eijkl(klmn1,klmn) end do do klmn1=klmn+1,lmn2_size dijhartree(klmn1)=dijhartree(klmn1)& & +ro(1)*pawtab%eijkl(klmn,klmn1) end do jrhoij=jrhoij+pawrhoij%cplex end do end do ! Complex on-site quantities (response function calculation) else do ispden=1,nspdiag jrhoij=1 do irhoij=1,pawrhoij%nrhoijsel klmn=pawrhoij%rhoijselect(irhoij);kklmn=2*klmn-1 ro(1:2)=pawrhoij%rhoijp(jrhoij:jrhoij+1,ispden)*pawtab%dltij(klmn) dijhartree(kklmn:kklmn+1)=dijhartree(kklmn:kklmn+1)& & +ro(1:2)*pawtab%eijkl(klmn,klmn) do klmn1=1,klmn-1 kklmn1=2*klmn1-1 dijhartree(kklmn1:kklmn1+1)=dijhartree(kklmn1:kklmn1+1)& & +ro(1:2)*pawtab%eijkl(klmn1,klmn) end do do klmn1=klmn+1,lmn2_size kklmn1=2*klmn1-1 dijhartree(kklmn1:kklmn1+1)=dijhartree(kklmn1:kklmn1+1)& & +ro(1:2)*pawtab%eijkl(klmn,klmn1) end do jrhoij=jrhoij+pawrhoij%cplex end do end do end if DBG_EXIT("COLL") end subroutine pawdijhartree !!*** !---------------------------------------------------------------------- !!****f* m_pawdij/pawdijxc !! NAME !! pawdijxc !! !! FUNCTION !! Compute the eXchange-Correlation contribution to the PAW pseudopotential strength Dij, !! using densities and potential expressed on a (r,theta,phi) grid !! (for one atom only): !! D_ij^XC= < Phi_i|Vxc( n1+ nc[+nhat])| Phi_j> !! -<tPhi_i|Vxc(tn1+tnc[+nhat])|tPhi_j> !! -Intg_omega [ Vxc(tn1+tnc[+nhat])(r). Sum_L(Qij^L(r)). dr] !! !! COPYRIGHT !! Copyright (C) 1998-2014 ABINIT group (MT) !! This file is distributed under the terms of the !! GNU General Public License, see ~abinit/COPYING !! or http://www.gnu.org/copyleft/gpl.txt . !! For the initials of contributors, see ~abinit/doc/developers/contributors.txt. !! !! INPUTS !! cplex=(RF calculations only) - 1 if RF 1st-order quantities are REAL, 2 if COMPLEX !! cplex_dij=1 if dij is REAL, 2 if complex (2 for spin-orbit) !! ndij= number of spin components for Dij^hat !! nspden=number of spin density components !! nsppol=number of independent spin WF components !! pawang <type(pawang_type)>=paw angular mesh and related data, for current atom !! pawrad <type(pawrad_type)>=paw radial mesh and related data, for current atom !! pawtab <type(pawtab_type)>=paw tabulated starting data !! vxc1(mesh_size,angl_size,nspden)=all-electron on-site XC potential for current atom !! given on a (r,theta,phi) grid !! vxct1(mesh_size,angl_size,nspden)=all-electron on-site XC potential for current atom !! given on a (r,theta,phi) grid !! usexcnhat= 1 if compensation density is included in Vxc, 0 otherwise !! !! OUTPUT !! dijxc(cplex_dij*lmn2_size,ndij)= D_ij^XC terms !! !! NOTES !! cplex is for RF, cplex_dij is for non-collinear (nspinor==2) !! !! PARENTS !! m_pawdij !! !! CHILDREN !! free_my_atmtab,get_my_atmtab !! !! SOURCE subroutine pawdijxc(cplex,cplex_dij,dijxc,ndij,nspden,nsppol,& & pawang,pawrad,pawtab,vxc1,vxct1,usexcnhat) !This section has been created automatically by the script Abilint (TD). !Do not modify the following lines by hand. #undef ABI_FUNC #define ABI_FUNC 'pawdijxc' !End of the abilint section implicit none !Arguments --------------------------------------------- !scalars integer,intent(in) :: cplex,cplex_dij,ndij,nspden,nsppol,usexcnhat type(pawang_type),intent(in) :: pawang !arrays real(dp),intent(in) :: vxc1(:,:,:),vxct1(:,:,:) real(dp),intent(out) :: dijxc(:,:) type(pawrad_type),intent(in) :: pawrad type(pawtab_type),intent(in) :: pawtab !Local variables --------------------------------------- !scalars integer :: angl_size,idij,idijend,ij_size,ilm,ils,ils1,ilslm,ipts,ir,ir1,isel,ispden integer :: jlm,j0lm,klmn,klmn1,klm,kln,l_size,lm0,lmax,lmin,lm_size,lmn2_size integer :: mesh_size,mm,nsploop real(dp) :: tmp,vi,vr,vxcijhat,vxcijhat_i character(len=500) :: msg !arrays real(dp),allocatable :: dijxc_idij(:),ff(:),gg(:),vxcij1(:),vxcij2(:),yylmr(:,:) ! ************************************************************************* DBG_ENTER("COLL") !Useful data lm_size=pawtab%lcut_size**2 lmn2_size=pawtab%lmn2_size ij_size=pawtab%ij_size l_size=pawtab%l_size mesh_size=pawtab%mesh_size angl_size=pawang%angl_size !Check data consistency if (size(dijxc,1)/=cplex_dij*lmn2_size.or.size(dijxc,2)/=ndij) then msg='invalid sizes for Dijxc !' MSG_BUG(msg) end if if (size(vxc1,1)/=cplex*mesh_size.or.size(vxct1,1)/=cplex*mesh_size.or.& & size(vxc1,2)/=angl_size.or.size(vxct1,2)/=angl_size.or.& & size(vxc1,3)/=nspden.or.size(vxct1,3)/=nspden) then msg='invalid sizes for vxc1 or vxct1 !' MSG_BUG(msg) end if if (cplex_dij<cplex) then msg='cplex_dij must be >= cplex !' MSG_BUG(msg) end if !Precompute products Ylm*Ylpmp lmax=maxval(pawtab%indklmn(4,1:lmn2_size)) ABI_ALLOCATE(yylmr,(lmax**2*(lmax**2+1)/2,angl_size)) do ipts=1,angl_size do jlm=1,lmax**2 j0lm=jlm*(jlm-1)/2 do ilm=1,jlm klm=j0lm+ilm yylmr(klm,ipts)=pawang%ylmr(ilm,ipts)*pawang%ylmr(jlm,ipts) end do end do end do !Init memory dijxc=zero ABI_ALLOCATE(dijxc_idij,(cplex*lmn2_size)) ABI_ALLOCATE(vxcij1,(cplex*ij_size)) ABI_ALLOCATE(vxcij2,(cplex*l_size)) ABI_ALLOCATE(ff,(mesh_size)) ABI_ALLOCATE(gg,(mesh_size)) !---------------------------------------------------------- !Loop over spin components !---------------------------------------------------------- nsploop=nsppol;if (ndij==4) nsploop=4 do idij=1,nsploop if (idij<=nsppol.or.(nspden==4.and.idij<=3).or.cplex==2) then idijend=idij+idij/3;if (cplex==2) idijend=idij do ispden=idij,idijend dijxc_idij=zero ! ---------------------------------------------------------- ! Loop on angular mesh ! ---------------------------------------------------------- do ipts=1,angl_size ! ===== Vxc_ij_1 (tmp) ===== vxcij1=zero if (cplex==1) then do kln=1,ij_size ff(1:mesh_size)= & & vxc1(1:mesh_size,ipts,ispden)*pawtab%phiphj(1:mesh_size,kln) & & -vxct1(1:mesh_size,ipts,ispden)*pawtab%tphitphj(1:mesh_size,kln) call simp_gen(vxcij1(kln),ff,pawrad) end do else do kln=1,ij_size do ir=1,mesh_size ir1=2*ir ff(ir)= & & vxc1(ir1-1,ipts,ispden)*pawtab%phiphj(ir,kln) & & -vxct1(ir1-1,ipts,ispden)*pawtab%tphitphj(ir,kln) gg(ir)= & & vxc1(ir1,ipts,ispden)*pawtab%phiphj(ir,kln) & & -vxct1(ir1,ipts,ispden)*pawtab%tphitphj(ir,kln) end do call simp_gen(vxcij1(2*kln-1),ff,pawrad) call simp_gen(vxcij1(2*kln ),gg,pawrad) end do end if ! ===== Vxc_ij_2 (tmp) ===== vxcij2=zero if (usexcnhat/=0) then if (cplex==1) then do ils=1,l_size ff(1:mesh_size)=vxct1(1:mesh_size,ipts,ispden) & & *pawtab%shapefunc(1:mesh_size,ils) & & *pawrad%rad(1:mesh_size)**2 call simp_gen(vxcij2(ils),ff,pawrad) end do else do ils=1,l_size do ir=1,mesh_size ir1=2*ir tmp=pawtab%shapefunc(ir,ils)*pawrad%rad(ir)**2 ff(ir)=vxct1(ir1-1,ipts,ispden)*tmp gg(ir)=vxct1(ir1 ,ipts,ispden)*tmp end do call simp_gen(vxcij2(2*ils-1),ff,pawrad) call simp_gen(vxcij2(2*ils ),gg,pawrad) end do end if end if ! ===== Integrate Vxc_ij_1 and Vxc_ij_2 over the angular mesh ===== ! ===== and accummulate in total Vxc_ij ===== if (cplex==1) then do klmn=1,lmn2_size klm=pawtab%indklmn(1,klmn);kln=pawtab%indklmn(2,klmn) lmin=pawtab%indklmn(3,klmn);lmax=pawtab%indklmn(4,klmn) dijxc_idij(klmn)=dijxc_idij(klmn) & & +vxcij1(kln)*pawang%angwgth(ipts)*yylmr(klm,ipts)*four_pi if (usexcnhat/=0) then vxcijhat=zero do ils=lmin,lmax,2 lm0=ils**2+ils+1 vr=four_pi*pawang%angwgth(ipts)*vxcij2(ils+1) do mm=-ils,ils ilslm=lm0+mm;isel=pawang%gntselect(ilslm,klm) if (isel>0) then tmp=pawang%ylmr(ilslm,ipts)*pawtab%qijl(ilslm,klmn) vxcijhat=vxcijhat+vr*tmp end if end do end do dijxc_idij(klmn)=dijxc_idij(klmn)-vxcijhat end if end do ! Loop klmn else klmn1=1 do klmn=1,lmn2_size klm=pawtab%indklmn(1,klmn);kln=pawtab%indklmn(2,klmn) lmin=pawtab%indklmn(3,klmn);lmax=pawtab%indklmn(4,klmn) tmp=pawang%angwgth(ipts)*yylmr(klm,ipts)*four_pi dijxc_idij(klmn1 )=dijxc_idij(klmn1 )+vxcij1(2*kln-1)*tmp dijxc_idij(klmn1+1)=dijxc_idij(klmn1+1)+vxcij1(2*kln )*tmp if (usexcnhat/=0) then vxcijhat=zero;vxcijhat_i=zero do ils=lmin,lmax,2 lm0=ils**2+ils+1;ils1=2*(ils+1) vr=four_pi*pawang%angwgth(ipts)*vxcij2(ils1-1) vi=four_pi*pawang%angwgth(ipts)*vxcij2(ils1 ) do mm=-ils,ils ilslm=lm0+mm;isel=pawang%gntselect(ilslm,klm) if (isel>0) then tmp=pawang%ylmr(ilslm,ipts)*pawtab%qijl(ilslm,klmn) vxcijhat =vxcijhat +vr*tmp vxcijhat_i=vxcijhat_i+vi*tmp end if end do end do dijxc_idij(klmn1 )=dijxc_idij(klmn1 )-vxcijhat dijxc_idij(klmn1+1)=dijxc_idij(klmn1+1)-vxcijhat_i end if klmn1=klmn1+cplex end do ! Loop klmn end if ! ---------------------------------------------------------- ! End loop on angular points end do ! ---------------------------------------------------------- ! Deduce some part of Dij according to symmetries ! ---------------------------------------------------------- if (cplex==1) then if (ispden<3) then if (cplex_dij==1) then dijxc(1:lmn2_size,idij)=dijxc_idij(1:lmn2_size) else klmn1=1 do klmn=1,lmn2_size dijxc(klmn1 ,idij)=dijxc_idij(klmn) dijxc(klmn1+1,idij)=zero klmn1=klmn1+cplex_dij end do end if else klmn1=max(1,ispden-2) do klmn=1,lmn2_size dijxc(klmn1,idij)=dijxc_idij(klmn) klmn1=klmn1+cplex_dij end do end if else !cplex=2 if (ispden<=3) then dijxc(1:cplex*lmn2_size,idij)=dijxc_idij(1:cplex*lmn2_size) else klmn1=1 ! Remember V(4) contains i.V^21 do klmn=1,lmn2_size dijxc(klmn1 ,idij)= dijxc_idij(klmn+1) dijxc(klmn1+1,idij)=-dijxc_idij(klmn ) klmn1=klmn1+cplex_dij end do end if end if end do !ispden else if (nspden==4.and.idij==4) then ! cplex=1 here dijxc(:,idij)=dijxc(:,idij-1) klmn1=2 do klmn=1,lmn2_size dijxc(klmn1,idij)=-dijxc(klmn1,idij) klmn1=klmn1+cplex_dij end do else if (nsppol==1.and.idij==2) then ! cplex=1 here dijxc(:,idij)=dijxc(:,idij-1) end if !---------------------------------------------------------- !End loop on spin density components end do !Free temporary memory spaces ABI_DEALLOCATE(yylmr) ABI_DEALLOCATE(dijxc_idij) ABI_DEALLOCATE(vxcij1) ABI_DEALLOCATE(vxcij2) ABI_DEALLOCATE(ff) ABI_DEALLOCATE(gg) DBG_EXIT("COLL") end subroutine pawdijxc !!*** !---------------------------------------------------------------------- !!****f* m_pawdij/pawdijxcm !! NAME !! pawdijxcm !! !! FUNCTION !! Compute the eXchange-Correlation contribution to the PAW pseudopotential strength Dij, !! using densities and potential expressed as (l,m) spherical moments !! (for one atom only): !! D_ij^XC= < Phi_i|Vxc( n1+ nc[+nhat])| Phi_j> !! -<tPhi_i|Vxc(tn1+tnc[+nhat])|tPhi_j> !! -Intg_omega [ Vxc(tn1+tnc[+nhat])(r). Sum_L(Qij^L(r)). dr] !! !! COPYRIGHT !! Copyright (C) 1998-2014 ABINIT group (MT) !! This file is distributed under the terms of the !! GNU General Public License, see ~abinit/COPYING !! or http://www.gnu.org/copyleft/gpl.txt . !! For the initials of contributors, see ~abinit/doc/developers/contributors.txt. !! !! INPUTS !! cplex=(RF calculations only) - 1 if RF 1st-order quantities are REAL, 2 if COMPLEX !! cplex_dij=1 if dij is REAL, 2 if complex (2 for spin-orbit) !! lmselect(lm_size)=select the non-zero LM-moments of on-site potentials !! ndij= number of spin components for Dij^hat !! nspden=number of spin density components !! nsppol=number of independent spin WF components !! pawang <type(pawang_type)>=paw angular mesh and related data, for current atom !! pawrad <type(pawrad_type)>=paw radial mesh and related data, for current atom !! pawtab <type(pawtab_type)>=paw tabulated starting data !! vxc1(mesh_size,lm_size,nspden)=all-electron on-site XC potential for current atom !! given on (l,m) spherical moments !! vxct1(mesh_size,lm_size,nspden)=all-electron on-site XC potential for current atom !! given on (l,m) spherical moments !! usexcnhat= 1 if compensation density is included in Vxc, 0 otherwise !! !! OUTPUT !! dijxc(cplex_dij*lmn2_size,ndij)= D_ij^XC terms !! !! NOTES !! cplex is for RF, cplex_dij is for non-collinear (nspinor==2) !! !! PARENTS !! m_pawdij !! !! CHILDREN !! free_my_atmtab,get_my_atmtab !! !! SOURCE subroutine pawdijxcm(cplex,cplex_dij,dijxc,lmselect,ndij,nspden,nsppol,& & pawang,pawrad,pawtab,vxc1,vxct1,usexcnhat) !This section has been created automatically by the script Abilint (TD). !Do not modify the following lines by hand. #undef ABI_FUNC #define ABI_FUNC 'pawdijxcm' !End of the abilint section implicit none !Arguments --------------------------------------------- !scalars integer,intent(in) :: cplex,cplex_dij,ndij,nspden,nsppol,usexcnhat type(pawang_type),intent(in) :: pawang !arrays logical :: lmselect(:) real(dp),intent(in) :: vxc1(:,:,:),vxct1(:,:,:) real(dp),intent(out) :: dijxc(:,:) type(pawrad_type),intent(in) :: pawrad type(pawtab_type),intent(in) :: pawtab !Local variables --------------------------------------- !scalars integer :: idij,idijend,ij_size,ir,ir1,isel,ispden,klm,klm1,klmn,klmn1,kln integer :: lm_size,lmn2_size,ll,mesh_size,nsploop real(dp) :: tmp,vxcij2,vxcij2_i character(len=500) :: msg !arrays real(dp),allocatable :: dijxc_idij(:),ff(:),gg(:),vxcij1(:) ! ************************************************************************* DBG_ENTER("COLL") !Useful data lm_size=pawtab%lcut_size**2 lmn2_size=pawtab%lmn2_size ij_size=pawtab%ij_size mesh_size=pawtab%mesh_size !Check data consistency if (size(dijxc,1)/=cplex_dij*lmn2_size.or.size(dijxc,2)/=ndij) then msg='invalid sizes for Dijxc !' MSG_BUG(msg) end if if (size(lmselect)/=lm_size) then msg='invalid size for lmselect !' MSG_BUG(msg) end if if (size(vxc1,1)/=cplex*mesh_size.or.size(vxct1,1)/=cplex*mesh_size.or.& & size(vxc1,2)/=lm_size.or.size(vxct1,2)/=lm_size.or.& & size(vxc1,3)/=nspden.or.size(vxct1,3)/=nspden) then msg='invalid sizes for vxc1 or vxct1 !' MSG_BUG(msg) end if if (cplex_dij<cplex) then msg='cplex_dij must be >= cplex !' MSG_BUG(msg) end if !Init memory dijxc=zero ABI_ALLOCATE(dijxc_idij,(cplex*lmn2_size)) ABI_ALLOCATE(vxcij1,(cplex*ij_size)) ABI_ALLOCATE(ff,(mesh_size)) ABI_ALLOCATE(gg,(mesh_size)) !---------------------------------------------------------- !Loop over spin components !---------------------------------------------------------- nsploop=nsppol;if (ndij==4) nsploop=4 do idij=1,nsploop if (idij<=nsppol.or.(nspden==4.and.idij<=3).or.cplex==2) then idijend=idij+idij/3;if (cplex==2) idijend=idij do ispden=idij,idijend dijxc_idij=zero ! ---------------------------------------------------------- ! Summing over (l,m) moments ! ---------------------------------------------------------- do klm=1,lm_size if (lmselect(klm)) then ! ===== Vxc_ij_1 (tmp) ===== vxcij1=zero if (cplex==1) then do kln=1,ij_size ff(1:mesh_size)= & & vxc1(1:mesh_size,klm,ispden)*pawtab%phiphj(1:mesh_size,kln) & & -vxct1(1:mesh_size,klm,ispden)*pawtab%tphitphj(1:mesh_size,kln) call simp_gen(vxcij1(kln),ff,pawrad) end do else ! cplex==2 do kln=1,ij_size do ir=1,mesh_size ir1=2*ir ff(ir)= & & vxc1(ir1-1,klm,ispden)*pawtab%phiphj(ir,kln) & & -vxct1(ir1-1,klm,ispden)*pawtab%tphitphj(ir,kln) gg(ir)= & & vxc1(ir1,klm,ispden)*pawtab%phiphj(ir,kln) & & -vxct1(ir1,klm,ispden)*pawtab%tphitphj(ir,kln) end do call simp_gen(vxcij1(2*kln-1),ff,pawrad) call simp_gen(vxcij1(2*kln ),gg,pawrad) end do end if ! ===== Vxc_ij_2 (tmp) ===== vxcij2=zero;vxcij2_i=zero if (usexcnhat/=0) then ll=1+int(sqrt(dble(klm)-0.1_dp)) if (cplex==1) then ff(1:mesh_size)=vxct1(1:mesh_size,klm,ispden) & & *pawtab%shapefunc(1:mesh_size,ll) & & *pawrad%rad(1:mesh_size)**2 call simp_gen(vxcij2,ff,pawrad) else ! cplex==2 do ir=1,mesh_size ir1=2*ir tmp=pawtab%shapefunc(ir,ll)*pawrad%rad(ir)**2 ff(ir)=vxct1(ir1-1,klm,ispden)*tmp gg(ir)=vxct1(ir1 ,klm,ispden)*tmp end do call simp_gen(vxcij2 ,ff,pawrad) call simp_gen(vxcij2_i,gg,pawrad) end if end if ! ===== Accumulate over klm moments Vxc_ij_1 and Vxc_ij_2 ===== ! ===== into total Vxc_ij ===== if (cplex==1) then do klmn=1,lmn2_size klm1=pawtab%indklmn(1,klmn) kln=pawtab%indklmn(2,klmn) isel=pawang%gntselect(klm,klm1) if (isel>0) & & dijxc_idij(klmn)=dijxc_idij(klmn)+vxcij1(kln)*pawang%realgnt(isel) if (usexcnhat/=0) & dijxc_idij(klmn)=dijxc_idij(klmn)-pawtab%qijl(klm,klmn)*vxcij2 end do ! Loop klmn else ! cplex==2 klmn1=1 do klmn=1,lmn2_size klm1=pawtab%indklmn(1,klmn) kln=pawtab%indklmn(2,klmn) isel=pawang%gntselect(klm,klm1) if (isel>0) then dijxc_idij(klmn1 )=dijxc_idij(klmn1) & & +vxcij1(2*kln-1)*pawang%realgnt(isel) dijxc_idij(klmn1+1)=dijxc_idij(klmn1+1) & & +vxcij1(2*kln )*pawang%realgnt(isel) end if if (usexcnhat/=0) then dijxc_idij(klmn1 )=dijxc_idij(klmn1) & & -pawtab%qijl(klm,klmn)*vxcij2 dijxc_idij(klmn1+1)=dijxc_idij(klmn1+1) & & -pawtab%qijl(klm,klmn)*vxcij2_i end if klmn1=klmn1+cplex end do ! Loop klmn end if end if ! klm selection end do ! Loop klm ! ---------------------------------------------------------- ! Deduce some part of Dij according to symmetries ! ---------------------------------------------------------- if (cplex==1) then if (ispden<3) then if (cplex_dij==1) then dijxc(1:lmn2_size,idij)=dijxc_idij(1:lmn2_size) else klmn1=1 do klmn=1,lmn2_size dijxc(klmn1 ,idij)=dijxc_idij(klmn) dijxc(klmn1+1,idij)=zero klmn1=klmn1+cplex_dij end do end if else klmn1=max(1,ispden-2) do klmn=1,lmn2_size dijxc(klmn1,idij)=dijxc_idij(klmn) klmn1=klmn1+cplex_dij end do end if else !cplex=2 if (ispden<=3) then dijxc(1:cplex*lmn2_size,idij)=dijxc_idij(1:cplex*lmn2_size) else klmn1=1 ! Remember V(4) contains i.V^21 do klmn=1,lmn2_size dijxc(klmn1 ,idij)= dijxc_idij(klmn+1) dijxc(klmn1+1,idij)=-dijxc_idij(klmn ) klmn1=klmn1+cplex_dij end do end if end if end do !ispden else if (nspden==4.and.idij==4) then ! cplex=1 here dijxc(:,idij)=dijxc(:,idij-1) klmn1=2 do klmn=1,lmn2_size dijxc(klmn1,idij)=-dijxc(klmn1,idij) klmn1=klmn1+cplex_dij end do else if (nsppol==1.and.idij==2) then ! cplex=1 here dijxc(:,idij)=dijxc(:,idij-1) end if !---------------------------------------------------------- !End loop on spin density components end do !Free temporary memory spaces ABI_DEALLOCATE(dijxc_idij) ABI_DEALLOCATE(vxcij1) ABI_DEALLOCATE(ff) ABI_DEALLOCATE(gg) DBG_EXIT("COLL") end subroutine pawdijxcm !!*** !---------------------------------------------------------------------- !!****f* m_pawdij/pawdijhat !! NAME !! pawdijhat !! !! FUNCTION !! Compute the "hat" contribution to the PAW pseudopotential strength Dij, !! i.e. the compensation charge contribution (for one atom only): !! D_ij^hat=Intg_R [ V(r). Sum_L(Qij^L(r)). dr] !! !! COPYRIGHT !! Copyright (C) 1998-2014 ABINIT group (MT) !! This file is distributed under the terms of the !! GNU General Public License, see ~abinit/COPYING !! or http://www.gnu.org/copyleft/gpl.txt . !! For the initials of contributors, see ~abinit/doc/developers/contributors.txt. !! !! INPUTS !! cplex=(RF calculations only) - 1 if RF 1st-order quantities are REAL, 2 if COMPLEX !! cplex_dij=1 if dij is REAL, 2 if complex (2 for spin-orbit) !! gprimd(3,3)=dimensional primitive translations for reciprocal space !! iatom=absolute index of current atom (between 1 and natom) !! ipert=index of perturbation; used only for RF calculation ; set ipert<=0 for GS calculations. !! natom=total number of atoms !! ndij= number of spin components for Dij^hat !! ngrid=number of points of the real space grid (FFT, WVL, ...) treated by current proc !! ngridtot=total number of points of the real space grid (FFT, WVL, ...) !! For the FFT grid, thi should be equal to ngfft1*ngfft2*ngfft3 !! nspden=number of spin density components !! nsppol=number of independent spin WF components !! pawang <type(pawang_type)>=paw angular mesh and related data !! pawfgrtab<type(pawfgrtab_type)>=atomic data given on fine rectangular grid for current atom !! pawtab(ntypat) <type(pawtab_type)>=paw tabulated starting data, for current atom !! Pot(cplex*ngrid,nspden)=potential on real space grid !! qphon(3)=(RF calculations only) - wavevector of the phonon !! ucvol=unit cell volume !! xred(3,my_natom)= reduced atomic coordinates !! !! OUTPUT !! dijhat(cplex_dij*lmn2_size,ndij)= D_ij^hat terms !! !! NOTES !! cplex is for RF, cplex_dij is for non-collinear (nspinor==2) !! !! PARENTS !! m_pawdij !! !! CHILDREN !! free_my_atmtab,get_my_atmtab !! !! SOURCE subroutine pawdijhat(cplex,cplex_dij,dijhat,gprimd,iatom,ipert,& & natom,ndij,ngrid,ngridtot,nspden,nsppol,pawang,pawfgrtab,& & pawtab,Pot,qphon,ucvol,xred,& & mpi_comm_grid) ! Optional argument !This section has been created automatically by the script Abilint (TD). !Do not modify the following lines by hand. #undef ABI_FUNC #define ABI_FUNC 'pawdijhat' !End of the abilint section implicit none !Arguments --------------------------------------------- !scalars integer,intent(in) :: cplex,cplex_dij,iatom,ipert,natom,ndij integer,intent(in) :: ngrid,ngridtot,nspden,nsppol integer,intent(in),optional :: mpi_comm_grid real(dp),intent(in) :: ucvol type(pawang_type),intent(in) :: pawang type(pawfgrtab_type),intent(inout) :: pawfgrtab !arrays real(dp),intent(in) :: gprimd(3,3),Pot(cplex*ngrid,nspden),qphon(3),xred(3,natom) real(dp),intent(out) :: dijhat(:,:) type(pawtab_type),intent(in) :: pawtab !Local variables --------------------------------------- !scalars integer :: ic,idij,idijend,ier,ils,ilslm,ilslm1,isel,ispden,jc,klm,klmn,klmn1 integer :: lm0,lm_size,lmax,lmin,lmn2_size,mm,my_comm_grid,nfgd,nsploop,optgr0,optgr1 logical :: has_phase,qne0 real(dp) :: vi,vr character(len=500) :: msg !arrays real(dp) :: rdum(1) real(dp),allocatable :: dijhat_idij(:),prod(:) ! ************************************************************************* DBG_ENTER("COLL") !Useful data lm_size=pawtab%lcut_size**2 lmn2_size=pawtab%lmn2_size nfgd=pawfgrtab%nfgd has_phase=.false. qne0=(qphon(1)**2+qphon(2)**2+qphon(3)**2>=1.d-15) my_comm_grid=xmpi_self;if (present(mpi_comm_grid)) my_comm_grid=mpi_comm_grid !Check data consistency if (size(dijhat,1)/=cplex_dij*lmn2_size.or.size(dijhat,2)/=ndij) then msg='invalid sizes for Dijhat !' MSG_BUG(msg) end if if (pawfgrtab%rfgd_allocated==0.and.ipert>0.and.ipert<=natom.and.qne0) then msg='pawfgrtab()%rfgd array must be allocated !' MSG_BUG(msg) end if if (cplex_dij<cplex) then msg='cplex_dij must be >= cplex !' MSG_BUG(msg) end if !Eventually compute g_l(r).Y_lm(r) factors for the current atom (if not already done) if ((pawfgrtab%gylm_allocated==0).or.((ipert==iatom).and.(pawfgrtab%gylmgr_allocated==0))) then optgr0=0;optgr1=0 if (pawfgrtab%gylm_allocated==0) then if (allocated(pawfgrtab%gylm)) then ABI_DEALLOCATE(pawfgrtab%gylm) end if ABI_ALLOCATE(pawfgrtab%gylm,(nfgd,lm_size)) pawfgrtab%gylm_allocated=2;optgr0=1 end if if ((ipert==iatom).and.(pawfgrtab%gylmgr_allocated==0)) then if (allocated(pawfgrtab%gylmgr)) then ABI_DEALLOCATE(pawfgrtab%gylmgr) end if ABI_ALLOCATE(pawfgrtab%gylmgr,(3,nfgd,lm_size)) pawfgrtab%gylmgr_allocated=2;optgr1=1 end if if (optgr0+optgr1>0) then call pawgylm(pawfgrtab%gylm,pawfgrtab%gylmgr,rdum,lm_size,nfgd,optgr0,optgr1,0,& & pawtab,pawfgrtab%rfgd) end if end if !Eventually compute exp(-i.q.r) factors for the current atom (if not already done) if ((ipert==iatom).and.qne0.and.(pawfgrtab%expiqr_allocated==0)) then if (allocated(pawfgrtab%expiqr)) then ABI_DEALLOCATE(pawfgrtab%expiqr) end if ABI_ALLOCATE(pawfgrtab%expiqr,(2,nfgd)) call pawexpiqr(pawfgrtab%expiqr,gprimd,nfgd,qphon,pawfgrtab%rfgd,xred(:,iatom)) pawfgrtab%expiqr_allocated=2 end if has_phase=(qne0.and.ipert>0.and.pawfgrtab%expiqr_allocated/=0) !Init memory dijhat=zero ABI_ALLOCATE(prod,(cplex*lm_size)) ABI_ALLOCATE(dijhat_idij,(cplex*lmn2_size)) !---------------------------------------------------------- !Loop over spin components !---------------------------------------------------------- nsploop=nsppol;if (ndij==4) nsploop=4 do idij=1,nsploop if (idij<=nsppol.or.(nspden==4.and.idij<=3).or.cplex==2) then idijend=idij+idij/3;if (cplex==2) idijend=idij do ispden=idij,idijend ! ------------------------------------------------------ ! Compute Int[V(r).g_l(r).Y_lm(r)] ! ------------------------------------------------------ ! Note for non-collinear magnetism: ! We compute Int[V^(alpha,beta)(r).g_l(r).Y_lm(r)] ! Remember: if nspden=4, V is stored as : V^11, V^22, V^12, i.V^21 prod=zero ! ===== Standard case ============================ if (.not.has_phase) then if (cplex==1) then do ilslm=1,lm_size do ic=1,nfgd vr=Pot(pawfgrtab%ifftsph(ic),ispden) prod(ilslm)=prod(ilslm)+vr*pawfgrtab%gylm(ic,ilslm) end do end do else ilslm1=1 do ilslm=1,lm_size do ic=1,nfgd jc=2*pawfgrtab%ifftsph(ic) vr=Pot(jc-1,ispden);vi=Pot(jc,ispden) prod(ilslm1 )=prod(ilslm1 )+vr*pawfgrtab%gylm(ic,ilslm) prod(ilslm1+1)=prod(ilslm1+1)+vi*pawfgrtab%gylm(ic,ilslm) end do ilslm1=ilslm1+cplex end do end if ! ===== Including Exp(iqr) phase (DFPT only) ===== else if (cplex==1) then do ilslm=1,lm_size do ic=1,nfgd vr=Pot(pawfgrtab%ifftsph(ic),ispden) prod(ilslm)=prod(ilslm)+vr*pawfgrtab%gylm(ic,ilslm)& & *pawfgrtab%expiqr(1,ic) end do end do else ilslm1=1 do ilslm=1,lm_size do ic=1,nfgd jc=2*pawfgrtab%ifftsph(ic) vr=Pot(jc-1,ispden);vi=Pot(jc,ispden) prod(ilslm1 )=prod(ilslm1 )+pawfgrtab%gylm(ic,ilslm)& & *(vr*pawfgrtab%expiqr(1,ic)-vi*pawfgrtab%expiqr(2,ic)) prod(ilslm1+1)=prod(ilslm1+1)+pawfgrtab%gylm(ic,ilslm)& & *(vr*pawfgrtab%expiqr(2,ic)+vi*pawfgrtab%expiqr(1,ic)) end do ilslm1=ilslm1+cplex end do end if end if ! Scaling factor (unit volume) prod=prod*ucvol/dble(ngridtot) ! Reduction in case of parallelism if (xcomm_size(my_comm_grid)>1) then call xmpi_sum(prod,my_comm_grid,ier) end if ! ---------------------------------------------------------- ! Compute Sum_(i,j)_LM { q_ij^L Int[V(r).g_l(r).Y_lm(r)] } ! ---------------------------------------------------------- ! Note for non-collinear magnetism: ! We compute Sum_(i,j)_LM { q_ij^L Int[V^(alpha,beta)(r).g_l(r).Y_lm(r)] } dijhat_idij=zero if (cplex==1) then do klmn=1,lmn2_size klm =pawtab%indklmn(1,klmn) lmin=pawtab%indklmn(3,klmn) lmax=pawtab%indklmn(4,klmn) do ils=lmin,lmax,2 lm0=ils**2+ils+1 do mm=-ils,ils ilslm=lm0+mm;isel=pawang%gntselect(lm0+mm,klm) if (isel>0) dijhat_idij(klmn)=dijhat_idij(klmn) & & +prod(ilslm)*pawtab%qijl(ilslm,klmn) end do end do end do else do klmn=1,lmn2_size klmn1=2*klmn-1 klm =pawtab%indklmn(1,klmn) lmin=pawtab%indklmn(3,klmn) lmax=pawtab%indklmn(4,klmn) do ils=lmin,lmax,2 lm0=ils**2+ils+1 do mm=-ils,ils ilslm=lm0+mm;ilslm1=2*ilslm;isel=pawang%gntselect(lm0+mm,klm) if (isel>0) dijhat_idij(klmn1:klmn1+1)=dijhat_idij(klmn1:klmn1+1) & & +prod(ilslm1-1:ilslm1)*pawtab%qijl(ilslm,klmn) end do end do end do end if ! ---------------------------------------------------------- ! Deduce some part of Dij according to symmetries ! ---------------------------------------------------------- if (cplex==1) then if (ispden<3) then if (cplex_dij==1) then dijhat(1:lmn2_size,idij)=dijhat_idij(1:lmn2_size) else klmn1=1 do klmn=1,lmn2_size dijhat(klmn1 ,idij)=dijhat_idij(klmn) dijhat(klmn1+1,idij)=zero klmn1=klmn1+cplex_dij end do end if else klmn1=max(1,ispden-2) do klmn=1,lmn2_size dijhat(klmn1,idij)=dijhat_idij(klmn) klmn1=klmn1+cplex_dij end do end if else !cplex=2 if (ispden<=3) then dijhat(1:cplex*lmn2_size,idij)=dijhat_idij(1:cplex*lmn2_size) else klmn1=1 ! Remember V(4) contains i.V^21 do klmn=1,lmn2_size dijhat(klmn1 ,idij)= dijhat_idij(klmn+1) dijhat(klmn1+1,idij)=-dijhat_idij(klmn ) klmn1=klmn1+cplex_dij end do end if end if end do !ispden else if (nspden==4.and.idij==4) then ! cplex=1 here dijhat(:,idij)=dijhat(:,idij-1) klmn1=2 do klmn=1,lmn2_size dijhat(klmn1,idij)=-dijhat(klmn1,idij) klmn1=klmn1+cplex_dij end do else if (nsppol==1.and.idij==2) then ! cplex=1 here dijhat(:,idij)=dijhat(:,idij-1) end if !---------------------------------------------------------- !End loop on spin density components end do !Free temporary memory spaces ABI_DEALLOCATE(prod) ABI_DEALLOCATE(dijhat_idij) if (pawfgrtab%gylm_allocated==2) then ABI_DEALLOCATE(pawfgrtab%gylm) ABI_ALLOCATE(pawfgrtab%gylm,(0,0)) pawfgrtab%gylm_allocated=0 end if if (pawfgrtab%gylmgr_allocated==2) then ABI_DEALLOCATE(pawfgrtab%gylmgr) ABI_ALLOCATE(pawfgrtab%gylmgr,(0,0,0)) pawfgrtab%gylmgr_allocated=0 end if if (pawfgrtab%expiqr_allocated==2) then ABI_DEALLOCATE(pawfgrtab%expiqr) ABI_ALLOCATE(pawfgrtab%expiqr,(0,0)) pawfgrtab%expiqr_allocated=0 end if DBG_EXIT("COLL") end subroutine pawdijhat !!*** !---------------------------------------------------------------------- !!****f* m_pawdij/pawdiju !! NAME !! pawdiju !! !! FUNCTION !! Compute the LDA+U contribution to the PAW pseudopotential strength Dij, !! (for one atom only): !! Dijpawu^{\sigma}_{mi,ni,mj,nj}= !! \sum_{m,m'} [vpawu^{\sigma}_{m,m'}*phiphjint_{ni,nj}^{m,m'}]= !! [vpawu^{\sigma}_{mi,mj}*phiphjint_{ni,nj}] !! !! COPYRIGHT !! Copyright (C) 1998-2014 ABINIT group (MT,FJ,BA) !! This file is distributed under the terms of the !! GNU General Public License, see ~abinit/COPYING !! or http://www.gnu.org/copyleft/gpl.txt . !! For the initials of contributors, see ~abinit/doc/developers/contributors.txt. !! !! INPUTS !! cplex_dij=1 if dij is REAL, 2 if complex (2 for spin-orbit) !! ndij= number of spin components for Dij^hat !! nspden=number of spin density components !! nsppol=number of independent spin WF components !! pawtab <type(pawtab_type)>=paw tabulated starting data, for current atom !! vpawu(cplex_dij,lpawu*2+1,lpawu*2+1,nspden)=moments of LDA+U potential for current atom !! --- Optional arguments --- !! atvshift(natvshift,nsppol)=potential energy shift for lm channel & spin (current atom) !! fatvshift=factor that multiplies atvshift !! natvshift=number of atomic potential energy shifts (per atom) !! !! OUTPUT !! dijpawu(cplex_dij*lmn2_size,ndij)= D_ij^XC terms !! !! PARENTS !! m_pawdij !! !! CHILDREN !! free_my_atmtab,get_my_atmtab !! !! SOURCE subroutine pawdiju(cplex_dij,dijpawu,ndij,nspden,nsppol,pawtab,vpawu,& & natvshift,atvshift,fatvshift) ! optional arguments !This section has been created automatically by the script Abilint (TD). !Do not modify the following lines by hand. #undef ABI_FUNC #define ABI_FUNC 'pawdiju' !End of the abilint section implicit none !Arguments --------------------------------------------- !scalars integer,intent(in) :: cplex_dij,ndij,nspden,nsppol integer,intent(in),optional :: natvshift real(dp),intent(in),optional :: fatvshift !arrays real(dp),intent(out) :: dijpawu(:,:) real(dp),intent(in) :: vpawu(:,:,:,:) real(dp),intent(in),optional :: atvshift(:,:) type(pawtab_type),intent(in) :: pawtab !Local variables --------------------------------------- !scalars integer :: icount,idij,idijeff,idijend,im1,im2,in1,in2,klmn,klmn1,lmax,lmin,lmn2_size integer :: lpawu,natvshift_,nsploop character(len=500) :: msg !arrays real(dp),allocatable :: coeffpawu(:),dijpawu_idij(:),dijsymU(:,:) ! ************************************************************************* DBG_ENTER("COLL") !Useful data lpawu=pawtab%lpawu lmn2_size=pawtab%lmn2_size natvshift_=0;if (present(natvshift)) natvshift_=natvshift !Check data consistency if (size(dijpawu,1)/=cplex_dij*lmn2_size.or.size(dijpawu,2)/=ndij) then msg='invalid sizes for dijpawu !' MSG_BUG(msg) end if if (size(vpawu,1)/=cplex_dij.or.size(vpawu,2)/=2*lpawu+1.or.& & size(vpawu,3)/=2*lpawu+1.or.size(vpawu,4)/=nspden) then msg='invalid sizes for vpawu !' MSG_BUG(msg) end if if (natvshift_>0) then if ((.not.present(atvshift)).or.(.not.present(fatvshift))) then msg='when natvshift>0, atvshift and fatvshift arguments must be present !' MSG_BUG(msg) end if if (size(atvshift,1)/=natvshift.or.size(atvshift,2)/=nsppol) then msg='invalid sizes for atvshift !' MSG_BUG(msg) end if end if !Init memory dijpawu=zero ABI_ALLOCATE(dijpawu_idij,(cplex_dij*lmn2_size)) ABI_ALLOCATE(coeffpawu,(cplex_dij)) if (ndij==4) then ABI_ALLOCATE(dijsymU,(cplex_dij*lmn2_size,4)) end if !Loop over spin components !---------------------------------------------------------- nsploop=nsppol;if (ndij==4) nsploop=4 do idij=1,nsploop if (idij<=nsppol.or.(ndij==4.and.idij<=3)) then idijend=idij+idij/3 do idijeff=idij,idijend ! if ndij==4, idijeff is used to compute updn and dnup contributions dijpawu_idij=zero ! Loop over (l,m,n) moments ! ---------------------------------------------------------- klmn1=1 do klmn=1,lmn2_size im1=pawtab%klmntomn(1,klmn) im2=pawtab%klmntomn(2,klmn) lmin=pawtab%indklmn(3,klmn) lmax=pawtab%indklmn(4,klmn) ! Select l=lpawu if (lmin==0.and.lmax==2*lpawu) then ! Check consistency in1=pawtab%klmntomn(3,klmn) in2=pawtab%klmntomn(4,klmn) icount=in1+(in2*(in2-1))/2 if (pawtab%ij_proj<icount) then msg='LDA+U: Problem while computing dijexxc !' MSG_BUG(msg) end if ! coeffpawu(:)=vpawu(:,im1,im2,idijeff) ! use real and imaginary part coeffpawu(:)=vpawu(:,im2,im1,idijeff) ! because of transposition in setnoccmmp (for the cplex_dij==2) if (natvshift_/=0.and.idij<3.and.im1==im2) then coeffpawu(1)=coeffpawu(1)+fatvshift*atvshift(im1,idij) end if if (cplex_dij==1) then !cplex_dij=nspinor=1 dijpawu_idij(klmn1)=pawtab%phiphjint(icount)*coeffpawu(1) ! *dtset%userra elseif (cplex_dij==2) then !cplex_dij=nspinor=2 dijpawu_idij(klmn1 )=pawtab%phiphjint(icount)*coeffpawu(1) dijpawu_idij(klmn1+1)=pawtab%phiphjint(icount)*coeffpawu(2) ! spinor==2 end if end if ! l selection klmn1=klmn1+cplex_dij end do ! klmn dijpawu(:,idij)=dijpawu_idij(:) if (ndij==4) dijsymU(:,idijeff)=dijpawu_idij(:) end do ! idijeff end if ! idij if (nspden==4.or.ndij==4.or.cplex_dij==2) then if (idij<=2) then dijpawu(:,idij)=dijpawu(:,idij) else dijpawu(:,idij)=dijsymU(:,idij) end if end if !End loop over spin components !---------------------------------------------------------- end do !Free temporary memory spaces ABI_DEALLOCATE(dijpawu_idij) ABI_DEALLOCATE(coeffpawu) if (ndij==4) then ABI_DEALLOCATE(dijsymU) end if DBG_EXIT("COLL") end subroutine pawdiju !!*** !---------------------------------------------------------------------- !!****f* m_pawdij/pawdijso !! NAME !! pawdijso !! !! FUNCTION !! Compute the spin-orbit contribution to the PAW !! pseudopotential strength Dij !! (for one atom only) !! !! COPYRIGHT !! Copyright (C) 1998-2014 ABINIT group (MT) !! This file is distributed under the terms of the !! GNU General Public License, see ~abinit/COPYING !! or http://www.gnu.org/copyleft/gpl.txt . !! For the initials of contributors, see ~abinit/doc/developers/contributors.txt. !! !! INPUTS !! cplex_dij=1 if dij is REAL, 2 if complex (2 for spin-orbit) !! ndij= number of spin components for Dij^SO !! nspden=number of spin density components !! paw_an <type(paw_an_type)>=paw arrays given on angular mesh, for current atom !! pawang <type(pawang_type)>=paw angular mesh and related data !! pawrad <type(pawrad_type)>=paw radial mesh and related data, for current atom !! pawtab <type(pawtab_type)>=paw tabulated starting data, for current atom !! pawxcdev=Choice of XC development (0=no dev. (use of angular mesh) ; 1 or 2=dev. on moments) !! spnorbscl=scaling factor for spin-orbit coupling !! vh1(mesh_size,v_size,nspden)=all-electron on-site Hartree potential for current atom !! only spherical moment is used !! vxc1(mesh_size,v_size,nspden)=all-electron on-site XC potential for current atom !! given on a (r,theta,phi) grid (v_size=angl_size) !! or on (l,m) spherical moments (v_size=lm_size) !! !! OUTPUT !! dijso(cplex_dij*lmn2_size,ndij)= spin-orbit Dij terms !! cplex_dij=2 must be 2 !! dijso(:,:,1) contains Dij_SO^up-up !! dijso(:,:,2) contains Dij_SO^dn-dn !! dijso(:,:,3) contains Dij_SO^up-dn !! dijso(:,:,4) contains Dij_SO^dn-up !! !! PARENTS !! m_pawdij,pawdenpot !! !! CHILDREN !! free_my_atmtab,get_my_atmtab !! !! SOURCE subroutine pawdijso(cplex_dij,dijso,ndij,nspden,& & pawang,pawrad,pawtab,pawxcdev,spnorbscl,vh1,vxc1) !This section has been created automatically by the script Abilint (TD). !Do not modify the following lines by hand. #undef ABI_FUNC #define ABI_FUNC 'pawdijso' !End of the abilint section implicit none !Arguments --------------------------------------------- !scalars integer,intent(in) :: cplex_dij,ndij,nspden,pawxcdev real(dp), intent(in) :: spnorbscl type(pawang_type),intent(in) :: pawang !arrays real(dp),intent(out) :: dijso(:,:) real(dp),intent(in) :: vh1(:,:,:),vxc1(:,:,:) type(pawrad_type),intent(in) :: pawrad type(pawtab_type),target,intent(in) :: pawtab !Local variables --------------------------------------- !scalars integer :: angl_size,cplex,idij,ij_size,ilm,ipts,ispden,jlm,klm,klmn,klmn1,kln integer :: lm_size,lmn2_size,mesh_size,nsploop real(dp), parameter :: HalfFineStruct2=half/InvFineStruct**2 real(dp) :: fact character(len=500) :: msg !arrays integer,ABI_CONTIGUOUS pointer :: indklmn(:,:) real(dp),allocatable :: dijso_rad(:),dv1dr(:),ff(:) ! ************************************************************************* DBG_ENTER("COLL") !Useful data lm_size=pawtab%lcut_size**2 lmn2_size=pawtab%lmn2_size ij_size=pawtab%ij_size angl_size=pawang%angl_size mesh_size=pawtab%mesh_size indklmn => pawtab%indklmn cplex=1 ! DijSO exists only for GS nsploop=4 !Check data consistency if (cplex_dij/=2) then msg='cplex_dij must be 2 for spin-orbit coupling !' MSG_BUG(msg) end if if (ndij/=4) then msg='ndij must be 4 for spin-orbit coupling !' MSG_BUG(msg) end if if (pawang%use_ls_ylm==0) then msg='pawang%use_ls_ylm should be /=0 !' MSG_BUG(msg) end if if (size(dijso,1)/=cplex_dij*lmn2_size.or.size(dijso,2)/=ndij) then msg='invalid sizes for DijSO !' MSG_BUG(msg) end if if (size(vh1,1)/=cplex*mesh_size.or.size(vh1,2)<1.or.size(vh1,3)<1) then msg='invalid sizes for vh1 !' MSG_BUG(msg) end if if (size(vxc1,1)/=cplex*mesh_size.or.size(vxc1,3)/=nspden.or.& & (size(vxc1,2)/=angl_size.and.pawxcdev==0).or.& & (size(vxc1,2)/=lm_size.and.pawxcdev/=0)) then msg='invalid sizes for vxc1 !' MSG_BUG(msg) end if !------------------------------------------------------------------------ !----------- Allocations and initializations !------------------------------------------------------------------------ !Eventually compute <Phi_i|1/r.dV/dr|Phi_j>*alpha2/2*Y_00 (for spin-orbit) ABI_ALLOCATE(dv1dr,(mesh_size)) ABI_ALLOCATE(dijso_rad,(ij_size)) ABI_ALLOCATE(ff,(mesh_size)) fact=one/sqrt(four_pi) ! Y_00 if (pawxcdev/=0) then if (nspden==1) then ff(1:mesh_size)=vxc1(1:mesh_size,1,1) else ff(1:mesh_size)=half*(vxc1(1:mesh_size,1,1)+vxc1(1:mesh_size,1,2)) end if else ff(1:mesh_size)=zero if (nspden==1) then do ipts=1,angl_size ff(1:mesh_size)=ff(1:mesh_size) & & +vxc1(1:mesh_size,ipts,1)*pawang%angwgth(ipts) end do else do ipts=1,angl_size ff(1:mesh_size)=ff(1:mesh_size) & & +half*(vxc1(1:mesh_size,ipts,1)+vxc1(1:mesh_size,ipts,2)) & & *pawang%angwgth(ipts) end do end if ff(1:mesh_size)=sqrt(four_pi)*ff(1:mesh_size) end if ff(1:mesh_size)=fact*(ff(1:mesh_size)+vh1(1:mesh_size,1,1)) call nderiv_gen(dv1dr,ff,1,pawrad) dv1dr(2:mesh_size)=HalfFineStruct2*(one/(one-ff(2:mesh_size)/InvFineStruct**2)) & & *dv1dr(2:mesh_size)/pawrad%rad(2:mesh_size) call pawrad_deducer0(dv1dr,mesh_size,pawrad) do kln=1,ij_size ff(1:mesh_size)= dv1dr(1:mesh_size)*pawtab%phiphj(1:mesh_size,kln) call simp_gen(dijso_rad(kln),ff,pawrad) end do ABI_DEALLOCATE(dv1dr) ABI_DEALLOCATE(ff) dijso_rad(:)=spnorbscl*dijso_rad(:) !------------------------------------------------------------------------ !----- Loop over density components !------------------------------------------------------------------------ do idij=1,nsploop ! ------------------------------------------------------------------------ ! ----- Computation of Dij_so ! ------------------------------------------------------------------------ klmn1=1 dijso(:,idij)=zero if (mod(idij,2)==1) then ispden=(1+idij)/2 do klmn=1,lmn2_size if (indklmn(3,klmn)==0) then ! il==jl klm=indklmn(1,klmn);kln=indklmn(2,klmn) ilm=indklmn(5,klmn);jlm=indklmn(6,klmn) fact=dijso_rad(kln);if (ilm>jlm) fact=-fact dijso(klmn1 ,idij)=fact*pawang%ls_ylm(1,klm,ispden) dijso(klmn1+1,idij)=fact*pawang%ls_ylm(2,klm,ispden) end if klmn1=klmn1+cplex_dij end do else if (idij==2) then do klmn=1,lmn2_size if (indklmn(3,klmn)==0) then ! il==jl dijso(klmn1:klmn1+1,2)=-dijso(klmn1:klmn1+1,1) end if klmn1=klmn1+cplex_dij end do else if (idij==4) then do klmn=1,lmn2_size if (indklmn(3,klmn)==0) then ! il==jl dijso(klmn1 ,4)=-dijso(klmn1 ,3) dijso(klmn1+1,4)= dijso(klmn1+1,3) end if klmn1=klmn1+cplex_dij end do end if ! ----- End loop over idij end do ABI_DEALLOCATE(dijso_rad) DBG_EXIT("COLL") end subroutine pawdijso !!*** !---------------------------------------------------------------------- !!****f* m_pawdij/pawdijexxc !! NAME !! pawdijexxc !! !! FUNCTION !! Compute the local Exact-Exchange contribution to the PAW pseudopotential strength Dij, !! using a potential expressed as (l,m) spherical moments !! (for one atom only; only for correlated electrons): !! D_ij^EXXC= < Phi_i|alpha*(VFock(correlated)-Vxc(n1_correlated)|Phi_j> !! !! COPYRIGHT !! Copyright (C) 1998-2014 ABINIT group (MT,FJ,BA) !! This file is distributed under the terms of the !! GNU General Public License, see ~abinit/COPYING !! or http://www.gnu.org/copyleft/gpl.txt . !! For the initials of contributors, see ~abinit/doc/developers/contributors.txt. !! !! INPUTS !! cplex=(RF calculations only) - 1 if RF 1st-order quantities are REAL, 2 if COMPLEX !! cplex_dij=1 if dij is REAL, 2 if complex (2 for spin-orbit) !! lmselect(lm_size)=select the non-zero LM-moments of on-site potentials !! ndij= number of spin components for Dij^hat !! nspden=number of spin density components !! nsppol=number of independent spin WF components !! pawang <type(pawang_type)>=paw angular mesh and related data !! pawrad <type(pawrad_type)>=paw radial mesh and related data, for current atom !! pawtab <type(pawtab_type)>=paw tabulated starting data, for current atom !! vpawx(1,lmn2_size,nspden)=moments of exact exchange potential !! for current atom and for correlated electrons !! vxc_ex(mesh_size,lm_size,nspden)=all-electron on-site XC potential for current atom !! taken into account only valence correlated electrons !! !! OUTPUT !! dijexxc(cplex_dij*lmn2_size,ndij)= D_ij^XC terms !! !! NOTES !! cplex is for RF, cplex_dij is for non-collinear (nspinor==2) !! !! PARENTS !! m_pawdij !! !! CHILDREN !! free_my_atmtab,get_my_atmtab !! !! SOURCE subroutine pawdijexxc(cplex,cplex_dij,dijexxc,lmselect,ndij,nspden,nsppol,& & pawang,pawrad,pawtab,vpawx,vxc_ex) !This section has been created automatically by the script Abilint (TD). !Do not modify the following lines by hand. #undef ABI_FUNC #define ABI_FUNC 'pawdijexxc' !End of the abilint section implicit none !Arguments --------------------------------------------- !scalars integer,intent(in) :: cplex,cplex_dij,ndij,nspden,nsppol type(pawang_type),intent(in) :: pawang !arrays logical :: lmselect(:) real(dp),intent(in) :: vpawx(:,:,:),vxc_ex(:,:,:) real(dp),intent(out) :: dijexxc(:,:) type(pawrad_type),intent(in) :: pawrad type(pawtab_type),intent(in) :: pawtab !Local variables --------------------------------------- !scalars integer :: icount,idij,idijend,ij_size,iln,in1,in2,ir,ir1,isel,ispden integer :: jln,j0ln,klm,klm1,klmn,klmn1,kln,lexexch,ln_min,ln_max,lmax,lmin integer :: lm_size,lmn2_size,mesh_size,nsploop character(len=500) :: msg !arrays real(dp),allocatable :: dijexxc_idij(:),ff(:),gg(:),vxcij1(:) ! ************************************************************************* DBG_ENTER("COLL") !Useful data lm_size=pawtab%lcut_size**2 lmn2_size=pawtab%lmn2_size ij_size=pawtab%ij_size mesh_size=pawtab%mesh_size lexexch=pawtab%lexexch ln_min=pawtab%lnproju(1) ln_max=pawtab%lnproju(pawtab%nproju) !Check data consistency if (size(dijexxc,1)/=cplex_dij*lmn2_size.or.size(dijexxc,2)/=ndij) then msg='invalid sizes for dijexxc !' MSG_BUG(msg) end if if (size(lmselect)/=lm_size) then msg='invalid size for lmselect !' MSG_BUG(msg) end if if (size(vxc_ex,1)/=cplex*mesh_size.or.size(vxc_ex,2)/=lm_size.or.& & size(vxc_ex,3)/=nspden) then msg='invalid sizes for vxc_ex !' MSG_BUG(msg) end if if (size(vpawx,1)/=1.or.size(vpawx,2)/=lmn2_size.or.& & size(vpawx,3)/=nspden) then msg='invalid sizes for vpawx !' MSG_BUG(msg) end if if (cplex_dij<cplex) then msg='cplex_dij must be >= cplex !' MSG_BUG(msg) end if !Init memory dijexxc=zero ABI_ALLOCATE(dijexxc_idij,(cplex*lmn2_size)) ABI_ALLOCATE(vxcij1,(cplex*ij_size)) ABI_ALLOCATE(ff,(mesh_size)) ABI_ALLOCATE(gg,(mesh_size)) !---------------------------------------------------------- !Loop over spin components !---------------------------------------------------------- nsploop=nsppol;if (ndij==4) nsploop=4 do idij=1,nsploop if (idij<=nsppol.or.(nspden==4.and.idij<=3).or.cplex==2) then idijend=idij+idij/3;if (cplex==2) idijend=idij do ispden=idij,idijend dijexxc_idij=zero ! ---------------------------------------------------------- ! Summing over (l,m) moments ! ---------------------------------------------------------- do klm=1,lm_size if (lmselect(klm)) then ! ===== Vxc_ij_1 (tmp) ===== vxcij1=zero if (cplex==1) then do jln=ln_min,ln_max j0ln=jln*(jln-1)/2 do iln=ln_min,jln kln=j0ln+iln ff(1:mesh_size)= & & vxc_ex(1:mesh_size,klm,idij)*pawtab%phiphj(1:mesh_size,kln) call simp_gen(vxcij1(kln),ff,pawrad) end do end do else do jln=ln_min,ln_max j0ln=jln*(jln-1)/2 do iln=ln_min,jln kln=j0ln+iln do ir=1,mesh_size ir1=2*ir ff(ir)= & & vxc_ex(ir1-1,klm,ispden)*pawtab%phiphj(ir,kln) gg(ir)= & & vxc_ex(ir1,klm,ispden)*pawtab%phiphj(ir,kln) end do call simp_gen(vxcij1(2*kln-1),ff,pawrad) call simp_gen(vxcij1(2*kln ),gg,pawrad) end do end do end if ! ===== Accumulate Vxc_ij_1 over klm moments ===== if (cplex==1) then do klmn=1,lmn2_size lmin=pawtab%indklmn(3,klmn) lmax=pawtab%indklmn(4,klmn) if (lmin==0.and.lmax==2*lexexch) then klm1=pawtab%indklmn(1,klmn) kln=pawtab%indklmn(2,klmn) isel=pawang%gntselect(klm,klm1) if (isel>0) dijexxc_idij(klmn)=dijexxc_idij(klmn) & & +vxcij1(kln)*pawang%realgnt(isel) end if end do ! Loop klmn else ! cplex==2 klmn1=1 do klmn=1,lmn2_size lmin=pawtab%indklmn(3,klmn) lmax=pawtab%indklmn(4,klmn) if (lmin==0.and.lmax==2*lexexch) then klm1=pawtab%indklmn(1,klmn) kln=pawtab%indklmn(2,klmn) isel=pawang%gntselect(klm,klm1) if (isel>0) then dijexxc_idij(klmn1 )=dijexxc_idij(klmn1) & & +vxcij1(2*kln-1)*pawang%realgnt(isel) dijexxc_idij(klmn1+1)=dijexxc_idij(klmn1+1) & & +vxcij1(2*kln )*pawang%realgnt(isel) end if end if klmn1=klmn1+cplex end do ! Loop klmn end if end if ! lmselect end do ! Loop klm ! Mix Hartree and GGA terms if (cplex==1) then do klmn=1,lmn2_size lmin=pawtab%indklmn(3,klmn) lmax=pawtab%indklmn(4,klmn) if (lmin==0.and.lmax==2*lexexch) then in1=pawtab%klmntomn(3,klmn) in2=pawtab%klmntomn(4,klmn) icount=in1+(in2*(in2-1))/2 if(pawtab%ij_proj<icount) then msg='PAW local exact-exchange: Problem while computing dijexxc !' MSG_BUG(msg) end if dijexxc_idij(klmn)=pawtab%exchmix & & *(vpawx(1,klmn,idij)-dijexxc_idij(klmn)) end if end do else ! cplex=2 klmn1=1 do klmn=1,lmn2_size lmin=pawtab%indklmn(3,klmn) lmax=pawtab%indklmn(4,klmn) if (lmin==0.and.lmax==2*lexexch) then in1=pawtab%klmntomn(3,klmn) in2=pawtab%klmntomn(4,klmn) icount=in1+(in2*(in2-1))/2 if(pawtab%ij_proj<icount) then msg='PAW local exact-exchange: Problem while computing dijexxc !' MSG_BUG(msg) end if dijexxc_idij(klmn1) =pawtab%exchmix & & *(vpawx(1,klmn,idij)-dijexxc_idij(klmn1)) dijexxc_idij(klmn1+1)=pawtab%exchmix & & *(vpawx(1,klmn,idij)-dijexxc_idij(klmn1+1)) end if klmn1=klmn1+cplex end do ! Loop klmn end if ! ---------------------------------------------------------- ! Deduce some part of Dij according to symmetries ! ---------------------------------------------------------- if (cplex==1) then if (ispden<3) then if (cplex_dij==1) then dijexxc(1:lmn2_size,idij)=dijexxc_idij(1:lmn2_size) else klmn1=1 do klmn=1,lmn2_size dijexxc(klmn1 ,idij)=dijexxc_idij(klmn) dijexxc(klmn1+1,idij)=zero klmn1=klmn1+cplex_dij end do end if else klmn1=max(1,ispden-2) do klmn=1,lmn2_size dijexxc(klmn1,idij)=dijexxc_idij(klmn) klmn1=klmn1+cplex_dij end do end if else !cplex=2 if (ispden<=3) then dijexxc(1:cplex*lmn2_size,idij)=dijexxc_idij(1:cplex*lmn2_size) else klmn1=1 ! Remember V(4) contains i.V^21 do klmn=1,lmn2_size dijexxc(klmn1 ,idij)= dijexxc_idij(klmn+1) dijexxc(klmn1+1,idij)=-dijexxc_idij(klmn ) klmn1=klmn1+cplex_dij end do end if end if end do !ispden else if (nspden==4.and.idij==4) then ! cplex=1 here dijexxc(:,idij)=dijexxc(:,idij-1) klmn1=2 do klmn=1,lmn2_size dijexxc(klmn1,idij)=-dijexxc(klmn1,idij) klmn1=klmn1+cplex_dij end do else if (nsppol==1.and.idij==2) then ! cplex=1 here dijexxc(:,idij)=dijexxc(:,idij-1) end if !---------------------------------------------------------- !End loop on spin density components end do !Free temporary memory spaces ABI_DEALLOCATE(dijexxc_idij) ABI_DEALLOCATE(vxcij1) ABI_DEALLOCATE(ff) ABI_DEALLOCATE(gg) DBG_EXIT("COLL") end subroutine pawdijexxc !!*** !---------------------------------------------------------------------- !!****f* m_pawdij/pawdijfr !! !! NAME !! pawdijfr !! !! FUNCTION !! PAW, Response Function only: !! Compute frozen part of psp strength Dij due to 1st-order compensation density !! and first order local potential: !! Dijfr =Int_R^3{vtrial*Sum_LM[Q_ij_q^LM^(1)] + Vloc^(1)*Sum_LM[Q_ij_q^LM]} !! Depends on q wave vector but not on first-order wave-function. !! !! COPYRIGHT !! Copyright (C) 2012-2014 ABINIT group (MT) !! This file is distributed under the terms of the !! GNU General Public License, see ~abinit/COPYING !! or http://www.gnu.org/copyleft/gpl.txt . !! For the initials of contributors, see ~abinit/doc/developers/contributors. !! !! INPUTS !! cplex: if 1, real space 1-order functions on FFT grid are REAL; if 2, COMPLEX !! gprimd(3,3)=dimensional primitive translations for reciprocal space !! idir=direction of atomic displacement (in case of phonons perturb.) !! ipert=nindex of perturbation !! mpi_atmtab(:)=--optional-- indexes of the atoms treated by current proc !! mpi_comm_atom=--optional-- MPI communicator over atoms !! mpi_comm_grid=--optional-- MPI communicator over real space grid components !! my_natom=number of atoms treated by current processor !! natom=total number of atoms in cell !! nfft=(effective) number of FFT grid points (for this processor) !! nspden=number of spin-density components !! ntypat=number of types of atoms !! option=0: computes full frozen part of Dij !! 1: computes frozen part of Dij without contribution from Vpsp1 !! pawang <type(pawang_type)>=paw angular mesh and related data !! pawfgrtab(my_natom) <type(pawfgrtab_type)>=atomic data given on fine rectangular grid !! pawrad(ntypat*usepaw) <type(pawrad_type)>=paw radial mesh and related data !! pawtab(ntypat) <type(pawtab_type)>=paw tabulated starting data !! qphon(3)=wavevector of the phonon !! rprimd(3,3)=dimensional primitive translations for real space !! ucvol=unit cell volume (bohr^3) !! vpsp1(cplex*nfft)= first-order change of local potential !! vtrial(nfft,nspden)= total GS potential !! vxc(nfft,nspden)=XC potential !! xred(3,my_natom)= reduced atomic coordinates !! !! OUTPUT !! paw_ij1(iatom)%dijfr(cplex_dij*lmn2_size,nspden)= !! frozen contribution to psp strength Dij !! =Int_R^3{vtrial*Sum_LM[Q_ij_q^LM^(1)] + Vloc^(1)*Sum_LM[Q_ij_q^LM]} !! !! PARENTS !! d2frnl,nstpaw3,rhofermi3,scfcv3 !! !! CHILDREN !! free_my_atmtab,get_my_atmtab !! !! SOURCE subroutine pawdijfr(cplex,gprimd,idir,ipert,my_natom,natom,nfft,ngfft,nspden,ntypat,& & option,paw_ij1,pawang,pawfgrtab,pawrad,pawtab,qphon,rprimd,ucvol,vpsp1,vtrial,vxc,xred,& & mpi_atmtab,mpi_comm_atom,mpi_comm_grid) ! optional arguments (parallelism) !This section has been created automatically by the script Abilint (TD). !Do not modify the following lines by hand. #undef ABI_FUNC #define ABI_FUNC 'pawdijfr' !End of the abilint section implicit none !Arguments ------------------------------------ !scalars integer,intent(in) :: cplex,idir,ipert,my_natom,natom,nfft,nspden,ntypat,option integer,optional,intent(in) :: mpi_comm_atom,mpi_comm_grid real(dp),intent(in) :: ucvol type(pawang_type),intent(in) :: pawang !arrays integer,intent(in) :: ngfft(18) integer,optional,target,intent(in) :: mpi_atmtab(:) real(dp),intent(in) :: gprimd(3,3),qphon(3),rprimd(3,3) real(dp),intent(in) :: vpsp1(cplex*nfft),vtrial(nfft,nspden),vxc(nfft,nspden) real(dp),intent(in) :: xred(3,natom) type(paw_ij_type),intent(inout) :: paw_ij1(my_natom) type(pawfgrtab_type),intent(inout) :: pawfgrtab(my_natom) type(pawrad_type),intent(in) :: pawrad(ntypat) type(pawtab_type),intent(in) :: pawtab(ntypat) !Local variables------------------------------- !scalars integer :: dplex,iatom,iatom_tot,ic,ier,ils,ilslm,isel,ispden,istr,itypat,jc integer :: klm,klmn,klmn1,kln,lm_size,lmn2_size,lm0,lmax,lmin,mesh_size integer :: mm,my_comm_atom,my_comm_grid,mu,mua,mub,nfftot,nfgd,optgr0,optgr1,optgr2,usexcnhat logical :: has_phase,my_atmtab_allocated,need_dijfr_1,need_dijfr_2,need_dijfr_3,need_dijfr_4 logical :: paral_atom,qne0,testdij1,testdij2,testdij3 real(dp) :: c1,fact,intg,rg1 !arrays integer,parameter :: m_index(3)=(/1,-1,0/) integer,pointer :: my_atmtab(:) integer,parameter :: alpha(9)=(/1,2,3,3,3,2,2,1,1/),beta(9)=(/1,2,3,2,1,1,3,3,2/) real(dp) :: contrib(2) real(dp),allocatable :: ff(:),intv(:,:),intvloc(:,:),intv_tmp(:,:),rg(:),vloc(:,:) ! ************************************************************************* DBG_ENTER("COLL") !Nothing to be done for DDK if (ipert==natom+1) return !Set up parallelism over atoms paral_atom=(present(mpi_comm_atom).and.(my_natom/=natom)) nullify(my_atmtab);if (present(mpi_atmtab)) my_atmtab => mpi_atmtab my_comm_atom=xmpi_self;if (present(mpi_comm_atom)) my_comm_atom=mpi_comm_atom my_comm_grid=xmpi_self;if (present(mpi_comm_grid)) my_comm_grid=mpi_comm_grid call get_my_atmtab(my_comm_atom,my_atmtab,my_atmtab_allocated,paral_atom,natom,my_natom_ref=my_natom) !Compatibility tests qne0=(qphon(1)**2+qphon(2)**2+qphon(3)**2>=1.d-15) if (my_natom>0) then if (paw_ij1(1)%cplex_dij<cplex) then MSG_BUG('paw_ij1()%cplex_dij must be >=cplex !') end if if (paw_ij1(1)%cplex/=cplex) then MSG_BUG('paw_ij1()%cplex and cplex must be equal !') end if if (paw_ij1(1)%has_dijfr==0) then MSG_BUG('pawdij1()%dijfr must be allocated !') end if testdij1=(ipert<=natom.and.option==0.and.pawfgrtab(1)%gylm_allocated==0) testdij2=(ipert<=natom.and.pawfgrtab(1)%gylmgr_allocated==0) testdij3=(testdij2.and.qne0.and.pawfgrtab(1)%expiqr_allocated==0) if ((testdij1.or.testdij2.or.testdij3).and.pawfgrtab(1)%rfgd_allocated==0) then MSG_BUG('pawfgrtab()%rfgd array must be allocated !') end if end if !Get correct index of strain pertubation if (ipert==natom+3) istr = idir if (ipert==natom+4) istr = idir + 3 !Some inits usexcnhat=maxval(pawtab(1:ntypat)%usexcnhat) nfftot=ngfft(1)*ngfft(2)*ngfft(3) fact=ucvol/dble(nfftot) dplex=cplex-1 !Loops over atoms do iatom=1,my_natom iatom_tot=iatom;if (paral_atom) iatom_tot=my_atmtab(iatom) ! Select which part of Dijfr to compute need_dijfr_1=(ipert==iatom_tot.and.paw_ij1(iatom)%has_dijfr==1) need_dijfr_2=(ipert<=natom.and.paw_ij1(iatom)%has_dijfr==1.and.(option==0)) need_dijfr_3=((ipert==natom+2).and.paw_ij1(iatom)%has_dijfr==1) need_dijfr_4=((ipert==natom+3.or.ipert==natom+4).and.paw_ij1(iatom)%has_dijfr==1) if ((.not.need_dijfr_1).and.(.not.need_dijfr_2).and.(.not.need_dijfr_3).and.(.not.need_dijfr_4)) then if (paw_ij1(iatom)%has_dijfr>0) then paw_ij1(iatom)%dijfr=zero ; paw_ij1(iatom)%has_dijfr=2 end if cycle end if ! Some atom-dependent quantities itypat=pawfgrtab(iatom)%itypat lm_size=pawtab(itypat)%lcut_size**2 lmn2_size=pawtab(itypat)%lmn2_size ! Eventually compute g_l(r).Y_lm(r) factors for the current atom (if not already done) nfgd=0 if (need_dijfr_1.or.need_dijfr_2.or.need_dijfr_4) then nfgd=pawfgrtab(iatom)%nfgd if (((need_dijfr_2.or.need_dijfr_4).and.(pawfgrtab(iatom)%gylm_allocated==0)).or.& & ((need_dijfr_1).and.(pawfgrtab(iatom)%gylmgr_allocated==0))) then optgr0=0;optgr1=0;optgr2=0 if ((need_dijfr_2.or. need_dijfr_4).and.(pawfgrtab(iatom)%gylm_allocated==0)) then if (allocated(pawfgrtab(iatom)%gylm)) then ABI_DEALLOCATE(pawfgrtab(iatom)%gylm) end if ABI_ALLOCATE(pawfgrtab(iatom)%gylm,(nfgd,lm_size)) pawfgrtab(iatom)%gylm_allocated=2;optgr0=1 end if if ((need_dijfr_1).and.(pawfgrtab(iatom)%gylmgr_allocated==0)) then if (allocated(pawfgrtab(iatom)%gylmgr)) then ABI_DEALLOCATE(pawfgrtab(iatom)%gylmgr) end if ABI_ALLOCATE(pawfgrtab(iatom)%gylmgr,(3,nfgd,lm_size)) pawfgrtab(iatom)%gylmgr_allocated=2;optgr1=1 end if if (optgr0+optgr1+optgr2>0) then call pawgylm(pawfgrtab(iatom)%gylm,pawfgrtab(iatom)%gylmgr,pawfgrtab(iatom)%gylmgr2,& & lm_size,nfgd,optgr0,optgr1,optgr2,pawtab(itypat),pawfgrtab(iatom)%rfgd) end if end if end if ! Eventually compute exp(-i.q.r) factors for the current atom (if not already done) has_phase=.false. if (need_dijfr_2) then if (qne0.and.(pawfgrtab(iatom)%expiqr_allocated==0)) then if (allocated(pawfgrtab(iatom)%expiqr)) then ABI_DEALLOCATE(pawfgrtab(iatom)%expiqr) end if ABI_ALLOCATE(pawfgrtab(iatom)%expiqr,(2,nfgd)) call pawexpiqr(pawfgrtab(iatom)%expiqr,gprimd,nfgd,qphon,& & pawfgrtab(iatom)%rfgd,xred(:,iatom_tot)) pawfgrtab(iatom)%expiqr_allocated=2 end if has_phase=(pawfgrtab(iatom)%expiqr_allocated/=0) end if ! Loop over spin components do ispden=1,nspden ! ============ Phonons ==================================== if (ipert<=natom) then if (need_dijfr_1.or.need_dijfr_2) then ABI_ALLOCATE(intv,(cplex,lm_size)) intv(:,:)=zero ! First part: Int_R^3{vtrial*Sum_LM[Q_ij_q^LM^(1)]} if (need_dijfr_1) then ! ----- Retrieve potential Vlocal (subtle if nspden=4 ;-) if (nspden/=4) then ABI_ALLOCATE(vloc,(1,nfgd)) if (usexcnhat==0) then do ic=1,nfgd jc=pawfgrtab(iatom)%ifftsph(ic) vloc(1,ic)=vtrial(jc,ispden)-vxc(jc,ispden) end do else do ic=1,nfgd vloc(1,ic)=vtrial(pawfgrtab(iatom)%ifftsph(ic),ispden) end do end if else ! nspden/=4 ABI_ALLOCATE(vloc,(2,nfgd)) if (ispden<=2) then if (usexcnhat==0) then do ic=1,nfgd jc=pawfgrtab(iatom)%ifftsph(ic) vloc(1,ic)=vtrial(jc,ispden)-vxc(jc,ispden) vloc(2,ic)=zero end do else do ic=1,nfgd jc=pawfgrtab(iatom)%ifftsph(ic) vloc(1,ic)=vtrial(jc,ispden) vloc(2,ic)=zero end do end if else if (ispden==3) then if (usexcnhat==0) then vloc(:,:)=zero else do ic=1,nfgd jc=pawfgrtab(iatom)%ifftsph(ic) vloc(1,ic)=vtrial(jc,3) vloc(2,ic)=vtrial(jc,4) end do end if else ! ispden=4 vloc(2,1:nfgd)=-vloc(2,1:nfgd) end if end if ! ----- Compute Integral [ Vtrial(r).(g_l(r).Y_lm(r))^(1) dr ] ABI_ALLOCATE(intv_tmp,(cplex,3)) do ilslm=1,lm_size intv_tmp=zero if (nspden/=4) then do ic=1,nfgd do mu=1,3 ! Minus sign because dg(r-R)/dR = -dg(r-R)/dr contrib(1)=-vloc(1,ic)*pawfgrtab(iatom)%gylmgr(mu,ic,ilslm) intv_tmp(1,mu)=intv_tmp(1,mu)+contrib(1) end do end do else ! nspden=4 do ic=1,nfgd do mu=1,3 ! Minus sign because dg(r-R)/dR = -dg(r-R)/dr contrib(1:2)=-vloc(1:2,ic)*pawfgrtab(iatom)%gylmgr(mu,ic,ilslm) intv_tmp(1:2,mu)=intv_tmp(1:2,mu)+contrib(1:2) end do end do end if ! Convert from cartesian to reduced coordinates intv(1:cplex,ilslm)=intv(1:cplex,ilslm) & & +(rprimd(1,idir)*intv_tmp(1:cplex,1) & & +rprimd(2,idir)*intv_tmp(1:cplex,2) & & +rprimd(3,idir)*intv_tmp(1:cplex,3)) end do ABI_DEALLOCATE(vloc) ABI_DEALLOCATE(intv_tmp) end if ! need_dijfr_1 ! 2nd part: Int_R^3{Vloc^(1)*Sum_LM[Q_ij_q^LM]} if (need_dijfr_2) then if (ispden==1) then ! ----- Retrieve potential Vloc^(1) ABI_ALLOCATE(vloc,(cplex,nfgd)) do ic=1,nfgd jc=cplex*pawfgrtab(iatom)%ifftsph(ic)-dplex vloc(1:cplex,ic)=vpsp1(jc:jc+dplex) end do ! ----- Compute Integral [ Vloc^(1)(r).g_l(r).Y_lm(r) ] ABI_ALLOCATE(intvloc,(cplex,lm_size)) intvloc=zero if (has_phase) then if (cplex==1) then do ilslm=1,lm_size do ic=1,nfgd contrib(1)=vloc(1,ic)*pawfgrtab(iatom)%gylm(ic,ilslm) intvloc(1,ilslm)=intvloc(1,ilslm)+contrib(1)*pawfgrtab(iatom)%expiqr(1,ic) end do end do else do ilslm=1,lm_size do ic=1,nfgd contrib(1:cplex)=vloc(1:cplex,ic)*pawfgrtab(iatom)%gylm(ic,ilslm) intvloc(1,ilslm)=intvloc(1,ilslm)+contrib(1)*pawfgrtab(iatom)%expiqr(1,ic) & & -contrib(2)*pawfgrtab(iatom)%expiqr(2,ic) intvloc(2,ilslm)=intvloc(2,ilslm)+contrib(1)*pawfgrtab(iatom)%expiqr(2,ic) & & +contrib(2)*pawfgrtab(iatom)%expiqr(1,ic) end do end do end if else ! no phase do ilslm=1,lm_size do ic=1,nfgd contrib(1:cplex)=vloc(1:cplex,ic)*pawfgrtab(iatom)%gylm(ic,ilslm) intvloc(1:cplex,ilslm)=intvloc(1:cplex,ilslm)+contrib(1:cplex) end do end do end if ABI_DEALLOCATE(vloc) end if ! ispden=1 if (ispden<=min(nspden,2)) then intv(1:cplex,1:lm_size)=intv(1:cplex,1:lm_size)+intvloc(1:cplex,1:lm_size) if (ispden==min(nspden,2)) then ABI_DEALLOCATE(intvloc) end if end if end if ! need_dijfr_2 ! Apply ucvol/nfft factor on integral intv(:,:)=fact*intv(:,:) ! --- Reduction in case of parallelization --- call xmpi_sum(intv,my_comm_grid,ier) paw_ij1(iatom)%dijfr(:,ispden)=zero ! ---- Loop over (i,j) components klmn1=1 do klmn=1,lmn2_size klm =pawtab(itypat)%indklmn(1,klmn) lmin=pawtab(itypat)%indklmn(3,klmn) lmax=pawtab(itypat)%indklmn(4,klmn) do ils=lmin,lmax,2 lm0=ils**2+ils+1 do mm=-ils,ils ilslm=lm0+mm;isel=pawang%gntselect(lm0+mm,klm) if (isel>0) then paw_ij1(iatom)%dijfr(klmn1:klmn1+dplex,ispden)= & & paw_ij1(iatom)%dijfr(klmn1:klmn1+dplex,ispden) & & +pawtab(itypat)%qijl(ilslm,klmn)*intv(1:cplex,ilslm) end if end do end do klmn1=klmn1+paw_ij1(iatom)%cplex_dij end do ABI_DEALLOCATE(intv) ! Dijfr is marked as computed paw_ij1(iatom)%has_dijfr=2 end if ! ============ Electric field perturbation ======================= else if (ipert==natom+2) then if (need_dijfr_3) then ! The following factor arises in expanding the angular dependence of the dipole ! vector in terms of real spherical harmonics. The real spherical harmonics are as ! in the routine initylmr.F90; ! see http://www.unioviedo.es/qcg/art/Theochem419-19-ov-BF97-rotation-matrices.pdf c1 = sqrt(four_pi/three) mesh_size=pawrad(itypat)%mesh_size if (ispden==1) then ABI_ALLOCATE(ff,(mesh_size)) ABI_ALLOCATE(rg,(3)) ! loop over basis state pairs for this atom klmn1=1 do klmn = 1, paw_ij1(iatom)%lmn2_size klm =pawtab(itypat)%indklmn(1,klmn) kln =pawtab(itypat)%indklmn(2,klmn) lmin=pawtab(itypat)%indklmn(3,klmn) lmax=pawtab(itypat)%indklmn(4,klmn) ! Select only l=1, because the dipole is a vector operator if (lmin==1) then lm0=3 ! (l^2+l+1) for l=1 ! Computation of <phi_i|r|phi_j>- <tphi_i|r|tphi_j> ! the dipole vector has radial dependence r ff(1:mesh_size)=(pawtab(itypat)%phiphj(1:mesh_size,kln)& & -pawtab(itypat)%tphitphj(1:mesh_size,kln))& & *pawrad(itypat)%rad(1:mesh_size) ! call pawrad_deducer0(ff,mesh_size,pawrad(itypat)) call simp_gen(intg,ff,pawrad(itypat)) ! Compute <S_li_mi|r-R|S_lj_mj>: use a real Gaunt expression (with selection rule) rg(1:3)=zero do ic=1,3 isel=pawang%gntselect(lm0+m_index(ic),klm) if (isel>0) rg(ic)=pawang%realgnt(isel) end do ! Translate from cartesian to reduced coordinates (in idir direction) rg1=gprimd(1,idir)*rg(1)+gprimd(2,idir)*rg(2)+gprimd(3,idir)*rg(3) ! Build sqrt(4pi/3).<S_li_mi|r-R|S_lj_mj>.(<phi_i|r-R|phi_j>- <tphi_i|r-R|tphi_j> paw_ij1(iatom)%dijfr(klmn1,ispden)=c1*rg1*intg if (cplex==2) paw_ij1(iatom)%dijfr(klmn1+1,ispden)=zero else paw_ij1(iatom)%dijfr(klmn1,ispden)=zero end if ! end gaunt constraint klmn1=klmn1+paw_ij1(iatom)%cplex_dij end do ! end loop over lmn2_size pairs of basis states ABI_DEALLOCATE(ff) ABI_DEALLOCATE(rg) ! Dijfr is spin-independent for electric field case else if (ispden==2) then paw_ij1(iatom)%dijfr(:,ispden)=paw_ij1(iatom)%dijfr(:,1) else paw_ij1(iatom)%dijfr(:,ispden)=zero end if ! Dijfr is marked as computed paw_ij1(iatom)%has_dijfr=2 end if ! ============ Elastic tensor =============================== else if (ipert==natom+3.or.ipert==natom+4) then ! ----- Retrieve potential Vlocal (subtle if nspden=4 ;-) if (nspden/=4) then ABI_ALLOCATE(vloc,(1,nfgd)) if (usexcnhat==0) then do ic=1,nfgd jc=pawfgrtab(iatom)%ifftsph(ic) vloc(1,ic)=vtrial(jc,ispden)-vxc(jc,ispden) end do else do ic=1,nfgd vloc(1,ic)=vtrial(pawfgrtab(iatom)%ifftsph(ic),ispden) end do end if else ! nspden/=4 ABI_ALLOCATE(vloc,(2,nfgd)) if (ispden<=2) then if (usexcnhat==0) then do ic=1,nfgd jc=pawfgrtab(iatom)%ifftsph(ic) vloc(1,ic)=vtrial(jc,ispden)-vxc(jc,ispden) vloc(2,ic)=zero end do else do ic=1,nfgd jc=pawfgrtab(iatom)%ifftsph(ic) vloc(1,ic)=vtrial(jc,ispden) vloc(2,ic)=zero end do end if else if (ispden==3) then if (usexcnhat==0) then vloc(:,:)=zero else do ic=1,nfgd jc=pawfgrtab(iatom)%ifftsph(ic) vloc(1,ic)=vtrial(jc,3) vloc(2,ic)=vtrial(jc,4) end do end if else ! ispden=4 vloc(2,1:nfgd)=-vloc(2,1:nfgd) end if end if ABI_ALLOCATE(intv,(cplex,lm_size)) intv(:,:)=zero ! option = 0 Insulator case if(option==0)then do ilslm=1,lm_size do ic=1,nfgd jc=pawfgrtab(iatom)%ifftsph(ic) contrib(1) = 0 ! Int_R^3{vtrial*Sum_LM[Q_ij_q^LM^(1)]} mua=alpha(istr);mub=beta(istr) contrib(1)=contrib(1)+half*vloc(1,ic)& & *(pawfgrtab(iatom)%gylmgr(mua,ic,ilslm)*pawfgrtab(iatom)%rfgd(mub,ic)& & + pawfgrtab(iatom)%gylmgr(mub,ic,ilslm)*pawfgrtab(iatom)%rfgd(mua,ic)) ! Int_R^3{Vloc^(1)*Sum_LM[Q_ij_q^LM]} contrib(1)=contrib(1)+vpsp1(jc)*pawfgrtab(iatom)%gylm(ic,ilslm) ! delta_{alphabeta}Int_R^3{Vloc*Sum_LM[Q_ij_q^LM]} if(istr<=3)then contrib(1)=contrib(1)+vloc(1,ic)*pawfgrtab(iatom)%gylm(ic,ilslm) end if intv(1,ilslm)=intv(1,ilslm)+contrib(1) end do end do ! option = 1 Metal case (without Vpsp1) else if (option==1)then do ilslm=1,lm_size do ic=1,nfgd jc=pawfgrtab(iatom)%ifftsph(ic) contrib(1) = 0 ! Int_R^3{vtrial*Sum_LM[Q_ij_q^LM^(1)]} mua=alpha(istr);mub=beta(istr) contrib(1)=contrib(1)+half*vloc(1,ic)& & *(pawfgrtab(iatom)%gylmgr(mua,ic,ilslm)*pawfgrtab(iatom)%rfgd(mub,ic)& & + pawfgrtab(iatom)%gylmgr(mub,ic,ilslm)*pawfgrtab(iatom)%rfgd(mua,ic)) ! delta_{alphabeta}Int_R^3{Vtrial*Sum_LM[Q_ij_q^LM]} if(istr<=3)then contrib(1)=contrib(1)+vloc(1,ic)*pawfgrtab(iatom)%gylm(ic,ilslm) end if intv(1,ilslm)=intv(1,ilslm)+contrib(1) end do end do end if ! Apply ucvol/nfft factor on integral intv(:,:)=fact*intv(:,:) ! --- Reduction in case of parallelization --- call xmpi_sum(intv,my_comm_grid,ier) paw_ij1(iatom)%dijfr(:,ispden)=zero ! ---- Loop over (i,j) components klmn1=1 do klmn=1,lmn2_size klm =pawtab(itypat)%indklmn(1,klmn) lmin=pawtab(itypat)%indklmn(3,klmn) lmax=pawtab(itypat)%indklmn(4,klmn) do ils=lmin,lmax,2 lm0=ils**2+ils+1 do mm=-ils,ils ilslm=lm0+mm;isel=pawang%gntselect(lm0+mm,klm) if (isel>0) then paw_ij1(iatom)%dijfr(klmn1:klmn1+dplex,ispden)= & & paw_ij1(iatom)%dijfr(klmn1:klmn1+dplex,ispden) & & +pawtab(itypat)%qijl(ilslm,klmn)*intv(1:cplex,ilslm) end if end do end do klmn1=klmn1+paw_ij1(iatom)%cplex_dij end do ABI_DEALLOCATE(intv) ABI_DEALLOCATE(vloc) ! Dijfr is marked as computed paw_ij1(iatom)%has_dijfr=2 ! ============ Magnetic field perturbation ======================= else if (ipert==natom+5) then if (need_dijfr_3) then ! Dijfr is marked as computed paw_ij1(iatom)%has_dijfr=2 end if end if ! ipert ! End loop over spin components end do ! ispden ! Eventually free temporary space for g_l(r).Y_lm(r) gradients and exp(-i.q.r) if (need_dijfr_1.or.need_dijfr_2) then if (pawfgrtab(iatom)%gylm_allocated==2) then ABI_DEALLOCATE(pawfgrtab(iatom)%gylm) ABI_ALLOCATE(pawfgrtab(iatom)%gylm,(0,0)) pawfgrtab(iatom)%gylm_allocated=0 end if if (pawfgrtab(iatom)%gylmgr_allocated==2) then ABI_DEALLOCATE(pawfgrtab(iatom)%gylmgr) ABI_ALLOCATE(pawfgrtab(iatom)%gylmgr,(0,0,0)) pawfgrtab(iatom)%gylmgr_allocated=0 end if if (pawfgrtab(iatom)%expiqr_allocated==2) then ABI_DEALLOCATE(pawfgrtab(iatom)%expiqr) ABI_ALLOCATE(pawfgrtab(iatom)%expiqr,(0,0)) pawfgrtab(iatom)%expiqr_allocated=0 end if end if ! End loop on atoms end do !Destroy atom table used for parallelism call free_my_atmtab(my_atmtab,my_atmtab_allocated) DBG_EXIT("COLL") end subroutine pawdijfr !!*** !---------------------------------------------------------------------- !!****f* m_pawdij/pawpupot !! NAME !! pawpupot !! !! FUNCTION !! Compute the PAW LDA+U on-site potential !! !! COPYRIGHT !! Copyright (C) 1998-2014 ABINIT group (BA,FJ,MT) !! This file is distributed under the terms of the !! GNU General Public License, see ~ABINIT/COPYING !! or http://www.gnu.org/copyleft/gpl.txt . !! For the initials of contributors, see ~ABINIT/Infos/contributors. !! !! INPUTS !! cplex_dij=1 if dij is REAL, 2 if complex (2 for spin-orbit) !! ndij=number of spin components for Dij^hat !! nspden=number of spin density components !! pawprtvol=control print volume and debugging output for PAW !! noccmmp(cplex_dij,2*lpawu+1,2*lpawu+1,ndij)=density matrix in the augm. region !! nocctot(ndij)=number of electrons in the correlated subspace !! pawtab(ntypat) <type(pawtab_type)>=paw tabulated starting data: !! %usepawu, %upawu, %jpau !! %vee(2*lpawu+1*4)=screened coulomb matrix !! !! OUTPUT !! vpawu(cplex_dij,lpawu*2+1,lpawu*2+1,nspden)=lda+u potential !! (see eg PRB 52, 5467 (1995)) !! !! PARENTS !! ldau_self,m_paw_commutator,m_pawdij !! !! CHILDREN !! free_my_atmtab,get_my_atmtab !! !! SOURCE subroutine pawpupot(cplex_dij,ndij,noccmmp,nocctot,nspden,& & pawprtvol,pawtab,vpawu) !This section has been created automatically by the script Abilint (TD). !Do not modify the following lines by hand. #undef ABI_FUNC #define ABI_FUNC 'pawpupot' use interfaces_14_hidewrite !End of the abilint section implicit none !Arguments --------------------------------------------- !scalars integer,intent(in) :: cplex_dij,ndij,nspden,pawprtvol type(pawtab_type),intent(in) :: pawtab !arrays real(dp),intent(in) :: noccmmp(:,:,:,:),nocctot(:) real(dp),intent(out) :: vpawu(:,:,:,:) !Local variables --------------------------------------- !scalars !Option for interaction energy in case of non-collinear magnetism: ! 1: E_int=-J/4.N.(N-2) (better) ! 2: E_int=-J/2.(Nup.(Nup-1)+Ndn.(Ndn-1)) (Nup and Ndn are ill-defined) integer,parameter :: option_interaction=1 integer :: iplex,ispden,jspden,lpawu,m1,m11,m2,m21,m3,m31,m4,m41 real(dp) :: mnorm,mx,my,mz,n_sig,n_msig,n_tot,VUKStemp,n_sigs,n_msigs real(dp),save :: VUKS character(len=500) :: msg !arrays real(dp),parameter :: factcg(3:4)=(/one,-one/) real(dp) :: n34_msig(cplex_dij),n34_sig(cplex_dij) !real(dp) :: n43_sig(cplex_dij) ! ***************************************************** DBG_ENTER("COLL") !Useful data lpawu=pawtab%lpawu !Check data consistency if(option_interaction==3.and.pawtab%usepawu>=10) then msg = "Option_interaction==3 is not compatible with usepawu>=10 in pawpupot" MSG_ERROR(msg) end if if (size(vpawu,1)/=cplex_dij.or.size(vpawu,2)/=2*lpawu+1.or.& & size(vpawu,3)/=2*lpawu+1.or.size(vpawu,4)/=nspden) then write (msg,'(a,4I5, a,4I5)') ' invalid sizes for vpawu !',cplex_dij,2*lpawu+1,2*lpawu+1,nspden, & & ' /= ', size(vpawu,1), size(vpawu,2), size(vpawu,3), size(vpawu,4) MSG_BUG(msg) end if if (size(noccmmp,1)/=cplex_dij.or.size(noccmmp,2)/=2*lpawu+1.or.& & size(noccmmp,3)/=2*lpawu+1.or.size(noccmmp,4)/=ndij) then write (msg,'(a,4I5, a,4I5)') ' invalid sizes for noccmmp !',cplex_dij,2*lpawu+1,2*lpawu+1,ndij, & & ' /= ', size(noccmmp,1), size(noccmmp,2), size(noccmmp,3), size(noccmmp,4) MSG_BUG(msg) end if if (size(nocctot,1)/=ndij) then msg='invalid size for nocctot !' MSG_BUG(msg) end if !===================================================== !Compute LDA+U Potential on the basis of projectors !cf PRB 52 5467 (1995) !----------------------------------------------------- vpawu=zero do ispden=1,nspden if (ispden<=2) then ! cases ndij=4, ispden=1,2 or ndij<4 jspden=min(ndij,2)-ispden+1 ! (ispden,ndij)=(1,4)=>jspden=2 if (nspden<=2) then n_sig =nocctot(ispden) n_msig=nocctot(jspden) n_tot =n_sig+n_msig else n_tot=nocctot(1) mx=nocctot(2) my=nocctot(3) mz=nocctot(4) mnorm=sqrt(mx*mx+my*my+mz*mz) if (ispden==1) then ! n_sig =half*(n_tot+mnorm) ! n_msig=half*(n_tot-mnorm) n_sig =half*(n_tot+sign(mnorm,mz)) n_msig=half*(n_tot-sign(mnorm,mz)) else ! n_sig =half*(n_tot-mnorm) ! n_msig=half*(n_tot+mnorm) n_sig =half*(n_tot-sign(mnorm,mz)) n_msig=half*(n_tot+sign(mnorm,mz)) end if end if n_sigs =n_sig/(float(2*lpawu+1)) n_msigs =n_msig/(float(2*lpawu+1)) do m1=-lpawu,lpawu m11=m1+lpawu+1 do m2=-lpawu,lpawu m21=m2+lpawu+1 do m3=-lpawu,lpawu m31=m3+lpawu+1 do m4=-lpawu,lpawu m41=m4+lpawu+1 n34_sig(:) =noccmmp(:,m31,m41,ispden) ! spin sigma n34_msig(:)=noccmmp(:,m31,m41,jspden) ! opposite spin (-sigma) if(m31==m41.and.pawtab%usepawu==3) then n34_sig(1)= n34_sig(1) - n_sigs n34_msig(1)= n34_msig(1) - n_msigs end if do iplex=1,cplex_dij vpawu(iplex,m11,m21,ispden)=vpawu(iplex,m11,m21,ispden) & & +n34_msig(iplex)*pawtab%vee(m11,m31,m21,m41) & & +n34_sig(iplex)*(pawtab%vee(m11,m31,m21,m41)-pawtab%vee(m11,m31,m41,m21)) end do ! if(abs(pawprtvol)>=3.and.m11==1.and.m21==1) then ! write(msg,'(a,i4,i4,2e20.10)') "m31,m41,vu=",m31,m41,& ! & vpawu(:,m11,m21,ispden) ! call wrtout(std_out,msg,'COLL') ! write(msg,'(a,4e20.10)') "vee",pawtab%vee(m11,m31,m21,m41),& ! & pawtab%vee(m11,m31,m41,m21) ! call wrtout(std_out,msg,'COLL') ! write(msg,'(a,4e20.10)') "n34_msig,n34_sig",n34_msig(1),n34_sig(1) ! call wrtout(std_out,msg,'COLL') ! end if end do end do ! if(abs(pawprtvol)>=3) then ! if(m11/=m21) then ! write(msg,'(a,i4,i4,2e20.10)') "vu=",m11,m21,vpawu(:,m11,m21,ispden) ! call wrtout(std_out,msg,'COLL') ! write(msg,'(a,2e20.10)') "vupred=",-pawtab%upawu*noccmmp(:,m21,m11,ispden) ! call wrtout(std_out,msg,'COLL') ! end if ! end if end do ! m2 if(abs(pawprtvol)>=3) then write(msg,'(a,i3,14f11.5)') & & "vpawu ",m11, (vpawu(:,m11,m21,ispden),m21=1,2*lpawu+1) call wrtout(std_out, msg,'COLL') write(msg,'(a,i3,14f11.5)') & & "noccmmp ",m11, (noccmmp(:,m11,m21,ispden),m21=1,2*lpawu+1) call wrtout(std_out, msg,'COLL') end if ! Full localized limit if(pawtab%usepawu==1) then ! not activated if usepawu=10 !! ! Here we compute vpawu=vpawu-v_dc vpawu(1,m11,m11,ispden)=vpawu(1,m11,m11,ispden)-pawtab%upawu*(n_tot-half) if (ndij/=4.or.option_interaction==2) then vpawu(1,m11,m11,ispden)=vpawu(1,m11,m11,ispden)+pawtab%jpawu*(n_sig-half) else if (ndij==4.and.option_interaction==1) then vpawu(1,m11,m11,ispden)=vpawu(1,m11,m11,ispden)+half*pawtab%jpawu*(n_tot-one) else if (ndij==4.and.option_interaction==3) then ! Here vdc^{alpha,beta}=\vect{m}.\vect{sigma}^{\beta,\alpha} vpawu(1,m11,m11,ispden)=vpawu(1,m11,m11,ispden)+half*pawtab%jpawu*(n_tot-one) end if ! Around mean field else if(pawtab%usepawu==2) then vpawu(1,m11,m11,ispden)=vpawu(1,m11,m11,ispden)-n_msig*pawtab%upawu & & -n_sig*(pawtab%upawu-pawtab%jpawu) & & *(dble(2*lpawu)/dble(2*lpawu+1)) end if ! if (abs(pawprtvol)>=3) then ! write(msg,'(a,i4,i4,2x,e20.10)') "vudiag= ",m11,m11,vpawu(1,m11,m11,ispden) ! call wrtout(std_out, msg,'COLL') ! write(msg,'(a,2e20.10)') "vudiagpred= ",pawtab%upawu*(half-noccmmp(:,m11,m11,ispden)) ! call wrtout(std_out, msg,'COLL') ! end if if(abs(pawprtvol)>=3) then write(msg,*) "nocctot",nocctot call wrtout(std_out, msg,'COLL') write(msg,'(a,i3,14f11.5)') & & "vpawu 2",m11, (vpawu(:,m11,m21,ispden),m21=1,2*lpawu+1) call wrtout(std_out, msg,'COLL') write(msg,'(a,i3,14f11.5)') & & "noccmmp2",m11, (noccmmp(:,m11,m21,ispden),m21=1,2*lpawu+1) call wrtout(std_out, msg,'COLL') end if end do ! m1 end if ! ispden<=2 ! Non-collinear magnetism: add non-diagonal term; see (Eq 6) in PRB 72, 024458 (2005) ! BA Here, we compute the transpose --- with respect to spin indices --- of ! BA equation (6) of this reference, because of differences in notations, ! BA namely Eband=\sum rhoij^{alpha,beta}*Dij(beta,alpha) contrary to PRB 72, 024458 (2005) if (ispden>=3) then mx=nocctot(2) my=nocctot(3) do m1=-lpawu,lpawu m11=m1+lpawu+1 do m2=-lpawu,lpawu m21=m2+lpawu+1 do m3=-lpawu,lpawu m31=m3+lpawu+1 do m4=-lpawu,lpawu m41=m4+lpawu+1 ! n43_sig(:) =noccmmp(:,m41,m31,ispden) ! vpawu(1,m11,m21,ispden)=vpawu(1,m11,m21,ispden)-n43_sig(1)*pawtab%vee(m11,m31,m41,m21) ! vpawu(2,m11,m21,ispden)=vpawu(2,m11,m21,ispden)+n43_sig(2)*pawtab%vee(m11,m31,m41,m21) n34_sig(:) =noccmmp(:,m31,m41,ispden) vpawu(1,m11,m21,ispden)=vpawu(1,m11,m21,ispden)-n34_sig(1)*pawtab%vee(m11,m31,m41,m21) vpawu(2,m11,m21,ispden)=vpawu(2,m11,m21,ispden)-n34_sig(2)*pawtab%vee(m11,m31,m41,m21) end do end do end do if(pawtab%usepawu==1.and.option_interaction==3) then ! not activated if usepawu=10 !! vpawu(1,m11,m11,ispden)=vpawu(1,m11,m21,ispden)+half*pawtab%jpawu*mx if(ispden==3) then vpawu(2,m11,m11,ispden)=vpawu(1,m11,m21,ispden)-half*pawtab%jpawu*my else vpawu(2,m11,m11,ispden)=vpawu(1,m11,m21,ispden)+half*pawtab%jpawu*my end if end if end do end if if(abs(pawprtvol)>=3) then write(std_out,*) "vpawu, ispden",ispden do m11=1,2*lpawu+1 write(msg,'(12(1x,9(1x,"(",f10.7,",",f10.7,")")))') & & (vpawu(1:cplex_dij,m11,m21,ispden),m21=1,2*lpawu+1) call wrtout(std_out,msg,'COLL') end do end if ! Printing for test if (abs(pawprtvol)>=3) then if (ispden==1) VUKS=zero VUKStemp=zero do m1=-lpawu,lpawu m11=m1+lpawu+1 do m2=-lpawu,lpawu m21=m2+lpawu+1 VUKStemp=VUKStemp+vpawu(1,m11,m21,ispden)*noccmmp(1,m11,m21,ispden) if (cplex_dij == 2) then VUKStemp=VUKStemp-vpawu(2,m11,m21,ispden)*noccmmp(2,m11,m21,ispden) end if write(msg,'(a,2e20.10,2e20.10)') "m1,m2,vpawu,noccmmp= ", & & vpawu(:,m11,m21,ispden),noccmmp(:,m11,m21,ispden) call wrtout(std_out, msg,'COLL') end do end do VUKS=VUKS+VUKStemp write(msg,*) "pawpupot: VUKStemp= ",ispden,VUKStemp call wrtout(std_out, msg,'COLL') if (ispden==nspden) then write(msg,*) "pawpupot: VUKS= ",ispden,VUKS call wrtout(std_out, msg,'COLL') end if end if end do ! Loop on ispden DBG_EXIT("COLL") end subroutine pawpupot !!*** !---------------------------------------------------------------------- !!****f* m_pawdij/pawxpot !! NAME !! pawxpot !! !! FUNCTION !! Compute the PAW Local Exact-Exchange on-site potential !! !! COPYRIGHT !! Copyright (C) 1998-2014 ABINIT group (BA,FJ) !! This file is distributed under the terms of the !! GNU General Public License, see ~ABINIT/COPYING !! or http://www.gnu.org/copyleft/gpl.txt . !! For the initials of contributors, see ~ABINIT/Infos/contributors. !! !! INPUTS !! nspden=number of spin-density components !! pawprtvol=control print volume and debugging output for PAW !! paw_ij <type(paw_ij_type)>=paw arrays given on (i,j) channels !! pawtab <type(pawtab_type)>=paw tabulated starting data: !! pawrhoij <type(pawrhoij_type)>= paw rhoij occupancies and related data !! !! OUTPUT !! paw_ij%vpawx(pawtab%lexexch*2+1,pawtab%lexexch*2+1)=local exact-exchange potential !! !! PARENTS !! m_pawdij,pawdenpot !! !! CHILDREN !! free_my_atmtab,get_my_atmtab !! !! SOURCE subroutine pawxpot(nspden,pawprtvol,pawrhoij,pawtab,vpawx) !This section has been created automatically by the script Abilint (TD). !Do not modify the following lines by hand. #undef ABI_FUNC #define ABI_FUNC 'pawxpot' use interfaces_14_hidewrite !End of the abilint section implicit none !Arguments --------------------------------------------- !scalars integer,intent(in) :: nspden,pawprtvol type(pawrhoij_type),intent(in) :: pawrhoij type(pawtab_type),intent(in) :: pawtab real(dp),intent(out) :: vpawx(:,:,:) !Local variables --------------------------------------- !scalars integer :: irhoij,irhoij1,ispden,jrhoij,jrhoij1,klmn,klmn1,lexexch,ll,lmn2_size integer :: m11,m21,m31,m41,n1,n2,n3,n4,nk,nn1,nn2 real(dp) :: tot character(len=500) :: msg !arrays integer :: indn(3,3) real(dp) :: factnk(6) ! ***************************************************** DBG_ENTER("COLL") !Useful data lexexch=pawtab%lexexch lmn2_size=pawtab%lmn2_size if (pawtab%nproju==1) nk=1 if (pawtab%nproju==2) nk=6 factnk(1)=one;factnk(2)=one;factnk(3)=one factnk(4)=two;factnk(5)=two;factnk(6)=two indn(1,1)=1;indn(1,2)=4;indn(1,3)=5 indn(2,1)=4;indn(2,2)=2;indn(2,3)=6 indn(3,1)=5;indn(3,2)=6;indn(3,3)=3 !Check data consistency if (size(vpawx,1)/=1.or.size(vpawx,2)/=lmn2_size.or.& & size(vpawx,3)/=nspden) then msg='invalid sizes for vpawx !' MSG_BUG(msg) end if !===================================================== !Compute local exact exchange Potential !on the basis of projectors. !----------------------------------------------------- vpawx=zero do ispden=1,nspden jrhoij=1 do irhoij=1,pawrhoij%nrhoijsel klmn=pawrhoij%rhoijselect(irhoij) if(pawtab%indklmn(3,klmn)==0.and.pawtab%indklmn(4,klmn)==2*lexexch) then m11=pawtab%klmntomn(1,klmn);m21=pawtab%klmntomn(2,klmn) n1=pawtab%klmntomn(3,klmn);n2=pawtab%klmntomn(4,klmn) nn1=(n1*n2)/2+1 jrhoij1=1 do irhoij1=1,pawrhoij%nrhoijsel klmn1=pawrhoij%rhoijselect(irhoij1) if(pawtab%indklmn(3,klmn1)==0.and.pawtab%indklmn(4,klmn1)==2*lexexch) then m31=pawtab%klmntomn(1,klmn1);m41=pawtab%klmntomn(2,klmn1) n3=pawtab%klmntomn(3,klmn1);n4=pawtab%klmntomn(4,klmn1) nn2=(n3*n4)/2+1 do ll=1,lexexch+1 vpawx(1,klmn,ispden)=vpawx(1,klmn,ispden)& & -pawtab%vex(m11,m31,m41,m21,ll)*pawtab%dltij(klmn1) & & *pawtab%fk(indn(nn1,nn2),ll)*pawrhoij%rhoijp(jrhoij1,ispden) end do end if jrhoij1=jrhoij1+pawrhoij%cplex end do !irhoij1 end if jrhoij=jrhoij+pawrhoij%cplex end do !irhoij end do !ispden !Test if (abs(pawprtvol)>=2) then tot=zero do ispden=1,pawrhoij%nspden jrhoij=1 do irhoij=1,pawrhoij%nrhoijsel klmn=pawrhoij%rhoijselect(irhoij) tot=tot+vpawx(1,klmn,ispden)*pawrhoij%rhoijp(jrhoij,ispden)*pawtab%dltij(klmn) jrhoij=jrhoij+pawrhoij%cplex end do end do write(msg, '(a,es22.15)' )" Vpawx: tot=",tot*half call wrtout(std_out,msg,'COLL') end if DBG_EXIT("COLL") end subroutine pawxpot !!*** !---------------------------------------------------------------------- !!****f* m_pawdij/symdij !! NAME !! symdij !! !! FUNCTION !! Symmetrize PAW non-local strengths Dij !! Symmetrize total Dij or one part of it !! !! COPYRIGHT !! Copyright (C) 2001-2014 ABINIT group (FJ, MT) !! This file is distributed under the terms of the !! GNU General Public License, see ~abinit/COPYING !! or http://www.gnu.org/copyleft/gpl.txt . !! For the initials of contributors, see ~abinit/doc/developers/contributors.txt. !! !! INPUTS !! gprimd(3,3)=dimensional primitive translations for reciprocal space(bohr^-1). !! indsym(4,nsym,natom)=indirect indexing array for atom labels !! ipert=index of perturbation if pawrhoij is a pertubed rhoij !! no meaning for ground-state calculations (should be 0) !! [mpi_atmtab(:)]=--optional-- indexes of the atoms treated by current proc !! [mpi_comm_atom]=--optional-- MPI communicator over atoms !! my_natom=number of atoms treated by current processor !! natom=number of atoms in cell !! nsym=number of symmetry elements in space group !! ntypat=number of types of atoms in unit cell. !! option_dij=choose which part of Dij has to be symmetrized (which paw_ij(:)%dijxxx): !! 0: total dij (dij) !! 1: dij due to compensation charge (dijhat) !! 2: dij due to +U (dijU) !! 3: dij XC (dijxc) !! 4: dij XC due to compensation charge (dijxc_hat) !! 5: dij XC valence only (dijxc_val) !! 6: dij spin-orbit (dijso) !! 7: dij exact exchange (dijexxc) !! 8: dij, RF frozen part (dijfr) !! paw_ij(natom)%cplex_dij=1 if dij are REAL, 2 if they are COMPLEX !! paw_ij(natom)%lmn_size=number of (l,m,n) elements for the paw basis !! paw_ij(natom)%nspden=number of spin-density components !! paw_ij(natom)%nsppol=number of independant spin-density components !! paw_ij(natom)%dij(lmn2_size,nspden)=non-symmetrized paw dij quantities !! pawang <type(pawang_type)>=angular mesh discretization and related data !! pawprtvol=control print volume and debugging output for PAW !! pawtab(ntypat) <type(pawtab_type)>=paw tabulated starting data !! [qphon(3)]=--optional-- (RF calculations only) - wavevector of the phonon !! rprimd(3,3)=real space primitive translations. !! symafm(nsym)=(anti)ferromagnetic part of symmetry operations !! symrec(3,3,nsym)=symmetries of group in terms of operations on !! reciprocal space primitive translations !! !! SIDE EFFECTS !! paw_ij(natom)%dij???(cplex_dij*lmn2_size,nspden)=symmetrized dij quantities as output !! !! PARENTS !! bethe_salpeter,m_pawdij,paw_mknewh0,respfn,scfcv,scfcv3,screening,sigma !! !! CHILDREN !! free_my_atmtab,get_my_atmtab !! !! SOURCE subroutine symdij(gprimd,indsym,ipert,my_natom,natom,nsym,ntypat,option_dij,& & paw_ij,pawang,pawprtvol,pawtab,rprimd,symafm,symrec, & & mpi_atmtab,mpi_comm_atom,qphon) ! optional arguments (parallelism) !This section has been created automatically by the script Abilint (TD). !Do not modify the following lines by hand. #undef ABI_FUNC #define ABI_FUNC 'symdij' use interfaces_14_hidewrite !End of the abilint section implicit none !Arguments --------------------------------------------- !scalars integer,intent(in) :: ipert,my_natom,natom,nsym,ntypat,option_dij,pawprtvol integer,optional,intent(in) :: mpi_comm_atom type(pawang_type),intent(in) :: pawang !arrays integer,intent(in) :: indsym(4,nsym,natom),symafm(nsym),symrec(3,3,nsym) integer,optional,target,intent(in) :: mpi_atmtab(:) real(dp),intent(in) :: gprimd(3,3),rprimd(3,3) real(dp),intent(in),optional :: qphon(3) type(paw_ij_type),intent(inout) :: paw_ij(my_natom) type(pawtab_type),target,intent(in) :: pawtab(ntypat) !Local variables --------------------------------------- !scalars integer :: at_indx,cplex,cplex_dij,iafm,iatom,iatom_tot,ierr integer :: il,il0,ilmn,iln,iln0,ilpm,indexi,indexii,indexj,indexjj,indexjj0,indexk,indexkc integer :: iplex,irot,ispden,itypat,j0lmn,jl,jl0,jlmn,jln,jln0,jlpm,jspden integer :: klmn,klmnc,kspden,lmn_size,mi,mj,my_comm_atom,mu,natinc,ndij0,ndij1,nu,optsym,sz1,sz2 logical,parameter :: afm_noncoll=.true. ! TRUE if antiferro symmetries are used with non-collinear magnetism logical :: antiferro,have_phase,my_atmtab_allocated,noncoll,paral_atom,use_afm !DEBUG_ALTERNATE_ALGO !Set to TRUE to choose an alternate algorithm (with another representation) !to symmetrize Dij within non-collinear magnetism or spin-orbit logical,parameter :: lsymnew=.false. !DEBUG_ALTERNATE_ALGO real(dp) :: arg,factafm,zarot2 character(len=6) :: pertstrg,wrt_mode character(len=500) :: msg !arrays integer :: nsym_used(2) integer, ABI_CONTIGUOUS pointer :: indlmn(:,:) integer,pointer :: my_atmtab(:) integer :: idum(0) real(dp) :: dijc(2),factsym(2),phase(2),rotdij(2,2),sumdij(2,2) real(dp),allocatable :: dijnew(:,:),dijtmp(:,:),rotmag(:,:),summag(:,:) real(dp),allocatable :: symrec_cart(:,:,:),work(:,:) character(len=7),parameter :: dspin(6)=(/"up ","down ","up-up ", & & "dwn-dwn","up-dwn ","dwn-up "/) type(coeff2_type),target, allocatable :: my_tmp_dij(:) type(coeff2_type),pointer :: tmp_dij(:) !DEBUG_ALTERNATE_ALGO !integer :: i1,i2,i3,i4,symrel_conv(3,3) !real(dp) :: spinrot(4) !real(dp),allocatable :: dijtemp(:,:),sumrhoso(:,:) !complex(dpc) :: dijt(2,2),dijt2(2,2),Rspinrot(2,2) !DEBUG_ALTERNATE_ALGO ! ********************************************************************* DBG_ENTER("COLL") !Tests of compatibility: if (my_natom>0) then if ((option_dij==1.and.paw_ij(1)%has_dijhat==0).or.& & (option_dij==2.and.paw_ij(1)%has_dijU==0).or.& & (option_dij==3.and.paw_ij(1)%has_dijxc==0).or.& & (option_dij==4.and.paw_ij(1)%has_dijxc_hat==0).or.& & (option_dij==5.and.paw_ij(1)%has_dijxc_val==0).or.& & (option_dij==6.and.paw_ij(1)%has_dijso==0).or.& & (option_dij==7.and.paw_ij(1)%has_dijexxc==0).or.& & (option_dij==8.and.paw_ij(1)%has_dijfr==0)) then msg='Incompatibilty between option_dij and allocation of Dij!' MSG_BUG(msg) end if end if !Set up parallelism over atoms paral_atom=(present(mpi_comm_atom).and.(my_natom/=natom)) nullify(my_atmtab);if (present(mpi_atmtab)) my_atmtab => mpi_atmtab my_comm_atom=xmpi_self;if (present(mpi_comm_atom)) my_comm_atom=mpi_comm_atom call get_my_atmtab(my_comm_atom,my_atmtab,my_atmtab_allocated,paral_atom,natom,my_natom_ref=my_natom) !Symmetrization occurs only when nsym>1 if (nsym>1.and.ipert/=natom+1.and.ipert/=natom+5) then if (pawang%nsym==0) then msg='pawang%zarot must be allocated!' MSG_BUG(msg) end if cplex_dij=1;antiferro=.false.;noncoll=.false. if (my_natom>0) then cplex_dij=paw_ij(1)%cplex_dij ! Antiferro case ? antiferro=(paw_ij(1)%nspden==2.and.paw_ij(1)%nsppol==1.and.paw_ij(1)%ndij/=4) ! Non-collinear case noncoll=(paw_ij(1)%ndij==4) if (noncoll.and.paw_ij(1)%cplex_dij/=2) then msg='cplex_dij must be 2 with ndij=4!' MSG_BUG(msg) end if end if if (noncoll) then ABI_ALLOCATE(summag,(cplex_dij,3)) ABI_ALLOCATE(rotmag,(cplex_dij,3)) ABI_ALLOCATE(work,(cplex_dij,3)) ABI_ALLOCATE(symrec_cart,(3,3,nsym)) do irot=1,nsym symrec_cart(:,:,irot)=symdij_symcart(gprimd,rprimd,symrec(:,:,irot)) end do !DEBUG_ALTERNATE_ALGO ! if(lsymnew) then ! ABI_ALLOCATE(sumrhoso,(cplex_dij,4)) ! end if !DEBUG_ALTERNATE_ALGO end if ! Do we use antiferro symmetries ? use_afm=((antiferro).or.(noncoll.and.afm_noncoll)) ! Do we have a phase due to q-vector (phonons only) ? have_phase=.false. if (ipert>0.and.present(qphon).and.my_natom>0) then have_phase=(abs(qphon(1))>tol8.or.abs(qphon(2))>tol8.or.abs(qphon(3))>tol8) if (have_phase.and.cplex_dij==1) then msg='Should have cplex_dij=2 for a non-zero q!' MSG_BUG(msg) end if end if ! Have to make a temporary copy of dij ABI_DATATYPE_ALLOCATE(my_tmp_dij,(my_natom)) do iatom=1,my_natom sz1=paw_ij(iatom)%cplex_dij*paw_ij(iatom)%lmn2_size;sz2=paw_ij(iatom)%ndij ABI_ALLOCATE(my_tmp_dij(iatom)%value,(sz1,sz2)) ABI_ALLOCATE(dijtmp,(sz1,sz2)) if (option_dij==0) then dijtmp(:,:)=paw_ij(iatom)%dij(:,:) else if (option_dij==1) then dijtmp(:,:)=paw_ij(iatom)%dijhat(:,:) else if (option_dij==2) then dijtmp(:,:)=paw_ij(iatom)%dijU(:,:) else if (option_dij==3) then dijtmp(:,:)=paw_ij(iatom)%dijxc(:,:) else if (option_dij==4) then dijtmp(:,:)=paw_ij(iatom)%dijxc_hat(:,:) else if (option_dij==5) then dijtmp(:,:)=paw_ij(iatom)%dijxc_val(:,:) else if (option_dij==6) then dijtmp(:,:)=paw_ij(iatom)%dijso(:,:) else if (option_dij==7) then dijtmp(:,:)=paw_ij(iatom)%dijexxc(:,:) else if (option_dij==8) then dijtmp(:,:)=paw_ij(iatom)%dijfr(:,:) end if !Has to translate Dij^{alpha,beta} into (Dij, Dij magnetic field) format if (paw_ij(1)%ndij==4) then my_tmp_dij(iatom)%value(:,1)=dijtmp(:,1)+dijtmp(:,2) my_tmp_dij(iatom)%value(:,2)=dijtmp(:,3)+dijtmp(:,4) my_tmp_dij(iatom)%value(:,4)=dijtmp(:,1)-dijtmp(:,2) do klmn=1,paw_ij(iatom)%lmn2_size my_tmp_dij(iatom)%value(2*klmn-1,3)=-dijtmp(2*klmn ,3)+dijtmp(2*klmn ,4) my_tmp_dij(iatom)%value(2*klmn ,3)= dijtmp(2*klmn-1,3)-dijtmp(2*klmn-1,4) end do !DEBUG_ALTERNATE_ALGO ! if(lsymnew) my_tmp_dij(iatom)%value(:,:)=dijtmp(:,:) !DEBUG_ALTERNATE_ALGO else my_tmp_dij(iatom)%value(:,:)=dijtmp(:,:) end if ABI_DEALLOCATE(dijtmp) end do ! Parallelism: gather all Dij if (paral_atom) then ABI_DATATYPE_ALLOCATE(tmp_dij,(natom)) call xmpi_allgatherv(my_tmp_dij,tmp_dij,my_comm_atom,my_atmtab,ierr) do iatom=1,my_natom ABI_DEALLOCATE(my_tmp_dij(iatom)%value) end do ABI_DATATYPE_DEALLOCATE(my_tmp_dij) else tmp_dij=>my_tmp_dij end if ndij1=1 if (antiferro) ndij1=2 if (noncoll) ndij1=4 ndij0=ndij1-1 ABI_ALLOCATE(dijnew,(cplex_dij,ndij1)) ! Loops over atoms and spin components do iatom=1,my_natom iatom_tot=iatom;if (paral_atom) iatom_tot=my_atmtab(iatom) itypat=paw_ij(iatom)%itypat lmn_size=paw_ij(iatom)%lmn_size cplex_dij=paw_ij(iatom)%cplex_dij cplex=paw_ij(iatom)%cplex indlmn => pawtab(itypat)%indlmn !DEBUG_ALTERNATE_ALGO ! if (noncoll.and.lsymnew) then ! ABI_ALLOCATE(dijtemp,(paw_ij(iatom)%cplex_dij,paw_ij(iatom)%ndij)) ! end if !DEBUG_ALTERNATE_ALGO do ispden=1,paw_ij(iatom)%nsppol jspden=min(3-ispden,paw_ij(iatom)%nsppol) ! Loops over (il,im) and (jl,jm) jl0=-1;jln0=-1;indexj=1 do jlmn=1,lmn_size jl=indlmn(1,jlmn) jlpm=1+jl+indlmn(2,jlmn) jln=indlmn(5,jlmn) if (jln/=jln0) indexj=indexj+2*jl0+1 j0lmn=jlmn*(jlmn-1)/2 il0=-1;iln0=-1;indexi=1 do ilmn=1,jlmn il=indlmn(1,ilmn) ilpm=1+il+indlmn(2,ilmn) iln=indlmn(5,ilmn) if (iln/=iln0) indexi=indexi+2*il0+1 klmn=j0lmn+ilmn;klmnc=cplex_dij*(klmn-1) nsym_used(:)=0 rotdij(:,:)=zero if (noncoll) rotmag(:,:)=zero !DEBUG_ALTERNATE_ALGO ! if (noncoll.and.lsymnew) sumrhoso(:,:)=zero !DEBUG_ALTERNATE_ALGO ! Loop over symmetries do irot=1,nsym !DEBUG_ALTERNATE_ALGO ! if(lsymnew) then ! call mati3inv(symrec(:,:,irot),symrel_conv) ! call getspinrot(rprimd,spinrot,symrel_conv) ! Rspinrot(1,1)=cmplx(spinrot(1),-spinrot(4)) ! Rspinrot(1,2)=cmplx(-spinrot(3),-spinrot(2)) ! Rspinrot(2,1)=cmplx(spinrot(3),-spinrot(2)) ! Rspinrot(2,2)=cmplx(spinrot(1),spinrot(4)) ! end if !DEBUG_ALTERNATE_ALGO if ((symafm(irot)/=1).and.(.not.use_afm)) cycle kspden=ispden;if (symafm(irot)==-1) kspden=jspden iafm=1;if ((antiferro).and.(symafm(irot)==-1)) iafm=2 factafm=dble(symafm(irot)) nsym_used(iafm)=nsym_used(iafm)+1 at_indx=indsym(4,irot,iatom_tot) if (have_phase) then arg=two_pi*(qphon(1)*indsym(1,irot,iatom)+qphon(2)*indsym(2,irot,iatom) & & +qphon(3)*indsym(3,irot,iatom)) phase(1)=cos(arg);phase(2)=sin(arg) end if sumdij(:,:)=zero if (noncoll) summag(:,:)=zero ! Accumulate values over (mi,mj) and symmetries do mj=1,2*jl+1 indexjj=indexj+mj;indexjj0=indexjj*(indexjj-1)/2 do mi=1,2*il+1 indexii=indexi+mi factsym(:)=one if (indexii<=indexjj) then indexk=indexjj0+indexii if(cplex_dij==2.and.cplex==1) factsym(2)=one else indexk=indexii*(indexii-1)/2+indexjj if(cplex_dij==2.and.cplex==1) factsym(2)=-one end if indexkc=cplex_dij*(indexk-1) !DEBUG_ALTERNATE_ALGO ! if (noncoll.and.lsymnew) then ! do iplex=1,cplex_dij ! if(factafm>zero) then ! dijtemp(iplex,1)=factsym(iplex)*tmp_dij(at_indx)%value(indexkc+iplex,1) ! dijtemp(iplex,2)=factsym(iplex)*tmp_dij(at_indx)%value(indexkc+iplex,2) ! else ! dijtemp(iplex,1)=factsym(iplex)*tmp_dij(at_indx)%value(indexkc+iplex,2) ! dijtemp(iplex,2)=factsym(iplex)*tmp_dij(at_indx)%value(indexkc+iplex,1) ! end if ! if(factsym(2)<zero) then ! to be changed if symafm ! dijtemp(iplex,3)=factafm*factsym(iplex)*tmp_dij(at_indx)%value(indexkc+iplex,4) ! dijtemp(iplex,4)=factafm*factsym(iplex)*tmp_dij(at_indx)%value(indexkc+iplex,3) ! else ! dijtemp(iplex,3)=factafm*factsym(iplex)*tmp_dij(at_indx)%value(indexkc+iplex,3) ! dijtemp(iplex,4)=factafm*factsym(iplex)*tmp_dij(at_indx)%value(indexkc+iplex,4) ! end if ! end do ! end if !DEBUG_ALTERNATE_ALGO ! Be careful: use here R_rel^-1 in term of spherical harmonics ! which is tR_rec in term of spherical harmonics ! so, use transpose[zarot].... however, we use here zarot (??) zarot2=pawang%zarot(mi,ilpm,il+1,irot)*pawang%zarot(mj,jlpm,jl+1,irot) ! zarot2=pawang%zarot(ilpm,mi,il+1,irot)*pawang%zarot(jlpm,mj,jl+1,irot) if((.not.noncoll).or.(.not.lsymnew)) then sumdij(1,iafm)=sumdij(1,iafm)+factsym(1)*zarot2*tmp_dij(at_indx)%value(indexkc+1,kspden) if(cplex_dij==2) sumdij(2,iafm)= & & sumdij(2,iafm)+factsym(2)*factafm*zarot2*tmp_dij(at_indx)%value(indexkc+2,kspden) end if if (noncoll.and.(.not.lsymnew)) then do mu=1,3 summag(1,mu)=summag(1,mu)+factsym(1)*factafm*zarot2*tmp_dij(at_indx)%value(indexkc+1,1+mu) if(cplex_dij==2) summag(2,mu)= & & summag(2,mu)+factsym(2)*zarot2*tmp_dij(at_indx)%value(indexkc+2,1+mu) end do end if !DEBUG_ALTERNATE_ALGO ! if (noncoll.and.(lsymnew)) then ! dijt(1,1)=cmplx(dijtemp(1,1),dijtemp(2,1)) ! dijt(2,2)=cmplx(dijtemp(1,2),dijtemp(2,2)) ! dijt(1,2)=cmplx(dijtemp(1,3),dijtemp(2,3)) ! dijt(2,1)=cmplx(dijtemp(1,4),dijtemp(2,4)) ! dijt2(:,:)=czero ! do i1=1,2 ! do i4=1,2 ! do i2=1,2 ! do i3=1,2 ! dijt2(i1,i4)=dijt2(i1,i4)+Rspinrot(i1,i2)*dijt(i2,i3)*conjg(Rspinrot(i4,i3)) ! end do ! end do ! end do ! end do ! do mu=1,4 ! if(mu==1) then ! i1=1;i4=1 ! else if(mu==2) then ! i1=2;i4=2 ! else if(mu==3) then ! i1=1;i4=2 ! else if(mu==4) then ! i1=2;i4=1 ! end if ! sumrhoso(1,mu)=sumrhoso(1,mu)+zarot2*real(dijt2(i1,i4)) ! sumrhoso(2,mu)=sumrhoso(2,mu)+zarot2*imag(dijt2(i1,i4)) ! end do ! end if end do ! mi end do ! mj !DEBUG_ALTERNATE_ALGO ! Apply phase for phonons if (have_phase) then if((.not.noncoll).or.(.not.lsymnew)) then dijc(1:2)=sumdij(1:2,iafm) sumdij(1,iafm)=phase(1)*dijc(1)-phase(2)*dijc(2) sumdij(2,iafm)=phase(1)*dijc(2)+phase(2)*dijc(1) end if if (noncoll.and.(.not.lsymnew)) then do mu=1,3 dijc(1:2)=summag(1:2,mu) summag(1,mu)=phase(1)*dijc(1)-phase(2)*dijc(2) summag(2,mu)=phase(1)*dijc(2)+phase(2)*dijc(1) end do end if !DEBUG_ALTERNATE_ALGO ! if (noncoll.and.(lsymnew) then ! do mu=1,4 ! dijc(1:2)=sumrhoso(1:2,mu) ! sumrhoso(1,mu)=phase(1)*dijc(1)-phase(2)*dijc(2) ! sumrhoso(2,mu)=phase(1)*dijc(2)+phase(2)*dijc(1) ! end do ! end do ! end if !DEBUG_ALTERNATE_ALGO end if ! Add contribution of this rotation rotdij(1:cplex_dij,iafm)=rotdij(1:cplex_dij,iafm)+sumdij(1:cplex_dij,iafm) if (noncoll.and.(.not.lsymnew)) then ! If non-collinear case, rotate Dij magnetization ! Should use symrel^1 but use transpose[symrec] instead do nu=1,3 do mu=1,3 !we need the transpose ? rotmag(1:cplex_dij,mu)=rotmag(1:cplex_dij,mu) & & +symrec_cart(mu,nu,irot)*summag(1:cplex_dij,nu) end do end do end if end do ! End loop over symmetries if((.not.noncoll).or.(.not.lsymnew)) then ! Store new value of dij do iplex=1,cplex_dij dijnew(iplex,1)=rotdij(iplex,1)/nsym_used(1) if (abs(dijnew(iplex,1))<=tol10) dijnew(iplex,1)=zero end do ! Antiferromagnetic case: has to fill up "down" component of dij if (antiferro.and.nsym_used(2)>0) then do iplex=1,cplex_dij dijnew(iplex,2)=rotdij(iplex,2)/nsym_used(2) if (abs(dijnew(iplex,2))<=tol10) dijnew(iplex,2)=zero end do end if !DEBUG_ALTERNATE_ALGO ! else if (noncoll.and.(lsymnew)) then ! do mu=1,4 ! do iplex=1,cplex_dij ! dijnew(iplex,mu)=sumrhoso(iplex,mu)/nsym_used(1) ! if (abs(dijnew(iplex,mu))<=tol10) dijnew(iplex,mu)=zero ! end do ! end do !DEBUG_ALTERNATE_ALGO end if ! Non-collinear case: store new values of Dij magnetization if (noncoll.and.(.not.lsymnew)) then ! Select on-zero elements do mu=1,3 do iplex=1,cplex_dij rotmag(iplex,mu)=rotmag(iplex,mu)/nsym_used(1) if (abs(rotmag(iplex,mu))<=tol10) rotmag(iplex,mu)=zero end do end do ! Transfer back to Dij^{alpha,beta} if(.not.lsymnew) then dijnew(1,1)=half*(dijnew(1,1)+rotmag(1,3)) dijnew(2,1)=half*(dijnew(2,1)+rotmag(2,3)) dijnew(1,2)= dijnew(1,1)-rotmag(1,3) dijnew(2,2)= dijnew(2,1)-rotmag(2,3) dijnew(1,3)=half*(rotmag(1,1)+rotmag(2,2)) dijnew(2,3)=half*(rotmag(2,1)-rotmag(1,2)) dijnew(1,4)=half*(rotmag(1,1)-rotmag(2,2)) dijnew(2,4)=half*(rotmag(2,1)+rotmag(1,2)) end if end if ! Transfer new value of Dij in suitable pointer if (option_dij==0) then paw_ij(iatom)%dij(klmnc+1:klmnc+cplex_dij,ispden:ispden+ndij0)=dijnew(1:cplex_dij,1:ndij1) else if (option_dij==1) then paw_ij(iatom)%dijhat(klmnc+1:klmnc+cplex_dij,ispden:ispden+ndij0)=dijnew(1:cplex_dij,1:ndij1) else if (option_dij==2) then paw_ij(iatom)%dijU(klmnc+1:klmnc+cplex_dij,ispden:ispden+ndij0)=dijnew(1:cplex_dij,1:ndij1) else if (option_dij==3) then paw_ij(iatom)%dijxc(klmnc+1:klmnc+cplex_dij,ispden:ispden+ndij0)=dijnew(1:cplex_dij,1:ndij1) else if (option_dij==4) then paw_ij(iatom)%dijxc_hat(klmnc+1:klmnc+cplex_dij,ispden:ispden+ndij0)=dijnew(1:cplex_dij,1:ndij1) else if (option_dij==5) then paw_ij(iatom)%dijxc_val(klmnc+1:klmnc+cplex_dij,ispden:ispden+ndij0)=dijnew(1:cplex_dij,1:ndij1) else if (option_dij==6) then paw_ij(iatom)%dijso(klmnc+1:klmnc+cplex_dij,ispden:ispden+ndij0)=dijnew(1:cplex_dij,1:ndij1) else if (option_dij==7) then paw_ij(iatom)%dijexxc(klmnc+1:klmnc+cplex_dij,ispden:ispden+ndij0)=dijnew(1:cplex_dij,1:ndij1) else if (option_dij==8) then paw_ij(iatom)%dijfr(klmnc+1:klmnc+cplex_dij,ispden:ispden+ndij0)=dijnew(1:cplex_dij,1:ndij1) end if il0=il;iln0=iln ! End loops over (il,im) and (jl,jm) end do jl0=jl;jln0=jln end do end do ! ispden !DEBUG_ALTERNATE_ALGO ! if (noncoll.and.lsymnew) then ! ABI_DEALLOCATE(dijtemp) ! end if !DEBUG_ALTERNATE_ALGO end do ! iatom ABI_DEALLOCATE(dijnew) if (noncoll) then ABI_DEALLOCATE(summag) ABI_DEALLOCATE(rotmag) ABI_DEALLOCATE(symrec_cart) ABI_DEALLOCATE(work) !DEBUG_ALTERNATE_ALGO ! if (lsymnew) then ! ABI_DEALLOCATE(sumrhoso) ! end if !DEBUG_ALTERNATE_ALGO end if if (paral_atom) then do iatom=1,natom ABI_DEALLOCATE(tmp_dij(iatom)%value) end do ABI_DATATYPE_DEALLOCATE(tmp_dij) else do iatom=1,my_natom ABI_DEALLOCATE(my_tmp_dij(iatom)%value) end do ABI_DATATYPE_DEALLOCATE(my_tmp_dij) end if else if (ipert/=natom+1.and.ipert/=natom+5) then ! nsym>1 ! ********************************************************************* ! If nsym==1, only cut small components of dij if (my_natom>0) then if(paw_ij(1)%nspden==2.and.paw_ij(1)%nsppol==1) then MSG_BUG(' In the antiferromagnetic case, nsym cannot be 1') end if end if do iatom=1,my_natom do ispden=1,paw_ij(iatom)%ndij if (option_dij==0) then do klmn=1,paw_ij(iatom)%lmn2_size*paw_ij(iatom)%cplex_dij if (abs(paw_ij(iatom)%dij(klmn,ispden))<=tol10) paw_ij(iatom)%dij(klmn,ispden)=zero end do else if (option_dij==1) then do klmn=1,paw_ij(iatom)%lmn2_size*paw_ij(iatom)%cplex_dij if (abs(paw_ij(iatom)%dijhat(klmn,ispden))<=tol10) paw_ij(iatom)%dijhat(klmn,ispden)=zero end do else if (option_dij==2) then do klmn=1,paw_ij(iatom)%lmn2_size*paw_ij(iatom)%cplex_dij if (abs(paw_ij(iatom)%dijU(klmn,ispden))<=tol10) paw_ij(iatom)%dijU(klmn,ispden)=zero end do else if (option_dij==3) then do klmn=1,paw_ij(iatom)%lmn2_size*paw_ij(iatom)%cplex_dij if (abs(paw_ij(iatom)%dijxc(klmn,ispden))<=tol10) paw_ij(iatom)%dijxc(klmn,ispden)=zero end do else if (option_dij==4) then do klmn=1,paw_ij(iatom)%lmn2_size*paw_ij(iatom)%cplex_dij if (abs(paw_ij(iatom)%dijxc_hat(klmn,ispden))<=tol10) paw_ij(iatom)%dijxc_hat(klmn,ispden)=zero end do else if (option_dij==5) then do klmn=1,paw_ij(iatom)%lmn2_size*paw_ij(iatom)%cplex_dij if (abs(paw_ij(iatom)%dijxc_val(klmn,ispden))<=tol10) paw_ij(iatom)%dijxc_val(klmn,ispden)=zero end do else if (option_dij==6) then do klmn=1,paw_ij(iatom)%lmn2_size*paw_ij(iatom)%cplex_dij if (abs(paw_ij(iatom)%dijso(klmn,ispden))<=tol10) paw_ij(iatom)%dijso(klmn,ispden)=zero end do else if (option_dij==7) then do klmn=1,paw_ij(iatom)%lmn2_size*paw_ij(iatom)%cplex_dij if (abs(paw_ij(iatom)%dijexxc(klmn,ispden))<=tol10) paw_ij(iatom)%dijexxc(klmn,ispden)=zero end do else if (option_dij==8) then do klmn=1,paw_ij(iatom)%lmn2_size*paw_ij(iatom)%cplex_dij if (abs(paw_ij(iatom)%dijfr(klmn,ispden))<=tol10) paw_ij(iatom)%dijfr(klmn,ispden)=zero end do end if end do end do end if ! nsym>1 !********************************************************************* !Printing of Dij if (abs(pawprtvol)>=1.and.option_dij==0.and.ipert/=natom+1.and.ipert/=natom+5) then wrt_mode='COLL';if (paral_atom) wrt_mode='PERS' pertstrg="DIJ";if (ipert>0) pertstrg="DIJ(1)" natinc=1;if(my_natom>1.and.pawprtvol>=0) natinc=my_natom-1 do iatom=1,my_natom,natinc iatom_tot=iatom; if (paral_atom) iatom_tot=my_atmtab(iatom) write(msg, '(6a,i3,a)') ch10," PAW TEST:",ch10,& & ' ====== Values of ',trim(pertstrg),' in symdij (iatom=',iatom_tot,') (Hartree) ======' call wrtout(std_out,msg,wrt_mode) optsym=2;if (paw_ij(iatom)%cplex_dij==2.and.ipert>0) optsym=1 do ispden=1,paw_ij(iatom)%ndij if (paw_ij(iatom)%ndij==1) then write(msg, '(4a,i3,a)') ch10,& & ' *********** ',trim(pertstrg),' (atom ',iatom_tot,') **********' else write(msg, '(4a,i3,3a)') ch10,& & ' *********** ',trim(pertstrg),' (atom ',iatom_tot,', Component ', & & trim(dspin(ispden+2*(paw_ij(iatom)%ndij/4))),') **********' end if call wrtout(std_out,msg,wrt_mode) if (paw_ij(iatom)%ndij/=4.or.ispden<=2) then call pawio_print_ij(std_out,paw_ij(iatom)%dij(:,ispden),paw_ij(iatom)%lmn2_size,& & paw_ij(iatom)%cplex_dij,paw_ij(iatom)%lmn_size,-1,idum,0,pawprtvol,idum,50.d0*dble(3-2*ispden),1,& & opt_sym=optsym,mode_paral=wrt_mode) else if (ipert==0) then call pawio_print_ij(std_out,paw_ij(iatom)%dij(:,ispden),paw_ij(iatom)%lmn2_size,& & paw_ij(iatom)%cplex_dij,paw_ij(iatom)%lmn_size,-1,idum,0,pawprtvol,idum,50.d0*dble(3-2*ispden),1,& & asym_ij=paw_ij(iatom)%dij(:,7-ispden),mode_paral=wrt_mode) else call pawio_print_ij(std_out,paw_ij(iatom)%dij(:,ispden),paw_ij(iatom)%lmn2_size,& & paw_ij(iatom)%cplex_dij,paw_ij(iatom)%lmn_size,-1,idum,0,pawprtvol,idum,50.d0*dble(3-2*ispden),1,& & opt_sym=optsym,mode_paral=wrt_mode) end if end if end do end do call wrtout(std_out,"",wrt_mode) end if !Destroy atom table used for parallelism call free_my_atmtab(my_atmtab,my_atmtab_allocated) DBG_EXIT("COLL") !********************************************************************* !Small function: convert a symmetry operation !from reduced coordinates (integers) to cartesian coordinates (reals) contains function symdij_symcart(aprim,bprim,symred) !This section has been created automatically by the script Abilint (TD). !Do not modify the following lines by hand. #undef ABI_FUNC #define ABI_FUNC 'symdij_symcart' !End of the abilint section implicit none real(dp) :: symdij_symcart(3,3) integer,intent(in) :: symred(3,3) real(dp),intent(in) :: aprim(3,3),bprim(3,3) integer :: ii,jj,kk real(dp) :: tmp(3,3) symdij_symcart=zero;tmp=zero do kk=1,3 do jj=1,3 do ii=1,3 tmp(ii,jj)=tmp(ii,jj)+bprim(ii,kk)*dble(symred(jj,kk)) end do end do end do do kk=1,3 do jj=1,3 do ii=1,3 symdij_symcart(ii,jj)=symdij_symcart(ii,jj)+aprim(ii,kk)*tmp(jj,kk) end do end do end do end function symdij_symcart end subroutine symdij !!*** !---------------------------------------------------------------------- !!****f* m_pawdij/symdij_all !! NAME !! symdij_all !! !! FUNCTION !! Symmetrize all contributions to PAW non-local strengths Dij !! !! INPUTS !! gprimd(3,3)=dimensional primitive translations for reciprocal space(bohr^-1). !! indsym(4,nsym,natom)=indirect indexing array for atom labels !! ipert=index of perturbation if pawrhoij is a pertubed rhoij !! no meaning for ground-state calculations (should be 0) !! mpi_atmtab(:)=--optional-- indexes of the atoms treated by current proc !! mpi_comm_atom=--optional-- MPI communicator over atoms !! my_natom=number of atoms treated by current processor !! natom=number of atoms in cell !! nsym=number of symmetry elements in space group !! ntypat=number of types of atoms in unit cell. !! paw_ij(natom)%cplex_dij=1 if dij are REAL, 2 if they are COMPLEX !! paw_ij(natom)%lmn_size=number of (l,m,n) elements for the paw basis !! paw_ij(natom)%nspden=number of spin-density components !! paw_ij(natom)%nsppol=number of independant spin-density components !! paw_ij(natom)%dij(lmn2_size,nspden)=non-symmetrized paw dij quantities !! pawang <type(pawang_type)>=angular mesh discretization and related data !! pawprtvol=control print volume and debugging output for PAW !! pawtab(ntypat) <type(pawtab_type)>=paw tabulated starting data !! rprimd(3,3)=real space primitive translations. !! symafm(nsym)=(anti)ferromagnetic part of symmetry operations !! symrec(3,3,nsym)=symmetries of group in terms of operations on !! reciprocal space primitive translations !! !! SIDE EFFECTS !! paw_ij(natom)%dij???(cplex_dij*lmn2_size,nspden)=symmetrized dij quantities as output !! !! PARENTS !! paw_mknewh0,screening,sigma !! !! CHILDREN !! free_my_atmtab,get_my_atmtab,symdij !! !! SOURCE subroutine symdij_all(gprimd,indsym,ipert,my_natom,natom,nsym,ntypat,& & paw_ij,pawang,pawprtvol,pawtab,rprimd,symafm,symrec,& & mpi_atmtab,mpi_comm_atom) ! optional arguments (parallelism) !This section has been created automatically by the script Abilint (TD). !Do not modify the following lines by hand. #undef ABI_FUNC #define ABI_FUNC 'symdij_all' !End of the abilint section implicit none !Arguments --------------------------------------------- !scalars integer,intent(in) :: ipert,my_natom,natom,nsym,ntypat,pawprtvol integer,optional,intent(in) :: mpi_comm_atom type(pawang_type),intent(in) :: pawang !arrays integer,intent(in) :: indsym(4,nsym,natom),symafm(nsym),symrec(3,3,nsym) integer,optional,target,intent(in) :: mpi_atmtab(:) real(dp),intent(in) :: gprimd(3,3),rprimd(3,3) type(paw_ij_type),intent(inout) :: paw_ij(my_natom) type(pawtab_type),intent(in) :: pawtab(ntypat) !Local variables --------------------------------------- !scalars integer,parameter :: MAX_NOPTS=11 integer :: ii,option_dij,my_comm_atom,nopt logical :: my_atmtab_allocated,paral_atom !arrays integer :: options(MAX_NOPTS) integer,pointer :: my_atmtab(:) ! ********************************************************************* nopt = 0 if (ANY(paw_ij(:)%has_dij==2)) then nopt = nopt + 1 options(nopt) = 0 end if if (ANY(paw_ij(:)%has_dijhat==2)) then nopt = nopt + 1 options(nopt) = 1 end if if (ANY(paw_ij(:)%has_dijU==2)) then nopt = nopt + 1 options(nopt) = 2 end if if (ANY(paw_ij(:)%has_dijxc==2)) then nopt = nopt + 1 options(nopt) = 3 end if if (ANY(paw_ij(:)%has_dijxc_hat==2)) then nopt = nopt + 1 options(nopt) = 4 end if if (ANY(paw_ij(:)%has_dijxc_val==2)) then nopt = nopt + 1 options(nopt) = 5 end if if (ANY(paw_ij(:)%has_dijso==2)) then nopt = nopt + 1 options(nopt) = 6 end if if (ANY(paw_ij(:)%has_dijexxc==2)) then nopt = nopt + 1 options(nopt) = 7 end if if (ANY(paw_ij(:)%has_dijfr==2)) then nopt = nopt + 1 options(nopt) = 8 end if !FIXME Dij_hartree and exech_pot are not symmetrized, if (ANY(paw_ij(:)%has_dijhartree==2)) then MSG_WARNING("symdij does not symmetrize dijhartree term!") !nopt = nopt + 1 !options(nopt) = 9 end if if (ANY(paw_ij(:)%has_exexch_pot==2)) then nopt = nopt + 1 options(nopt) = 10 MSG_ERROR("Not coded") end if !Set up parallelism over atoms paral_atom=(present(mpi_comm_atom)) nullify(my_atmtab);if (present(mpi_atmtab)) my_atmtab => mpi_atmtab my_comm_atom=xmpi_self;if (present(mpi_comm_atom)) my_comm_atom=mpi_comm_atom call get_my_atmtab(my_comm_atom,my_atmtab,my_atmtab_allocated,paral_atom,natom,my_natom_ref=my_natom) do ii=1,nopt option_dij = options(ii) if (paral_atom) then call symdij(gprimd,indsym,ipert,my_natom,natom,nsym,ntypat,option_dij,& & paw_ij,pawang,pawprtvol,pawtab,rprimd,symafm,symrec,& & mpi_comm_atom=my_comm_atom,mpi_atmtab=my_atmtab) else call symdij(gprimd,indsym,ipert,my_natom,natom,nsym,ntypat,option_dij,& & paw_ij,pawang,pawprtvol,pawtab,rprimd,symafm,symrec) end if end do !Destroy atom table used for parallelism call free_my_atmtab(my_atmtab,my_atmtab_allocated) end subroutine symdij_all !!*** !---------------------------------------------------------------------- END MODULE m_pawdij !!***
gpl-3.0
zachary-williamson/ITK
Modules/ThirdParty/VNL/src/vxl/v3p/netlib/blas/ztrmv.f
41
10389
SUBROUTINE ZTRMV ( UPLO, TRANS, DIAG, N, A, LDA, X, INCX ) * .. Scalar Arguments .. INTEGER INCX, LDA, N CHARACTER*1 DIAG, TRANS, UPLO * .. Array Arguments .. COMPLEX*16 A( LDA, * ), X( * ) * .. * * Purpose * ======= * * ZTRMV performs one of the matrix-vector operations * * x := A*x, or x := A'*x, or x := conjg( A' )*x, * * where x is an n element vector and A is an n by n unit, or non-unit, * upper or lower triangular matrix. * * Parameters * ========== * * UPLO - CHARACTER*1. * On entry, UPLO specifies whether the matrix is an upper or * lower triangular matrix as follows: * * UPLO = 'U' or 'u' A is an upper triangular matrix. * * UPLO = 'L' or 'l' A is a lower triangular matrix. * * Unchanged on exit. * * TRANS - CHARACTER*1. * On entry, TRANS specifies the operation to be performed as * follows: * * TRANS = 'N' or 'n' x := A*x. * * TRANS = 'T' or 't' x := A'*x. * * TRANS = 'C' or 'c' x := conjg( A' )*x. * * Unchanged on exit. * * DIAG - CHARACTER*1. * On entry, DIAG specifies whether or not A is unit * triangular as follows: * * DIAG = 'U' or 'u' A is assumed to be unit triangular. * * DIAG = 'N' or 'n' A is not assumed to be unit * triangular. * * Unchanged on exit. * * N - INTEGER. * On entry, N specifies the order of the matrix A. * N must be at least zero. * Unchanged on exit. * * A - COMPLEX*16 array of DIMENSION ( LDA, n ). * Before entry with UPLO = 'U' or 'u', the leading n by n * upper triangular part of the array A must contain the upper * triangular matrix and the strictly lower triangular part of * A is not referenced. * Before entry with UPLO = 'L' or 'l', the leading n by n * lower triangular part of the array A must contain the lower * triangular matrix and the strictly upper triangular part of * A is not referenced. * Note that when DIAG = 'U' or 'u', the diagonal elements of * A are not referenced either, but are assumed to be unity. * Unchanged on exit. * * LDA - INTEGER. * On entry, LDA specifies the first dimension of A as declared * in the calling (sub) program. LDA must be at least * max( 1, n ). * Unchanged on exit. * * X - COMPLEX*16 array of dimension at least * ( 1 + ( n - 1 )*abs( INCX ) ). * Before entry, the incremented array X must contain the n * element vector x. On exit, X is overwritten with the * transformed vector x. * * INCX - INTEGER. * On entry, INCX specifies the increment for the elements of * X. INCX must not be zero. * Unchanged on exit. * * * Level 2 Blas routine. * * -- Written on 22-October-1986. * Jack Dongarra, Argonne National Lab. * Jeremy Du Croz, Nag Central Office. * Sven Hammarling, Nag Central Office. * Richard Hanson, Sandia National Labs. * * * .. Parameters .. COMPLEX*16 ZERO PARAMETER ( ZERO = ( 0.0D+0, 0.0D+0 ) ) * .. Local Scalars .. COMPLEX*16 TEMP INTEGER I, INFO, IX, J, JX, KX LOGICAL NOCONJ, NOUNIT * .. External Functions .. LOGICAL LSAME EXTERNAL LSAME * .. External Subroutines .. EXTERNAL XERBLA * .. Intrinsic Functions .. INTRINSIC DCONJG, MAX * .. * .. Executable Statements .. * * Test the input parameters. * INFO = 0 IF ( .NOT.LSAME( UPLO , 'U' ).AND. $ .NOT.LSAME( UPLO , 'L' ) )THEN INFO = 1 ELSE IF( .NOT.LSAME( TRANS, 'N' ).AND. $ .NOT.LSAME( TRANS, 'T' ).AND. $ .NOT.LSAME( TRANS, 'C' ) )THEN INFO = 2 ELSE IF( .NOT.LSAME( DIAG , 'U' ).AND. $ .NOT.LSAME( DIAG , 'N' ) )THEN INFO = 3 ELSE IF( N.LT.0 )THEN INFO = 4 ELSE IF( LDA.LT.MAX( 1, N ) )THEN INFO = 6 ELSE IF( INCX.EQ.0 )THEN INFO = 8 END IF IF( INFO.NE.0 )THEN CALL XERBLA( 'ZTRMV ', INFO ) RETURN END IF * * Quick return if possible. * IF( N.EQ.0 ) $ RETURN * NOCONJ = LSAME( TRANS, 'T' ) NOUNIT = LSAME( DIAG , 'N' ) * * Set up the start point in X if the increment is not unity. This * will be ( N - 1 )*INCX too small for descending loops. * IF( INCX.LE.0 )THEN KX = 1 - ( N - 1 )*INCX ELSE IF( INCX.NE.1 )THEN KX = 1 END IF * * Start the operations. In this version the elements of A are * accessed sequentially with one pass through A. * IF( LSAME( TRANS, 'N' ) )THEN * * Form x := A*x. * IF( LSAME( UPLO, 'U' ) )THEN IF( INCX.EQ.1 )THEN DO 20, J = 1, N IF( X( J ).NE.ZERO )THEN TEMP = X( J ) DO 10, I = 1, J - 1 X( I ) = X( I ) + TEMP*A( I, J ) 10 CONTINUE IF( NOUNIT ) $ X( J ) = X( J )*A( J, J ) END IF 20 CONTINUE ELSE JX = KX DO 40, J = 1, N IF( X( JX ).NE.ZERO )THEN TEMP = X( JX ) IX = KX DO 30, I = 1, J - 1 X( IX ) = X( IX ) + TEMP*A( I, J ) IX = IX + INCX 30 CONTINUE IF( NOUNIT ) $ X( JX ) = X( JX )*A( J, J ) END IF JX = JX + INCX 40 CONTINUE END IF ELSE IF( INCX.EQ.1 )THEN DO 60, J = N, 1, -1 IF( X( J ).NE.ZERO )THEN TEMP = X( J ) DO 50, I = N, J + 1, -1 X( I ) = X( I ) + TEMP*A( I, J ) 50 CONTINUE IF( NOUNIT ) $ X( J ) = X( J )*A( J, J ) END IF 60 CONTINUE ELSE KX = KX + ( N - 1 )*INCX JX = KX DO 80, J = N, 1, -1 IF( X( JX ).NE.ZERO )THEN TEMP = X( JX ) IX = KX DO 70, I = N, J + 1, -1 X( IX ) = X( IX ) + TEMP*A( I, J ) IX = IX - INCX 70 CONTINUE IF( NOUNIT ) $ X( JX ) = X( JX )*A( J, J ) END IF JX = JX - INCX 80 CONTINUE END IF END IF ELSE * * Form x := A'*x or x := conjg( A' )*x. * IF( LSAME( UPLO, 'U' ) )THEN IF( INCX.EQ.1 )THEN DO 110, J = N, 1, -1 TEMP = X( J ) IF( NOCONJ )THEN IF( NOUNIT ) $ TEMP = TEMP*A( J, J ) DO 90, I = J - 1, 1, -1 TEMP = TEMP + A( I, J )*X( I ) 90 CONTINUE ELSE IF( NOUNIT ) $ TEMP = TEMP*DCONJG( A( J, J ) ) DO 100, I = J - 1, 1, -1 TEMP = TEMP + DCONJG( A( I, J ) )*X( I ) 100 CONTINUE END IF X( J ) = TEMP 110 CONTINUE ELSE JX = KX + ( N - 1 )*INCX DO 140, J = N, 1, -1 TEMP = X( JX ) IX = JX IF( NOCONJ )THEN IF( NOUNIT ) $ TEMP = TEMP*A( J, J ) DO 120, I = J - 1, 1, -1 IX = IX - INCX TEMP = TEMP + A( I, J )*X( IX ) 120 CONTINUE ELSE IF( NOUNIT ) $ TEMP = TEMP*DCONJG( A( J, J ) ) DO 130, I = J - 1, 1, -1 IX = IX - INCX TEMP = TEMP + DCONJG( A( I, J ) )*X( IX ) 130 CONTINUE END IF X( JX ) = TEMP JX = JX - INCX 140 CONTINUE END IF ELSE IF( INCX.EQ.1 )THEN DO 170, J = 1, N TEMP = X( J ) IF( NOCONJ )THEN IF( NOUNIT ) $ TEMP = TEMP*A( J, J ) DO 150, I = J + 1, N TEMP = TEMP + A( I, J )*X( I ) 150 CONTINUE ELSE IF( NOUNIT ) $ TEMP = TEMP*DCONJG( A( J, J ) ) DO 160, I = J + 1, N TEMP = TEMP + DCONJG( A( I, J ) )*X( I ) 160 CONTINUE END IF X( J ) = TEMP 170 CONTINUE ELSE JX = KX DO 200, J = 1, N TEMP = X( JX ) IX = JX IF( NOCONJ )THEN IF( NOUNIT ) $ TEMP = TEMP*A( J, J ) DO 180, I = J + 1, N IX = IX + INCX TEMP = TEMP + A( I, J )*X( IX ) 180 CONTINUE ELSE IF( NOUNIT ) $ TEMP = TEMP*DCONJG( A( J, J ) ) DO 190, I = J + 1, N IX = IX + INCX TEMP = TEMP + DCONJG( A( I, J ) )*X( IX ) 190 CONTINUE END IF X( JX ) = TEMP JX = JX + INCX 200 CONTINUE END IF END IF END IF * RETURN * * End of ZTRMV . * END
apache-2.0
slitvinov/packmol
fgcommon.f
1
28118
c c Written by Leandro Martínez, 2009-2011. c Copyright (c) 2009-2011, Leandro Martínez, Jose Mario Martinez, c Ernesto G. Birgin. c c This program is free software; you can redistribute it and/or c modify it under the terms of the GNU General Public License c as published by the Free Software Foundation; either version 2 c of the License, or (at your option) any later version. c c c This file contains the parts of the evaluation of the function c and gradient which are identical in the serial and parallel c versions. c c c Objective function evaluation c c c Subroutine comprest: Compute the function value relative to c to the restrictions for one atom c c subroutine comprest(xcart,restpars, + scale,scale2, + nratom,ityperest,iratom, + icart,f) implicit none include 'sizes.i' integer iratcount, irest, icart integer nratom(maxatom), ityperest(maxrest) integer iratom(maxatom,mrperatom) double precision xcart(maxatom,3), restpars(maxrest,9) double precision xmin, ymin, zmin, clength, a1, a2, a3, a4, w, + b1, b2, b3, d, a5, a6 double precision scale, scale2 double precision f double precision xmax, ymax, zmax double precision v1, v2, v3 double precision vnorm f = 0.d0 do iratcount = 1, nratom(icart) irest = iratom(icart,iratcount) if(ityperest(irest).eq.2) then clength = restpars(irest,4) xmin = restpars(irest,1) ymin = restpars(irest,2) zmin = restpars(irest,3) xmax = restpars(irest,1) + clength ymax = restpars(irest,2) + clength zmax = restpars(irest,3) + clength a1 = dmin1(xcart(icart,1) - xmin, 0.d0) a2 = dmin1(xcart(icart,2) - ymin, 0.d0) a3 = dmin1(xcart(icart,3) - zmin, 0.d0) f = f + scale*(a1 * a1 + a2 * a2 + a3 * a3) a1 = dmax1(xcart(icart,1) - xmax, 0.d0) a2 = dmax1(xcart(icart,2) - ymax, 0.d0) a3 = dmax1(xcart(icart,3) - zmax, 0.d0) f = f + scale*(a1 * a1 + a2 * a2 + a3 * a3) else if(ityperest(irest).eq.3) then xmin = restpars(irest,1) ymin = restpars(irest,2) zmin = restpars(irest,3) xmax = restpars(irest,4) ymax = restpars(irest,5) zmax = restpars(irest,6) a1 = dmin1(xcart(icart,1) - xmin, 0.d0) a2 = dmin1(xcart(icart,2) - ymin, 0.d0) a3 = dmin1(xcart(icart,3) - zmin, 0.d0) f = f + scale*(a1 * a1 + a2 * a2 + a3 * a3) a1 = dmax1(xcart(icart,1) - xmax, 0.d0) a2 = dmax1(xcart(icart,2) - ymax, 0.d0) a3 = dmax1(xcart(icart,3) - zmax, 0.d0) f = f + scale*(a1 * a1 + a2 * a2 + a3 * a3) else if(ityperest(irest).eq.4) then w = (xcart(icart,1)-restpars(irest,1))**2 + + (xcart(icart,2)-restpars(irest,2))**2 + + (xcart(icart,3)-restpars(irest,3))**2 - + restpars(irest,4)**2 a1 = dmax1(w,0.d0) f = f + scale2*a1*a1 else if(ityperest(irest).eq.5) then a1 = (xcart(icart,1)-restpars(irest,1))**2 / + restpars(irest,4)**2 a2 = (xcart(icart,2)-restpars(irest,2))**2 / + restpars(irest,5)**2 a3 = (xcart(icart,3)-restpars(irest,3))**2 / + restpars(irest,6)**2 a4 = restpars(irest,7)**2 w = a1 + a2 + a3 - a4 a1 = dmax1(w,0.d0) f = f + scale2*a1*a1 else if(ityperest(irest).eq.6) then xmin = restpars(irest,1) ymin = restpars(irest,2) zmin = restpars(irest,3) xmax = restpars(irest,1) + restpars(irest,4) ymax = restpars(irest,2) + restpars(irest,4) zmax = restpars(irest,3) + restpars(irest,4) a1 = dmax1(xcart(icart,1) - xmin,0.d0) a2 = dmax1(xcart(icart,2) - ymin,0.d0) a3 = dmax1(xcart(icart,3) - zmin,0.d0) a4 = dmax1(xmax - xcart(icart,1),0.d0) a5 = dmax1(ymax - xcart(icart,2),0.d0) a6 = dmax1(zmax - xcart(icart,3),0.d0) f = f + a1*a2*a3*a4*a5*a6 else if(ityperest(irest).eq.7) then xmin = restpars(irest,1) ymin = restpars(irest,2) zmin = restpars(irest,3) xmax = restpars(irest,4) ymax = restpars(irest,5) zmax = restpars(irest,6) a1 = dmax1(xcart(icart,1) - xmin,0.d0) a2 = dmax1(xcart(icart,2) - ymin,0.d0) a3 = dmax1(xcart(icart,3) - zmin,0.d0) a4 = dmax1(xmax - xcart(icart,1),0.d0) a5 = dmax1(ymax - xcart(icart,2),0.d0) a6 = dmax1(zmax - xcart(icart,3),0.d0) f = f + a1*a2*a3*a4*a5*a6 else if(ityperest(irest).eq.8) then w = (xcart(icart,1)-restpars(irest,1))**2 + + (xcart(icart,2)-restpars(irest,2))**2 + + (xcart(icart,3)-restpars(irest,3))**2 - + restpars(irest,4)**2 a1 = dmin1(w,0.d0) f = f + scale2*a1*a1 else if(ityperest(irest).eq.9) then a1 = (xcart(icart,1)-restpars(irest,1))**2 / + restpars(irest,4)**2 a2 = (xcart(icart,2)-restpars(irest,2))**2 / + restpars(irest,5)**2 a3 = (xcart(icart,3)-restpars(irest,3))**2 / + restpars(irest,6)**2 a4 = restpars(irest,7)**2 w = a1 + a2 + a3 - a4 a1 = dmin1(w,0.d0) f = f + a1*a1 else if(ityperest(irest).eq.10) then w = restpars(irest,1)*xcart(icart,1) + + restpars(irest,2)*xcart(icart,2) + + restpars(irest,3)*xcart(icart,3) - + restpars(irest,4) a1 = dmin1(w,0.d0) f = f + scale * a1*a1 else if(ityperest(irest).eq.11) then w = restpars(irest,1)*xcart(icart,1) + + restpars(irest,2)*xcart(icart,2) + + restpars(irest,3)*xcart(icart,3) - + restpars(irest,4) a1 = dmax1(w,0.d0) f = f + scale * a1*a1 else if(ityperest(irest).eq.12) then a1 = xcart(icart,1) - restpars(irest,1) a2 = xcart(icart,2) - restpars(irest,2) a3 = xcart(icart,3) - restpars(irest,3) vnorm = sqrt(restpars(irest,4)**2 + restpars(irest,5)**2 + + restpars(irest,6)**2) v1 = restpars(irest,4)/vnorm v2 = restpars(irest,5)/vnorm v3 = restpars(irest,6)/vnorm b1 = v1 * a1 b2 = v2 * a2 b3 = v3 * a3 w = b1 + b2 + b3 d = ( a1 - v1*w )**2 + + ( a2 - v2*w )**2 + + ( a3 - v3*w )**2 f = f + scale2 * ( + dmax1(-w , 0.d0)**2 + + dmax1(w - restpars(irest,9), 0.d0)**2 + + dmax1(d - restpars(irest,7)**2 , 0.d0 )**2 ) else if(ityperest(irest).eq.13) then a1 = xcart(icart,1) - restpars(irest,1) a2 = xcart(icart,2) - restpars(irest,2) a3 = xcart(icart,3) - restpars(irest,3) vnorm = sqrt(restpars(irest,4)**2 + restpars(irest,5)**2 + + restpars(irest,6)**2) v1 = restpars(irest,4)/vnorm v2 = restpars(irest,5)/vnorm v3 = restpars(irest,6)/vnorm b1 = v1 * a1 b2 = v2 * a2 b3 = v3 * a3 w = b1 + b2 + b3 d = ( a1 - v1*w )**2 + + ( a2 - v2*w )**2 + + ( a3 - v3*w )**2 f = f + scale2 * ( + dmin1(-w , 0.d0)**2 * + dmin1(w - restpars(irest,9), 0.d0)**2 * + dmin1(d - restpars(irest,7)**2 , 0.d0 )**2 ) end if end do return end c c Gradient evaluation c c c Gradient relative to restraints c subroutine gwalls(icart,irest,gxcar) implicit none include 'sizes.i' include 'molpa.i' integer icart, irest double precision a1, a2, a3, a4, a5, a6, xmin, ymin, zmin, + xmax, ymax, zmax, + clength, b1, b2, b3, c1, c2, w, d, rg(3), + vnorm, vv1, vv2, vv3, frab, frac, frbc, + dfra(3), dfrb(3), dfrc(3), gxcar(maxatom,3) if(ityperest(irest).eq.2) then clength = restpars(irest,4) xmin = restpars(irest,1) ymin = restpars(irest,2) zmin = restpars(irest,3) xmax = restpars(irest,1) + clength ymax = restpars(irest,2) + clength zmax = restpars(irest,3) + clength a1 = xcart(icart,1) - xmin a2 = xcart(icart,2) - ymin a3 = xcart(icart,3) - zmin if(a1.lt.0.d0) gxcar(icart,1) = + gxcar(icart,1) + scale * 2.d0 * a1 if(a2.lt.0.d0) gxcar(icart,2) = + gxcar(icart,2) + scale * 2.d0 * a2 if(a3.lt.0.d0) gxcar(icart,3) = + gxcar(icart,3) + scale * 2.d0 * a3 a1 = xcart(icart,1) - xmax a2 = xcart(icart,2) - ymax a3 = xcart(icart,3) - zmax if(a1.gt.0.d0) gxcar(icart,1) = + gxcar(icart,1) + scale * 2.d0 * a1 if(a2.gt.0.d0) gxcar(icart,2) = + gxcar(icart,2) + scale * 2.d0 * a2 if(a3.gt.0.d0) gxcar(icart,3) = + gxcar(icart,3) + scale * 2.d0 * a3 else if(ityperest(irest).eq.3) then xmin = restpars(irest,1) ymin = restpars(irest,2) zmin = restpars(irest,3) xmax = restpars(irest,4) ymax = restpars(irest,5) zmax = restpars(irest,6) a1 = xcart(icart,1) - xmin a2 = xcart(icart,2) - ymin a3 = xcart(icart,3) - zmin if(a1.lt.0.d0) gxcar(icart,1) = + gxcar(icart,1) + scale * 2.d0 * a1 if(a2.lt.0.d0) gxcar(icart,2) = + gxcar(icart,2) + scale * 2.d0 * a2 if(a3.lt.0.d0) gxcar(icart,3) = + gxcar(icart,3) + scale * 2.d0 * a3 a1 = xcart(icart,1) - xmax a2 = xcart(icart,2) - ymax a3 = xcart(icart,3) - zmax if(a1.gt.0.d0) gxcar(icart,1) = + gxcar(icart,1) + scale * 2.d0 * a1 if(a2.gt.0.d0) gxcar(icart,2) = + gxcar(icart,2) + scale * 2.d0 * a2 if(a3.gt.0.d0) gxcar(icart,3) = + gxcar(icart,3) + scale * 2.d0 * a3 else if(ityperest(irest).eq.4) then d = (xcart(icart,1)-restpars(irest,1))**2 + + (xcart(icart,2)-restpars(irest,2))**2 + + (xcart(icart,3)-restpars(irest,3))**2 - + restpars(irest,4)**2 if(d.gt.0.d0) then gxcar(icart,1) = gxcar(icart,1) + 4.d0 * scale2 * + (xcart(icart,1)-restpars(irest,1))*d gxcar(icart,2) = gxcar(icart,2) + 4.d0 * scale2 * + (xcart(icart,2)-restpars(irest,2))*d gxcar(icart,3) = gxcar(icart,3) + 4.d0 * scale2 * + (xcart(icart,3)-restpars(irest,3))*d end if else if(ityperest(irest).eq.5) then a1 = xcart(icart,1)-restpars(irest,1) b1 = xcart(icart,2)-restpars(irest,2) c1 = xcart(icart,3)-restpars(irest,3) a2 = restpars(irest,4)**2 b2 = restpars(irest,5)**2 c2 = restpars(irest,6)**2 d = a1**2/a2+b1**2/b2+c1**2/c2-restpars(irest,7)**2 if(d.gt.0) then gxcar(icart,1) = gxcar(icart,1) + scale2*4.d0*d*a1/a2 gxcar(icart,2) = gxcar(icart,2) + scale2*4.d0*d*b1/b2 gxcar(icart,3) = gxcar(icart,3) + scale2*4.d0*d*c1/c2 end if else if(ityperest(irest).eq.6) then xmin = restpars(irest,1) ymin = restpars(irest,2) zmin = restpars(irest,3) xmax = restpars(irest,1) + restpars(irest,4) ymax = restpars(irest,2) + restpars(irest,4) zmax = restpars(irest,3) + restpars(irest,4) a1 = dmax1(xcart(icart,1) - xmin,0.d0) a2 = dmax1(xcart(icart,2) - ymin,0.d0) a3 = dmax1(xcart(icart,3) - zmin,0.d0) a4 = dmax1(xmax - xcart(icart,1),0.d0) a5 = dmax1(ymax - xcart(icart,2),0.d0) a6 = dmax1(zmax - xcart(icart,3),0.d0) w = a1*a2*a3*a4*a5*a6 if(w.gt.0.d0) then gxcar(icart,1) = gxcar(icart,1) + a2*a3*a5*a6*(a4-a1) gxcar(icart,2) = gxcar(icart,2) + a1*a3*a4*a6*(a5-a2) gxcar(icart,3) = gxcar(icart,3) + a1*a2*a4*a5*(a6-a3) end if else if(ityperest(irest).eq.7) then xmin = restpars(irest,1) ymin = restpars(irest,2) zmin = restpars(irest,3) xmax = restpars(irest,4) ymax = restpars(irest,5) zmax = restpars(irest,6) a1 = dmax1(xcart(icart,1) - xmin,0.d0) a2 = dmax1(xcart(icart,2) - ymin,0.d0) a3 = dmax1(xcart(icart,3) - zmin,0.d0) a4 = dmax1(xmax - xcart(icart,1),0.d0) a5 = dmax1(ymax - xcart(icart,2),0.d0) a6 = dmax1(zmax - xcart(icart,3),0.d0) w = a1*a2*a3*a4*a5*a6 if(w.gt.0.d0) then gxcar(icart,1) = gxcar(icart,1) + a2*a3*a5*a6*(a4-a1) gxcar(icart,2) = gxcar(icart,2) + a1*a3*a4*a6*(a5-a2) gxcar(icart,3) = gxcar(icart,3) + a1*a2*a4*a5*(a6-a3) end if else if(ityperest(irest).eq.8) then d = (xcart(icart,1)-restpars(irest,1))**2 + + (xcart(icart,2)-restpars(irest,2))**2 + + (xcart(icart,3)-restpars(irest,3))**2 - + restpars(irest,4)**2 if(d.lt.0.d0) then gxcar(icart,1) = gxcar(icart,1) + 4.d0 * scale2 * + (xcart(icart,1)-restpars(irest,1))*d gxcar(icart,2) = gxcar(icart,2) + 4.d0 * scale2 * + (xcart(icart,2)-restpars(irest,2))*d gxcar(icart,3) = gxcar(icart,3) + 4.d0 * scale2 * + (xcart(icart,3)-restpars(irest,3))*d end if else if(ityperest(irest).eq.9) then a1 = xcart(icart,1)-restpars(irest,1) b1 = xcart(icart,2)-restpars(irest,2) c1 = xcart(icart,3)-restpars(irest,3) a2 = restpars(irest,4)**2 b2 = restpars(irest,5)**2 c2 = restpars(irest,6)**2 d = a1**2/a2+b1**2/b2+c1**2/c2-restpars(irest,7)**2 if(d.lt.0) then d = scale2 * d gxcar(icart,1) = gxcar(icart,1) + 4.d0*d*a1/a2 gxcar(icart,2) = gxcar(icart,2) + 4.d0*d*b1/b2 gxcar(icart,3) = gxcar(icart,3) + 4.d0*d*c1/c2 end if else if(ityperest(irest).eq.10) then d = restpars(irest,1)*xcart(icart,1) + + restpars(irest,2)*xcart(icart,2) + + restpars(irest,3)*xcart(icart,3) - + restpars(irest,4) if(d.lt.0.d0) then d = scale * d gxcar(icart,1) = gxcar(icart,1) + + 2.d0*restpars(irest,1)*d gxcar(icart,2) = gxcar(icart,2) + + 2.d0*restpars(irest,2)*d gxcar(icart,3) = gxcar(icart,3) + + 2.d0*restpars(irest,3)*d end if else if(ityperest(irest).eq.11) then d = restpars(irest,1)*xcart(icart,1) + + restpars(irest,2)*xcart(icart,2) + + restpars(irest,3)*xcart(icart,3) - + restpars(irest,4) if(d.gt.0.d0) then d = scale * d gxcar(icart,1) = gxcar(icart,1) + + 2.d0*restpars(irest,1)*d gxcar(icart,2) = gxcar(icart,2) + + 2.d0*restpars(irest,2)*d gxcar(icart,3) = gxcar(icart,3) + + 2.d0*restpars(irest,3)*d end if else if(ityperest(irest).eq.12) then rg(1) = 0.0d0 rg(2) = 0.0d0 rg(3) = 0.0d0 a1 = xcart(icart,1) - restpars(irest,1) a2 = xcart(icart,2) - restpars(irest,2) a3 = xcart(icart,3) - restpars(irest,3) vnorm = sqrt(restpars(irest,4)**2 + restpars(irest,5)**2 + + restpars(irest,6)**2) vv1 = restpars(irest,4)/vnorm vv2 = restpars(irest,5)/vnorm vv3 = restpars(irest,6)/vnorm b1 = vv1 * a1 b2 = vv2 * a2 b3 = vv3 * a3 w = b1 + b2 + b3 d = (a1 - vv1*w)**2 + + (a2 - vv2*w)**2 + + (a3 - vv3*w)**2 rg(1) = scale2 * ( + -2*dmax1(-w , 0.d0) * vv1 + + 2*dmax1(w - restpars(irest,9), 0.d0) * vv1 + + 2*dmax1(d - restpars(irest,7)**2 , 0.d0) * + (2*(a1 - vv1*w)*(1 - vv1**2)+ + 2*(a2 - vv2*w)*(-vv2*vv1)+ + 2*(a3 - vv3*w)*(-vv3*vv1) )) rg(2) = scale2 * ( + -2*dmax1(-w , 0.d0) * vv2 + + 2*dmax1(w - restpars(irest,9), 0.d0) * vv2 + + 2*dmax1(d - restpars(irest,7)**2 , 0.d0) * + (2*(a1 - vv1*w)*(-vv1*vv2)+ + 2*(a2 - vv2*w)*(1 - vv2**2)+ + 2*(a3 - vv3*w)*(-vv3*vv2) )) rg(3) = scale2 * ( + -2*dmax1(-w , 0.d0) * vv3 + + 2*dmax1(w - restpars(irest,9), 0.d0) * vv3 + + 2*dmax1(d - restpars(irest,7)**2 , 0.d0) * + (2*(a1 - vv1*w)*(-vv1*vv3)+ + 2*(a2 - vv2*w)*(-vv2*vv3)+ + 2*(a3 - vv3*w)*(1 - vv3**2) )) gxcar(icart,1) = gxcar(icart,1) + rg(1) gxcar(icart,2) = gxcar(icart,2) + rg(2) gxcar(icart,3) = gxcar(icart,3) + rg(3) else if(ityperest(irest).eq.13) then rg(1) = 0.0d0 rg(2) = 0.0d0 rg(3) = 0.0d0 a1 = xcart(icart,1) - restpars(irest,1) a2 = xcart(icart,2) - restpars(irest,2) a3 = xcart(icart,3) - restpars(irest,3) vnorm = sqrt(restpars(irest,4)**2 + restpars(irest,5)**2 + + restpars(irest,6)**2) vv1 = restpars(irest,4)/vnorm vv2 = restpars(irest,5)/vnorm vv3 = restpars(irest,6)/vnorm b1 = vv1 * a1 b2 = vv2 * a2 b3 = vv3 * a3 w = b1 + b2 + b3 d = (a1 - vv1*w)**2 + + (a2 - vv2*w)**2 + + (a3 - vv3*w)**2 frab = dmin1(-w , 0.d0)**2 * + dmin1(w - restpars(irest,9), 0.d0)**2 frac = dmin1(-w , 0.d0)**2 * + dmin1(d - restpars(irest,7)**2 , 0.d0 )**2 frbc = dmin1(w - restpars(irest,9), 0.d0)**2 * + dmin1(d - restpars(irest,7)**2 , 0.d0 )**2 dfra(1) = -2*dmin1(-w , 0.d0) * vv1 dfrb(1) = 2*dmin1(w - restpars(irest,9), 0.d0) * vv1 dfrc(1) = 2*dmin1(d - restpars(irest,7)**2 , 0.d0) * + (2*(a1 - vv1*w)*(1 - vv1**2)+ + 2*(a2 - vv2*w)*(-vv2*vv1)+ + 2*(a3 - vv3*w)*(-vv3*vv1) ) dfra(2) = -2*dmin1(-w , 0.d0) * vv2 dfrb(2) = 2*dmin1(w - restpars(irest,9), 0.d0) * vv2 dfrc(2) = 2*dmin1(d - restpars(irest,7)**2 , 0.d0) * + (2*(a1 - vv1*w)*(-vv1*vv2)+ + 2*(a2 - vv2*w)*(1 - vv2**2)+ + 2*(a3 - vv3*w)*(-vv3*vv2) ) dfra(3) = -2*dmin1(-w , 0.d0) * vv3 dfrb(3) = 2*dmin1(w - restpars(irest,9), 0.d0) * vv3 dfrc(3) = 2*dmin1(d - restpars(irest,7)**2 , 0.d0) * + (2*(a1 - vv1*w)*(-vv1*vv3)+ + 2*(a2 - vv2*w)*(-vv2*vv3)+ + 2*(a3 - vv3*w)*(1 - vv3**2) ) rg(1) = scale2 * ( dfra(1)*frbc + dfrb(1)*frac + + dfrc(1)*frab) rg(2) = scale2 * ( dfra(2)*frbc + dfrb(2)*frac + + dfrc(2)*frab) rg(3) = scale2 * ( dfra(3)*frbc + dfrb(3)*frac + + dfrc(3)*frab) gxcar(icart,1) = gxcar(icart,1) + rg(1) gxcar(icart,2) = gxcar(icart,2) + rg(2) gxcar(icart,3) = gxcar(icart,3) + rg(3) end if return end c c Subroutine that performs finite difference and analytical gradient c comparision. Used only for test purpouses c subroutine compgrad(n,x) implicit none include 'sizes.i' integer n, i, iworst double precision x(*), g(nn), fx, step, gcomp, gbest, eworst, + error, steperror, stepbest real time0, tarray(2), etime write(*,*) write(*,*) ' Comparing analytical and finite-difference ' write(*,*) ' gradients... may take a while. ' write(*,*) write(*,*) ' Five first center of masses and angles', + ' of tested point: ' do i = 1, 15, 3 write(*,15) (i+2)/3, x(i), x(i+1), x(i+2), + x(n/2+i),x(n/2+i+1),x(n/2+i+2) end do 15 format(i4,6(tr2,f8.3)) write(*,*) write(*,*) ' Computing gradient ... ' call feasy(x, fx) write(*,*) ' Function value on test point: ', fx open(98, file = 'chkgrad.log',status='unknown') write(98, *)'Function Value = ', fx call geasy(n, x, g) write(98,10) 10 format(t2,'Component',t16,'Analytical',t33,'Discrete', + t51,'Error',t62,'Best step') time0 = etime(tarray) eworst = 0.d0 do i = 1, n if(etime(tarray)-time0.gt.10.) then time0 = etime(tarray) write(*,*) ' Computing the ',i,'th of ',n,' components. ' end if error = 1.d20 step = 1.d-2 do while(error.gt.1.d-6.and.step.ge.1.d-20) call discret(i,x,gcomp,step) if(dmin1(abs(g(i)),abs(gcomp)).gt.1.d-10) then steperror = abs( ( gcomp - g(i) ) / g(i) ) else steperror = abs( gcomp - g(i) ) end if if( steperror .lt. error ) then error = steperror gbest = gcomp stepbest = step end if step = step / 10.d0 end do write(98,20) i, g(i), gbest, error, stepbest 20 format(i10,4(tr2,d13.7)) if(error.gt.eworst) then iworst = i eworst = error end if end do write(98,*) 'Maximum difference = ', + iworst,' Error= ', eworst write(*,*) ' Done. ' stop end subroutine discret(icomp,x,gcomp,step) implicit none integer icomp double precision save, step, x(*), fplus, fminus, gcomp save = x(icomp) x(icomp) = save + step call feasy(x, fplus) x(icomp) = save - step call feasy(x, fminus) gcomp = (fplus - fminus) / (2.d0 * step) x(icomp) = save return end c c Subroutine that computes the function value c c c subroutine feasyseq(x,f) implicit none include 'sizes.i' include 'molpa.i' double precision v1(3), v2(3), v3(3) double precision x(nn) double precision f,fparcs,fplus double precision xtemp, ytemp, ztemp double precision xbar, ybar, zbar double precision beta, gama, teta double precision flast integer i, j, k integer ilugan, ilubar, icart, itype, imol, iatom, idatom, + iboxx, iboxy, iboxz c Reset function value f = 0.d0 frest = 0.d0 fdist = 1.d20 c Reset boxes if(.not.init1) call resetboxes(nboxes,latomfirst,latomfix) c Transform baricenter and angles into cartesian coordinates c Computes cartesian coordinates from vector x and coor ilubar = 0 ilugan = ntotmol*3 icart = natfix do itype = 1, ntype if(.not.comptype(itype)) then icart = icart + nmols(itype)*natoms(itype) else do imol = 1, nmols(itype) xbar = x(ilubar+1) ybar = x(ilubar+2) zbar = x(ilubar+3) c Computing the rotation matrix beta = x(ilugan+1) gama = x(ilugan+2) teta = x(ilugan+3) call eulerrmat(beta,gama,teta,v1,v2,v3) c Looping over the atoms of this molecule idatom = idfirst(itype) - 1 do iatom = 1, natoms(itype) icart = icart + 1 idatom = idatom + 1 c Computing the cartesian coordinates for this atom call compcart(icart,xcart, + xbar,ybar,zbar, + coor(idatom,1),coor(idatom,2),coor(idatom,3), + v1,v2,v3) c Adding to f the value relative to constraints for this atom call comprest(xcart,restpars, + scale,scale2, + nratom,ityperest,iratom, + icart,fplus) f = f + fplus frest = dmax1(frest,fplus) if(move) fatom(icart) = fatom(icart) + fplus c Putting atoms in their boxes if(.not.init1) then xtemp = xcart(icart,1) - sizemin(1) ytemp = xcart(icart,2) - sizemin(2) ztemp = xcart(icart,3) - sizemin(3) iboxx = int(xtemp/boxl(1)) + 1 iboxy = int(ytemp/boxl(2)) + 1 iboxz = int(ztemp/boxl(3)) + 1 if(xtemp.le.0) iboxx = 1 if(ytemp.le.0) iboxy = 1 if(ztemp.le.0) iboxz = 1 if(iboxx.gt.nboxes(1)) iboxx = nboxes(1) if(iboxy.gt.nboxes(2)) iboxy = nboxes(2) if(iboxz.gt.nboxes(3)) iboxz = nboxes(3) latomnext(icart) = latomfirst(iboxx,iboxy,iboxz) latomfirst(iboxx,iboxy,iboxz) = icart ibtype(icart) = itype ibmol(icart) = imol end if end do ilugan = ilugan + 3 ilubar = ilubar + 3 end do end if end do if(init1) return c Minimum distance function evaluation do i = 1, nboxes(1) do j = 1, nboxes(2) do k = 1, nboxes(3) icart = latomfirst(i,j,k) do while ( icart .ne. 0 ) if(comptype(ibtype(icart))) then c Vector that keeps the value for this atom if(move) flast = f c Interactions inside box f = f + fparcs(icart,latomnext(icart)) c Interactions of boxes that share faces f = f + fparcs(icart,latomfirst(i+1,j,k)) f = f + fparcs(icart,latomfirst(i,j+1,k)) f = f + fparcs(icart,latomfirst(i,j,k+1)) c Interactions of boxes that share axes f = f + fparcs(icart,latomfirst(i+1,j+1,k)) f = f + fparcs(icart,latomfirst(i+1,j,k+1)) f = f + fparcs(icart,latomfirst(i+1,j-1,k)) f = f + fparcs(icart,latomfirst(i+1,j,k-1)) f = f + fparcs(icart,latomfirst(i,j+1,k+1)) f = f + fparcs(icart,latomfirst(i,j+1,k-1)) c Interactions of boxes that share vertices f = f + fparcs(icart,latomfirst(i+1,j+1,k+1)) f = f + fparcs(icart,latomfirst(i+1,j+1,k-1)) f = f + fparcs(icart,latomfirst(i+1,j-1,k+1)) f = f + fparcs(icart,latomfirst(i+1,j-1,k-1)) c If going to move bad molecules, update fatom if(move) fatom(icart) = fatom(icart) + f - flast end if icart = latomnext(icart) end do end do end do end do return end c c Function that computes the main part of the objective function c double precision function fparcs(icart,firstjcart) c Dimensions include 'sizes.i' C SCALAR ARGUMENTS integer icart,firstjcart C LOCAL SCALARS integer jcart double precision a1,a2,a3,datom C COMMON BLOCK include 'molpa.i' fparcs = 0.0d0 jcart = firstjcart do while ( jcart .ne. 0 ) if(comptype(ibtype(jcart))) then if(ibmol(icart).ne.ibmol(jcart).or. + ibtype(icart).ne.ibtype(jcart)) then a1 = xcart(icart, 1)-xcart(jcart, 1) a2 = xcart(icart, 2)-xcart(jcart, 2) a3 = xcart(icart, 3)-xcart(jcart, 3) datom = a1 * a1 + a2 * a2 + a3 * a3 a1 = dmin1(datom - dism2, 0.d0) fparcs = fparcs + a1 * a1 fdist = dmin1(datom,fdist) end if end if jcart = latomnext(jcart) end do end
gpl-3.0
qsnake/abinit
src/66_wfs/prep_kpgio.F90
1
22319
!{\src2tex{textfont=tt}} !!****f* ABINIT/prep_kpgio !! NAME !! prep_kpgio !! !! FUNCTION !! Used only in BandFFT parallelization. !! Do initialization of kg information. !! Transposition of all quantities which depend on kg_k !! In case of istwfk==2, this routine completes also !! the kg_k_gather vector by the opposite values. !! The values are distributed on the processors in function of !! the value of modulo(-kg_k_gather(2,i),nproc_fft) !! !! COPYRIGHT !! !! INPUTS !! accesswff = defines the format of the output !! ecut_eff = kinetic energy planewave cutoff (hartree) !! exchn2n3d = if 1, n2 and n3 are exchanged !! gmet(3,3) = reciprocal space metric (bohr^-2) !! istwfk(nkpt) = input option parameter that describes the storage of wfs !! kptns(3,nkpt) = reduced coords of k points !! fnametmp_kg = name of unkg file !! mgfft = maximum single fft dimension (IN) !! mkmem = number of k points which can fit in memory; set to 0 if use disk !! mode_paral = either 'COLL' or 'PERS', tells whether !! the loop over k points must be done by all processors or not, !! in case of parallel execution. !! mpi_enreg = informations about MPI parallelization !! mpw = maximum number of planewaves as dimensioned in calling routine !! nband(nkpt*nsppol) = number of bands at each k point !! nkpt = number of k points !! nsppol = 1 for unpolarized, 2 for polarized !! unkg = unit number for storage of basis sphere data: stores indirect !! indexing array and integer coordinates for all planewaves in basis !! sphere for each k point being considered !! !! OUTPUT !! kg(3,mpw*mkmem) = dimensionless coords of G vecs in basis sphere at k point !! npwarr(nkpt) = array holding npw for each k point, taking into account !! the effect of istwfk, and the spreading over processors !! npwtot(nkpt) = array holding the total number of plane waves for each k point, !!--------------------------------------------------------------------- !! within the mpi_enreg%bandfft_kpt data_type : Initialize and compute !!--------------------------------------------------------------------- !! gbound = sphere boundary info !! idatarecv0 = position of the planewave coordinates (0,0,0) !! istwf_k = input option parameter that describes the storage of wfs !! kg_k_gather = planewave coordinates !! (of the processor + sended by other processors band) !! kg_k_gather_sym = planewave coordinates !! (kg_k_gather + opposited planewave coordinates sended by the processors fft) !! ndatarecv = total number of values received by the processor and sended !! by the other processors band !! ndatasend_sym = number of sended values to the processors fft to create opposited !! planewave coordinates !! ndatarecv_tot = total number of received values by the processor !! (ndatarecv + number of received opposited planewave coordinates) !! recvcounts = number of values received by the processor from each processor band !! recvcounts_sym = number of values received by the processor from each processor fft !! recvcounts_sym_tot = number of values received by each processor from the other processors fft !! rdispls = positions of values received by the processor from each processor band !! rdispls_sym = positions of values received by the processor from each processor fft !! sendcounts = number of values sended by the processor to each processor band !! sendcounts_sym = number of values sended by the processor to each processor fft !! sendcounts_sym_all = number of values sended by each processor to the other processors fft !! sdispls = postions of values sended by the processor to each processor band !! sdispls_sym = postions of values sended by the processor to each processor fft !! tab_proc = positions of opposited planewave coordinates in the list of the !! processors fft !! !! SIDE EFFECTS !! !! NOTES !! Note that in case of band parallelism, the number of spin-up !! and spin-down bands must be equal at each k points !! !! PARENTS !! gstate,inwffil !! !! CHILDREN !! flush_unit,kpgio,leave_new,sphereboundary,wrtout,xallgather_mpi !! xallgatherv_mpi,xalltoallv_mpi,xsum_mpi !! !! SOURCE #if defined HAVE_CONFIG_H #include "config.h" #endif #include "abi_common.h" subroutine prep_kpgio(accesswff,ecut_eff,exchn2n3d,gmet,istwfk,kg,kptns,fnametmp_kg,mgfft,mkmem,mode_paral,& & mpi_enreg,mpw,nband,nkpt,npwarr,npwtot,nsppol,unkg) use m_profiling use defs_basis use defs_datatypes use defs_abitypes use m_xmpi use m_io_tools, only : flush_unit !This section has been created automatically by the script Abilint (TD). !Do not modify the following lines by hand. #undef ABI_FUNC #define ABI_FUNC 'prep_kpgio' use interfaces_14_hidewrite use interfaces_16_hideleave use interfaces_53_ffts use interfaces_56_recipspace !End of the abilint section implicit none !Arguments ------------------------------------ !scalars integer,intent(in) :: accesswff,exchn2n3d,mgfft,mkmem,mpw,nkpt,nsppol,unkg real(dp),intent(in) :: ecut_eff character(len=4),intent(in) :: mode_paral character(len=fnlen),intent(in) :: fnametmp_kg type(MPI_type),intent(inout) :: mpi_enreg !arrays integer,intent(in) :: istwfk(nkpt),nband(nkpt*nsppol) integer,intent(out) :: kg(3,mpw*mkmem),npwarr(nkpt),npwtot(nkpt) real(dp),intent(in) :: gmet(3,3),kptns(3,nkpt) !Local variables------------------------------- !scalars integer :: comm_band,comm_fft,idatarecv,idatarecv0,ierr,ikg,ikpt,ikpt_this_proc,iproc,isppol,istwf_k,jsendloc,me_band integer :: me_fft,me_kpt,ndatarecv,ndatarecv_tot,ndatasend_sym,nproc_band,nproc_fft,npw_k,npw_tot character(len=500) :: message !arrays integer,allocatable :: gbound(:,:) integer,allocatable :: kg_k(:,:),kg_k_gather(:,:),kg_k_gather_all(:,:),kg_k_gather_send(:,:),kg_k_gather_sym(:,:) integer,allocatable :: npw_per_proc(:) integer,allocatable :: rdispls(:),rdispls_all(:),rdispls_sym(:),rdispls_sym_loc(:) integer,allocatable :: recvcounts(:),recvcounts_sym(:),recvcounts_sym_loc(:),recvcounts_sym_tot(:) integer,allocatable :: sdispls(:),sdispls_sym_loc(:),sdispls_sym(:) integer,allocatable :: sendcounts(:),sendcounts_sym(:),sendcounts_sym_all(:),sendcounts_sym_loc(:) integer,allocatable :: sum_kg(:),tab_proc(:) ! ********************************************************************* !DEBUG !write(std_out,*)' prep_kpgio : enter ' !ENDDEBUG !--------------------------------------------- !Initialisation !--------------------------------------------- nproc_fft = mpi_enreg%nproc_fft nproc_band = mpi_enreg%nproc_band me_band = mpi_enreg%me_band me_fft = mpi_enreg%me_fft me_kpt = mpi_enreg%me_kpt comm_band = mpi_enreg%comm_band comm_fft = mpi_enreg%comm_fft !============================================================================= !Initialize all various tabs within the mpi_enreg%bandfft_kpt(ikpt) data_struc !These tabs are distributed over the kpt processors !============================================================================= ABI_ALLOCATE(mpi_enreg%bandfft_kpt,(mkmem)) ABI_ALLOCATE(mpi_enreg%tab_kpt_distrib,(nkpt)) mpi_enreg%bandfft_kpt(:)%flag1_is_allocated=0 mpi_enreg%bandfft_kpt(:)%flag2_is_allocated=0 mpi_enreg%bandfft_kpt(:)%flag3_is_allocated=0 mpi_enreg%tab_kpt_distrib(:)=0 do isppol=1,nsppol ikpt_this_proc=0 do ikpt=1,nkpt if(minval(abs(mpi_enreg%proc_distrb(ikpt,:,isppol)-me_kpt))/=0) then cycle end if ikpt_this_proc=ikpt_this_proc+1 ! This test should be done when dataset are read and slipt of work do between processor ! If this test is not good for one proc then other procs fall in deadlock->so PERS and MPI_ABORT if (ikpt_this_proc > mkmem) then write(message, '(a,a,a,a)' ) ch10,' gstate : BUG -',ch10,& & ' this bandfft tab cannot be allocated !' call wrtout(std_out,message,'PERS') call flush_unit(std_out) call leave_new('PERS') end if mpi_enreg%tab_kpt_distrib(ikpt)=ikpt_this_proc ABI_ALLOCATE(mpi_enreg%bandfft_kpt(ikpt_this_proc)%gbound ,(2*mgfft+8,2)) ABI_ALLOCATE(mpi_enreg%bandfft_kpt(ikpt_this_proc)%recvcounts,(nproc_band)) ABI_ALLOCATE(mpi_enreg%bandfft_kpt(ikpt_this_proc)%sendcounts,(nproc_band)) ABI_ALLOCATE(mpi_enreg%bandfft_kpt(ikpt_this_proc)%rdispls ,(nproc_band)) ABI_ALLOCATE(mpi_enreg%bandfft_kpt(ikpt_this_proc)%sdispls ,(nproc_band)) mpi_enreg%bandfft_kpt(ikpt_this_proc)%flag1_is_allocated=1 nullify(mpi_enreg%bandfft_kpt(ikpt_this_proc)%kg_k_gather) ! Initialize various quantities which will be computed in vtorho nullify(mpi_enreg%bandfft_kpt(ikpt_this_proc)%ffnl_gather) nullify(mpi_enreg%bandfft_kpt(ikpt_this_proc)%kinpw_gather) nullify(mpi_enreg%bandfft_kpt(ikpt_this_proc)%kpg_k_gather) nullify(mpi_enreg%bandfft_kpt(ikpt_this_proc)%ph3d_gather) ! Initialize various quantities which will be computed below in case of istwf_k=2 nullify(mpi_enreg%bandfft_kpt(ikpt_this_proc)%kg_k_gather_sym) nullify(mpi_enreg%bandfft_kpt(ikpt_this_proc)%rdispls_sym) nullify(mpi_enreg%bandfft_kpt(ikpt_this_proc)%recvcounts_sym) nullify(mpi_enreg%bandfft_kpt(ikpt_this_proc)%recvcounts_sym_tot) nullify(mpi_enreg%bandfft_kpt(ikpt_this_proc)%sdispls_sym) nullify(mpi_enreg%bandfft_kpt(ikpt_this_proc)%sendcounts_sym) nullify(mpi_enreg%bandfft_kpt(ikpt_this_proc)%sendcounts_sym_all) nullify(mpi_enreg%bandfft_kpt(ikpt_this_proc)%tab_proc) ! In case of MPI_IO, initialize the following tab nullify(mpi_enreg%bandfft_kpt(ikpt_this_proc)%ind_kg_mpi_to_seq) end do end do if((mpi_enreg%paral_compil_mpio==1).and.accesswff==IO_MODE_MPI) then mpi_enreg%flag_ind_kg_mpi_to_seq = 1 end if !============================================================================= !End of the initialization of the mpi_enreg%bandfft_kpt(ikpt) data_struc !============================================================================= !Compute kg, npwarr and npwtot call kpgio(ecut_eff,exchn2n3d,gmet,istwfk,kg,fnametmp_kg, & & kptns,mkmem,nband,nkpt,mode_paral,mpi_enreg,& & mpw,npwarr,npwtot,nsppol,unkg) !============================================================================= !Compute and store various tabs in mpi_enreg%bandfft_kpt(ikpt) data_struc !These ones will be used in following subroutines: !vtorho, mkrho, prep_nonlop, prep_fourwf, prep_getghc... !============================================================================= ABI_ALLOCATE(sdispls ,(nproc_band)) ABI_ALLOCATE(sendcounts ,(nproc_band)) ABI_ALLOCATE(rdispls ,(nproc_band)) ABI_ALLOCATE(recvcounts ,(nproc_band)) do isppol=1,nsppol ikg=0 do ikpt=1,nkpt npw_k=npwarr(ikpt) istwf_k=istwfk(ikpt) if(minval(abs(mpi_enreg%proc_distrb(ikpt,:,isppol)-me_kpt))/=0) then cycle end if ikpt_this_proc=mpi_enreg%tab_kpt_distrib(ikpt) if ((ikpt_this_proc > mkmem).or.(ikpt_this_proc==0)) then write(message, '(a,a,a,a)' ) ch10,' gstate : BUG -',ch10,& & ' this bandfft tab is not allocated !' call wrtout(std_out,message,'COLL') call leave_new('COLL') end if call xallgather_mpi(npw_k,recvcounts,comm_band,ierr) rdispls(1)=0 do iproc=2,nproc_band rdispls(iproc)=rdispls(iproc-1)+recvcounts(iproc-1) end do ndatarecv=rdispls(nproc_band)+recvcounts(nproc_band) ABI_ALLOCATE(kg_k_gather,(3,ndatarecv)) ABI_ALLOCATE(kg_k,(3,mpw)) kg_k(:,1:npw_k)=kg(:,1+ikg:npw_k+ikg) call xallgatherv_mpi(kg_k,3*npw_k,kg_k_gather,3*recvcounts(:),3*rdispls(:),comm_band,ierr) sendcounts(:)=npw_k*mpi_enreg%bandpp do iproc=1,nproc_band sdispls(iproc)=(iproc-1)*npw_k*mpi_enreg%bandpp end do ! ============================================================================ ! Here we compute gbound, as well for istwf_k=1 as for istwf_k=2 and store it ! ============================================================================ ABI_ALLOCATE(npw_per_proc,(nproc_fft)) ABI_ALLOCATE(rdispls_all,(nproc_fft)) ABI_ALLOCATE(gbound,(2*mgfft+8,2)) if (mgfft>0) gbound(:,:)=0 if (istwf_k==1) then call xallgather_mpi(ndatarecv,npw_per_proc,mpi_enreg%comm_fft,ierr) rdispls_all(1)=0 do iproc=2,nproc_fft rdispls_all(iproc)=rdispls_all(iproc-1)+npw_per_proc(iproc-1) end do npw_tot=rdispls_all(nproc_fft)+npw_per_proc(nproc_fft) ABI_ALLOCATE(kg_k_gather_all,(3,npw_tot)) call xallgatherv_mpi(kg_k_gather,& & 3*ndatarecv,kg_k_gather_all,3*npw_per_proc(:),3*rdispls_all,mpi_enreg%comm_fft,ierr) if (mgfft>0) then call sphereboundary(gbound,istwf_k,kg_k_gather_all,mgfft,npw_tot) end if else if (istwf_k==2) then ! ============================================================================ ! In this case, we have to add the opposite values in the kg_k_gather tab ! before computing gbound ! ============================================================================ ! Allocation ABI_ALLOCATE(tab_proc ,(ndatarecv)) ABI_ALLOCATE(sendcounts_sym ,(nproc_fft)) ABI_ALLOCATE(sendcounts_sym_all,(nproc_fft*nproc_fft)) ABI_ALLOCATE(sdispls_sym ,(nproc_fft)) ABI_ALLOCATE(recvcounts_sym ,(nproc_fft)) ABI_ALLOCATE(recvcounts_sym_tot,(nproc_fft)) ABI_ALLOCATE(rdispls_sym ,(nproc_fft)) ABI_ALLOCATE(sendcounts_sym_loc,(nproc_fft)) ABI_ALLOCATE(sdispls_sym_loc ,(nproc_fft)) ABI_ALLOCATE(recvcounts_sym_loc,(nproc_fft)) ABI_ALLOCATE(rdispls_sym_loc ,(nproc_fft)) ! Initialisation tab_proc(:) = 0 sendcounts_sym(:) = 0 sendcounts_sym_all(:) = 0 sdispls_sym(:) = 0 recvcounts_sym(:) = 0 recvcounts_sym_tot(:) = 0 ! Localisation of kg_k==[0 0 0] ABI_ALLOCATE(sum_kg,(ndatarecv)) idatarecv0 = -1 ndatasend_sym = ndatarecv sum_kg=sum(abs(kg_k_gather),1) if (count(sum_kg==0)/=0) then do idatarecv=1,ndatarecv if (sum_kg(idatarecv)==0) idatarecv0=idatarecv end do ndatasend_sym = ndatarecv-1 end if ! Localisation of the processor where the vector -k2 is do idatarecv=1,ndatarecv if (idatarecv/=idatarecv0) then tab_proc(idatarecv) = modulo(-kg_k_gather(2,idatarecv),nproc_fft) else tab_proc(idatarecv) = -1 end if end do ! Number of values send by the processor to the others do iproc=1,nproc_fft sendcounts_sym(iproc) = count(tab_proc(:)==(iproc-1)) end do ! Save sendcounts_sym for each processor in sendcounts_sym_all ! knowed by all processors of comm_fft rdispls_sym(1)=0 do iproc=2,nproc_fft rdispls_sym(iproc)= nproc_fft*(iproc-1) end do recvcounts_sym(:)=nproc_fft call xallgatherv_mpi(sendcounts_sym(:),nproc_fft,& sendcounts_sym_all(:),recvcounts_sym,rdispls_sym,comm_fft,ierr) ! Calculation of the dimension of kg_k_gather_sym for each processor ! recvcounts_sym_tot is knowed by all processors of comm_fft call xsum_mpi(sendcounts_sym,recvcounts_sym_tot,nproc_fft,comm_fft,ierr) ! Dimension of kg_k_gather_sym ndatarecv_tot = ndatarecv+recvcounts_sym_tot(me_fft+1) ! Intialize kg_k_gather_sym ABI_ALLOCATE(kg_k_gather_sym,(3,ndatarecv_tot)) kg_k_gather_sym(:,:)=0 kg_k_gather_sym(:,1:ndatarecv) = kg_k_gather(:,:) ! Allocation and initialisation ABI_ALLOCATE(kg_k_gather_send,(3,ndatasend_sym)) kg_k_gather_send(:,:)=0 ! The values are sorted in blocks jsendloc=0 do iproc=1,nproc_fft ! Position of the beginning of the block sdispls_sym(iproc)=jsendloc ! Creation of the blocks do idatarecv=1,ndatarecv if (tab_proc(idatarecv)==(iproc-1)) then jsendloc=jsendloc+1 kg_k_gather_send(:,jsendloc) = -kg_k_gather(:,idatarecv) end if end do end do ! Position of received data rdispls_sym(1)= ndatarecv recvcounts_sym(1)= sendcounts_sym_all((me_fft+1)) do iproc=2,nproc_fft rdispls_sym(iproc) = rdispls_sym(iproc-1) + & sendcounts_sym_all((me_fft+1)+(iproc-2)*nproc_fft) recvcounts_sym(iproc) = sendcounts_sym_all((me_fft+1)+(iproc-1)*nproc_fft) end do ! Exchange of kg_k sendcounts_sym_loc = sendcounts_sym*3 sdispls_sym_loc = sdispls_sym *3 recvcounts_sym_loc = recvcounts_sym*3 rdispls_sym_loc = rdispls_sym *3 call xalltoallv_mpi(kg_k_gather_send(:,:),sendcounts_sym_loc,sdispls_sym_loc,& kg_k_gather_sym(:,:) ,recvcounts_sym_loc,rdispls_sym_loc,comm_fft,ierr) ! Store the following data in the mpi_enreg%bandfft_kpt data_struc ikpt_this_proc=mpi_enreg%tab_kpt_distrib(ikpt) ABI_ALLOCATE(mpi_enreg%bandfft_kpt(ikpt_this_proc)%kg_k_gather_sym,(3,ndatarecv_tot)) ABI_ALLOCATE(mpi_enreg%bandfft_kpt(ikpt_this_proc)%rdispls_sym,(nproc_fft)) ABI_ALLOCATE(mpi_enreg%bandfft_kpt(ikpt_this_proc)%recvcounts_sym,(nproc_fft)) ABI_ALLOCATE(mpi_enreg%bandfft_kpt(ikpt_this_proc)%recvcounts_sym_tot,(nproc_fft)) ABI_ALLOCATE(mpi_enreg%bandfft_kpt(ikpt_this_proc)%sdispls_sym,(nproc_fft)) ABI_ALLOCATE(mpi_enreg%bandfft_kpt(ikpt_this_proc)%sendcounts_sym,(nproc_fft)) ABI_ALLOCATE(mpi_enreg%bandfft_kpt(ikpt_this_proc)%sendcounts_sym_all,(nproc_fft*nproc_fft)) ABI_ALLOCATE(mpi_enreg%bandfft_kpt(ikpt_this_proc)%tab_proc,(ndatarecv)) mpi_enreg%bandfft_kpt(ikpt_this_proc)%flag3_is_allocated=1 mpi_enreg%bandfft_kpt(ikpt_this_proc)%idatarecv0 =idatarecv0 mpi_enreg%bandfft_kpt(ikpt_this_proc)%ndatarecv_tot =ndatarecv_tot mpi_enreg%bandfft_kpt(ikpt_this_proc)%ndatasend_sym =ndatasend_sym mpi_enreg%bandfft_kpt(ikpt_this_proc)%kg_k_gather_sym(:,:) =kg_k_gather_sym(:,:) mpi_enreg%bandfft_kpt(ikpt_this_proc)%rdispls_sym(:) =rdispls_sym(:) mpi_enreg%bandfft_kpt(ikpt_this_proc)%recvcounts_sym(:) =recvcounts_sym(:) mpi_enreg%bandfft_kpt(ikpt_this_proc)%recvcounts_sym_tot(:)=recvcounts_sym_tot(:) mpi_enreg%bandfft_kpt(ikpt_this_proc)%sdispls_sym(:) =sdispls_sym(:) mpi_enreg%bandfft_kpt(ikpt_this_proc)%sendcounts_sym(:) =sendcounts_sym(:) mpi_enreg%bandfft_kpt(ikpt_this_proc)%sendcounts_sym_all(:)=sendcounts_sym_all(:) mpi_enreg%bandfft_kpt(ikpt_this_proc)%tab_proc(:) =tab_proc(:) ABI_DEALLOCATE(tab_proc) ABI_DEALLOCATE(sendcounts_sym) ABI_DEALLOCATE(sendcounts_sym_all) ABI_DEALLOCATE(sdispls_sym) ABI_DEALLOCATE(recvcounts_sym) ABI_DEALLOCATE(recvcounts_sym_tot) ABI_DEALLOCATE(rdispls_sym) ABI_DEALLOCATE(kg_k_gather_sym) ABI_DEALLOCATE(sendcounts_sym_loc) ABI_DEALLOCATE(recvcounts_sym_loc) ABI_DEALLOCATE(sdispls_sym_loc) ABI_DEALLOCATE(rdispls_sym_loc) ABI_DEALLOCATE(kg_k_gather_send) ABI_DEALLOCATE(sum_kg) ! Then compute gbound call xallgather_mpi(ndatarecv_tot,npw_per_proc,mpi_enreg%comm_fft,ierr) rdispls_all(1)=0 do iproc=2,nproc_fft rdispls_all(iproc)=rdispls_all(iproc-1)+npw_per_proc(iproc-1) end do npw_tot=rdispls_all(nproc_fft)+npw_per_proc(nproc_fft) ABI_ALLOCATE(kg_k_gather_all,(3,npw_tot)) call xallgatherv_mpi(mpi_enreg%bandfft_kpt(ikpt_this_proc)%kg_k_gather_sym,& & 3*ndatarecv_tot,kg_k_gather_all,3*npw_per_proc(:),3*rdispls_all,mpi_enreg%comm_fft,ierr) if (mgfft>0) then call sphereboundary(gbound,istwf_k,kg_k_gather_all,mgfft,npw_tot) end if ! Only calculations with istwfk=1 or 2 else write(message, '(a,a,a,a,i2,a)' ) ch10,' gstate : BUG -',ch10,& & ' the value istwfk=',istwf_k,' is not allowed in case of bandfft parallelization!' call wrtout(std_out,message,'COLL') call leave_new('COLL') end if ABI_DEALLOCATE(kg_k_gather_all) ABI_DEALLOCATE(npw_per_proc) ABI_DEALLOCATE(rdispls_all) ! ============================================================================ ! End of gbound ! ============================================================================ ! Tabs which are common to istwf_k=1 and 2 ABI_ALLOCATE(mpi_enreg%bandfft_kpt(ikpt_this_proc)%kg_k_gather,(3,ndatarecv)) mpi_enreg%bandfft_kpt(ikpt_this_proc)%recvcounts(:) =recvcounts(:) mpi_enreg%bandfft_kpt(ikpt_this_proc)%sendcounts(:) =sendcounts(:) mpi_enreg%bandfft_kpt(ikpt_this_proc)%rdispls(:) =rdispls(:) mpi_enreg%bandfft_kpt(ikpt_this_proc)%sdispls(:) =sdispls(:) mpi_enreg%bandfft_kpt(ikpt_this_proc)%gbound(:,:) =gbound(:,:) mpi_enreg%bandfft_kpt(ikpt_this_proc)%kg_k_gather(:,:)=kg_k_gather(:,:) mpi_enreg%bandfft_kpt(ikpt_this_proc)%ndatarecv =ndatarecv mpi_enreg%bandfft_kpt(ikpt_this_proc)%istwf_k =istwf_k mpi_enreg%bandfft_kpt(ikpt_this_proc)%npw_tot =npw_tot ABI_DEALLOCATE(kg_k_gather) ABI_DEALLOCATE(kg_k) ABI_DEALLOCATE(gbound) ikg=ikg+npw_k end do end do ABI_DEALLOCATE(recvcounts) ABI_DEALLOCATE(sendcounts) ABI_DEALLOCATE(rdispls) ABI_DEALLOCATE(sdispls) !============================================================================= !End of computation and storage of the mpi_enreg%bandfft_kpt(ikpt) data_struc !============================================================================= end subroutine prep_kpgio !!***
gpl-3.0
stephenR/gcc-fpp
gcc/testsuite/gfortran.dg/merge_init_expr.f90
162
1071
! { dg-do run } ! ! Check simplification of MERGE. ! INTEGER, PARAMETER :: array(3) = [1, 2, 3] LOGICAL, PARAMETER :: mask(3) = [ .TRUE., .FALSE., .TRUE. ] INTEGER, PARAMETER :: scalar_1 = MERGE (1, 0, .TRUE.) INTEGER, PARAMETER :: scalar_2 = MERGE (0, 1, .FALSE.) INTEGER, PARAMETER :: array_1(3) = MERGE (array, 0, .TRUE.) INTEGER, PARAMETER :: array_2(3) = MERGE (array, 0, .FALSE.) INTEGER, PARAMETER :: array_3(3) = MERGE (0, array, .TRUE.) INTEGER, PARAMETER :: array_4(3) = MERGE (0, array, .FALSE.) INTEGER, PARAMETER :: array_5(3) = MERGE (1, 0, mask) INTEGER, PARAMETER :: array_6(3) = MERGE (array, -array, mask) INTEGER, PARAMETER :: array_7(3) = MERGE ([1,2,3], -array, mask) IF (scalar_1 /= 1 .OR. scalar_2 /= 1) CALL abort IF (.NOT. ALL (array_1 == array)) CALL abort IF (.NOT. ALL (array_2 == [0, 0, 0])) CALL abort IF (.NOT. ALL (array_3 == [0, 0, 0])) CALL abort IF (.NOT. ALL (array_4 == array)) CALL abort IF (.NOT. ALL (array_5 == [1, 0, 1])) CALL abort IF (.NOT. ALL (array_6 == [1, -2, 3])) CALL abort END
gpl-2.0
qsnake/abinit
src/12_hide_mpi/xalltoall_mpi.F90
1
2139
!{\src2tex{textfont=tt}} !!****f* ABINIT/xalltoall_mpi !! NAME !! xalltoall_mpi !! !! FUNCTION !! This module contains functions that calls MPI routine, !! if we compile the code using the MPI CPP flags. !! xalltoall_mpi is the generic function. !! !! COPYRIGHT !! Copyright (C) 2001-2012 ABINIT group (AR,XG) !! This file is distributed under the terms of the !! GNU General Public License, see ~ABINIT/COPYING !! or http://www.gnu.org/copyleft/gpl.txt . !! !! SOURCE #if defined HAVE_CONFIG_H #include "config.h" #endif !!*** !!****f* ABINIT/xalltoall_mpi_dp2d !! NAME !! xalltoall_mpi_dp2d !! !! FUNCTION !! Sends data from all to all processes. !! Target: double precision two-dimensional arrays. !! !! COPYRIGHT !! Copyright (C) 2001-2012 ABINIT group (AR,XG) !! This file is distributed under the terms of the !! GNU General Public License, see ~ABINIT/COPYING !! or http://www.gnu.org/copyleft/gpl.txt . !! !! INPUTS !! !! OUTPUT !! !! SIDE EFFECTS !! !! PARENTS !! !! CHILDREN !! mpi_alltoall !! !! SOURCE subroutine xalltoall_mpi_dp2d(xval, sendsize, recvbuf, recvsize, spaceComm, ier) use defs_basis #if defined HAVE_MPI2 && ! defined HAVE_MPI_INCLUDED_ONCE use mpi #endif !This section has been created automatically by the script Abilint (TD). !Do not modify the following lines by hand. #undef ABI_FUNC #define ABI_FUNC 'xalltoall_mpi_dp2d' !End of the abilint section implicit none #if defined HAVE_MPI1 include 'mpif.h' #endif !Arguments------------------------- real(dp),intent(in) :: xval(:,:) real(dp),intent(inout) :: recvbuf(:,:) integer ,intent(in) :: sendsize, recvsize integer ,intent(in) :: spaceComm integer ,intent(out) :: ier !Local variables------------------- ! ************************************************************************* ier=0 #if defined HAVE_MPI if (spaceComm /= MPI_COMM_SELF .and. spaceComm /= MPI_COMM_NULL) then ! allgather xval on all proc. in spaceComm call MPI_ALLTOALL(xval, sendsize, MPI_DOUBLE_PRECISION, recvbuf, & & recvsize, MPI_DOUBLE_PRECISION, spaceComm, ier) end if #endif end subroutine xalltoall_mpi_dp2d !!***
gpl-3.0
qsnake/abinit
src/77_ddb/m_phdos.F90
1
32813
!{\src2tex{textfont=tt}} !!****m* ABINIT/m_phdos !! NAME !! m_phdos !! !! FUNCTION !! Module for the phonon density of states. !! Container type is defined, and destruction, print subroutines !! as well as the central mkphdos !! !! COPYRIGHT !! Copyright (C) 1999-2012 ABINIT group (MG,MJV) !! This file is distributed under the terms of the !! GNU General Public Licence, see ~abinit/COPYING !! or http://www.gnu.org/copyleft/gpl.txt . !! For the initials of contributors, see ~abinit/doc/developers/contributors.txt . !! !! SOURCE #if defined HAVE_CONFIG_H #include "config.h" #endif #include "abi_common.h" module m_phdos use m_profiling use defs_basis use defs_abitypes, only : anaddb_dataset_type use m_errors use m_io_tools, only : get_unit implicit none private !!*** !!****t* m_phdos/phonon_dos_type !! NAME !! phonon_dos_type !! !! FUNCTION !! Container for phonon DOS and atom projected contributions !! !! SOURCE type,public :: phonon_dos_type ! Integer integer :: ntypat ! Number of type of atoms. integer :: natom ! Number of atoms is the unit cell. integer :: prtdos ! Option of DOS calculation (1 for Gaussian, 2 for tetrahedrons). integer :: nomega ! Number of frequency points in DOS mesh. integer :: nqibz ! Number of q-points in the IBZ. integer :: ntetra_ibz ! Number of tetrahedrons in the IBZ. ! Reals real(dp) :: omega_min ! Min frequency for DOS calculation. real(dp) :: omega_max ! Max frequency for DOS calculation. real(dp) :: omega_step ! Frequency step. real(dp) :: dossmear ! Gaussian broadening. ! Real pointers real(dp), pointer :: omega(:) SET2NULL ! omega(nomega) ! Frequency grid. real(dp), pointer :: phdos(:) SET2NULL ! phdos(nomega) ! phonon DOS. real(dp), pointer :: phdos_int(:) SET2NULL ! phdos_int(nomega) ! integrated phonon DOS real(dp), pointer :: pjdos(:,:,:) SET2NULL ! pjdos(nomega,3,natom) ! projected DOS (over atoms) real(dp), pointer :: pjdos_int(:,:,:) SET2NULL ! pjdos_int(nomega,3,natom) ! Integrate atomic PJDOS real(dp), pointer :: pjdos_typ(:,:) SET2NULL ! pjdos_typ(nomega,ntypat) ! phonon DOS contribution arising from a particular atom-type. real(dp), pointer :: pjdos_typ_int(:,:) SET2NULL ! pjdos_typ_int(nomega,ntypat) ! Integrate phonon DOS contribution arising from a particular atom-type. real(dp), pointer :: pjdos_xyz_typ(:,:,:) SET2NULL ! phdos(nomega,3,ntypat) ! phonon DOS contribution arising from a particular atom-type ! decomposed along the three reduced directions. end type phonon_dos_type public :: print_phondos public :: print_phondos_debye public :: init_phondos public :: nullify_phondos public :: destroy_phondos public :: mkphdos !!** CONTAINS !========================================================================================================================= !!*** !!****f* m_phdos/print_phondos !! !! NAME !! print_phondos !! !! FUNCTION !! Print out phonon DOS (and partial DOS etc) in meV units !! !! INPUTS !! PHdos= container object for phonon DOS !! fname=File name for output !! !! OUTPUT !! !! PARENTS !! anaddb,elphon,scphon_interpolate_phonon_and_dos !! !! CHILDREN !! get_full_kgrid,get_tetra_weight,gtdyn9,init_phondos,init_tetra,matr3inv !! mkrdim,phfrq3,simpson_int,smpbz,symkpt,wrtout !! !! SOURCE subroutine print_phondos(PHdos,fname) !This section has been created automatically by the script Abilint (TD). !Do not modify the following lines by hand. #undef ABI_FUNC #define ABI_FUNC 'print_phondos' use interfaces_14_hidewrite !End of the abilint section implicit none !Arguments ------------------------------------ character(len=*),intent(in) :: fname type(phonon_dos_type),intent(in) :: PHdos !Local variables------------------------------- integer :: io,itype,ios,unt real(dp) :: cfact character(len=50) :: frmt character(len=500) :: msg character(len=3) :: unitname ! ************************************************************************* ! === Convert everything into meV === cfact=Ha_eV*1000 ; unitname='meV' ! === Leave everything in Ha === ! this should be the abinit default! cfact=one ; unitname='Ha' ! === Open external file and write results === ! TODO Here I have to rationalize how to write all this stuff!! ! unt=get_unit() ! open(unit=unt,file=fname,form='formatted',status='new') open(unit=unt,file=fname,form='formatted',iostat=ios) ABI_CHECK(ios==0,'Opening '//TRIM(fname)) write(msg,'(3a)')'# ',ch10,'# Phonon density of states and projected DOS' call wrtout(unt,msg,'COLL') write(msg,'(6a)')'# ',ch10,'# Energy in ',unitname,', DOS in states/',unitname call wrtout(unt,msg,'COLL') select case (PHdos%prtdos) case (1) write(msg,'(a,es16.8,2a,i4)')& & '# Gaussian method with smearing = ',PHdos%dossmear*cfact,unitname,', nqibz =',PHdos%nqibz case (2) write(msg,'(a,i5,a,i4)')'# Tetrahedron method, number of irreducible tetrahedrons = ',& & PHdos%ntetra_ibz,', nqibz= ',PHdos%nqibz case default write(msg,'(a,i0)')" Wrong prtdos = ",PHdos%prtdos MSG_ERROR(msg) end select call wrtout(unt,msg,'COLL') write(msg,'(5a)')'# ',ch10,'# omega PHDOS INT_PHDOS PJDOS[atom_type=1] INT_PJDOS[atom_type1] ... ',ch10,'# ' call wrtout(unt,msg,'COLL') write(frmt,*)'(',PHdos%ntypat,'(2es17.8))' do io=1,PHdos%nomega write(unt,'(3es17.8)',advance='NO')PHdos%omega(io)*cfact,PHdos%phdos(io)/cfact,PHdos%phdos_int(io)/cfact do itype=1,PHdos%ntypat write(unt,frmt,advance='NO')PHdos%pjdos_typ(io,itype)/cfact,PHdos%pjdos_typ_int(io,itype)/cfact end do write(unt,*) end do close(unt) end subroutine print_phondos !!*** !---------------------------------------------------------------------- !****f* m_phdos/print_phondos_debye !! !! NAME !! print_phondos_debye !! !! FUNCTION !! Print out global Debye temperature, force constant, etc... from phonon DOS !! !! INPUTS !! phonon_dos= container object for phonon DOS !! ucvol = unit cell volume !! !! OUTPUT !! !! PARENTS !! anaddb !! !! CHILDREN !! get_full_kgrid,get_tetra_weight,gtdyn9,init_phondos,init_tetra,matr3inv !! mkrdim,phfrq3,simpson_int,smpbz,symkpt,wrtout !! !! SOURCE subroutine print_phondos_debye(PHdos, ucvol) !This section has been created automatically by the script Abilint (TD). !Do not modify the following lines by hand. #undef ABI_FUNC #define ABI_FUNC 'print_phondos_debye' use interfaces_14_hidewrite use interfaces_32_util !End of the abilint section implicit none !Arguments ------------------------------------ real(dp), intent(in) :: ucvol type(phonon_dos_type),intent(in) :: PHdos !Local variables------------------------------- integer :: io, iomax, iomin real(dp) :: avgom2dos, avgspeedofsound real(dp) :: debyefreq, meanfreq, meanfreq2 real(dp), allocatable :: om2dos(:), om1dos(:), intdos(:) character(len=500) :: msg ! average speed of sound: coefficient of omega^2 in the DOS is = Volume / 2 pi^2 hbar^3 v_s^3 ! first find how far out we can fit with a parabola ABI_ALLOCATE(om2dos,(PHdos%nomega)) ABI_ALLOCATE(om1dos,(PHdos%nomega)) ABI_ALLOCATE(intdos,(PHdos%nomega)) avgom2dos = zero do io=1,PHdos%nomega om1dos(io) = PHdos%omega(io) * PHdos%phdos(io) om2dos(io) = PHdos%omega(io)**2 * PHdos%phdos(io) end do ! integrate dos * omega intdos = zero call simpson_int(PHdos%nomega,PHdos%omega_step,om1dos,intdos) meanfreq = intdos(PHdos%nomega) ! integrate dos * omega^2 intdos = zero call simpson_int(PHdos%nomega,PHdos%omega_step,om2dos,intdos) meanfreq2 = intdos(PHdos%nomega) ! Debye frequency = sqrt(<omega^2>* 3/2) debyefreq = sqrt (meanfreq2 * three * half) write (msg,'(a,E20.10,a,E20.10,a)') ' Debye frequency from DOS: ', debyefreq, ' (Ha) = ', & & debyefreq*Ha_THz, ' (THz)' call wrtout (ab_out,msg,"COLL") call wrtout (std_out,msg,"COLL") ! Debye temperature = hbar * Debye frequency / kb write (msg,'(a,E20.10,2a)') ' Debye temperature from DOS: ', debyefreq*Ha_K, ' (K)', ch10 call wrtout (ab_out,msg,"COLL") call wrtout (std_out,msg,"COLL") iomin = 1 iomax = PHdos%nomega do io = 1, PHdos%nomega ! skip eventual negative frequency modes if (PHdos%omega(io) <= tol10) then iomin = io cycle end if ! accumulate dos * om^2 to make an average avgom2dos = avgom2dos + om2dos(io) ! first deviation from initial value of more than 10 percent if (abs(one-om2dos(1)/om2dos(io)) > 0.1_dp) then iomax = io exit end if end do avgom2dos = avgom2dos / (iomax-iomin+1) ! this value is also useful for partial atomic DOS, related to kinetic energy and Force constant in Moessbauer avgspeedofsound = (ucvol / 2 / pi**2 / avgom2dos)**third write (msg,'(a,E20.10,a,F16.4,2a)') '- Average speed of sound: ', avgspeedofsound, ' (at units) = ', & & avgspeedofsound * Bohr_Ang * 1.d-10 / Time_Sec, ' (m/s)',ch10 call wrtout (ab_out,msg,"COLL") call wrtout (std_out,msg,"COLL") ! average force constant ! ABI_DEALLOCATE(om2dos) ABI_DEALLOCATE(om1dos) ABI_DEALLOCATE(intdos) end subroutine print_phondos_debye !!*** !---------------------------------------------------------------------- !!****f* m_phdos/nullify_phondos !! !! NAME !! nullify_phondos !! !! FUNCTION !! Set all pointers to null() !! !! SIDE EFFECTS !! PHdos= Pointers in the datastructure set to null() !! !! PARENTS !! m_phdos !! !! CHILDREN !! get_full_kgrid,get_tetra_weight,gtdyn9,init_phondos,init_tetra,matr3inv !! mkrdim,phfrq3,simpson_int,smpbz,symkpt,wrtout !! !! SOURCE subroutine nullify_phondos(PHdos) !This section has been created automatically by the script Abilint (TD). !Do not modify the following lines by hand. #undef ABI_FUNC #define ABI_FUNC 'nullify_phondos' !End of the abilint section implicit none !Arguments ------------------------------- type(phonon_dos_type),intent(inout) :: PHdos ! ************************************************************************* !@phonon_dos_type nullify(PHdos%omega) nullify(PHdos%phdos) nullify(PHdos%phdos_int) nullify(PHdos%pjdos) nullify(PHdos%pjdos_int) nullify(PHdos%pjdos_typ) nullify(PHdos%pjdos_typ_int) nullify(PHdos%pjdos_xyz_typ) end subroutine nullify_phondos !!*** !---------------------------------------------------------------------- !!****f* m_phdos/init_phondos !! !! NAME !! init_phondos !! !! FUNCTION !! Init function for phonon DOS object !! !! INPUTS !! !! OUTPUT !! PHdos= container object for phonon DOS, filled and allocated !! !! PARENTS !! m_phdos,scphon !! !! CHILDREN !! get_full_kgrid,get_tetra_weight,gtdyn9,init_phondos,init_tetra,matr3inv !! mkrdim,phfrq3,simpson_int,smpbz,symkpt,wrtout !! !! SOURCE subroutine init_phondos(PHdos,ntypat,natom,prtdos,nomega,nqibz,ntetra_ibz,omega_max,omega_min,omega_step,dossmear) !This section has been created automatically by the script Abilint (TD). !Do not modify the following lines by hand. #undef ABI_FUNC #define ABI_FUNC 'init_phondos' !End of the abilint section implicit none !Arguments ------------------------------- integer, intent(in) :: ntypat,natom,prtdos integer, intent(in) :: nomega,nqibz,ntetra_ibz real(dp), intent(in) :: omega_step,dossmear real(dp), intent(in) :: omega_max,omega_min type(phonon_dos_type),intent(out) :: PHdos ! ************************************************************************* !@phonon_dos_type call nullify_phondos(PHdos) PHdos%ntypat = ntypat PHdos%natom = natom PHdos%prtdos = prtdos PHdos%nomega = nomega PHdos%nqibz = nqibz PHdos%ntetra_ibz = ntetra_ibz PHdos%omega_max = omega_max PHdos%omega_min = omega_min PHdos%omega_step = omega_step PHdos%dossmear = dossmear ABI_ALLOCATE(PHdos%omega,(nomega)) ABI_ALLOCATE(PHdos%phdos,(nomega)) ABI_ALLOCATE(PHdos%phdos_int,(nomega)) ABI_ALLOCATE(PHdos%pjdos,(nomega,3,natom)) ABI_ALLOCATE(PHdos%pjdos_int,(nomega,3,natom)) ABI_ALLOCATE(PHdos%pjdos_typ,(nomega,ntypat)) ABI_ALLOCATE(PHdos%pjdos_typ_int,(nomega,ntypat)) ABI_ALLOCATE(PHdos%pjdos_xyz_typ,(nomega,3,ntypat)) end subroutine init_phondos !!*** !---------------------------------------------------------------------- !!****f* m_phdos/destroy_phondos !! !! NAME !! destroy_phondos !! !! FUNCTION !! destructor function for phonon DOS object !! !! INPUTS !! PHdos= container object for phonon DOS !! !! OUTPUT !! !! PARENTS !! anaddb,elphon !! !! CHILDREN !! get_full_kgrid,get_tetra_weight,gtdyn9,init_phondos,init_tetra,matr3inv !! mkrdim,phfrq3,simpson_int,smpbz,symkpt,wrtout !! !! SOURCE subroutine destroy_phondos(PHdos) !This section has been created automatically by the script Abilint (TD). !Do not modify the following lines by hand. #undef ABI_FUNC #define ABI_FUNC 'destroy_phondos' !End of the abilint section implicit none !Arguments ------------------------------- type(phonon_dos_type),intent(inout) ::PHdos ! ************************************************************************* !@phonon_dos_type if (associated(PHdos%omega)) then ABI_DEALLOCATE(PHdos%omega) end if if (associated(PHdos%phdos)) then ABI_DEALLOCATE(PHdos%phdos) end if if (associated(PHdos%phdos_int)) then ABI_DEALLOCATE(PHdos%phdos_int) end if if (associated(PHdos%pjdos)) then ABI_DEALLOCATE(PHdos%pjdos) end if if (associated(PHdos%pjdos_int)) then ABI_DEALLOCATE(PHdos%pjdos_int) end if if (associated(PHdos%pjdos_typ)) then ABI_DEALLOCATE(PHdos%pjdos_typ) end if if (associated(PHdos%pjdos_typ_int)) then ABI_DEALLOCATE(PHdos%pjdos_typ_int) end if if (associated(PHdos%pjdos_xyz_typ)) then ABI_DEALLOCATE(PHdos%pjdos_xyz_typ) end if end subroutine destroy_phondos !!*** !---------------------------------------------------------------------- !!****f* m_phdos/mkphdos !! !! NAME !! mkphdos !! !! FUNCTION !! Function to calculate the phonon density of states as well as !! the contributions associated to the different types of atoms in the unit cell. !! Two methods are implemented: gaussian method and linear interpolation based on !! tetrahedrons. !! !! INPUTS !! prtdos=1 for Gaussian method, 2 for tetrahedra. !! dosdeltae=Step for the frequency mesh. !! dossmear=Gaussian broadening used if prtdos==1. !! dipdip= if 0, no dipole-dipole interaction was subtracted in atmfrc !! if 1, atmfrc has been build without dipole-dipole part !! symdynmat=if 1, (re)symmetrize the dynamical matrix, except if Gamma wavevector with electric field added. !! acell(3) =length scales by which rprim is to be multiplied !! amu(ntypat)=mass of the atoms (atomic mass unit) !! anaddb_dtset= (derived datatype) contains all the input variables !! atmfrc(2,3,natom,3,natom,nrpt) = Interatomic Forces in real space !! dielt(3,3)=dielectric tensor !! dyewq0(3,3,natom)=Ewald part of the dynamical matrix, at q=0. !! gmet(3,3)= metric tensor in reciprocal space. !! gprim(3,3)=normalized coordinates in reciprocal space !! indsym(4,nsym,natom)=label given by subroutine symatm, indicating atom !! label which gets rotated into given atom by given symmetry !! (first three elements are related primitive translation-- !! see symatm where this is computed) !! mpert =maximum number of ipert !! msym = maximum number of symmetries !! natom=number of atoms in the unit cell !! nrpt=number of R points in the Big Box !! nsym=number of symmetries !! ntypat=number of atom types !! rmet(3,3)=metric tensor in real space. !! rprim(3,3)=dimensionless primitive translations in real space !! rpt(3,nprt)=canonical coordinates of the R points in the unit cell !! These coordinates are normalized (=> * acell(3)!!) !! symrec(3,3,nsym)=symmetry operations !! symrel(3,3,nsym)=symmetry operations !! trans(3,natom)=atomic translations : xred = rcan + trans !! typat(natom)=integer label of each type of atom (1,2,...) !! ucvol=unit cell volume !! wghatm(natom,natom,nrpt)=weights associated to a pair of atoms and to a R vector !! xred(3,natom)= relative coords of atoms in unit cell (dimensionless) !! zeff(3,3,natom)=effective charge on each atom, versus electric !! field and atomic displacement !! !! OUTPUT !! !! NOTES !! !! On the use of the q-grids : !! Two different q-meshes are used in this subroutine. The first one is the coarse !! mesh where the interatomic forces have been calculated during the DFPT run. !! This q-grid is used to obtain an initial guess for the max and min frequency !! value of the phonon spectrum. These values are, indeed, required to dimension !! the array containing the PHDOS. The second (dense) grid is used to perform the !! PHDOS calculation. If the Fourier interpolation on the second dense q-grid !! generates a phonon frequency outside the initially calculated frequency mesh, !! the mesh is enlarged and the calculation is restarted. !! !! PARENTS !! anaddb,elphon,scphon_interpolate_phonon_and_dos !! !! CHILDREN !! get_full_kgrid,get_tetra_weight,gtdyn9,init_phondos,init_tetra,matr3inv !! mkrdim,phfrq3,simpson_int,smpbz,symkpt,wrtout !! !! SOURCE subroutine mkphdos(PHdos,prtdos,dosdeltae,dossmear,dipdip,symdynmat,acell,amu,anaddb_dtset,& & atmfrc,dielt,dyewq0,gmet,gprim,indsym,& & mpert,msym,natom,nrpt,nsym,ntypat,rmet,rprim,rpt,symrec,symrel,trans,typat,ucvol,wghatm,xred,zeff) use m_tetrahedron use m_errors !This section has been created automatically by the script Abilint (TD). !Do not modify the following lines by hand. #undef ABI_FUNC #define ABI_FUNC 'mkphdos' use interfaces_14_hidewrite use interfaces_32_util use interfaces_42_geometry use interfaces_56_recipspace use interfaces_72_response use interfaces_77_ddb !End of the abilint section implicit none !Arguments ------------------------------- !scalars integer,intent(in) :: prtdos,dipdip,symdynmat integer,intent(in) :: mpert,msym,natom,nrpt,nsym,ntypat real(dp),intent(in) :: dosdeltae,dossmear,ucvol type(anaddb_dataset_type),intent(in) :: anaddb_dtset type(phonon_dos_type),intent(inout) :: PHdos !arrays integer,intent(in) :: indsym(4,nsym,natom),symrec(3,3,nsym),symrel(3,3,nsym),typat(natom) real(dp),intent(in) :: acell(3),amu(ntypat),dielt(3,3),gmet(3,3),gprim(3,3) real(dp),intent(in) :: rmet(3,3),rprim(3,3),rpt(3,nrpt) real(dp),intent(in) :: trans(3,natom),wghatm(natom,natom,nrpt),xred(3,natom) real(dp),intent(in) :: zeff(3,3,natom) real(dp),intent(inout) :: atmfrc(2,3,natom,3,natom,nrpt),dyewq0(3,3,natom) !Local variables ------------------------- !scalars integer,parameter :: brav1=1,chksymbreak0=0 integer :: facbrv,iat,idir,imesh,imode,io,iq_ibz,istat,itype,mtetra,nkpt_fullbz integer :: nmesh,nqbz,nqpt_max,nqshft,option,timrev integer :: ierr real(dp) :: bzvol,dum,gaussfactor,gaussprefactor real(dp) :: gaussval,low_bound,max_occ,pnorm real(dp) :: qphnrm,upr_bound,xx logical :: out_of_bounds character(len=500) :: msg character(len=80) :: errstr type(t_tetrahedron) :: tetrahedra_q !arrays integer :: qptrlatt(3,3) integer,allocatable :: bz2ibz(:),ibz2bz(:),ngqpt(:,:),tetra_full(:,:,:) integer,allocatable :: tetra_mult(:),tetra_wrap(:,:,:) real(dp) :: d2cart(2,3,mpert,3,mpert),displ(2*3*natom*3*natom),eigval(3*natom) real(dp) :: eigvec(2,3,natom,3*natom),gprimd(3,3),phfrq(3*natom) real(dp) :: qlatt(3,3),qphon(3),rlatt(3,3),rprimd(3,3) real(dp),allocatable :: dtweightde(:,:),full_eigvec(:,:,:,:,:),full_phfrq(:,:) real(dp),allocatable :: kpt_fullbz(:,:),qbz(:,:),qibz(:,:),qshft(:,:),tmp_phfrq(:),tweight(:,:) real(dp),allocatable :: wtq(:),wtq_folded(:),wtqibz(:) ! ********************************************************************* DBG_ENTER("COLL") if ( ALL(prtdos/=(/1,2/) ) ) then write(msg,'(a,i0)')& & ' The argument prtdos should be 1 or 2, however prtdos = ',prtdos MSG_BUG(msg) end if if (dosdeltae<=zero) then write(msg,'(a,es16.8)')& & ' The argument dosdeltae should be positive, however dosdeltae = ',dosdeltae MSG_BUG(msg) end if if (prtdos==1.and.dossmear<=zero) then write(msg,'(a,es16.8)')& & ' The argument anaddb%dossmear should be positive however dossmear = ',dossmear MSG_BUG(msg) end if ! call mkrdim(acell,rprim,rprimd) call matr3inv(rprimd,gprimd) bzvol=ABS ( gprimd(1,1)*(gprimd(2,2)*gprimd(3,3)-gprimd(3,2)*gprimd(2,3)) & & -gprimd(2,1)*(gprimd(1,2)*gprimd(3,3)-gprimd(3,2)*gprimd(1,3)) & & +gprimd(3,1)*(gprimd(1,2)*gprimd(2,3)-gprimd(2,2)*gprimd(1,3))) ! ! Initialize container type, but with minimal values call init_phondos(PHdos,ntypat,natom,prtdos,1,1,1,smallest_real,greatest_real,dosdeltae,dossmear) ! ! === Parameters defining the gaussian approximant === if (prtdos==1) then gaussprefactor=one/(dossmear*sqrt(two_pi)) gaussfactor=one/(sqrt2*dossmear) write(msg,'(4a,f8.5,2a,f8.5)')ch10,& & ' mkphdos : calculating phonon DOS using gaussian method :',ch10,& & ' gaussian smearing [meV] = ',dossmear*Ha_meV,ch10,& & ' frequency step [meV] = ',PHdos%omega_step*Ha_meV else if (prtdos==2) then write(msg,'(2a)')ch10,' mkphdos : calculating phonon DOS using tetrahedron method ' end if call wrtout(std_out,msg,'COLL') ! ! Initial lower and upper bound of the phonon spectrum. low_bound=greatest_real upr_bound=smallest_real ! ! Save memory during the generation of the q-mesh in the full BZ ! Take into account the type of Bravais lattice facbrv=1 if (brav1==2) facbrv=2 if (brav1==3) facbrv=4 nmesh=2 ABI_ALLOCATE(ngqpt,(3,nmesh)) do imesh=1,nmesh if (imesh==1) then ! Coarse q-mesh used during RF calculation. ngqpt(:,imesh)=anaddb_dtset%ngqpt(1:3) nqshft=anaddb_dtset%nqshft ABI_ALLOCATE(qshft,(3,nqshft)) ! TODO this has to be fixed there is a small inconsistency in the dimension of q1shft qshft(:,1:nqshft)=anaddb_dtset%q1shft(:,1:nqshft) ! else ! Dense q-mesh used for the Fourier interpolation. ngqpt(1:3,imesh)=anaddb_dtset%ng2qpt(1:3) nqshft=1 !always 1 ABI_ALLOCATE(qshft,(3,nqshft)) qshft(:,1)=anaddb_dtset%q2shft(:) ! FIXME small inconsistency in the dimension of q1shft end if nqpt_max=(ngqpt(1,imesh)*ngqpt(2,imesh)*ngqpt(3,imesh)*nqshft)/facbrv ABI_ALLOCATE(qibz,(3,nqpt_max)) ABI_ALLOCATE(qbz,(3,nqpt_max)) qptrlatt(:,:)=0 qptrlatt(1,1)=ngqpt(1,imesh) qptrlatt(2,2)=ngqpt(2,imesh) qptrlatt(3,3)=ngqpt(3,imesh) option=1 ! ! here I noticed a problem in the declaration of q1shft in the anaddb datatype ! FIXME we write on unit std_out just to avoid problem with automatic tests call smpbz(brav1,std_out,qptrlatt,nqpt_max,nqbz,nqshft,option,qshft,qbz) ! ! Reduce the number of such points by symmetrization. ABI_ALLOCATE(ibz2bz,(nqbz)) ABI_ALLOCATE(wtq,(nqbz)) ABI_ALLOCATE(wtq_folded,(nqbz)) wtq(:)=one/nqbz ! Weights sum up to one timrev=1; option=1 ! TODO timrev should be input ! ! This call will set PHdos%nqibz call symkpt(chksymbreak0,gmet,ibz2bz,std_out,qbz,nqbz,PHdos%nqibz,nsym,symrec,timrev,wtq,wtq_folded) write(std_out,*) 'PHdos%nqibz = ', PHdos%nqibz ABI_ALLOCATE(wtqibz,(PHdos%nqibz)) do iq_ibz=1,PHdos%nqibz wtqibz(iq_ibz)=wtq_folded(ibz2bz(iq_ibz)) qibz(:,iq_ibz)=qbz(:,ibz2bz(iq_ibz)) end do ABI_DEALLOCATE(wtq_folded) ABI_DEALLOCATE(qshft) if (prtdos==2.and.imesh==2) then ! ! Second mesh with tetrahedron method ! convert kptrlatt to double and invert, qlatt here refer to the shortest qpt vectors rlatt(:,:)=qptrlatt(:,:) call matr3inv(rlatt,qlatt) ABI_ALLOCATE(qshft,(3,nqshft)) qshft(:,1)=anaddb_dtset%q2shft(:) ! FIXME small inconsistency in the dimension of q1shft nkpt_fullbz=nqbz ABI_ALLOCATE(bz2ibz,(nkpt_fullbz)) ABI_ALLOCATE(kpt_fullbz,(3,nkpt_fullbz)) ! ! Make full kpoint grid and get equivalence to irred kpoints. ! This routines scales badly wrt nkpt_fullbz, should introduce checl on the norm. call get_full_kgrid(bz2ibz,qlatt,qibz,kpt_fullbz,qptrlatt,PHdos%nqibz,nkpt_fullbz,nqshft,nsym,qshft,symrel) ! ! Get tetrahedra, ie indexes of the full q-points at their summits ! tetra_full(:,1,i) contains the irred qpt number ! tetra_full(:,2,i) contains the full qpt number ! tetra_wrap(:,:,i) contains a flag to wrap q-points outside the IBZ (+-1) to get the irreducible tetrahedra ! the number of equivalent tetrahedra is counted in tetra_mult and the inequivalent few (ntetra < mtetra) are ! packed into the beginning of tetra_full mtetra=6*nqbz ABI_ALLOCATE(tetra_full,(4,2,mtetra)) ABI_ALLOCATE(tetra_wrap,(3,4,mtetra)) ABI_ALLOCATE(tetra_mult,(mtetra)) call init_tetra(bz2ibz, gprimd, qlatt, kpt_fullbz, nqbz, tetrahedra_q, ierr, errstr) ABI_CHECK(ierr==0,errstr) ABI_DEALLOCATE(bz2ibz) ! ! Allocate arrays used to store the entire spectrum, Required to calculate tetra weights. ABI_ALLOCATE(full_phfrq,(3*natom,PHdos%nqibz)) ABI_ALLOCATE(full_eigvec,(2,3,natom,3*natom,PHdos%nqibz)) istat = ABI_ALLOC_STAT ABI_CHECK(istat==0,'out-of-memory in full_eigvec') end if ! prtdos==2.and.imesh==2 ! ! This infinite loop is used to be sure that the frequency mesh is large enough to contain ! the entire phonon spectrum. The mesh is enlarged if, during the Fourier interpolation, ! a phonon frequency turns out to be outside the interval [omega_min:omega_max] do out_of_bounds=.FALSE. if (associated(PHdos%omega)) then ABI_DEALLOCATE(PHdos%omega) end if if (associated(PHdos%phdos)) then ABI_DEALLOCATE(PHdos%phdos) end if if (associated(PHdos%pjdos)) then ABI_DEALLOCATE(PHdos%pjdos) end if ! ! Frequency mesh. PHdos%omega_min=low_bound; if (ABS(PHdos%omega_min)<tol5) PHdos%omega_min=-tol5 PHdos%omega_max=upr_bound PHdos%nomega=NINT((PHdos%omega_max-PHdos%omega_min)/PHdos%omega_step)+1 PHdos%nomega=MAX(6,PHdos%nomega) ! Ensure Simpson integration will be ok ABI_ALLOCATE(PHdos%omega,(PHdos%nomega)) do io=1,PHdos%nomega PHdos%omega(io)=PHdos%omega_min+PHdos%omega_step*(io-1) end do if (imesh/=1) then write(std_out,*)& & 'nomega = ',PHdos%nomega,' omega_min [cm-1] =',PHdos%omega_min*Ha_cmm1,' omega_max [cm-1] =',PHdos%omega_max*Ha_cmm1 end if ABI_ALLOCATE(PHdos%phdos,(PHdos%nomega)) PHdos%phdos=zero ABI_ALLOCATE(PHdos%pjdos,(PHdos%nomega,3,natom)) PHdos%pjdos=zero ! ! === Sum over irreducible q-points === do iq_ibz=1,PHdos%nqibz qphon(:)=qibz(:,iq_ibz); qphnrm=one ! ! Get d2cart using interatomic forces and the long-range coulomb interaction through Ewald summation call gtdyn9(acell,atmfrc,dielt,dipdip,dyewq0,d2cart,gmet,gprim,& & mpert,natom,nrpt,qphnrm,qphon,rmet,rprim,rpt,trans,ucvol,wghatm,xred,zeff) ! ! Get eigenvectors and eigenvalues of the dynamical matrix, eigvec are normalized to one call phfrq3(amu,displ,d2cart,eigval,eigvec,indsym,mpert,msym,natom,nsym,ntypat,& & phfrq,qphnrm,qphon,rprimd,symdynmat,symrel,typat,ucvol) dum=MINVAL(phfrq); PHdos%omega_min=MIN(PHdos%omega_min,dum) dum=MAXVAL(phfrq); PHdos%omega_max=MAX(PHdos%omega_max,dum) out_of_bounds = (PHdos%omega_min<low_bound .or. PHdos%omega_max>upr_bound) if (imesh>1.and..not.out_of_bounds) then select case (prtdos) case (1) ! ! Accumulate PHDOS and PJDOS using gaussian method === do imode=1,3*natom do io=1,PHdos%nomega xx=(PHdos%omega(io)-phfrq(imode))*gaussfactor gaussval=gaussprefactor*exp(-xx*xx) PHdos%phdos(io)=PHdos%phdos(io) + wtqibz(iq_ibz)*gaussval do iat=1,natom do idir=1,3 pnorm=eigvec(1,idir,iat,imode)**2+eigvec(2,idir,iat,imode)**2 PHdos%pjdos(io,idir,iat)=PHdos%pjdos(io,idir,iat)+ pnorm*wtqibz(iq_ibz)*gaussval end do end do end do end do ! case (2) ! ! === Tetrahedrons === ! * Save phonon frequencies and eigenvectors. ! Summation is done after the loops over the two meshes. full_phfrq(:,iq_ibz)=phfrq(:) full_eigvec(:,:,:,:,iq_ibz)=eigvec(:,:,:,:) case default write(msg,'(a,i0)')" Wrong value for prtdos= ",prtdos MSG_ERROR(msg) end select end if !Second mesh and not out of boundaries ! end do !irred q-points if (out_of_bounds) then upr_bound=PHdos%omega_max+ABS(PHdos%omega_max/ten) low_bound=PHdos%omega_min-ABS(PHdos%omega_min/ten) write(msg,'(3a)')& & ' At least one phonon frequency falls outside the frequency mesh chosen',ch10,& & ' restarting the calculation with a larger frequency mesh ' if (imesh>1) then MSG_COMMENT(msg) end if else EXIT !infinite loop end if end do !infinite loop ABI_DEALLOCATE(ibz2bz) ABI_DEALLOCATE(qibz) ABI_DEALLOCATE(qbz) ABI_DEALLOCATE(wtq) ABI_DEALLOCATE(wtqibz) end do !imesh ABI_DEALLOCATE(ngqpt) if (associated(PHdos%phdos_int)) then ABI_DEALLOCATE(PHdos%phdos_int) end if if (associated(PHdos%pjdos_int)) then ABI_DEALLOCATE(PHdos%pjdos_int) end if ABI_ALLOCATE(PHdos%phdos_int,(PHdos%nomega)) PHdos%phdos_int=zero if (prtdos==2) then ! === Integrate using tetrahedrons === ! * All the data are contained in full_phfrq and full_eigvec. ! * low_bound and upr_bound contain the entire spectrum calculated on the dense mesh. ABI_ALLOCATE(tmp_phfrq,(PHdos%nqibz)) ABI_ALLOCATE(tweight,(PHdos%nqibz,PHdos%nomega)) ABI_ALLOCATE(dtweightde,(PHdos%nqibz,PHdos%nomega)) ABI_ALLOCATE(PHdos%pjdos_int,(PHdos%nomega,3,natom)) PHdos%phdos=zero; PHdos%pjdos=zero; PHdos%pjdos_int=zero max_occ=one do imode=1,3*natom tmp_phfrq(:)=full_phfrq(imode,:) ! ! === Calculate general integration weights at each irred kpoint as in Blochl et al PRB 49 16223 === call get_tetra_weight(tmp_phfrq, low_bound, upr_bound,& & max_occ, PHdos%nomega, PHdos%nqibz, tetrahedra_q,& & tweight,dtweightde) do io=1,PHdos%nomega do iq_ibz=1,PHdos%nqibz PHdos%phdos(io)=PHdos%phdos(io)+dtweightde(iq_ibz,io) PHdos%phdos_int(io)=PHdos%phdos_int(io)+tweight(iq_ibz,io) do iat=1,natom do idir=1,3 pnorm=full_eigvec(1,idir,iat,imode,iq_ibz)**2 + full_eigvec(2,idir,iat,imode,iq_ibz)**2 PHdos%pjdos(io,idir,iat)=PHdos%pjdos(io,idir,iat) + pnorm*dtweightde(iq_ibz,io) PHdos%pjdos_int(io,idir,iat)=PHdos%pjdos_int(io,idir,iat) + pnorm*tweight(iq_ibz,io) end do end do end do end do end do ABI_DEALLOCATE(tmp_phfrq) ABI_DEALLOCATE(tweight) ABI_DEALLOCATE(dtweightde) end if ! ! ======================= ! === calculate IPDOS === ! ======================= if (associated(PHdos%pjdos_xyz_typ)) then ABI_DEALLOCATE(PHdos%pjdos_xyz_typ) end if if (associated(PHdos%pjdos_typ)) then ABI_DEALLOCATE(PHdos%pjdos_typ) end if if (associated(PHdos%pjdos_typ_int)) then ABI_DEALLOCATE(PHdos%pjdos_typ_int) end if ABI_ALLOCATE(PHdos%pjdos_xyz_typ,(PHdos%nomega,3,ntypat)) PHdos%pjdos_xyz_typ=zero ABI_ALLOCATE(PHdos%pjdos_typ ,(PHdos%nomega,ntypat)) PHdos%pjdos_typ =zero ABI_ALLOCATE(PHdos%pjdos_typ_int,(PHdos%nomega,ntypat)) PHdos%pjdos_typ_int=zero do iat=1,natom itype=typat(iat) do io=1,PHdos%nomega PHdos%pjdos_xyz_typ(io,:,itype)=PHdos%pjdos_xyz_typ(io,:,itype)+PHdos%pjdos(io,:,iat) PHdos%pjdos_typ(io,itype)=PHdos%pjdos_typ(io,itype)+sum(PHdos%pjdos(io,:,iat)) end do if (prtdos==2) then do io=1,PHdos%nomega PHdos%pjdos_typ_int(io,itype)=PHdos%pjdos_typ_int(io,itype)+SUM(PHdos%pjdos_int(io,:,iat)) end do end if end do ! ! Evaluate IDOS using simple simpson integration ! TODO should avoid the simpson rule using derf.F90, just to be consistent if (prtdos==1) then call simpson_int(PHdos%nomega,PHdos%omega_step,PHdos%phdos,PHdos%phdos_int) do itype=1,ntypat call simpson_int(PHdos%nomega,PHdos%omega_step,PHdos%pjdos_typ(:,itype),PHdos%pjdos_typ_int(:,itype)) end do end if if (prtdos==2) then ABI_DEALLOCATE(tetra_full) ABI_DEALLOCATE(tetra_wrap) ABI_DEALLOCATE(tetra_mult) ABI_DEALLOCATE(full_phfrq) ABI_DEALLOCATE(full_eigvec) end if DBG_EXIT("COLL") end subroutine mkphdos !!*** end module m_phdos !!***
gpl-3.0
jjones-cavium/gcc
gcc/testsuite/gfortran.dg/array_constructor_12.f90
174
1261
! Like array_constructor_6.f90, but check integer(8) iterators. ! { dg-do run } program main integer (kind = 8) :: i, l8, u8, step8 integer (kind = 4) :: l4, step4 integer (kind = 8), parameter :: big = 10000000000_8 l4 = huge (l4) u8 = l4 + 10_8 step4 = 2 call test ((/ (i, i = l4, u8, step4) /), l4 + 0_8, u8, step4 + 0_8) l8 = big u8 = big * 20 step8 = big call test ((/ (i, i = l8, u8, step8) /), l8, u8, step8) u8 = big + 100 l8 = big step4 = -20 call test ((/ (i, i = u8, l8, step4) /), u8, l8, step4 + 0_8) u8 = big * 40 l8 = big * 20 step8 = -big * 2 call test ((/ (i, i = u8, l8, step8) /), u8, l8, step8) u8 = big l4 = big / 100 step4 = -big / 500 call test ((/ (i, i = u8, l4, step4) /), u8, l4 + 0_8, step4 + 0_8) u8 = big * 40 + 200 l4 = 200 step8 = -big call test ((/ (i, i = u8, l4, step8) /), u8, l4 + 0_8, step8) contains subroutine test (a, l, u, step) integer (kind = 8), dimension (:), intent (in) :: a integer (kind = 8), intent (in) :: l, u, step integer (kind = 8) :: i integer :: j j = 1 do i = l, u, step if (a (j) .ne. i) call abort j = j + 1 end do if (size (a, 1) .ne. j - 1) call abort end subroutine test end program main
gpl-2.0
qsnake/abinit
src/28_numeric_noabirule/interp.F90
1
3922
#if defined HAVE_CONFIG_H #include "config.h" #endif #include "abi_common.h" function interp(n,z,f,z0,zz) use defs_basis use m_numeric_tools, only : linfit !This section has been created automatically by the script Abilint (TD). !Do not modify the following lines by hand. #undef ABI_FUNC #define ABI_FUNC 'interp' !End of the abilint section implicit none integer :: n complex(gwpc) :: z(n), f(n), z0, zz complex(gwpc) :: interp complex(gwpc) :: a, b real(dp) :: x(n),smrt if(.false.)write(std_out,*)z0 x(:) = real(z(:)) smrt=linfit(n,x,f,a,b) if( smrt>0.1/Ha_eV) then write(std_out,*) '**WARNING: the values are not linear' write(std_out,*) smrt,a,b,f endif interp = a * zz + b return end function interp function dinterp(n,z,f,z0,zz) use defs_basis use m_numeric_tools, only : linfit !This section has been created automatically by the script Abilint (TD). !Do not modify the following lines by hand. #undef ABI_FUNC #define ABI_FUNC 'dinterp' !End of the abilint section implicit none integer n complex(gwpc) :: z(n), f(n), z0, zz complex(gwpc) :: dinterp complex(gwpc) a, b real(dp) :: x(n), smrt if(.false.)write(std_out,*)z0,zz x(:) = real(z(:)) smrt=linfit(n,x,f,a,b) if( smrt>0.1/Ha_eV) then write(std_out,*) '**WARNING: the values are not linear' write(std_out,*) smrt,a,b,f endif dinterp = a return end function dinterp function taylor_interp(n,z,f,z0,zz) use defs_basis ! calculate in zz the Taylor polinomial around z0 that interpolate the function f ! at the n points z !This section has been created automatically by the script Abilint (TD). !Do not modify the following lines by hand. #undef ABI_FUNC #define ABI_FUNC 'taylor_interp' use interfaces_28_numeric_noabirule, except_this_one => taylor_interp !End of the abilint section implicit none integer n complex(gwpc) :: z(n), f(n), z0, zz complex(gwpc) :: taylor_interp integer i complex(gwpc) :: c(n), zz_minus_z0_to_i call calculate_taylor_c(n,z,f,z0,c) ! calculate the Taylor polinomial in zz zz_minus_z0_to_i = 1 taylor_interp = 0 do i = 1, n taylor_interp = taylor_interp + c(i) * zz_minus_z0_to_i zz_minus_z0_to_i = zz_minus_z0_to_i * (zz - z0) enddo return end function taylor_interp function dtaylor_interp(n,z,f,z0,zz) use defs_basis ! calculate in zz the Taylor polinomial derivative !This section has been created automatically by the script Abilint (TD). !Do not modify the following lines by hand. #undef ABI_FUNC #define ABI_FUNC 'dtaylor_interp' use interfaces_28_numeric_noabirule, except_this_one => dtaylor_interp !End of the abilint section implicit none integer n complex(gwpc) :: z(n), f(n), z0, zz complex(gwpc) :: dtaylor_interp integer i complex(gwpc) :: c(n), zz_minus_z0_to_i call calculate_taylor_c(n,z,f,z0,c) ! calculate the Taylor polinomial in zz zz_minus_z0_to_i = 1 dtaylor_interp = 0 do i = 2, n dtaylor_interp = dtaylor_interp + (i-1) * c(i) * zz_minus_z0_to_i zz_minus_z0_to_i = zz_minus_z0_to_i * (zz - z0) enddo return end function dtaylor_interp subroutine calculate_taylor_c(n,z,f,z0,c) use m_profiling use defs_basis ! calculate the Taylor coefficients polinomial expansion around z0 ! for the function f at the n points z !This section has been created automatically by the script Abilint (TD). !Do not modify the following lines by hand. #undef ABI_FUNC #define ABI_FUNC 'calculate_taylor_c' !End of the abilint section implicit none integer n complex(gwpc) :: z(n), f(n), z0, c(n) integer, parameter :: nrhs=1 integer i,j,info complex(gwpc) :: a(n,n), bb(n,nrhs) ! calculate the coefficient matrix a(:,1) = 1 do i = 1, n do j = 2, n a(i,j) = a(i,j-1) * (z(i) - z0) enddo enddo ! solve the linear system to find the Taylor expansion coefficients bb(:,1) = f(:) stop 'introduce cgesv' !call cgesv(n,nrhs,a,n,ipiv,bb,n,info) if(info/=0) then write(std_out,*) info stop 'cgesv failed' endif c(:) = bb(:,1) return end subroutine calculate_taylor_c
gpl-3.0
qsnake/abinit
src/68_rsprc/prcref.F90
1
26946
!{\src2tex{textfont=tt}} !!****f* ABINIT/prcref !! !! NAME !! prcref !! !! FUNCTION !! Compute preconditioned residual potential (or density) and forces. !! iprcel, iprcch and iprcfc govern the choice of the preconditioner. !! Three tasks are done : !! 1) Preconditioning of the forces (residual has already been included) !! using the approximate force constant matrix. Get proposed !! change of atomic positions. !! 2) Precondition the residual, get first part of proposed trial !! potential change. !! 3) PAW only: precondition the rhoij residuals (simple preconditionning) !! 4) Take into account the proposed change of atomic positions to !! modify the proposed trial potential change. !! !! NOTE !! This routine is almost similar to prcref_PMA.F90 which is employed in !! case of potential mixing. Yet it has undergone strong changes simultaneously !! from two different sources at the same time which resulted in a splitting. !! !! COPYRIGHT !! Copyright (C) 1998-2012 ABINIT group (DCA,XG,MT) !! This file is distributed under the terms of the !! GNU General Public License, see ~abinit/COPYING !! or http://www.gnu.org/copyleft/gpl.txt . !! For the initials of contributors, see ~abinit/doc/developers/contributors.txt . !! !! INPUTS !! atindx(natom)=index table for atoms (see scfcv.f) !! dielar(7)=input parameters for dielectric matrix: !! diecut,dielng,diemac,diemix,diegap,dielam,diemixmag. !! dielstrt=number of the step at which the dielectric preconditioning begins. !! dtset <type(dataset_type)>=all input variables in this dataset !! | intxc=control xc quadrature !! | iprcch= not yet used here !! | iprcel= governs the preconditioning of the potential residual !! | 0 => simple model dielectric matrix, described by the !! | parameters dielng, diemac, diemix and diemixmag contained in dielar. !! | between 21 and 39 => until istep=dielstart, same as iprcel=0, then uses !! | the RPA dielectric matrix (routine dielmt) !! | between 41 and 49 => uses the RPA dielectric matrix (routine dielmt). !! | between 51 and 59 => uses the RPA dielectric matrix (routine dieltcel). !! | between 61 and 69 => uses the electronic dielectric matr (routine dieltcel). !! | between 71 and 79 => uses the real-space preconditioner based on Kerker prc (prcrskerkerN) !! | between 81 and 99 => reserved for futur version of the real-space preconditioner !! | between 141 and 169 -> same as between 41 and 69 but with a different periodicity: modulo(iprcel modulo (10)) !! | iprcfc= governs the preconditioning of the forces !! | 0 => hessian is the identity matrix !! | 1 => hessian is 0.5 times the identity matrix !! | 2 => hessian is 0.25 times the identity matrix !! | ixc=exchange-correlation choice parameter. !! | natom=number of atoms !! | nspden=number of spin-density components !! | occopt=option for occupancies !! | prtvol=control print volume and debugging !! | typat(natom)=integer type for each atom in cell !! etotal=total ennergy !! fcart(3,natom)=cartesian forces (hartree/bohr) !! ffttomix(nfft*(1-nfftprc/nfft))=Index of the points of the FFT (fine) grid on the grid used for mixing (coarse) !! gmet(3,3)=metrix tensor in G space in Bohr**-2. !! gsqcut=cutoff on (k+G)^2 (bohr^-2) !! !! istep= number of the step in the SCF cycle !! kg_diel(3,npwdiel)=reduced planewave coordinates for the dielectric matrix. !! mgfft=maximum size of 1D FFTs !! moved_atm_inside= if 1, then the preconditioned forces !! as well as the preconditioned potential residual must be computed; !! otherwise, compute only the preconditioned potential residual. !! mpi_enreg=informations about MPI parallelization !! nattyp(ntypat)=number of atoms of each type in cell. !! nfft=number of fft grid points !! nfftprc=size of FFT grid on which the potential residual will be preconditionned !! ngfft(18)=contain all needed information about 3D FFT, see ~abinit/doc/input_variables/vargs.htm#ngfft !! ngfftprc(18)=contain all needed information about 3D FFT for the grid corresponding to nfftprc !! nkxc=second dimension of the array kxc, see rhohxc.f for a description !! npawmix=-PAW only- number of spherical part elements to be mixed !! npwdiel=number of planewaves for dielectric matrix !! ntypat=number of types of atoms in cell. !! n1xccc=dimension of xccc1d ; 0 if no XC core correction is used !! optreal=1 if residual potential is is REAL space, 2 if it is in RECIPROCAL SPACE !! optres=0: the array vresid contains a potential residual !! 1: the array vresid contains a density residual !! pawrhoij(natom*usepaw) <type(pawrhoij_type)>= paw rhoij occupancies and related data !! Use here rhoij residuals (and gradients) !! pawtab(ntypat*usepaw) <type(pawtab_type)>=paw tabulated starting data !! psps <type(pseudopotential_type)>=variables related to pseudopotentials !! rhog(2,nfft)=array for electron density in reciprocal space !! rhor(nfft,nspden)=array for electron density in electrons/bohr**3. !! rprimd(3,3)=dimensional primitive translations in real space (bohr) !! susmat(2,npwdiel,nspden,npwdiel,nspden)= !! the susceptibility (or density-density response) matrix in reciprocal space !! vresid(optreal*nfftprc,nspden)=residual potential !! vxc(nfft,nspden)=exchange-correlation potential (hartree) !! vhartr(nfft)=array for holding Hartree potential !! vlspl(mqgrid,2,ntypat)=q^2 v(q) spline for each type of atom. !! vpsp(nfft)=array for holding local psp !! xred(3,natom)=reduced dimensionless atomic coordinates !! !! OUTPUT !! dtn_pc(3,natom)=preconditioned change of atomic position, !! in reduced coordinates !! vrespc(optreal*nfftprc,nspden)=preconditioned residual of the potential !! ==== if psps%usepaw==1 !! rhoijrespc(npawmix)= preconditionned rhoij residuals at output !! !! SIDE EFFECT !! dielinv(2,npwdiel,nspden,npwdiel,nspden)= !! inverse of the dielectric matrix in rec. space !! kxc(nfft,nkxc)=exchange-correlation kernel, !! needed if the electronic dielectric matrix is computed !! ===== if iprcch==3 .and. moved_atm_inside==1 ===== !! ph1d(2,3*(2*mgfft+1)*natom)=1-dim structure factor phases !! !! PARENTS !! newrho !! !! CHILDREN !! atm2fft,dielmt,dieltcel,fourdp,fresid,getph,indirect_parallel_fourier !! kgindex,leave_new,mean_fftr,metric,mkcore,mklocl,moddiel,prcrskerker1 !! prcrskerker2,rhohxc,testsusmat,wrtout,xredxcart,xsum_mpi,zerosym !! !! SOURCE #if defined HAVE_CONFIG_H #include "config.h" #endif #include "abi_common.h" subroutine prcref(atindx,dielar,dielinv,& & dielstrt,dtn_pc,dtset,etotal,fcart,ffttomix,gmet,gsqcut,& & istep,kg_diel,kxc,& & mgfft,moved_atm_inside,mpi_enreg,& & nattyp,nfft,nfftprc,ngfft,ngfftprc,nkxc,npawmix,npwdiel,ntypat,n1xccc,& & optreal,optres,pawrhoij,pawtab,ph1d,psps,rhog,rhoijrespc,rhor,rprimd,& & susmat,vhartr,vpsp,vresid,vrespc,vxc,wvl,xred) use m_profiling use defs_basis use defs_datatypes use defs_abitypes use defs_wvltypes use m_xmpi !This section has been created automatically by the script Abilint (TD). !Do not modify the following lines by hand. #undef ABI_FUNC #define ABI_FUNC 'prcref' use interfaces_14_hidewrite use interfaces_16_hideleave use interfaces_42_geometry use interfaces_52_fft_mpi_noabirule use interfaces_53_ffts use interfaces_53_spacepar use interfaces_56_recipspace use interfaces_56_xc use interfaces_65_psp use interfaces_67_common use interfaces_68_rsprc, except_this_one => prcref !End of the abilint section implicit none !Arguments------------------------------- !scalars integer,intent(in) :: dielstrt,istep,mgfft,moved_atm_inside,n1xccc integer,intent(in) :: nfft,nfftprc,nkxc,npawmix,npwdiel,ntypat,optreal,optres real(dp),intent(in) :: etotal,gsqcut type(MPI_type),intent(inout) :: mpi_enreg type(dataset_type),intent(in) :: dtset type(pseudopotential_type),intent(in) :: psps type(wvl_internal_type), intent(in) :: wvl !arrays integer,intent(in) :: atindx(dtset%natom),ffttomix(nfft*(1-nfftprc/nfft)) integer,intent(in) :: kg_diel(3,npwdiel),nattyp(ntypat),ngfft(18),ngfftprc(18) real(dp),intent(in) :: dielar(7),fcart(3,dtset%natom),rhog(2,nfft) real(dp),intent(in) :: rhor(nfft,dtset%nspden),rprimd(3,3) real(dp),intent(in) :: susmat(2,npwdiel,dtset%nspden,npwdiel,dtset%nspden) real(dp),intent(in) :: vhartr(nfft),vresid(nfftprc*optreal,dtset%nspden) real(dp),intent(in) :: vxc(nfft,dtset%nspden) real(dp),intent(inout) :: dielinv(2,npwdiel,dtset%nspden,npwdiel,dtset%nspden) real(dp),intent(inout) :: gmet(3,3),kxc(nfft,nkxc) real(dp),intent(inout) :: ph1d(2,3*(2*mgfft+1)*dtset%natom),vpsp(nfft) real(dp),intent(inout) :: xred(3,dtset%natom) real(dp),intent(out) :: dtn_pc(3,dtset%natom),rhoijrespc(npawmix) real(dp),intent(out) :: vrespc(nfftprc*optreal,dtset%nspden) type(pawrhoij_type),intent(inout) :: pawrhoij(dtset%natom*psps%usepaw) type(pawtab_type),intent(in) :: pawtab(ntypat*psps%usepaw) !Local variables------------------------------- !scalars integer :: cplex,dielop,iatom,ier,ifft,ii,index,ipw1 integer :: ipw2,ispden,klmn,kmix,n1,n2,n3,n3xccc,nfftot,nk3xc,optatm integer :: optdyfr,optgr,option,optn,optn2,optstr,optv real(dp) :: ai,ar,diemix,diemixmag,eei,enxc real(dp) :: mixfac real(dp) :: mixfac_eff,mixfacmag,ucvol,vxcavg logical :: computediel character(len=500) :: message !arrays integer :: qprtrb(3) integer,allocatable :: indpw_prc(:) real(dp) :: dummy6(6),dummy7(6),gprimd(3,3),qphon(3),rmet(3,3),strsxc(6) real(dp) :: vmean(dtset%nspden),vprtrb(2) real(dp),allocatable :: dummy(:),dummy1(:),dummy2(:),dummy3(:),dummy4(:),dummy5(:),dummy8(:) real(dp),allocatable :: dyfrlo_indx(:,:,:),dyfrx2(:,:,:) real(dp),allocatable :: fcart_pc(:,:),gresid(:,:),grtn_indx(:,:) real(dp),allocatable :: grxc(:,:),grxc_indx(:,:),rhog_wk(:,:),rhor_new(:,:) real(dp),allocatable :: rhor_wk(:,:),rhor_wk0(:,:),vhartr_wk(:),vpsp_wk(:) real(dp),allocatable :: vres_diel(:,:),vxc_wk(:,:),work(:),work1(:,:),work2(:) real(dp),allocatable :: work3(:,:),xccc3d(:),xred_wk(:,:) logical,allocatable :: mask(:) ! ************************************************************************* !DEBUG !write(std_out,*)' prcref : enter ' !stop !ENDDEBUG !Compute different geometric tensor, as well as ucvol, from rprimd call metric(gmet,gprimd,-1,rmet,rprimd,ucvol) !1) Eventually take care of the forces if(moved_atm_inside==1)then ABI_ALLOCATE(fcart_pc,(3,dtset%natom)) if(dtset%iprcfc==0)then fcart_pc(:,:)=fcart(:,:) else fcart_pc(:,:)= (two**dtset%iprcfc) * fcart(:,:) end if ! Compute preconditioned delta xred from preconditioned fcart and rprimd call xredxcart(dtset%natom,-1,rprimd,fcart_pc,dtn_pc) ABI_DEALLOCATE(fcart_pc) end if !####################################################################### !2) Take care of the potential residual !Compute the residuals corresponding to the solution !of an approximate realspace dielectric function according !to X. Gonze PRB vol54 nb7 p4383 (1996) if(dtset%iprcel>=71.and.dtset%iprcel<=79) then if (nfft==nfftprc) then if (dtset%iprcel<=78) then call prcrskerker1(dtset,mpi_enreg,nfft,dtset%nspden,ngfft,dielar,etotal, & & gprimd,vresid,vrespc,rhor(:,1)) else call prcrskerker2(dtset,nfft,dtset%nspden,ngfft,dielar,gprimd,rprimd, & & vresid,vrespc,dtset%natom,xred,mpi_enreg,ucvol) end if else ! If preconditionning has to be done on a coarse grid, ! has to transfer several arrays ABI_ALLOCATE(work1,(nfftprc,dtset%nspden)) ABI_ALLOCATE(work3,(nfftprc,dtset%nspden)) ABI_ALLOCATE(work,(2*nfftprc)) do ispden=1,dtset%nspden work(:)=vresid(:,ispden) call fourdp(1,work,work1(:,ispden),+1,mpi_enreg,nfftprc,ngfftprc,dtset%paral_kgb,0) end do ABI_DEALLOCATE(work) if (dtset%iprcel<=78) then ABI_ALLOCATE(rhog_wk,(2,nfftprc)) rhog_wk(:,:)=zero if (mpi_enreg%nproc_fft>1.and. mpi_enreg%paral_compil_fft==1) then nfftot=ngfft(1)*ngfft(2)*ngfft(3) call indirect_parallel_Fourier(ffttomix,rhog_wk,mpi_enreg,ngfftprc,& & ngfft,nfftprc,nfft,dtset%paral_kgb,rhog,nfftot) else do ii=1,nfft if (ffttomix(ii)>0) rhog_wk(:,ffttomix(ii))=rhog(:,ii) end do end if call zerosym(rhog_wk,2,mpi_enreg,ngfftprc(1),ngfftprc(2),ngfftprc(3)) ABI_ALLOCATE(work,(nfftprc)) call fourdp(1,rhog_wk,work,+1,mpi_enreg,nfftprc,ngfftprc,dtset%paral_kgb,0) call prcrskerker1(dtset,mpi_enreg,nfftprc,dtset%nspden,ngfftprc,dielar,etotal, & & gprimd,work1,work3,work) ABI_DEALLOCATE(work) else call prcrskerker2(dtset,nfftprc,dtset%nspden,ngfftprc,dielar,gprimd,rprimd, & & work1,work3,dtset%natom,xred,mpi_enreg,ucvol) end if do ispden=1,dtset%nspden call fourdp(1,vrespc(:,ispden),work3(:,ispden),-1,mpi_enreg,nfftprc,ngfftprc,dtset%paral_kgb,0) end do ABI_DEALLOCATE(work1) ABI_DEALLOCATE(work3) end if else if(dtset%iprcel==0 .or. (dtset%iprcel<40.and.istep<dielstrt) )then cplex=optreal qphon(:)=zero ! Simple scalar multiplication, or model dielectric function call moddiel(cplex,dielar,mpi_enreg,nfftprc,ngfftprc,dtset%nspden,optreal,optres,dtset%paral_kgb,qphon,rprimd,vresid,vrespc) ! Use the inverse dielectric matrix in a small G sphere else if( (istep>=dielstrt .and. dtset%iprcel>=21) .or. modulo(dtset%iprcel,100)>=41 )then ! With dielop=1, the matrices will be computed when istep=dielstrt ! With dielop=2, the matrices will be computed when istep=dielstrt and 1 dielop=1 if(modulo(dtset%iprcel,100)>=41)dielop=2 call testsusmat(computediel,dielop,dielstrt,dtset,istep) !test if the matrix is to be computed if(computediel) then ! Compute the inverse dielectric matrix from the susceptibility matrix ! There are two routines for the RPA matrix, while for the electronic ! dielectric matrix, only dieltcel will do the work if(modulo(dtset%iprcel,100)<=49)then call dielmt(dielinv,gmet,kg_diel,& & npwdiel,dtset%nspden,dtset%occopt,dtset%prtvol,susmat) else option=1 if(modulo(dtset%iprcel,100)>=61)option=2 call dieltcel(dielinv,gmet,kg_diel,kxc,& & nfft,ngfft,nkxc,npwdiel,dtset%nspden,dtset%occopt,option,dtset%paral_kgb,dtset%prtvol,susmat) end if end if ABI_ALLOCATE(work1,(2,nfftprc)) ABI_ALLOCATE(work2,(optreal*nfftprc)) ! Presently, one uses the inverse of the RPA dielectric matrix, ! for which spin must be averaged. ! Do fft from real space (work2) to G space (work1) if (optreal==1) then work2(:)=vresid(:,1) ! Must average over spins in the case of a potential residual if(dtset%nspden/=1.and.optres==0)work2(:)=(work2(:)+vresid(:,2))*half call fourdp(1,work1,work2,-1,mpi_enreg,nfftprc,ngfftprc,dtset%paral_kgb,0) else work1(:,:)=reshape(vresid(:,1),(/2,nfftprc/)) if(dtset%nspden/=1.and.optres==0)work1(:,:)=(work1(:,:)+reshape(vresid(:,2),(/2,nfftprc/)))*half end if ! Multiply by restricted inverse of dielectric matrix. ! Must first copy relevant elements of work1 to a npwdiel-dimensioned array, ! then zero work1, operate with the dielinv matrix, and store in work1. ABI_ALLOCATE(vres_diel,(2,npwdiel)) ABI_ALLOCATE(indpw_prc,(npwdiel)) ABI_ALLOCATE(mask,(npwdiel)) mask(:)=.true. call kgindex(indpw_prc,kg_diel,mask,mpi_enreg,ngfftprc,npwdiel) do ipw1=1,npwdiel if(mask(ipw1)) then vres_diel(1,ipw1)=work1(1,indpw_prc(ipw1)) vres_diel(2,ipw1)=work1(2,indpw_prc(ipw1)) end if end do work1(:,:)=zero do ipw1=1,npwdiel ar=zero ; ai=zero ! Use inverse of dielectric matrix (potential mixing) if (optres==0) then do ipw2=1,npwdiel if(mask(ipw2))then ar=ar+dielinv(1,ipw1,1,ipw2,1)*vres_diel(1,ipw2) & & -dielinv(2,ipw1,1,ipw2,1)*vres_diel(2,ipw2) ai=ai+dielinv(2,ipw1,1,ipw2,1)*vres_diel(1,ipw2) & & +dielinv(1,ipw1,1,ipw2,1)*vres_diel(2,ipw2) end if end do else ! Use symetric of inverse of dielectric matrix (density mixing) do ipw2=1,npwdiel if(mask(ipw2))then ar=ar+dielinv(1,ipw2,1,ipw1,1)*vres_diel(1,ipw2) & & +dielinv(2,ipw2,1,ipw1,1)*vres_diel(2,ipw2) ai=ai-dielinv(2,ipw2,1,ipw1,1)*vres_diel(1,ipw2) & & +dielinv(1,ipw2,1,ipw1,1)*vres_diel(2,ipw2) end if end do end if ! Must be careful not to count the diagonal 1 twice : it is added later, ! so must be subtracted now. call xsum_mpi(ar,mpi_enreg%comm_fft,ier) call xsum_mpi(ai,mpi_enreg%comm_fft,ier) if(mask(ipw1)) then work1(1,indpw_prc(ipw1))=ar-vres_diel(1,ipw1) work1(2,indpw_prc(ipw1))=ai-vres_diel(2,ipw1) end if !mask(ipw1) end do ! ipw1 ABI_DEALLOCATE(vres_diel) ABI_DEALLOCATE(indpw_prc) ABI_DEALLOCATE(mask) ! Fourier transform if (optreal==1) then call fourdp(1,work1,work2,1,mpi_enreg,nfftprc,ngfftprc,dtset%paral_kgb,0) else work2(:)=reshape(work1(:,:),(/nfftprc*2/)) end if ! Add to get the preconditioned vresid, must be careful about spins. if(dtset%iprcel>=30)then diemix=dielar(4);diemixmag=abs(dielar(7)) vrespc(:,1)=diemix*(vresid(:,1)+work2(:)) if(dtset%nspden/=1.and.optres==0)vrespc(:,2)=diemixmag*(vresid(:,2)+work2(:)) if(dtset%nspden==4.and.optres==0)vrespc(:,3:4)=diemixmag*vresid(:,3:4) if(dtset%nspden/=1.and.optres==1)vrespc(:,2:dtset%nspden)=diemixmag*vresid(:,2:dtset%nspden) else vrespc(:,1)=vresid(:,1)+work2(:) if(dtset%nspden/=1.and.optres==0)vrespc(:,2)=vresid(:,2)+work2(:) if(dtset%nspden==4.and.optres==0)vrespc(:,3:4)=vresid(:,3:4) if(dtset%nspden/=1.and.optres==1)vrespc(:,2:dtset%nspden)=vresid(:,2:dtset%nspden) end if ABI_DEALLOCATE(work1) ABI_DEALLOCATE(work2) ! Other choice ? else write(message, '(a,a,a,a,i3,a,a,a,a)' ) ch10,& & ' prcref : ERROR - ',ch10,& & ' From the calling routine, iprcel=',dtset%iprcel,ch10,& & ' The only allowed values are 0 or larger than 20.',ch10,& & ' Action : correct your input file.' call wrtout(std_out,message,'COLL') call leave_new('COLL') end if end if !####################################################################### !3) PAW only : precondition the rhoij quantities (augmentation !occupancies) residuals. Use a simple preconditionning !with the same mixing factor as the model dielectric function. if (psps%usepaw==1) then if (istep>=dielstrt.and.dtset%iprcel>=21.and.dtset%iprcel<30) then mixfac=one;mixfacmag=one else mixfac=dielar(4);mixfacmag=abs(dielar(7)) end if if (pawrhoij(1)%cplex==1) then index=0 do iatom=1,dtset%natom do ispden=1,pawrhoij(iatom)%nspden mixfac_eff=mixfac;if (ispden>1) mixfac_eff=mixfacmag do kmix=1,pawrhoij(iatom)%lmnmix_sz index=index+1;klmn=pawrhoij(iatom)%kpawmix(kmix) rhoijrespc(index)=mixfac_eff*pawrhoij(iatom)%rhoijres(klmn,ispden) end do end do end do else index=-1 do iatom=1,dtset%natom do ispden=1,pawrhoij(iatom)%nspden mixfac_eff=mixfac;if (ispden>1) mixfac_eff=mixfacmag do kmix=1,pawrhoij(iatom)%lmnmix_sz index=index+2;klmn=2*pawrhoij(iatom)%kpawmix(kmix)-1 rhoijrespc(index:index+1)=mixfac_eff*pawrhoij(iatom)%rhoijres(klmn:klmn+1,ispden) end do end do end do end if end if !####################################################################### !4) Take care of the change of atomic positions !Note : this part is very demanding on memory... !however, since this algorithm is still in development, !it was NOT included in the estimation provided by memory.f if(abs(dtset%iprcch)==3 .and. moved_atm_inside==1)then ! Not yet compatible with resid given in reciprocal space if (optreal/=1) then write(message, '(8a)' ) ch10,& & ' prcref : ERROR - ',ch10,& & ' From the calling routine, iprcch=3',ch10,& & ' You cannot use residuals in reciprocal space.',ch10,& & ' Action : correct your input file.' call wrtout(std_out,message,'COLL') call leave_new('COLL') end if ! Not compatible with non-collinear magnetism if(dtset%nspden==4)then write(message, '(4a)' ) ch10,& & ' prcref : ERROR -',ch10,& & 'iprcch=3 does not work for nspden=4 !' call wrtout(std_out,message,'COLL') call leave_new('COLL') end if n1=ngfft(1) ; n2=ngfft(2) ; n3=ngfft(3) nfftot=n1*n2*n3 if (optres==0) then ! Array vresid contains a potential residual ! ----------------------------------------------------------------- ! First subtract the current local, hartree and exchange correlation potentials do ispden=1,min(dtset%nspden,2) vrespc(:,ispden)=vrespc(:,ispden)-vpsp(:)-vhartr(:)-vxc(:,ispden) end do if (dtset%nspden==4) then do ispden=3,4 vrespc(:,ispden)=vrespc(:,ispden)-vxc(:,ispden) end do end if ! Compute the modified density, in rhor_wk option=2 ABI_ALLOCATE(gresid,(3,dtset%natom)) ABI_ALLOCATE(grxc,(3,dtset%natom)) ABI_ALLOCATE(rhor_wk,(nfft,dtset%nspden)) ABI_ALLOCATE(rhor_wk0,(nfft,dtset%nspden)) ABI_ALLOCATE(xred_wk,(3,dtset%natom)) xred_wk(:,:)=xred(:,:)+dtn_pc(:,:) call fresid(dtset,gresid,mpi_enreg,nfft,ngfft,& & ntypat,option,pawtab,rhor,rprimd,& & ucvol,rhor_wk,xred_wk,xred,psps%znuclpsp) ! Compute up+down rhog_wk(G) by fft ABI_ALLOCATE(work,(nfft)) ABI_ALLOCATE(rhog_wk,(2,nfft)) work(:)=rhor_wk(:,1) call fourdp(1,rhog_wk,work,-1,mpi_enreg,nfft,ngfft,dtset%paral_kgb,0) ABI_DEALLOCATE(work) ! Compute structure factor phases for new atomic pos: call getph(atindx,dtset%natom,n1,n2,n3,ph1d,xred_wk) ! Compute local ionic pseudopotential vpsp: ! and core electron density xccc3d, if needed. n3xccc=0;if (n1xccc/=0) n3xccc=nfft ABI_ALLOCATE(xccc3d,(n3xccc)) ABI_ALLOCATE(vpsp_wk,(nfft)) vprtrb(1:2)=zero if (psps%usepaw==1) then ! PAW: compute vpsp and xccc3d together in reciprocal space optatm=1;optdyfr=0;optgr=0;optstr=0;optv=1;optn=n3xccc/nfft;optn2=1 ! Note: atindx1 should be passed to atm2fft (instead of atindx) but it is unused... call atm2fft(atindx,xccc3d,vpsp,dummy,dummy2,eei,dummy1,gmet,gprimd,dummy3,dummy4,gsqcut,& & mgfft,mpi_enreg,psps%mqgrid_vl,dtset%natom,nattyp,nfft,ngfft,ntypat,& & optatm,optdyfr,optgr,optn,optn2,optstr,optv,dtset%paral_kgb,& & pawtab,ph1d,psps%qgrid_vl,qprtrb,dummy5,dummy6,dummy7,& & ucvol,psps%usepaw,dummy8,vprtrb,psps%vlspl) else ! Norm-conserving: compute vpsp in recip. space and xccc3d in real space option = 1 ABI_ALLOCATE(dyfrlo_indx,(3,3,dtset%natom)) ABI_ALLOCATE(grtn_indx,(3,dtset%natom)) call mklocl(dtset,dyfrlo_indx,eei,gmet,gprimd,grtn_indx,gsqcut,dummy6,& & mgfft,mpi_enreg,dtset%natom,nattyp,nfft,ngfft,dtset%nspden,& & ntypat,option,ph1d,psps,qprtrb,rhog_wk,rhor_wk,rprimd,& & ucvol,vprtrb,vpsp_wk,wvl,xred) ABI_DEALLOCATE(dyfrlo_indx) ABI_DEALLOCATE(grtn_indx) if (n1xccc/=0) then ABI_ALLOCATE(dyfrx2,(3,3,dtset%natom)) ABI_ALLOCATE(grxc_indx,(3,dtset%natom)) call mkcore(dummy6,dyfrx2,grxc_indx,mpi_enreg,dtset%natom,nfft,dtset%nspden,ntypat,& & n1,n1xccc,n2,n3,option,rprimd,dtset%typat,ucvol,vxc,psps%xcccrc,& & psps%xccc1d,xccc3d,xred_wk) ABI_DEALLOCATE(dyfrx2) ABI_DEALLOCATE(grxc_indx) end if end if ! Compute Hartree+xc potentials ABI_ALLOCATE(vxc_wk,(nfft,dtset%nspden)) ABI_ALLOCATE(vhartr_wk,(nfft)) option=1 ! to be adjusted for the call to rhohxc nk3xc=1 call rhohxc(dtset,enxc,gsqcut,psps%usepaw,kxc,mpi_enreg,nfft,ngfft,& & work,0,work,0,nkxc,nk3xc,dtset%nspden,n3xccc,option,rhog_wk,rhor_wk,rprimd,strsxc,1,& & vhartr_wk,vxc_wk,vxcavg,xccc3d) ABI_DEALLOCATE(xccc3d) ! Sum all contributions do ispden=1,min(dtset%nspden,2) do ifft=1,nfft vrespc(ifft,ispden)=vrespc(ifft,ispden)+vpsp_wk(ifft)+vhartr_wk(ifft)+vxc_wk(ifft,ispden) end do end do if (dtset%nspden==4) then do ispden=3,4 do ifft=1,nfft vrespc(ifft,ispden)=vrespc(ifft,ispden)+vxc_wk(ifft,ispden) end do end do end if call mean_fftr(vrespc,vmean,mpi_enreg,nfft,nfftot,dtset%nspden) if(dtset%nspden==2) then vmean(1)=half*(vmean(1)+vmean(2)) vmean(2)=vmean(1) end if do ispden=1,dtset%nspden vrespc(:,ispden)=vrespc(:,ispden)-vmean(ispden) end do ABI_DEALLOCATE(gresid) ABI_DEALLOCATE(grxc) ABI_DEALLOCATE(rhog_wk) ABI_DEALLOCATE(rhor_wk) ABI_DEALLOCATE(rhor_wk0) ABI_DEALLOCATE(xred_wk) ABI_DEALLOCATE(vhartr_wk) ABI_DEALLOCATE(vpsp_wk) ABI_DEALLOCATE(vxc_wk) else ! Array vresid contains a density residual ! ----------------------------------------------------------------- ! Only have to compute the modified preconditionned density residual option=2 ABI_ALLOCATE(gresid,(3,dtset%natom)) ABI_ALLOCATE(grxc,(3,dtset%natom)) ABI_ALLOCATE(rhor_new,(nfft,dtset%nspden)) ABI_ALLOCATE(rhor_wk,(nfft,dtset%nspden)) ABI_ALLOCATE(rhor_wk0,(nfft,dtset%nspden)) ABI_ALLOCATE(xred_wk,(3,dtset%natom)) xred_wk(:,:)=xred(:,:)+dtn_pc(:,:) rhor_new(:,1)=rhor(:,1)+vrespc(:,1) if (dtset%nspden==2) then rhor_new(:,1)=rhor_new(:,1)+vrespc(:,2) rhor_new(:,2)=rhor(:,2)+vrespc(:,1) end if call fresid(dtset,gresid,mpi_enreg,nfft,ngfft,& & ntypat,option,pawtab,rhor,rprimd,& & ucvol,rhor_wk0,xred_wk,xred,psps%znuclpsp) call fresid(dtset,gresid,mpi_enreg,nfft,ngfft,& & ntypat,option,pawtab,rhor_new,rprimd,& & ucvol,rhor_wk,xred_wk,xred,psps%znuclpsp) vrespc(:,1)=rhor_wk(:,dtset%nspden)-rhor_wk0(:,dtset%nspden) if (dtset%nspden==2) vrespc(:,2)=rhor_wk(:,1)-rhor_wk0(:,1)-vrespc(:,1) ABI_DEALLOCATE(gresid) ABI_DEALLOCATE(grxc) ABI_DEALLOCATE(rhor_new) ABI_DEALLOCATE(rhor_wk) ABI_DEALLOCATE(rhor_wk0) ABI_DEALLOCATE(xred_wk) end if end if !DEBUG !write(std_out,*)' prcref : exit ' !stop !ENDDEBUG end subroutine prcref !!***
gpl-3.0
stephenR/gcc-fpp
gcc/testsuite/gfortran.dg/g77/980628-3.f
188
1350
c { dg-do run } c { dg-options "-std=gnu" } c * g77 0.5.23 and previous had bugs involving too little space * allocated for EQUIVALENCE and COMMON areas needing initial * padding to meet alignment requirements of the system. call subr end subroutine subr implicit none save character c1(11), c2(11), c3(11) real r1, r2, r3 character c4, c5, c6 equivalence (c1(2), r1) equivalence (c2(2), r2) equivalence (c3(2), r3) c1(1) = '1' r1 = 1. c1(11) = '1' c4 = '4' c2(1) = '2' r2 = 2. c2(11) = '2' c5 = '5' c3(1) = '3' r3 = 3. c3(11) = '3' c6 = '6' call x (c1, r1, c2, r2, c3, r3, c4, c5, c6) end subroutine x (c1, r1, c2, r2, c3, r3, c4, c5, c6) implicit none character c1(11), c2(11), c3(11) real r1, r2, r3 character c4, c5, c6 if (c1(1) .ne. '1') call abort if (r1 .ne. 1.) call abort if (c1(11) .ne. '1') call abort if (c4 .ne. '4') call abort if (c2(1) .ne. '2') call abort if (r2 .ne. 2.) call abort if (c2(11) .ne. '2') call abort if (c5 .ne. '5') call abort if (c3(1) .ne. '3') call abort if (r3 .ne. 3.) call abort if (c3(11) .ne. '3') call abort if (c6 .ne. '6') call abort end
gpl-2.0
doslab/gcc-designated-initializer-support-cpp
gcc/testsuite/gfortran.dg/initialization_14.f90
180
1386
! { dg-do compile } ! PR 20851 ! Dummy arguments are disallowed in initialization expressions in ! elemental functions except as arguments to the intrinsic functions ! BIT_SIZE, KIND, LEN, or to the numeric inquiry functions listed ! in 13.11.8 MODULE TT INTEGER M CONTAINS ELEMENTAL REAL FUNCTION two(N) INTEGER, INTENT(IN) :: N INTEGER, DIMENSION(N) :: scr ! { dg-error "Dummy argument 'n' not allowed in expression" } END FUNCTION ELEMENTAL REAL FUNCTION twopointfive(N) INTEGER, INTENT(IN) :: N INTEGER, DIMENSION(MAX(N,2)) :: scr ! { dg-error "Dummy argument 'n' not allowed in expression" } end FUNCTION twopointfive REAL FUNCTION three(N) INTEGER, INTENT(IN) :: N INTEGER, DIMENSION(N) :: scr ! this time it's valid END FUNCTION ELEMENTAL REAL FUNCTION four(N) INTEGER, INTENT(IN) :: N INTEGER, DIMENSION(bit_size(N)) :: scr ! another valid variant END FUNCTION ELEMENTAL REAL FUNCTION gofourit(N) INTEGER, INTENT(IN) :: N INTEGER, DIMENSION(MIN(HUGE(N),1)) :: scr ! another valid variant END FUNCTION ELEMENTAL REAL FUNCTION fourplusone(N) INTEGER, INTENT(IN) :: N INTEGER, DIMENSION(M) :: scr ! another valid variant END FUNCTION ELEMENTAL REAL FUNCTION five(X) real, intent(in) :: x CHARACTER(LEN=PRECISION(X)) :: C ! valid again END FUNCTION END MODULE END
gpl-2.0
SamKChang/abinit-7.10.5_multipole
src/67_common/extrapwf.F90
1
27822
!{\src2tex{textfont=tt}} !!****f* ABINIT/extrapwf !! !! NAME !! extrapwf !! !! FUNCTION !! Extrapolate wavefunctions for new ionic positions !! from values of wavefunctions of previous SCF cycle. !! Use algorithm proposed by T. A. Arias et al. in PRB 45, 1538 (1992) !! !! COPYRIGHT !! Copyright (C) 1998-2014 ABINIT group (MT,FJ) !! This file is distributed under the terms of the !! GNU General Public License, see ~abinit/COPYING !! or http://www.gnu.org/copyleft/gpl.txt . !! For the initials of contributors, see ~abinit/doc/developers/contributors.txt . !! !! INPUTS !! atindx(natom)=index table for atoms !! atindx1(natom)=index table for atoms, inverse of atindx !! dtset <type(dataset_type)>=all input variables in this dataset !! istep=number of call the routine !! kg(3,mpw*mkmem)=reduced planewave coordinates. !! mcg=size of wave-functions array (cg) =mpw*nspinor*mband*mkmem*nsppol !! mgfft=maximum size of 1D FFTs !! mpi_enreg=informations about MPI parallelization !! nattyp(ntypat)=number of atoms of each type in cell. !! ngfft(18)=contain all needed information about 3D FFT !! npwarr(nkpt)=number of planewaves in basis at this k point !! ntypat=number of types of atoms in cell !! pawtab(ntypat*dtset%usepaw) <type(pawtab_type)>=paw tabulated starting data !! psps<type(pseudopotential_type)>=variables related to pseudopotentials !! usepaw= 0 for non paw calculation; =1 for paw calculation !! xred_old(3,natom)=old reduced coordinates for atoms in unit cell !! ylm(mpw*mkmem,mpsang*mpsang*useylm)= real spherical harmonics for each G and k point !! !! SIDE EFFECTS !! cg(2,mcg)= plane wave wavefunction coefficient !! Value from previous SCF cycle is input !! Extrapolated value is output !! scf_history <type(scf_history_type)>=arrays obtained from previous SCF cycles !! !! PARENTS !! extraprho !! !! CHILDREN !! ctocprj,dotprod_g,getph,hermit,metric,pawcprj_alloc,pawcprj_copy !! pawcprj_destroy,pawcprj_get,pawcprj_getdim,pawcprj_lincom,pawcprj_put !! pawcprj_zaxpby,xmpi_allgather,xmpi_alltoallv,zgemm,zhpev !! !! SOURCE #if defined HAVE_CONFIG_H #include "config.h" #endif #include "abi_common.h" subroutine extrapwf(atindx,atindx1,cg,dtset,istep,kg,mcg,mgfft,mpi_enreg,& & nattyp,ngfft,npwarr,ntypat,pawtab,psps,scf_history,usepaw,xred_old,ylm) use defs_basis use defs_abitypes use m_scf_history use m_xmpi use m_wffile use m_profiling_abi use m_errors use m_cgtools use defs_datatypes, only : pseudopotential_type use m_pawtab, only : pawtab_type use m_pawcprj, only : pawcprj_type, pawcprj_alloc, pawcprj_copy, pawcprj_get, pawcprj_lincom, & & pawcprj_destroy, pawcprj_zaxpby, pawcprj_put, pawcprj_getdim !This section has been created automatically by the script Abilint (TD). !Do not modify the following lines by hand. #undef ABI_FUNC #define ABI_FUNC 'extrapwf' use interfaces_32_util use interfaces_41_geometry use interfaces_56_recipspace use interfaces_65_nonlocal !End of the abilint section implicit none !Arguments ------------------------------------ !scalars integer,intent(in) :: istep,mcg,mgfft,ntypat,usepaw type(MPI_type),intent(inout) :: mpi_enreg type(dataset_type),intent(in) :: dtset type(scf_history_type),intent(inout) :: scf_history type(pseudopotential_type),intent(in) :: psps !arrays integer,intent(in) :: atindx(dtset%natom),atindx1(dtset%natom),kg(3,dtset%mpw*dtset%mkmem),nattyp(ntypat),ngfft(18) integer,intent(in) :: npwarr(dtset%nkpt) real(dp),intent(in) :: ylm(dtset%mpw*dtset%mkmem,psps%mpsang*psps%mpsang*psps%useylm) real(dp), intent(inout) :: cg(2,mcg) real(dp),intent(in) :: xred_old(3,dtset%natom) type(pawtab_type),intent(in) :: pawtab(ntypat*usepaw) !Local variables------------------------------- !scalars integer :: ia,iat,iatom,iband_max,iband_max1,iband_min,iband_min1,ibd,ibg,iblockbd,iblockbd1,icg,icgb,icgb1,icgb2 integer :: ierr,ig,ii,ikpt,ilmn1,ilmn2,inc,ind1,ind2,iorder_cprj integer :: isize,isppol,istep1,istwf_k,itypat,klmn,me_distrb,my_nspinor integer :: nband_k,nblockbd,nprocband,npw_k,npw_nk,spaceComm_band real(dp) :: dotr,dotr1,doti,doti1,eigval !character(len=500) :: message type(wffile_type):: wffnow !arrays real(dp) :: alpha(2),beta(2),gmet(3,3),gprimd(3,3),rmet(3,3),ph1d(2,3*(2*mgfft+1)*dtset%natom),ucvol integer,allocatable :: bufsize(:),bufsize_wf(:),bufdisp(:),bufdisp_wf(:),dimcprj(:),npw_block(:),npw_disp(:) real(dp),allocatable :: al(:,:),anm(:),cwavef(:,:),cwavef1(:,:),cwavef_tmp(:,:),deltawf1(:,:),deltawf2(:,:) real(dp),allocatable :: eig(:),evec(:,:) real(dp),allocatable :: unm(:,:,:) real(dp),allocatable :: work(:,:),work1(:,:),wf1(:,:),ylmgr_k(:,:,:),zhpev1(:,:),zhpev2(:) complex(dpc),allocatable :: unm_tmp(:,:),anm_tmp(:,:) type(pawcprj_type),allocatable :: cprj(:,:),cprj_k(:,:),cprj_k1(:,:),cprj_k2(:,:),cprj_k3(:,:),cprj_k4(:,:) !complex(dpc) :: aa ! ************************************************************************* !--------------------------------------------------------------- !----------- Inits !--------------------------------------------------------------- !Compatibility tests if (istep==0) return !Useful array if (usepaw==1) then ABI_ALLOCATE(dimcprj,(dtset%natom)) call pawcprj_getdim(dimcprj,dtset%natom,nattyp,ntypat,dtset%typat,pawtab,'O') end if !History indexes ind1=1;ind2=2 my_nspinor=max(1,dtset%nspinor/mpi_enreg%nproc_spinor) !scf_history%alpha=two !scf_history%beta=-one !write(std_out,*) 'ALPHA',scf_history%alpha,scf_history%beta if (istep==1) then scf_history%cg(:,:,ind1)=cg(:,:) ! scf_history%cg(:,:,ind2)=zero scf_history%cg(:,:,ind2)= cg(:,:) if(usepaw==1) then call metric(gmet,gprimd,-1,rmet,scf_history%rprimd,ucvol) call getph(atindx,dtset%natom,ngfft(1),ngfft(2),ngfft(3),ph1d,xred_old) iatom=0 ; iorder_cprj=0 call pawcprj_alloc(scf_history%cprj(:,:,ind1),0,dimcprj) call pawcprj_alloc(scf_history%cprj(:,:,ind2),0,dimcprj) ABI_ALLOCATE(ylmgr_k,(dtset%mpw,3,0)) call ctocprj(atindx,cg,1,scf_history%cprj(:,:,ind1),gmet,gprimd,& & iatom,0,iorder_cprj,dtset%istwfk,kg,dtset%kptns,dtset%mband,mcg,scf_history%mcprj,& & dtset%mgfft,dtset%mkmem,mpi_enreg,psps%mpsang,dtset%mpw,& & dtset%natom,nattyp,dtset%nband,dtset%natom,ngfft,dtset%nkpt,& & dtset%nloalg,npwarr,dtset%nspinor,dtset%nsppol,dtset%ntypat,& & dtset%paral_kgb,ph1d,psps,rmet,dtset%typat,ucvol,0,0,0,0,& & wffnow,xred_old,ylm,ylmgr_k) ABI_DEALLOCATE(ylmgr_k) ! call pawcprj_set_zero(scf_history%cprj(:,:,ind2)) call pawcprj_copy(scf_history%cprj(:,:,ind1),scf_history%cprj(:,:,ind2)) end if return end if if (istep>=2) then ! Init parallelism me_distrb=mpi_enreg%me_kpt if (mpi_enreg%paral_kgb==1) then spaceComm_band=mpi_enreg%comm_band nprocband=mpi_enreg%nproc_band else spaceComm_band=0 nprocband=1 end if ! !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! ! for the moment sequential part only nprocband=1 ! !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! ! Additional statements if band-fft parallelism if (nprocband>1) then ABI_ALLOCATE(npw_block,(nprocband)) ABI_ALLOCATE(npw_disp,(nprocband)) ABI_ALLOCATE(bufsize,(nprocband)) ABI_ALLOCATE(bufdisp,(nprocband)) ABI_ALLOCATE(bufsize_wf,(nprocband)) ABI_ALLOCATE(bufdisp_wf,(nprocband)) end if icg=0 ibg=0 if(usepaw==1) then call metric(gmet,gprimd,-1,rmet,scf_history%rprimd,ucvol) call getph(atindx,dtset%natom,ngfft(1),ngfft(2),ngfft(3),ph1d,xred_old) ABI_DATATYPE_ALLOCATE(cprj,(dtset%natom,scf_history%mcprj)) call pawcprj_alloc(cprj,0,dimcprj) iatom=0 ; iorder_cprj=0 ABI_ALLOCATE(ylmgr_k,(dtset%mpw,3,0)) call ctocprj(atindx,cg,1,cprj,gmet,gprimd,iatom,0,iorder_cprj,& & dtset%istwfk,kg,dtset%kptns,dtset%mband,mcg,scf_history%mcprj,dtset%mgfft,& & dtset%mkmem,mpi_enreg,psps%mpsang,dtset%mpw,dtset%natom,& & nattyp,dtset%nband,dtset%natom,ngfft,dtset%nkpt,dtset%nloalg,& & npwarr,dtset%nspinor,dtset%nsppol,dtset%ntypat,dtset%paral_kgb,& & ph1d,psps,rmet,dtset%typat,ucvol,0,0,0,0,wffnow,xred_old,& & ylm,ylmgr_k) ABI_DEALLOCATE(ylmgr_k) end if ! end usepaw=1 end if ! end istep>=2 !LOOP OVER SPINS do isppol=1,dtset%nsppol ! BIG FAT k POINT LOOP do ikpt=1,dtset%nkpt ! Select k point to be treated by this proc nband_k=dtset%nband(ikpt+(isppol-1)*dtset%nkpt) if(proc_distrb_cycle(mpi_enreg%proc_distrb,ikpt,1,nband_k,isppol,me_distrb)) cycle istwf_k=dtset%istwfk(ikpt) ! Retrieve number of plane waves npw_k=npwarr(ikpt) if (nprocband>1) then ! Special treatment for band-fft // call xmpi_allgather(npw_k,npw_block,spaceComm_band,ierr) npw_nk=sum(npw_block);npw_disp(1)=0 do ii=2,nprocband npw_disp(ii)=npw_disp(ii-1)+npw_block(ii-1) end do else npw_nk=npw_k end if if(istep>=2)then ! Allocate arrays for a wave-function (or a block of WFs) ABI_ALLOCATE(cwavef,(2,npw_nk*my_nspinor)) ABI_ALLOCATE(cwavef1,(2,npw_nk*my_nspinor)) if (nprocband>1) then isize=2*my_nspinor;bufsize(:)=isize*npw_block(:);bufdisp(:)=isize*npw_disp(:) isize=2*my_nspinor*npw_k;bufsize_wf(:)=isize do ii=1,nprocband bufdisp_wf(ii)=(ii-1)*isize end do end if ! Subspace alignment ! Loop over bands or blocks of bands icgb=icg nblockbd=nband_k/nprocband if(usepaw==1) then ABI_DATATYPE_ALLOCATE( cprj_k,(dtset%natom,my_nspinor*nblockbd)) call pawcprj_alloc(cprj_k,cprj(1,1)%ncpgr,dimcprj) call pawcprj_get(atindx1,cprj_k,cprj,dtset%natom,1,ibg,ikpt,1,isppol,dtset%mband,& & dtset%mkmem,dtset%natom,nblockbd,nblockbd,my_nspinor,dtset%nsppol,0,& & mpicomm=mpi_enreg%comm_kpt,proc_distrb=mpi_enreg%proc_distrb) ABI_DATATYPE_ALLOCATE( cprj_k1,(dtset%natom,my_nspinor*nblockbd)) call pawcprj_alloc(cprj_k1,scf_history%cprj(1,1,ind1)%ncpgr,dimcprj) call pawcprj_get(atindx1,cprj_k1,scf_history%cprj(:,:,ind1),dtset%natom,1,ibg,ikpt,1,isppol,& & dtset%mband,dtset%mkmem,dtset%natom,nblockbd,nblockbd,my_nspinor,dtset%nsppol,0,& & mpicomm=mpi_enreg%comm_kpt,proc_distrb=mpi_enreg%proc_distrb) ABI_DATATYPE_ALLOCATE( cprj_k2,(dtset%natom,my_nspinor*nblockbd)) call pawcprj_alloc(cprj_k2,scf_history%cprj(1,1,ind2)%ncpgr,dimcprj) call pawcprj_get(atindx1,cprj_k2,scf_history%cprj(:,:,ind2),dtset%natom,1,ibg,ikpt,1,isppol,& & dtset%mband,dtset%mkmem,dtset%natom,nblockbd,nblockbd,my_nspinor,dtset%nsppol,0,& & mpicomm=mpi_enreg%comm_kpt,proc_distrb=mpi_enreg%proc_distrb) end if !end usepaw=1 ABI_ALLOCATE(unm,(2,nblockbd,nblockbd)) unm=zero icgb2=0 do iblockbd=1,nblockbd iband_min=1+(iblockbd-1)*nprocband iband_max=iblockbd*nprocband if(xmpi_paral==1.and.mpi_enreg%paral_kgb/=1) then if (proc_distrb_cycle(mpi_enreg%proc_distrb,ikpt,iband_min,iband_max,isppol,me_distrb)) cycle end if ! Extract wavefunction information if (nprocband>1) then ! Special treatment for band-fft // ABI_ALLOCATE(cwavef_tmp,(2,npw_k*my_nspinor*nprocband)) do ig=1,npw_k*my_nspinor*nprocband cwavef_tmp(1,ig)=cg(1,ig+icgb) cwavef_tmp(2,ig)=cg(2,ig+icgb) end do call xmpi_alltoallv(cwavef_tmp,bufsize_wf,bufdisp_wf,cwavef,bufsize,bufdisp,spaceComm_band,ierr) ABI_DEALLOCATE(cwavef_tmp) else do ig=1,npw_k*my_nspinor cwavef(1,ig)=cg(1,ig+icgb) cwavef(2,ig)=cg(2,ig+icgb) end do end if icgb1=icg do iblockbd1=1,nblockbd iband_min1=1+(iblockbd1-1)*nprocband iband_max1=iblockbd1*nprocband if(xmpi_paral==1.and.mpi_enreg%paral_kgb/=1) then if (proc_distrb_cycle(mpi_enreg%proc_distrb,ikpt,iband_min1,iband_max1,isppol,me_distrb)) cycle end if ! Extract wavefunction information if (nprocband>1) then ! Special treatment for band-fft // ABI_ALLOCATE(cwavef_tmp,(2,npw_k*my_nspinor*nprocband)) do ig=1,npw_k*my_nspinor*nprocband cwavef_tmp(1,ig)=scf_history%cg(1,ig+icgb1,ind1) cwavef_tmp(2,ig)=scf_history%cg(2,ig+icgb1,ind1) end do call xmpi_alltoallv(cwavef_tmp,bufsize_wf,bufdisp_wf,cwavef1,bufsize,bufdisp,spaceComm_band,ierr) ABI_DEALLOCATE(cwavef_tmp) else do ig=1,npw_k*my_nspinor cwavef1(1,ig)=scf_history%cg(1,ig+icgb1,ind1) cwavef1(2,ig)=scf_history%cg(2,ig+icgb1,ind1) end do end if ! Calculate Unm=<psi_nk(t)|S|psi_mk(t-dt)> call dotprod_g(dotr,doti,istwf_k,npw_k*my_nspinor,2,cwavef,cwavef1,mpi_enreg%me_g0,mpi_enreg%comm_spinorfft) if(usepaw==1) then ia =0 do itypat=1,ntypat do iat=1+ia,nattyp(itypat)+ia do ilmn1=1,pawtab(itypat)%lmn_size do ilmn2=1,ilmn1 klmn=((ilmn1-1)*ilmn1)/2+ilmn2 dotr=dotr+pawtab(itypat)%sij(klmn)*(cprj_k(iat,iblockbd)%cp(1,ilmn1)*cprj_k1(iat,iblockbd1)%cp(1,ilmn2)+& & cprj_k(iat,iblockbd)%cp(2,ilmn1)*cprj_k1(iat,iblockbd1)%cp(2,ilmn2)) doti=doti+pawtab(itypat)%sij(klmn)*(cprj_k(iat,iblockbd)%cp(1,ilmn1)*cprj_k1(iat,iblockbd1)%cp(2,ilmn2)-& & cprj_k(iat,iblockbd)%cp(2,ilmn1)*cprj_k1(iat,iblockbd1)%cp(1,ilmn2)) end do do ilmn2=ilmn1+1,pawtab(itypat)%lmn_size klmn=((ilmn2-1)*ilmn2)/2+ilmn1 dotr=dotr+pawtab(itypat)%sij(klmn)*(cprj_k(iat,iblockbd)%cp(1,ilmn1)*cprj_k1(iat,iblockbd1)%cp(1,ilmn2)+& & cprj_k(iat,iblockbd)%cp(2,ilmn1)*cprj_k1(iat,iblockbd1)%cp(2,ilmn2)) doti=doti+pawtab(itypat)%sij(klmn)*(cprj_k(iat,iblockbd)%cp(1,ilmn1)*cprj_k1(iat,iblockbd1)%cp(2,ilmn2)-& & cprj_k(iat,iblockbd)%cp(2,ilmn1)*cprj_k1(iat,iblockbd1)%cp(1,ilmn2)) end do end do end do ia=ia+nattyp(itypat) end do end if ! unm(1,iblockbd,iblockbd1)=dotr ! unm(2,iblockbd,iblockbd1)=doti unm(1,iblockbd1,iblockbd)=dotr unm(2,iblockbd1,iblockbd)=doti ! End loop over bands iblockbd1 icgb1=icgb1+npw_k*my_nspinor*nprocband end do ! End loop over bands iblockbd icgb2=icgb2+npw_k*my_nspinor*nprocband icgb=icgb+npw_k*my_nspinor*nprocband end do ! write(std_out,*) 'UNM' ! do iblockbd=1,nblockbd ! write(std_out,11) (unm(1,iblockbd,iblockbd1),unm(2,iblockbd,iblockbd1),iblockbd1=1,nblockbd) ! end do ! 11 format(12(1x,f9.5),a) ! Compute A=tU^*U ABI_ALLOCATE(unm_tmp,(nblockbd,nblockbd)) ABI_ALLOCATE(anm_tmp,(nblockbd,nblockbd)) ABI_ALLOCATE(anm,(nblockbd*(nblockbd+1))) unm_tmp(:,:)=cmplx(unm(1,:,:),unm(2,:,:),kind=dp) call zgemm('C','N',nblockbd,nblockbd,nblockbd,dcmplx(1._dp), unm_tmp,nblockbd, & & unm_tmp,nblockbd,dcmplx(0._dp),anm_tmp,nblockbd) do iblockbd=1,nblockbd do iblockbd1=iblockbd,nblockbd ii=iblockbd1*(iblockbd1-1)+2*(iblockbd-1)+1 anm(ii)=real(anm_tmp(iblockbd,iblockbd1)) anm(ii+1)=aimag(anm_tmp(iblockbd,iblockbd1)) end do end do call hermit(anm,anm,ierr,nblockbd) ! aa=dcmplx(0._dp) ! do iblockbd=1,nblockbd ! aa=aa+conjg(unm_tmp(iblockbd,1))*unm_tmp(iblockbd,1) ! end do ! write(std_out,*) 'tU*U', aa ! write(std_out,*) 'ANM_tmp' ! do iblockbd=1,nblockbd ! write(std_out,11) (anm_tmp(iblockbd,iblockbd1),iblockbd1=1,nblockbd) ! end do ! write(std_out,*) 'ANM' ! do iblockbd=1,nblockbd*(nblockbd+1) ! write(std_out,11) anm(iblockbd) ! end do ! Diagonalize A ABI_ALLOCATE(eig,(nblockbd)) ABI_ALLOCATE(evec,(2*nblockbd,nblockbd)) ABI_ALLOCATE(zhpev1,(2,2*nblockbd-1)) ABI_ALLOCATE(zhpev2,(3*nblockbd-2)) call zhpev('V','U',nblockbd,anm,eig,evec,nblockbd,zhpev1,& & zhpev2,ierr) ABI_DEALLOCATE(anm) ABI_DEALLOCATE(zhpev1) ABI_DEALLOCATE(zhpev2) ! aa=dcmplx(0._dp) ! do iblockbd=1,nblockbd ! aa=aa+anm_tmp(1,iblockbd)*cmplx(evec((2*iblockbd-1),1),evec(2*iblockbd,1),kind=dp) ! end do ! write(std_out,*) 'EIG', aa, eig(1)*evec(1,1),eig(1)*evec(2,1) ! Compute A'=evec*tU^/sqrt(eig) call zgemm('C','C',nblockbd,nblockbd,nblockbd,dcmplx(1._dp),evec,nblockbd, & & unm_tmp,nblockbd,dcmplx(0._dp),anm_tmp,nblockbd) do iblockbd=1,nblockbd eigval=dsqrt(eig(iblockbd)) do iblockbd1=1,nblockbd anm_tmp(iblockbd,iblockbd1)=anm_tmp(iblockbd,iblockbd1)/eigval end do end do ! Compute tA^A'to come back to the initial subspace for the cg's call zgemm('N','N',nblockbd,nblockbd,nblockbd,dcmplx(1._dp),evec,nblockbd, & & anm_tmp,nblockbd,dcmplx(0._dp),unm_tmp,nblockbd) anm_tmp=unm_tmp ! write(std_out,*) 'ANM_tmp' ! do iblockbd=1,nblockbd ! write(std_out,11) (anm_tmp(iblockbd,iblockbd1),iblockbd1=1,nblockbd) ! end do ! Wavefunction alignment (istwfk=1 ?) ABI_ALLOCATE(work,(2,npw_nk*my_nspinor*nblockbd)) ABI_ALLOCATE(work1,(2,my_nspinor*nblockbd*npw_nk)) work1(:,:)=scf_history%cg(:,icg+1:icg+my_nspinor*nblockbd*npw_nk,ind1) call zgemm('N','N',npw_nk*my_nspinor,nblockbd,nblockbd,dcmplx(1._dp), & & work1,npw_nk*my_nspinor, & & anm_tmp,nblockbd,dcmplx(0._dp),work,npw_nk*my_nspinor) scf_history%cg(:,1+icg:npw_nk*my_nspinor*nblockbd+icg,ind1)=work(:,:) work1(:,:)=scf_history%cg(:,icg+1:icg+my_nspinor*nblockbd*npw_nk,ind2) call zgemm('N','N',npw_nk*my_nspinor,nblockbd,nblockbd,dcmplx(1._dp), & & work1,npw_nk*my_nspinor, & & anm_tmp,nblockbd,dcmplx(0._dp),work,npw_nk*my_nspinor) scf_history%cg(:,1+icg:npw_nk*my_nspinor*nblockbd+icg,ind2)=work(:,:) ABI_DEALLOCATE(work1) ! If paw, musb also align cprj: if (usepaw==1) then ! New version (MT): ABI_DATATYPE_ALLOCATE(cprj_k3,(dtset%natom,my_nspinor)) ABI_DATATYPE_ALLOCATE(cprj_k4,(dtset%natom,my_nspinor)) call pawcprj_alloc(cprj_k3,cprj_k1(1,1)%ncpgr,dimcprj) call pawcprj_alloc(cprj_k4,cprj_k2(1,1)%ncpgr,dimcprj) ABI_ALLOCATE(al,(2,nblockbd)) do iblockbd=1,nblockbd ii=(iblockbd-1)*my_nspinor do iblockbd1=1,nblockbd al(1,iblockbd1)=real (anm_tmp(iblockbd,iblockbd1)) al(2,iblockbd1)=aimag(anm_tmp(iblockbd,iblockbd1)) end do call pawcprj_lincom(al,cprj_k3,cprj_k1,nblockbd) call pawcprj_lincom(al,cprj_k4,cprj_k2,nblockbd) call pawcprj_copy(cprj_k3,cprj_k1(:,ii+1:ii+my_nspinor)) call pawcprj_copy(cprj_k4,cprj_k2(:,ii+1:ii+my_nspinor)) end do ABI_DEALLOCATE(al) ! Old version (FJ): ! allocate( cprj_k3(dtset%natom,my_nspinor*nblockbd)) ! call pawcprj_alloc(cprj_k3,cprj_k1(1,1)%ncpgr,dimcprj) ! allocate( cprj_k4(dtset%natom,my_nspinor*nblockbd)) ! call pawcprj_alloc(cprj_k4,cprj_k2(1,1)%ncpgr,dimcprj) ! beta(1)=one;beta(2)=zero ! do iblockbd=1,nblockbd*my_nspinor ! do iblockbd1=1,nblockbd*my_nspinor ! alpha(1)=real(anm_tmp(iblockbd,iblockbd1));alpha(2)=aimag(anm_tmp(iblockbd,iblockbd1)) ! call pawcprj_zaxpby(alpha,beta,cprj_k1(:,iblockbd1:iblockbd1),cprj_k3(:,iblockbd:iblockbd)) ! call pawcprj_zaxpby(alpha,beta,cprj_k2(:,iblockbd1:iblockbd1),cprj_k4(:,iblockbd:iblockbd)) ! end do ! end do ! call pawcprj_copy(cprj_k3,cprj_k1) ! call pawcprj_copy(cprj_k4,cprj_k2) call pawcprj_destroy(cprj_k3) call pawcprj_destroy(cprj_k4) ABI_DATATYPE_DEALLOCATE(cprj_k3) ABI_DATATYPE_DEALLOCATE(cprj_k4) end if ABI_DEALLOCATE(anm_tmp) ABI_DEALLOCATE(unm_tmp) ABI_DEALLOCATE(work) end if ! end istep>=2 ! Wavefunction extrapolation ibd=0 inc=npw_nk*my_nspinor ABI_ALLOCATE(deltawf2,(2,npw_nk*my_nspinor)) ABI_ALLOCATE(wf1,(2,npw_nk*my_nspinor)) ABI_ALLOCATE(deltawf1,(2,npw_nk*my_nspinor)) do iblockbd=1,nblockbd deltawf2(:,:)=scf_history%cg(:,1+icg+ibd:icg+ibd+inc,ind2) wf1(:,:)=scf_history%cg(:,1+icg+ibd:icg+ibd+inc,ind1) ! wf1(2,1)=zero;deltawf2(2,1)=zero if (istep>=2) then call dotprod_g(dotr,doti,istwf_k,npw_nk*my_nspinor,2,cg(:,icg+1+ibd:ibd+icg+inc),cg(:,icg+1+ibd:ibd+icg+inc),& & mpi_enreg%me_g0,mpi_enreg%comm_spinorfft) call dotprod_g(dotr1,doti1,istwf_k,npw_nk*my_nspinor,2,cg(:,icg+1+ibd:ibd+icg+inc),wf1,& & mpi_enreg%me_g0,mpi_enreg%comm_spinorfft) if(usepaw==1) then ia =0 do itypat=1,ntypat do iat=1+ia,nattyp(itypat)+ia do ilmn1=1,pawtab(itypat)%lmn_size do ilmn2=1,ilmn1 klmn=((ilmn1-1)*ilmn1)/2+ilmn2 dotr=dotr+pawtab(itypat)%sij(klmn)*(cprj_k(iat,iblockbd)%cp(1,ilmn1)*cprj_k(iat,iblockbd)%cp(1,ilmn2)+& & cprj_k(iat,iblockbd)%cp(2,ilmn1)*cprj_k(iat,iblockbd)%cp(2,ilmn2)) doti=doti+pawtab(itypat)%sij(klmn)*(cprj_k(iat,iblockbd)%cp(1,ilmn1)*cprj_k(iat,iblockbd)%cp(2,ilmn2)-& & cprj_k(iat,iblockbd)%cp(2,ilmn1)*cprj_k(iat,iblockbd)%cp(1,ilmn2)) dotr1=dotr1+pawtab(itypat)%sij(klmn)*(cprj_k(iat,iblockbd)%cp(1,ilmn1)*cprj_k1(iat,iblockbd)%cp(1,ilmn2)+& & cprj_k(iat,iblockbd)%cp(2,ilmn1)*cprj_k1(iat,iblockbd)%cp(2,ilmn2)) doti1=doti1+pawtab(itypat)%sij(klmn)*(cprj_k(iat,iblockbd)%cp(1,ilmn1)*cprj_k1(iat,iblockbd)%cp(2,ilmn2)-& & cprj_k(iat,iblockbd)%cp(2,ilmn1)*cprj_k1(iat,iblockbd)%cp(1,ilmn2)) end do do ilmn2=ilmn1+1,pawtab(itypat)%lmn_size klmn=((ilmn2-1)*ilmn2)/2+ilmn1 dotr=dotr+pawtab(itypat)%sij(klmn)*(cprj_k(iat,iblockbd)%cp(1,ilmn1)*cprj_k(iat,iblockbd)%cp(1,ilmn2)+& & cprj_k(iat,iblockbd)%cp(2,ilmn1)*cprj_k(iat,iblockbd)%cp(2,ilmn2)) doti=doti+pawtab(itypat)%sij(klmn)*(cprj_k(iat,iblockbd)%cp(1,ilmn1)*cprj_k(iat,iblockbd)%cp(2,ilmn2)-& & cprj_k(iat,iblockbd)%cp(2,ilmn1)*cprj_k(iat,iblockbd)%cp(1,ilmn2)) dotr1=dotr1+pawtab(itypat)%sij(klmn)*(cprj_k(iat,iblockbd)%cp(1,ilmn1)*cprj_k1(iat,iblockbd)%cp(1,ilmn2)+& & cprj_k(iat,iblockbd)%cp(2,ilmn1)*cprj_k1(iat,iblockbd)%cp(2,ilmn2)) doti1=doti1+pawtab(itypat)%sij(klmn)*(cprj_k(iat,iblockbd)%cp(1,ilmn1)*cprj_k1(iat,iblockbd)%cp(2,ilmn2)-& & cprj_k(iat,iblockbd)%cp(2,ilmn1)*cprj_k1(iat,iblockbd)%cp(1,ilmn2)) end do end do end do ia=ia+nattyp(itypat) end do end if dotr=sqrt(dotr**2+doti**2) dotr1=sqrt(dotr1**2+doti1**2) write(std_out,*)'DOTR, DOTR1',dotr,dotr1 dotr=dotr1/dotr write(std_out,*)'DOTR',dotr deltawf1=zero if(dotr>=0.9d0) then deltawf1(:,:)=cg(:,icg+1+ibd:ibd+icg+inc)-wf1(:,:) if(usepaw==1) then alpha(1)=one;alpha(2)=zero beta(1)=-one;beta(2)=zero ia =0 call pawcprj_zaxpby(alpha,beta,cprj_k(:,iblockbd:iblockbd),cprj_k1(:,iblockbd:iblockbd)) end if istep1=istep else istep1=1 end if end if scf_history%cg(:,1+icg+ibd:icg+ibd+inc,ind1)=cg(:,icg+1+ibd:ibd+icg+inc) scf_history%cg(:,1+icg+ibd:icg+ibd+inc,ind2)=deltawf1(:,:) if(usepaw==1) then call pawcprj_put(atindx1,cprj_k,scf_history%cprj(:,:,ind1),dtset%natom,1,ibg,ikpt,1,isppol,& & dtset%mband,dtset%mkmem,dtset%natom,nblockbd,nblockbd,dimcprj,my_nspinor,dtset%nsppol,0,& & mpicomm=mpi_enreg%comm_kpt,mpi_comm_band=spaceComm_band,proc_distrb=mpi_enreg%proc_distrb) call pawcprj_put(atindx1,cprj_k1,scf_history%cprj(:,:,ind2),dtset%natom,1,ibg,ikpt,1,isppol,& & dtset%mband,dtset%mkmem,dtset%natom,nblockbd,nblockbd,dimcprj,my_nspinor,dtset%nsppol,0,& & mpicomm=mpi_enreg%comm_kpt,mpi_comm_band=spaceComm_band,proc_distrb=mpi_enreg%proc_distrb) end if ! if(istep1>=3) then cg(:,icg+1+ibd:ibd+icg+inc)=cg(:,icg+1+ibd:ibd+icg+inc)+scf_history%alpha*deltawf1(:,:)+scf_history%beta*deltawf2(:,:) ! to be used later ! if(usepaw==1) then ! alpha(2)=zero ! beta(1)=one;beta(2)=zero ! alpha(1)=scf_history%alpha ! call pawcprj_zaxpby(alpha,beta,cprj_k1(:,iblockbd:iblockbd),cprj_k(:,iblockbd:iblockbd)) ! alpha(1)=scf_history%beta ! call pawcprj_zaxpby(alpha,beta,cprj_k2(:,iblockbd:iblockbd),cprj_k(:,iblockbd:iblockbd)) ! call pawcprj_put(atindx1,cprj_k,cprj,dtset%natom,1,ibg,ikpt,1,isppol,& ! & dtset%mband,dtset%mkmem,dtset%natom,nblockbd,nblockbd,dimcprj,my_nspinor,dtset%nsppol,0,& ! & mpicomm=mpi_enreg%comm_kpt,mpi_comm_band=spaceComm_band,proc_distrb=mpi_enreg%proc_distrb) ! end if ! else if (istep1==2) then ! cg(:,icg+1+ibd:ibd+icg+inc)=cg(:,icg+1+ibd:ibd+icg+inc)+scf_history%alpha*deltawf1(:,:)+scf_history%beta*wf1(:,:) ! ! cg(:,icg+1+ibd:ibd+icg+inc)=cg(:,icg+1+ibd:ibd+icg+inc)+deltawf1(:,:) ! if(usepaw==1) then ! alpha(2)=zero ! beta(1)=one;beta(2)=zero ! alpha(1)=scf_history%alpha ! call pawcprj_zaxpby(alpha,beta,cprj_k1(:,iblockbd:iblockbd),cprj_k(:,iblockbd:iblockbd)) ! alpha(1)=scf_history%beta ! call pawcprj_zaxpby(alpha,beta,cprj_k2(:,iblockbd:iblockbd),cprj_k(:,iblockbd:iblockbd)) ! call pawcprj_put(atindx1,cprj_k,cprj,dtset%natom,1,ibg,ikpt,1,isppol,& ! & dtset%mband,dtset%mkmem,dtset%natom,nblockbd,nblockbd,dimcprj,my_nspinor,dtset%nsppol,0,& ! & mpicomm=mpi_enreg%comm_kpt,mpi_comm_band=spaceComm_band,proc_distrb=mpi_enreg%proc_distrb) ! end if ! end if ibd=ibd+inc end do ! end loop on iblockbd ABI_DEALLOCATE(deltawf1) ABI_DEALLOCATE(deltawf2) ABI_DEALLOCATE(wf1) if (istep>=2) then ABI_DEALLOCATE(cwavef) ABI_DEALLOCATE(cwavef1) ABI_DEALLOCATE(eig) ABI_DEALLOCATE(evec) ABI_DEALLOCATE(unm) if(usepaw==1) then call pawcprj_destroy(cprj_k) ABI_DATATYPE_DEALLOCATE(cprj_k) call pawcprj_destroy(cprj_k1) ABI_DATATYPE_DEALLOCATE(cprj_k1) call pawcprj_destroy(cprj_k2) ABI_DATATYPE_DEALLOCATE(cprj_k2) end if end if ibg=ibg+my_nspinor*nband_k icg=icg+my_nspinor*nband_k*npw_k ! End big k point loop end do ! End loop over spins end do if (usepaw==1) then ABI_DEALLOCATE(dimcprj) end if if (istep>=2) then if(usepaw==1) then call pawcprj_destroy(cprj) ABI_DATATYPE_DEALLOCATE(cprj) end if if (nprocband>1) then ABI_DEALLOCATE(npw_block) ABI_DEALLOCATE(npw_disp) ABI_DEALLOCATE(bufsize) ABI_DEALLOCATE(bufdisp) ABI_DEALLOCATE(bufsize_wf) ABI_DEALLOCATE(bufdisp_wf) end if end if end subroutine extrapwf !!***
gpl-3.0
SamKChang/abinit-7.10.5_multipole
src/72_response/redgr.F90
1
4588
!{\src2tex{textfont=tt}} !!****f* ABINIT/redgr !! NAME !! redgr !! !! FUNCTION !! Compute reduced gradients of a real function on the usual unshifted !! fft grid. The gradient directions are the along the primitive !! reciprocal lattice vectors. !! The input function is intended to be a single spin component of !! the valence charge density, the valence + core charge densities !! or the first-order core charge density for use in frozen wf !! elastic tensor calculations within the GGA. !! !! NOTES !! Closely linked to xcden, but limited to Q=0, real charge densities, !! and unshifted grids. !! !! COPYRIGHT !! Copyright (C) 1998-2014 ABINIT group (DRH, DCA, XG, GMR) !! This file is distributed under the terms of the !! GNU General Public License, see ~abinit/COPYING !! or http://www.gnu.org/copyleft/gpl.txt . !! For the initials of contributors, see ~abinit/doc/developers/contributors.txt . !! !! INPUTS !! mpi_enreg=informations about MPI parallelization !! nfft=(effective) number of FFT grid points (for this processor) !! ngfft(18)=contain all needed information about 3D FFT, !! see ~abinit/doc/input_variables/vargs.htm#ngfft !! frin(nfft)=real space input function !! !! OUTPUT !! frredgr(nfft,3)= reduced gradient of input function (same units as frin) !! !! PARENTS !! eltfrxc3 !! !! CHILDREN !! fourdp,timab !! !! SOURCE #if defined HAVE_CONFIG_H #include "config.h" #endif #include "abi_common.h" subroutine redgr (frin,frredgr,mpi_enreg,nfft,ngfft,paral_kgb) use defs_basis use defs_abitypes use m_profiling_abi !This section has been created automatically by the script Abilint (TD). !Do not modify the following lines by hand. #undef ABI_FUNC #define ABI_FUNC 'redgr' use interfaces_18_timing use interfaces_53_ffts !End of the abilint section implicit none !Arguments ------------------------------------ !scalars integer,intent(in) :: nfft,paral_kgb type(MPI_type) :: mpi_enreg !arrays integer,intent(in) :: ngfft(18) real(dp),intent(in) :: frin(nfft) real(dp),intent(out) :: frredgr(nfft,3) !Local variables------------------------------- !scalars integer :: cplex_tmp,i1,i2,i3,id,idir,ifft,ig,ii,ing,n1,n2,n3 !arrays real(dp) :: tsec(2) real(dp),allocatable :: gg(:,:),wkcmpx(:,:),work(:),workgr(:,:) ! ************************************************************************* !Only real arrays are treated cplex_tmp=1 !Keep local copy of fft dimensions n1=ngfft(1) ; n2=ngfft(2) ; n3=ngfft(3) !In order to speed the routine, precompute the components of g, including 2pi factor ABI_ALLOCATE(gg,(max(n1,n2,n3),3)) do ii=1,3 id=ngfft(ii)/2+2 do ing=1,ngfft(ii) ig=ing-(ing/id)*ngfft(ii)-1 gg(ing,ii)=two_pi*ig end do ! Note that the G <-> -G symmetry must be maintained if(mod(ngfft(ii),2)==0)gg(ngfft(ii)/2+1,ii)=zero end do ABI_ALLOCATE(wkcmpx,(2,nfft)) ABI_ALLOCATE(work,(nfft)) ABI_ALLOCATE(workgr,(2,nfft)) !Obtain rho(G) in wkcmpx from input rho(r) work(:)=frin(:) call timab(82,1,tsec) call fourdp(cplex_tmp,wkcmpx,work,-1,mpi_enreg,nfft,ngfft,paral_kgb,0) call timab(82,2,tsec) !Gradient calculation for three reduced components in turn. !Code duplicated to remove logic from loops. do idir=1,3 if(idir==1) then !$OMP PARALLEL DO PRIVATE(ifft) do i3=1,n3 ifft=(i3-1)*n1*n2 do i2=1,n2 do i1=1,n1 ifft=ifft+1 ! Multiply by i 2pi G(idir) workgr(2,ifft)= gg(i1,idir)*wkcmpx(1,ifft) workgr(1,ifft)=-gg(i1,idir)*wkcmpx(2,ifft) end do end do end do else if(idir==2) then !$OMP PARALLEL DO PRIVATE(ifft) do i3=1,n3 ifft=(i3-1)*n1*n2 do i2=1,n2 do i1=1,n1 ifft=ifft+1 ! Multiply by i 2pi G(idir) workgr(2,ifft)= gg(i2,idir)*wkcmpx(1,ifft) workgr(1,ifft)=-gg(i2,idir)*wkcmpx(2,ifft) end do end do end do else !$OMP PARALLEL DO PRIVATE(ifft) do i3=1,n3 ifft=(i3-1)*n1*n2 do i2=1,n2 do i1=1,n1 ifft=ifft+1 ! Multiply by i 2pi G(idir) workgr(2,ifft)= gg(i3,idir)*wkcmpx(1,ifft) workgr(1,ifft)=-gg(i3,idir)*wkcmpx(2,ifft) end do end do end do end if !idir call timab(82,1,tsec) call fourdp(cplex_tmp,workgr,work,1,mpi_enreg,nfft,ngfft,paral_kgb,0) call timab(82,2,tsec) !$OMP PARALLEL DO do ifft=1,nfft frredgr(ifft,idir)=work(ifft) end do end do !idir ABI_DEALLOCATE(gg) ABI_DEALLOCATE(wkcmpx) ABI_DEALLOCATE(work) ABI_DEALLOCATE(workgr) end subroutine redgr !!***
gpl-3.0
sungsujo/nacl-llvm-branches.llvm-gcc-trunk
gcc/testsuite/gfortran.dg/used_dummy_types_6.f90
52
1422
! { dg-do compile } ! Tests the fix for PR30554, the USE statements in potential_energy ! would cause a segfault because the pointer_info for nfree coming ! from constraint would not find the existing symtree coming directly ! from atom. ! ! The last two modules came up subsequently to the original fix. The ! PRIVATE statement caused a revival of the original problem. This ! was tracked down to an interaction between the symbols being set ! referenced during module read and the application of the access ! attribute. ! ! Contributed by Tobias Burnus <burnus@gcc.gnu.org> MODULE ATOMS INTEGER :: NFREE = 0 END MODULE ATOMS MODULE CONSTRAINT USE ATOMS, ONLY: NFREE CONTAINS SUBROUTINE ENERGY_CONSTRAINT ( HESSIAN ) REAL , DIMENSION(1:(3*NFREE*(3*NFREE+1))/2):: HESSIAN END SUBROUTINE ENERGY_CONSTRAINT END MODULE CONSTRAINT MODULE POTENTIAL_ENERGY USE ATOMS USE CONSTRAINT, ONLY : ENERGY_CONSTRAINT END MODULE POTENTIAL_ENERGY MODULE P_CONSTRAINT USE ATOMS, ONLY: NFREE PRIVATE PUBLIC :: ENERGY_CONSTRAINT CONTAINS SUBROUTINE ENERGY_CONSTRAINT ( HESSIAN ) REAL , DIMENSION(1:(3*NFREE*(3*NFREE+1))/2):: HESSIAN END SUBROUTINE ENERGY_CONSTRAINT END MODULE P_CONSTRAINT MODULE P_POTENTIAL_ENERGY USE ATOMS USE CONSTRAINT, ONLY : ENERGY_CONSTRAINT END MODULE P_POTENTIAL_ENERGY ! { dg-final { cleanup-modules "atoms constraint potential_energy p_constraint p_potential_energy" } }
gpl-2.0
doslab/gcc-designated-initializer-support-cpp
gcc/testsuite/gfortran.dg/used_dummy_types_6.f90
52
1422
! { dg-do compile } ! Tests the fix for PR30554, the USE statements in potential_energy ! would cause a segfault because the pointer_info for nfree coming ! from constraint would not find the existing symtree coming directly ! from atom. ! ! The last two modules came up subsequently to the original fix. The ! PRIVATE statement caused a revival of the original problem. This ! was tracked down to an interaction between the symbols being set ! referenced during module read and the application of the access ! attribute. ! ! Contributed by Tobias Burnus <burnus@gcc.gnu.org> MODULE ATOMS INTEGER :: NFREE = 0 END MODULE ATOMS MODULE CONSTRAINT USE ATOMS, ONLY: NFREE CONTAINS SUBROUTINE ENERGY_CONSTRAINT ( HESSIAN ) REAL , DIMENSION(1:(3*NFREE*(3*NFREE+1))/2):: HESSIAN END SUBROUTINE ENERGY_CONSTRAINT END MODULE CONSTRAINT MODULE POTENTIAL_ENERGY USE ATOMS USE CONSTRAINT, ONLY : ENERGY_CONSTRAINT END MODULE POTENTIAL_ENERGY MODULE P_CONSTRAINT USE ATOMS, ONLY: NFREE PRIVATE PUBLIC :: ENERGY_CONSTRAINT CONTAINS SUBROUTINE ENERGY_CONSTRAINT ( HESSIAN ) REAL , DIMENSION(1:(3*NFREE*(3*NFREE+1))/2):: HESSIAN END SUBROUTINE ENERGY_CONSTRAINT END MODULE P_CONSTRAINT MODULE P_POTENTIAL_ENERGY USE ATOMS USE CONSTRAINT, ONLY : ENERGY_CONSTRAINT END MODULE P_POTENTIAL_ENERGY ! { dg-final { cleanup-modules "atoms constraint potential_energy p_constraint p_potential_energy" } }
gpl-2.0
qsnake/abinit
src/77_suscep/getlambda.F90
1
3726
!{\src2tex{textfont=tt}} !!****f* ABINIT/getlambda !! NAME !! getlambda !! !! FUNCTION !! Return the abcissas and weights for the coupling constant integration. !! !! COPYRIGHT !! Copyright (C) 1998-2012 ABINIT group (DCA, MF, XG, GMR, LSI, YMN). !! This file is distributed under the terms of the !! GNU General Public License,see ~abinit/COPYING !! or http://www.gnu.org/copyleft/gpl.txt . !! For the initials of contributors,see ~abinit/doc/developers/contributors.txt. !! !! INPUTS !! idyson = 1 solve the Dyson equation as linear system. !! (Gauss-Legendre mesh for the coupling constant integration). !! = 2 solve the Dyson equation as a differential equation !! (linear mesh for the coupling constant integration). !! = 3 solve the Dyson equation iteratively. !! (Gauss-Legendre mesh for the coupling constant integration). !! nlambda = number of mesh points. !! !! OUTPUT !! lambda(nlambda) = abscissas for the coupling constant integration. !! weight(nlambda) = weights for the coupling constant integration. !! !! SIDE EFFECTS !! !! WARNINGS !! !! TODO !! !! PARENTS !! acfd_dyson !! !! CHILDREN !! coeffs_gausslegint,leave_new,wrtout !! !! SOURCE #if defined HAVE_CONFIG_H #include "config.h" #endif #include "abi_common.h" subroutine getlambda(idyson,lambda,nlambda,weight) use m_profiling use defs_basis !This section has been created automatically by the script Abilint (TD). !Do not modify the following lines by hand. #undef ABI_FUNC #define ABI_FUNC 'getlambda' use interfaces_14_hidewrite use interfaces_16_hideleave use interfaces_28_numeric_noabirule !End of the abilint section implicit none !Arguments ------------------------------------------------------------- !scalars integer,intent(in) :: idyson,nlambda !arrays real(dp),intent(out) :: lambda(nlambda),weight(nlambda) !Local variables ------------------------------------------------------- !WARNING : This should be moved to a def_* file ! !scalars integer,parameter :: solve_DE=2 integer :: ii real(dp),parameter :: lambda_max=1._dp real(dp) :: lambda_step character(len=500) :: message !*********************************************************************** !Check input parameters. if (nlambda < 1) then write (message,'(4a)') ch10,& & ' getlambda: BUG - ',ch10,& & ' nlambda (number of points for the coupling constant integration) must be >= 2.' call wrtout(ab_out,message,'COLL') call wrtout(std_out,message,'COLL') call leave_new('COLL') end if !Calculate abscissas and weights. lambda(1) = 0._dp; weight(1) = 0.5_dp lambda(nlambda) = lambda_max; weight(nlambda) = 0.5_dp if (nlambda > 2) then if (idyson == solve_DE) then ! Linear mesh for the leap-frog solution of the Dyson equation. lambda_step = 1._dp/(nlambda-1) if (mod(nlambda,2) == 0) then ! Trapezoidal rule for an even number of supports. do ii = 1,nlambda weight(ii) = lambda_step lambda(ii) = (ii-1)*lambda_step end do weight(1) = 0.5_dp*lambda_step weight(nlambda) = 0.5_dp*lambda_step else ! Simpson rule for an odd number of supports. do ii = 1,nlambda lambda(ii) = (ii-1)*lambda_step weight(ii) = lambda_step/3._dp end do do ii = 2,nlambda-1,2 weight(ii) = 4._dp*weight(ii) end do do ii = 3,nlambda-1,2 weight(ii) = 2._dp*weight(ii) end do end if else ! Gauss-Legendre quadrature. call coeffs_gausslegint(0._dp,1._dp,lambda(2),weight(2),nlambda-2) weight(1) = 0._dp; weight(nlambda) = 0._dp end if end if end subroutine getlambda !!***
gpl-3.0
jamestwebber/scipy
scipy/sparse/linalg/eigen/arpack/ARPACK/SRC/cnapps.f
38
17542
c\BeginDoc c c\Name: cnapps c c\Description: c Given the Arnoldi factorization c c A*V_{k} - V_{k}*H_{k} = r_{k+p}*e_{k+p}^T, c c apply NP implicit shifts resulting in c c A*(V_{k}*Q) - (V_{k}*Q)*(Q^T* H_{k}*Q) = r_{k+p}*e_{k+p}^T * Q c c where Q is an orthogonal matrix which is the product of rotations c and reflections resulting from the NP bulge change sweeps. c The updated Arnoldi factorization becomes: c c A*VNEW_{k} - VNEW_{k}*HNEW_{k} = rnew_{k}*e_{k}^T. c c\Usage: c call cnapps c ( N, KEV, NP, SHIFT, V, LDV, H, LDH, RESID, Q, LDQ, c WORKL, WORKD ) c c\Arguments c N Integer. (INPUT) c Problem size, i.e. size of matrix A. c c KEV Integer. (INPUT/OUTPUT) c KEV+NP is the size of the input matrix H. c KEV is the size of the updated matrix HNEW. c c NP Integer. (INPUT) c Number of implicit shifts to be applied. c c SHIFT Complex array of length NP. (INPUT) c The shifts to be applied. c c V Complex N by (KEV+NP) array. (INPUT/OUTPUT) c On INPUT, V contains the current KEV+NP Arnoldi vectors. c On OUTPUT, V contains the updated KEV Arnoldi vectors c in the first KEV columns of V. c c LDV Integer. (INPUT) c Leading dimension of V exactly as declared in the calling c program. c c H Complex (KEV+NP) by (KEV+NP) array. (INPUT/OUTPUT) c On INPUT, H contains the current KEV+NP by KEV+NP upper c Hessenberg matrix of the Arnoldi factorization. c On OUTPUT, H contains the updated KEV by KEV upper Hessenberg c matrix in the KEV leading submatrix. c c LDH Integer. (INPUT) c Leading dimension of H exactly as declared in the calling c program. c c RESID Complex array of length N. (INPUT/OUTPUT) c On INPUT, RESID contains the the residual vector r_{k+p}. c On OUTPUT, RESID is the update residual vector rnew_{k} c in the first KEV locations. c c Q Complex KEV+NP by KEV+NP work array. (WORKSPACE) c Work array used to accumulate the rotations and reflections c during the bulge chase sweep. c c LDQ Integer. (INPUT) c Leading dimension of Q exactly as declared in the calling c program. c c WORKL Complex work array of length (KEV+NP). (WORKSPACE) c Private (replicated) array on each PE or array allocated on c the front end. c c WORKD Complex work array of length 2*N. (WORKSPACE) c Distributed array used in the application of the accumulated c orthogonal matrix Q. c c\EndDoc c c----------------------------------------------------------------------- c c\BeginLib c c\Local variables: c xxxxxx Complex c c\References: c 1. D.C. Sorensen, "Implicit Application of Polynomial Filters in c a k-Step Arnoldi Method", SIAM J. Matr. Anal. Apps., 13 (1992), c pp 357-385. c c\Routines called: c ivout ARPACK utility routine that prints integers. c arscnd ARPACK utility routine for timing. c cmout ARPACK utility routine that prints matrices c cvout ARPACK utility routine that prints vectors. c clacpy LAPACK matrix copy routine. c clanhs LAPACK routine that computes various norms of a matrix. c clartg LAPACK Givens rotation construction routine. c claset LAPACK matrix initialization routine. c slabad LAPACK routine for defining the underflow and overflow c limits. c slamch LAPACK routine that determines machine constants. c slapy2 LAPACK routine to compute sqrt(x**2+y**2) carefully. c cgemv Level 2 BLAS routine for matrix vector multiplication. c caxpy Level 1 BLAS that computes a vector triad. c ccopy Level 1 BLAS that copies one vector to another. c cscal Level 1 BLAS that scales a vector. c c\Author c Danny Sorensen Phuong Vu c Richard Lehoucq CRPC / Rice University c Dept. of Computational & Houston, Texas c Applied Mathematics c Rice University c Houston, Texas c c\SCCS Information: @(#) c FILE: napps.F SID: 2.3 DATE OF SID: 3/28/97 RELEASE: 2 c c\Remarks c 1. In this version, each shift is applied to all the sublocks of c the Hessenberg matrix H and not just to the submatrix that it c comes from. Deflation as in LAPACK routine clahqr (QR algorithm c for upper Hessenberg matrices ) is used. c Upon output, the subdiagonals of H are enforced to be non-negative c real numbers. c c\EndLib c c----------------------------------------------------------------------- c subroutine cnapps & ( n, kev, np, shift, v, ldv, h, ldh, resid, q, ldq, & workl, workd ) c c %----------------------------------------------------% c | Include files for debugging and timing information | c %----------------------------------------------------% c include 'debug.h' include 'stat.h' c c %------------------% c | Scalar Arguments | c %------------------% c integer kev, ldh, ldq, ldv, n, np c c %-----------------% c | Array Arguments | c %-----------------% c Complex & h(ldh,kev+np), resid(n), shift(np), & v(ldv,kev+np), q(ldq,kev+np), workd(2*n), workl(kev+np) c c %------------% c | Parameters | c %------------% c Complex & one, zero Real & rzero parameter (one = (1.0E+0, 0.0E+0), zero = (0.0E+0, 0.0E+0), & rzero = 0.0E+0) c c %------------------------% c | Local Scalars & Arrays | c %------------------------% c integer i, iend, istart, j, jj, kplusp, msglvl logical first Complex & cdum, f, g, h11, h21, r, s, sigma, t Real & c, ovfl, smlnum, ulp, unfl, tst1 save first, ovfl, smlnum, ulp, unfl c c %----------------------% c | External Subroutines | c %----------------------% c external caxpy, ccopy, cgemv, cscal, clacpy, clartg, & cvout, claset, slabad, cmout, arscnd, ivout c c %--------------------% c | External Functions | c %--------------------% c Real & clanhs, slamch, slapy2 external clanhs, slamch, slapy2 c c %----------------------% c | Intrinsics Functions | c %----------------------% c intrinsic abs, aimag, conjg, cmplx, max, min, real c c %---------------------% c | Statement Functions | c %---------------------% c Real & cabs1 cabs1( cdum ) = abs( real( cdum ) ) + abs( aimag( cdum ) ) c c %----------------% c | Data statments | c %----------------% c data first / .true. / c c %-----------------------% c | Executable Statements | c %-----------------------% c if (first) then c c %-----------------------------------------------% c | Set machine-dependent constants for the | c | stopping criterion. If norm(H) <= sqrt(OVFL), | c | overflow should not occur. | c | REFERENCE: LAPACK subroutine clahqr | c %-----------------------------------------------% c unfl = slamch( 'safe minimum' ) ovfl = real(one / unfl) call slabad( unfl, ovfl ) ulp = slamch( 'precision' ) smlnum = unfl*( n / ulp ) first = .false. end if c c %-------------------------------% c | Initialize timing statistics | c | & message level for debugging | c %-------------------------------% c call arscnd (t0) msglvl = mcapps c kplusp = kev + np c c %--------------------------------------------% c | Initialize Q to the identity to accumulate | c | the rotations and reflections | c %--------------------------------------------% c call claset ('All', kplusp, kplusp, zero, one, q, ldq) c c %----------------------------------------------% c | Quick return if there are no shifts to apply | c %----------------------------------------------% c if (np .eq. 0) go to 9000 c c %----------------------------------------------% c | Chase the bulge with the application of each | c | implicit shift. Each shift is applied to the | c | whole matrix including each block. | c %----------------------------------------------% c do 110 jj = 1, np sigma = shift(jj) c if (msglvl .gt. 2 ) then call ivout (logfil, 1, jj, ndigit, & '_napps: shift number.') call cvout (logfil, 1, sigma, ndigit, & '_napps: Value of the shift ') end if c istart = 1 20 continue c do 30 i = istart, kplusp-1 c c %----------------------------------------% c | Check for splitting and deflation. Use | c | a standard test as in the QR algorithm | c | REFERENCE: LAPACK subroutine clahqr | c %----------------------------------------% c tst1 = cabs1( h( i, i ) ) + cabs1( h( i+1, i+1 ) ) if( tst1.eq.rzero ) & tst1 = clanhs( '1', kplusp-jj+1, h, ldh, workl ) if ( abs(real(h(i+1,i))) & .le. max(ulp*tst1, smlnum) ) then if (msglvl .gt. 0) then call ivout (logfil, 1, i, ndigit, & '_napps: matrix splitting at row/column no.') call ivout (logfil, 1, jj, ndigit, & '_napps: matrix splitting with shift number.') call cvout (logfil, 1, h(i+1,i), ndigit, & '_napps: off diagonal element.') end if iend = i h(i+1,i) = zero go to 40 end if 30 continue iend = kplusp 40 continue c if (msglvl .gt. 2) then call ivout (logfil, 1, istart, ndigit, & '_napps: Start of current block ') call ivout (logfil, 1, iend, ndigit, & '_napps: End of current block ') end if c c %------------------------------------------------% c | No reason to apply a shift to block of order 1 | c | or if the current block starts after the point | c | of compression since we'll discard this stuff | c %------------------------------------------------% c if ( istart .eq. iend .or. istart .gt. kev) go to 100 c h11 = h(istart,istart) h21 = h(istart+1,istart) f = h11 - sigma g = h21 c do 80 i = istart, iend-1 c c %------------------------------------------------------% c | Construct the plane rotation G to zero out the bulge | c %------------------------------------------------------% c call clartg (f, g, c, s, r) if (i .gt. istart) then h(i,i-1) = r h(i+1,i-1) = zero end if c c %---------------------------------------------% c | Apply rotation to the left of H; H <- G'*H | c %---------------------------------------------% c do 50 j = i, kplusp t = c*h(i,j) + s*h(i+1,j) h(i+1,j) = -conjg(s)*h(i,j) + c*h(i+1,j) h(i,j) = t 50 continue c c %---------------------------------------------% c | Apply rotation to the right of H; H <- H*G | c %---------------------------------------------% c do 60 j = 1, min(i+2,iend) t = c*h(j,i) + conjg(s)*h(j,i+1) h(j,i+1) = -s*h(j,i) + c*h(j,i+1) h(j,i) = t 60 continue c c %-----------------------------------------------------% c | Accumulate the rotation in the matrix Q; Q <- Q*G' | c %-----------------------------------------------------% c do 70 j = 1, min(i+jj, kplusp) t = c*q(j,i) + conjg(s)*q(j,i+1) q(j,i+1) = - s*q(j,i) + c*q(j,i+1) q(j,i) = t 70 continue c c %---------------------------% c | Prepare for next rotation | c %---------------------------% c if (i .lt. iend-1) then f = h(i+1,i) g = h(i+2,i) end if 80 continue c c %-------------------------------% c | Finished applying the shift. | c %-------------------------------% c 100 continue c c %---------------------------------------------------------% c | Apply the same shift to the next block if there is any. | c %---------------------------------------------------------% c istart = iend + 1 if (iend .lt. kplusp) go to 20 c c %---------------------------------------------% c | Loop back to the top to get the next shift. | c %---------------------------------------------% c 110 continue c c %---------------------------------------------------% c | Perform a similarity transformation that makes | c | sure that the compressed H will have non-negative | c | real subdiagonal elements. | c %---------------------------------------------------% c do 120 j=1,kev if ( real( h(j+1,j) ) .lt. rzero .or. & aimag( h(j+1,j) ) .ne. rzero ) then t = h(j+1,j) / slapy2(real(h(j+1,j)),aimag(h(j+1,j))) call cscal( kplusp-j+1, conjg(t), h(j+1,j), ldh ) call cscal( min(j+2, kplusp), t, h(1,j+1), 1 ) call cscal( min(j+np+1,kplusp), t, q(1,j+1), 1 ) h(j+1,j) = cmplx( real( h(j+1,j) ), rzero ) end if 120 continue c do 130 i = 1, kev c c %--------------------------------------------% c | Final check for splitting and deflation. | c | Use a standard test as in the QR algorithm | c | REFERENCE: LAPACK subroutine clahqr. | c | Note: Since the subdiagonals of the | c | compressed H are nonnegative real numbers, | c | we take advantage of this. | c %--------------------------------------------% c tst1 = cabs1( h( i, i ) ) + cabs1( h( i+1, i+1 ) ) if( tst1 .eq. rzero ) & tst1 = clanhs( '1', kev, h, ldh, workl ) if( real( h( i+1,i ) ) .le. max( ulp*tst1, smlnum ) ) & h(i+1,i) = zero 130 continue c c %-------------------------------------------------% c | Compute the (kev+1)-st column of (V*Q) and | c | temporarily store the result in WORKD(N+1:2*N). | c | This is needed in the residual update since we | c | cannot GUARANTEE that the corresponding entry | c | of H would be zero as in exact arithmetic. | c %-------------------------------------------------% c if ( real( h(kev+1,kev) ) .gt. rzero ) & call cgemv ('N', n, kplusp, one, v, ldv, q(1,kev+1), 1, zero, & workd(n+1), 1) c c %----------------------------------------------------------% c | Compute column 1 to kev of (V*Q) in backward order | c | taking advantage of the upper Hessenberg structure of Q. | c %----------------------------------------------------------% c do 140 i = 1, kev call cgemv ('N', n, kplusp-i+1, one, v, ldv, & q(1,kev-i+1), 1, zero, workd, 1) call ccopy (n, workd, 1, v(1,kplusp-i+1), 1) 140 continue c c %-------------------------------------------------% c | Move v(:,kplusp-kev+1:kplusp) into v(:,1:kev). | c %-------------------------------------------------% c call clacpy ('A', n, kev, v(1,kplusp-kev+1), ldv, v, ldv) c c %--------------------------------------------------------------% c | Copy the (kev+1)-st column of (V*Q) in the appropriate place | c %--------------------------------------------------------------% c if ( real( h(kev+1,kev) ) .gt. rzero ) & call ccopy (n, workd(n+1), 1, v(1,kev+1), 1) c c %-------------------------------------% c | Update the residual vector: | c | r <- sigmak*r + betak*v(:,kev+1) | c | where | c | sigmak = (e_{kev+p}'*Q)*e_{kev} | c | betak = e_{kev+1}'*H*e_{kev} | c %-------------------------------------% c call cscal (n, q(kplusp,kev), resid, 1) if ( real( h(kev+1,kev) ) .gt. rzero ) & call caxpy (n, h(kev+1,kev), v(1,kev+1), 1, resid, 1) c if (msglvl .gt. 1) then call cvout (logfil, 1, q(kplusp,kev), ndigit, & '_napps: sigmak = (e_{kev+p}^T*Q)*e_{kev}') call cvout (logfil, 1, h(kev+1,kev), ndigit, & '_napps: betak = e_{kev+1}^T*H*e_{kev}') call ivout (logfil, 1, kev, ndigit, & '_napps: Order of the final Hessenberg matrix ') if (msglvl .gt. 2) then call cmout (logfil, kev, kev, h, ldh, ndigit, & '_napps: updated Hessenberg matrix H for next iteration') end if c end if c 9000 continue call arscnd (t1) tcapps = tcapps + (t1 - t0) c return c c %---------------% c | End of cnapps | c %---------------% c end
bsd-3-clause
SamKChang/abinit-7.10.5_multipole
src/43_ptgroups/m_ptgroups.F90
1
31552
!{\src2tex{textfont=tt}} !!****m* ABINIT/m_ptgroups !! NAME !! m_ptgroups !! !! FUNCTION !! This module contains the irreducible representations and the !! character tables of the 32 point groups. !! !! COPYRIGHT !! Copyright (C) 2010-2014 ABINIT group (MG) !! This file is distributed under the terms of the !! GNU General Public License, see ~abinit/COPYING !! or http://www.gnu.org/copyleft/gpl.txt . !! #if defined HAVE_CONFIG_H #include "config.h" #endif #include "abi_common.h" module m_ptgroups use defs_basis use m_defs_ptgroups use m_errors use m_profiling_abi use m_io_tools, only : open_file use m_numeric_tools, only : get_trace, cmplx_sphcart !use m_abilasi, only : xgeev, xginv implicit none private public :: get_point_group public :: get_classes public :: show_character_tables public :: destroy_point_group public :: init_point_group public :: print_point_group public :: locate_sym public :: destroy_irrep public :: copy_irrep public :: init_irrep public :: sum_irreps public :: mult_table !public :: polish_irreps interface destroy_irrep module procedure destroy_irrep_0D module procedure destroy_irrep_1D end interface destroy_irrep CONTAINS !=========================================================== !Structures !!*** !---------------------------------------------------------------------- !!****f* m_ptgroups/get_point_group !! NAME !! get_point_group !! !! FUNCTION !! !! INPUTS !! ptg_name=point group name as returned by symptgroup. !! !! OUTPUT !! nsym=Number of symmetries in the point group. !! nclass=Number of classes. !! sym(3,3,nsym)=Elements of the point group ordered by classe. !! class_ids(2,nclass)=Initial and final index in sym, for each !! Irreps(nclass)=Datatype gathering data on the different irreducible representations. !! !! NOTES !! !! PARENTS !! m_ptgroups !! !! CHILDREN !! destroy_irrep !! !! SOURCE subroutine get_point_group(ptg_name,nsym,nclass,sym,class_ids,class_names,Irreps) use defs_basis !This section has been created automatically by the script Abilint (TD). !Do not modify the following lines by hand. #undef ABI_FUNC #define ABI_FUNC 'get_point_group' use interfaces_43_ptgroups !End of the abilint section implicit none !Arguments ------------------------------------ !scalars integer,intent(out) :: nclass,nsym character(len=5),intent(in) :: ptg_name !arrays integer,allocatable,intent(out) :: sym(:,:,:),class_ids(:,:) character(len=5),allocatable,intent(out) :: class_names(:) type(irrep_t),allocatable,intent(out) :: Irreps(:) !Local variables------------------------------- !scalars integer :: irp,isym character(len=500) :: msg ! ************************************************************************* SELECT CASE (TRIM(ADJUSTL(ptg_name))) CASE ('1') call ptg_C1 (nsym,nclass,sym,class_ids,class_names,Irreps) CASE ('-1') call ptg_Ci (nsym,nclass,sym,class_ids,class_names,Irreps) CASE ('2') call ptg_C2 (nsym,nclass,sym,class_ids,class_names,Irreps) CASE ('m',"-2") ! Abinit uses "-2" call ptg_Cs (nsym,nclass,sym,class_ids,class_names,Irreps) CASE ('2/m') call ptg_C2h (nsym,nclass,sym,class_ids,class_names,Irreps) CASE ('222') call ptg_D2 (nsym,nclass,sym,class_ids,class_names,Irreps) CASE ('mm2') call ptg_C2v (nsym,nclass,sym,class_ids,class_names,Irreps) CASE ('mmm') call ptg_D2h (nsym,nclass,sym,class_ids,class_names,Irreps) CASE ('4') call ptg_C4 (nsym,nclass,sym,class_ids,class_names,Irreps) CASE ('-4') call ptg_S4 (nsym,nclass,sym,class_ids,class_names,Irreps) CASE ('4/m') call ptg_C4h (nsym,nclass,sym,class_ids,class_names,Irreps) CASE ('422') call ptg_D4 (nsym,nclass,sym,class_ids,class_names,Irreps) CASE ('4mm') call ptg_C4v (nsym,nclass,sym,class_ids,class_names,Irreps) CASE ('-42m') call ptg_D2d (nsym,nclass,sym,class_ids,class_names,Irreps) CASE ('4/mmm') call ptg_D4h (nsym,nclass,sym,class_ids,class_names,Irreps) CASE ('3') call ptg_C3 (nsym,nclass,sym,class_ids,class_names,Irreps) CASE ('-3') call ptg_C3i (nsym,nclass,sym,class_ids,class_names,Irreps) CASE ('32') call ptg_D3 (nsym,nclass,sym,class_ids,class_names,Irreps) CASE ('3m') call ptg_C3v (nsym,nclass,sym,class_ids,class_names,Irreps) CASE ('-3m') call ptg_D3d (nsym,nclass,sym,class_ids,class_names,Irreps) CASE ('6') call ptg_C6 (nsym,nclass,sym,class_ids,class_names,Irreps) CASE ('-6') call ptg_C3h (nsym,nclass,sym,class_ids,class_names,Irreps) CASE ('6/m') call ptg_C6h (nsym,nclass,sym,class_ids,class_names,Irreps) CASE ('622') call ptg_D6 (nsym,nclass,sym,class_ids,class_names,Irreps) CASE ('6mm') call ptg_C6v (nsym,nclass,sym,class_ids,class_names,Irreps) CASE ('-62m') call ptg_D3h (nsym,nclass,sym,class_ids,class_names,Irreps) CASE ('6/mmm') call ptg_D6h (nsym,nclass,sym,class_ids,class_names,Irreps) CASE ('23') call ptg_T (nsym,nclass,sym,class_ids,class_names,Irreps) CASE ('m-3') call ptg_Th (nsym,nclass,sym,class_ids,class_names,Irreps) CASE ('432') call ptg_O (nsym,nclass,sym,class_ids,class_names,Irreps) CASE ('-43m') call ptg_Td (nsym,nclass,sym,class_ids,class_names,Irreps) CASE ('m-3m') call ptg_Oh (nsym,nclass,sym,class_ids,class_names,Irreps) CASE DEFAULT msg = " Unknown value for ptg_name: "//TRIM(ptg_name) MSG_BUG(msg) END SELECT ! ! Calculate the trace of each irreducible representation in order to have the character at hand. do irp=1,SIZE(Irreps) ABI_MALLOC(Irreps(irp)%trace,(nsym)) do isym=1,nsym Irreps(irp)%trace(isym) = get_trace(Irreps(irp)%mat(:,:,isym)) end do end do end subroutine get_point_group !!*** !---------------------------------------------------------------------- !!****f* m_ptgroups/get_classes !! NAME !! get_classes !! !! FUNCTION !! Given a set of nsym 3x3 operations in reciprocal or real space, !! which are supposed to form a group, this routine divides the group into classes. !! !! INPUTS !! nsym=number of symmetry operation. !! sym(3,3,nsym)=The symmetry operations. !! !! OUTPUT !! nclass=The number of classes !! nelements(1:nclass)=For each class, the number of elements !! elements_idx(ii,1:nclass)=For each class, this table gives the index !! of its elements (ii=1,..,nelements(iclass)) !! !! NOTES !! * A class is defined as the set of distinct elements obtained by !! considering for each element, S, of the group all its conjugate !! elements X^-1 S X where X range over all the elements of the group. !! !! * It does not work in case of non-collinear magnetism. !! !! * The routine assumes that anti-ferromagnetic symmetries (if any) have been removed by the caller. !! !! PARENTS !! m_esymm,m_ptgroups !! !! CHILDREN !! destroy_irrep !! !! SOURCE subroutine get_classes(nsym,sym,nclass,nelements,elements_idx) use defs_basis !This section has been created automatically by the script Abilint (TD). !Do not modify the following lines by hand. #undef ABI_FUNC #define ABI_FUNC 'get_classes' use interfaces_32_util !End of the abilint section implicit none !Arguments ------------------------------------ !scalars integer,intent(in) :: nsym integer,intent(out) :: nclass !arrays integer,intent(in) :: sym(3,3,nsym) integer,intent(out) :: nelements(nsym),elements_idx(nsym,nsym) !Local variables------------------------------- !scalars integer :: isym,jsym,ksym,identity_idx !,ierr character(len=500) :: msg !arrays integer :: cjg(3,3),ss(3,3),xx(3,3),xxm1(3,3),test(3,3) integer :: identity(3,3) logical :: found(nsym),found_identity !************************************************************************ ! === Check if identity is present in the first position === identity=RESHAPE((/1,0,0,0,1,0,0,0,1/),(/3,3/)); found_identity=.FALSE. do isym=1,nsym if (ALL(sym(:,:,isym)==identity)) then found_identity=.TRUE.; identity_idx=isym; EXIT end if end do if (.not.found_identity.or.identity_idx/=1) then write(msg,'(3a)')& & ' Either identity is not present or it is not the first operation ',ch10,& & ' check set of symmetry operations ' MSG_ERROR(msg) end if ! ! Is it a group? Note that I assume that AFM sym.op (if any) have been pruned in the caller. !dummy_symafm=1 !call chkgrp(nsym,dummy_symafm,sym,ierr) !ABI_CHECK(ierr==0,"Error in group closure") nclass=0; nelements(:)=0; elements_idx(:,:)=0; found(:)=.FALSE. do isym=1,nsym if (.not.found(isym)) then nclass=nclass+1 ss(:,:)=sym(:,:,isym) do jsym=1,nsym ! Form conjugate. xx(:,:)=sym(:,:,jsym) call mati3inv(xx,xxm1) ; xxm1=TRANSPOSE(xxm1) cjg(:,:)=MATMUL(xxm1,MATMUL(ss,xx)) do ksym=1,nsym ! Is it already found? test(:,:)=sym(:,:,ksym) if (.not.found(ksym).and.(ALL((test-cjg)==0))) then found(ksym)=.TRUE. nelements(nclass)=nelements(nclass)+1 elements_idx(nelements(nclass),nclass)=ksym end if end do end do end if end do end subroutine get_classes !!*** !---------------------------------------------------------------------- !!****f* m_ptgroups/show_character_tables !! NAME !! show_character_tables !! !! FUNCTION !! Printout of the caracter tables of the 32 point groups. !! !! INPUTS !! [unit]=Unit number of output file. Defaults to std_out !! !! OUTPUT !! Only writing. !! !! PARENTS !! !! CHILDREN !! destroy_irrep !! !! SOURCE subroutine show_character_tables(unit) use defs_basis !This section has been created automatically by the script Abilint (TD). !Do not modify the following lines by hand. #undef ABI_FUNC #define ABI_FUNC 'show_character_tables' !End of the abilint section implicit none !Arguments ------------------------------------ !scalars integer,optional,intent(in) :: unit !Local variables------------------------------- integer :: igrp,my_unt character(len=5) :: ptg_name type(point_group_t) :: Ptg !arrays !integer,allocatable :: elements_idx(:,:),nelements(:) ! ********************************************************************* my_unt = std_out; if (PRESENT(unit)) my_unt=unit do igrp=1,SIZE(ptgroup_names) ptg_name = ptgroup_names(igrp) call init_point_group(Ptg,ptg_name) call print_point_group(Ptg,unit=my_unt) !allocate(nelements(Ptg%nsym),elements_idx(Ptg%nsym,Ptg%nsym)) !call get_classes(Ptg%nsym,Ptg%sym,nclass,nelements,elements_idx) !deallocate(nelements,elements_idx) call destroy_point_group(Ptg) end do end subroutine show_character_tables !!*** !---------------------------------------------------------------------- !!****f* m_ptgroups/destroy_point_group !! NAME !! destroy_point_group !! !! FUNCTION !! Deallocate all memory allocated in the point_group_t datatype. !! !! PARENTS !! m_ptgroups !! !! CHILDREN !! destroy_irrep !! !! SOURCE subroutine destroy_point_group(Ptg) use defs_basis !This section has been created automatically by the script Abilint (TD). !Do not modify the following lines by hand. #undef ABI_FUNC #define ABI_FUNC 'destroy_point_group' !End of the abilint section implicit none !Arguments ------------------------------------ type(point_group_t),intent(inout) :: Ptg !Local variables------------------------------- ! ********************************************************************* !@point_group_t if (allocated(Ptg%class_ids)) then ABI_FREE(Ptg%class_ids) end if if (allocated(Ptg%sym)) then ABI_FREE(Ptg%sym) end if if (allocated(Ptg%class_names)) then ABI_FREE(Ptg%class_names) end if if (allocated(Ptg%Irreps)) then call destroy_irrep(Ptg%Irreps) ABI_DT_FREE(Ptg%Irreps) end if end subroutine destroy_point_group !!*** !---------------------------------------------------------------------- !!****f* m_ptgroups/init_point_group !! NAME !! init_point_group !! !! FUNCTION !! Creation method for the point_group_t datatype. !! !! INPUTS !! ptg_name=The name of the point group (International conventions). !! !! OUTPUT !! The datatype completely initialized. !! !! PARENTS !! m_esymm,m_ptgroups !! !! CHILDREN !! destroy_irrep !! !! SOURCE subroutine init_point_group(Ptg,ptg_name) use defs_basis !This section has been created automatically by the script Abilint (TD). !Do not modify the following lines by hand. #undef ABI_FUNC #define ABI_FUNC 'init_point_group' !End of the abilint section implicit none !Arguments ------------------------------------ !scalars character(len=5),intent(in) :: ptg_name type(point_group_t),intent(inout) :: Ptg !Local variables------------------------------- ! ********************************************************************* !@point_group_t !call wrtout(std_out," Retrieving point group data for: "//TRIM(ptg_name),"COLL") Ptg%gname = ptg_name call get_point_group(Ptg%gname,Ptg%nsym,Ptg%nclass,Ptg%sym,Ptg%class_ids,Ptg%class_names,Ptg%Irreps) end subroutine init_point_group !!*** !---------------------------------------------------------------------- !!****f* m_ptgroups/print_point_group !! NAME !! print_point_group !! !! FUNCTION !! !! INPUTS !! !! OUTPUT !! !! PARENTS !! m_ptgroups !! !! CHILDREN !! destroy_irrep !! !! SOURCE subroutine print_point_group(Ptg,header,unit,mode_paral,prtvol) use defs_basis !This section has been created automatically by the script Abilint (TD). !Do not modify the following lines by hand. #undef ABI_FUNC #define ABI_FUNC 'print_point_group' use interfaces_14_hidewrite !End of the abilint section implicit none !Arguments ------------------------------------ !scalars integer,optional,intent(in) :: unit,prtvol character(len=4),optional,intent(in) :: mode_paral character(len=*),optional,intent(in) :: header type(point_group_t),target,intent(in) :: Ptg !Local variables------------------------------- integer :: my_unt,my_prtvol,irp,icls,sidx complex(dpc) :: trace character(len=4) :: my_mode character(len=500) :: msg type(irrep_t),pointer :: Row ! ********************************************************************* my_unt =std_out; if (PRESENT(unit )) my_unt =unit my_prtvol=0 ; if (PRESENT(prtvol )) my_prtvol=prtvol my_mode ='COLL' ; if (PRESENT(mode_paral)) my_mode =mode_paral msg=' ==== Point Group Table ==== ' if (PRESENT(header)) msg=' ==== '//TRIM(ADJUSTL(header))//' ==== ' call wrtout(my_unt,msg,my_mode) write(std_out,*)REPEAT("=",80) write(std_out,*)" Point group : ",TRIM(Ptg%gname)," Number of symmetries ",Ptg%nsym," Number of classes ",Ptg%nclass write(std_out,"(a6)",advance="no")"Class " do icls=1,Ptg%nclass write(std_out,"('|',a10)",advance="no")Ptg%class_names(icls) end do write(std_out,"('|')",advance="no") write(std_out,*)" " write(std_out,"(a6)",advance="no")"Mult " do icls=1,Ptg%nclass write(std_out,"('|',i10)",advance="no")Ptg%class_ids(2,icls)-Ptg%class_ids(1,icls) + 1 end do write(std_out,"('|')",advance="no") write(std_out,*)" " do irp=1,SIZE(Ptg%Irreps) Row => Ptg%Irreps(irp) write(std_out,'(a6)',advance="no")TRIM(Row%name) do icls=1,Ptg%nclass sidx = Ptg%class_ids(1,icls) trace = Row%trace(sidx) if (ABS(AIMAG(trace)) > 10**(-6)) then write(std_out,"('|',(2f5.2))",advance="no")trace else write(std_out,"('|',(f10.2))",advance="no")REAL(trace) end if end do write(std_out,"('|')",advance="no") write(std_out,*)" " end do write(std_out,*)REPEAT("=",80) end subroutine print_point_group !!*** !---------------------------------------------------------------------- !!****f* m_ptgroups/locate_sym !! NAME !! locate_sym !! !! FUNCTION !! Given a symmetry operation asym, this routine returns its index in the Ptg%sym !! array and the index of the class it belongs to. !! !! INPUTS !! !! OUTPUT !! !! PARENTS !! m_esymm !! !! CHILDREN !! destroy_irrep !! !! SOURCE subroutine locate_sym(Ptg,asym,sym_idx,cls_idx,ierr) use defs_basis !This section has been created automatically by the script Abilint (TD). !Do not modify the following lines by hand. #undef ABI_FUNC #define ABI_FUNC 'locate_sym' !End of the abilint section implicit none !Arguments ------------------------------------ !scalars integer,intent(out) :: sym_idx,cls_idx integer,optional,intent(out) :: ierr type(point_group_t),intent(in) :: Ptg !arrays integer,intent(in) :: asym(3,3) !Local variables------------------------------- !scalars integer :: isym,icls character(len=500) :: msg ! ********************************************************************* sym_idx = 0 do isym=1,Ptg%nsym if (ALL(asym == Ptg%sym(:,:,isym) )) then sym_idx = isym EXIT end if end do cls_idx = 0 do icls=1,Ptg%nclass if (sym_idx >= Ptg%class_ids(1,icls) .and. & & sym_idx <= Ptg%class_ids(2,icls) ) then cls_idx = icls EXIT end if end do if (PRESENT(ierr)) ierr=0 if (sym_idx==0 .or. cls_idx==0) then write(msg,'(a,9(i0,1x),3a,i1,a,i1)')& & " Symmetry: ",asym," not found in point group table ",ch10,& & " sym_idx= ",sym_idx, " and cls_idx= ",cls_idx if (PRESENT(ierr)) then ierr=1 MSG_WARNING(msg) else MSG_ERROR(msg) end if end if end subroutine locate_sym !!*** !---------------------------------------------------------------------- !!****f* m_ptgroups/mult_table !! NAME !! mult_table !! !! FUNCTION !! Given a set of nsym 3x3 operations which are supposed to form a group, !! this routine constructs the multiplication table of the group. !! !! INPUTS !! nsym=number of symmetry operation !! sym(3,3,nsym)=the operations !! !! OUTPUT !! mtab(nsym,nsym)=The index of the product S_i * S_j in the input set sym. !! !! PARENTS !! !! CHILDREN !! destroy_irrep !! !! SOURCE subroutine mult_table(nsym,sym,mtab) use defs_basis !This section has been created automatically by the script Abilint (TD). !Do not modify the following lines by hand. #undef ABI_FUNC #define ABI_FUNC 'mult_table' !End of the abilint section implicit none !Arguments ------------------------------------ !scalars integer,intent(in) :: nsym !arrays integer,intent(in) :: sym(3,3,nsym) integer,intent(out) :: mtab(nsym,nsym) !Local variables------------------------------- !scalars integer :: isym,jsym,ksym !character(len=500) :: msg !arrays integer :: prod_ij(3,3),found(nsym) !************************************************************************ do jsym=1,nsym found(:)=0 ! Each symmetry should compare only once in a given (row|col). do isym=1,nsym prod_ij = MATMUL(sym(:,:,isym),sym(:,:,jsym)) do ksym=1,nsym if ( ALL(prod_ij == sym(:,:,ksym)) ) then found(ksym)=found(ksym)+1 mtab(isym,jsym) = ksym end if end do end do ! jsym if ( ANY(found /= 1)) then write(std_out,*)"found = ",found MSG_ERROR("Input elements do not form a group") end if end do ! isym end subroutine mult_table !!*** !---------------------------------------------------------------------- !!****f* m_ptgroups/init_groupk_from_file !! NAME !! init_groupk_from_file !! !! FUNCTION !! Initialize the group_k_t datatype from an external database retrieved from !! the Bilbao server via the ptg.py script. !! !! INPUTS !! fname(len=*)=file name !! !! OUTPUT !! ierr=Status error !! Lgrps<group_k_t>=The structure completely initialized. !! !! TODO !! This is a stub. I still have to complete the fileformat for the Bilbao database. !! !! PARENTS !! !! CHILDREN !! destroy_irrep !! !! SOURCE subroutine init_groupk_from_file(Lgrps,spgroup,fname,nkpt,klist,ierr) use defs_basis !This section has been created automatically by the script Abilint (TD). !Do not modify the following lines by hand. #undef ABI_FUNC #define ABI_FUNC 'init_groupk_from_file' !End of the abilint section implicit none !Arguments ------------------------------------ !scalars integer,intent(in) :: spgroup integer,intent(out) :: ierr,nkpt character(len=fnlen),intent(in) :: fname !arrays type(group_k_t),target,allocatable :: Lgrps(:) real(dp),pointer :: klist(:,:) !Local variables------------------------------- !scalars integer,parameter :: last_file_version=1 integer :: unt,fvers,ik,nsym_ltgk,isym,nirreps_k,irp,icls integer :: irrep_idx,irrep_dim,sym_idx,ita_spgroup,nels,prev,now character(len=IRREPNAME_LEN) :: irrep_name character(len=1) :: basis character(len=500) :: msg type(group_k_t),pointer :: Gk !arrays integer,allocatable :: nelements(:),elements_idx(:,:) real(dp) :: kpt(3) character(len=10),allocatable :: kname(:) type(irrep_t),pointer :: OneIrr ! ************************************************************************* ierr=0 if (open_file(fname,msg,newunit=unt,form="formatted") /=0) then MSG_ERROR(msg) end if read(unt,*,ERR=10) ! Skip the header. read(unt,*,ERR=10) fvers ! File version. if (fvers > last_file_version) then write(msg,"(2(a,i0))")" Found file format= ",fvers," but the latest supported version is: ",last_file_version MSG_ERROR(msg) end if read(unt,*,ERR=10) ita_spgroup read(unt,*,ERR=10) basis if (spgroup/=ita_spgroup) then write(msg,'(a,2i0)')& & " Input space group does not match with the value reported on file: ",spgroup,ita_spgroup MSG_ERROR(msg) end if if (basis /= "b") then msg=" Wrong value for basis: "//TRIM(basis) MSG_ERROR(msg) end if ! * Read the list of the k-points. read(unt,*,ERR=10) nkpt ABI_DT_MALLOC(Lgrps,(nkpt)) ABI_MALLOC(klist,(3,nkpt)) ABI_MALLOC(kname,(nkpt)) do ik=1,nkpt read(unt,*,ERR=10) klist(:,ik), kname(ik) end do ! * Read tables for each k-point do ik=1,nkpt read(unt,*,ERR=10) kpt read(unt,*,ERR=10) nsym_ltgk Gk => Lgrps(ik) Gk%spgroup = ita_spgroup Gk%nsym = nsym_ltgk Gk%point = kpt ABI_MALLOC(Gk%sym,(3,3,nsym_ltgk)) ABI_MALLOC(Gk%tnons,(3,nsym_ltgk)) do isym=1,nsym_ltgk ! Read symmetries of the little group. read(unt,*,ERR=10) Gk%sym(:,:,isym) read(unt,*,ERR=10) Gk%tnons(:,isym) end do ABI_MALLOC(nelements,(nsym_ltgk)) ABI_MALLOC(elements_idx,(nsym_ltgk,nsym_ltgk)) call get_classes(nsym_ltgk,Gk%sym,Gk%nclass,nelements,elements_idx) ! The operations reported on the file are supposed to be packed in classes ! otherwise one should perform a rearrangement of the indices. prev = 0 do icls=1,Gk%nclass do isym=1,nelements(icls) now = elements_idx(isym,icls) if ( (now-prev) /= 1 ) then write(msg,"(2(a,i0))")& & " Symmetries on file are not ordered in classes. icls= ",icls,", isym= ",isym MSG_ERROR(msg) else prev = now end if end do end do ABI_MALLOC(Gk%class_ids,(2,Gk%nclass)) do icls=1,Gk%nclass nels = nelements(icls) Gk%class_ids(1,icls) = elements_idx(1, icls) Gk%class_ids(2,icls) = elements_idx(nels,icls) end do ABI_FREE(nelements) ABI_FREE(elements_idx) ! Read the irreducible representations. read(unt,*,ERR=10) nirreps_k ABI_CHECK(Gk%nclass == nirreps_k,"Gk%nclass /= nirreps_k") !$$ allocate(Gk%class_names(Gk%nclass)) ABI_DT_MALLOC(Gk%Irreps,(nirreps_k)) do irp=1,nirreps_k OneIrr => Gk%Irreps(irp) read(unt,*,ERR=10) irrep_idx, irrep_dim, irrep_name call init_irrep(OneIrr,nsym_ltgk,irrep_dim,irrep_name) do isym=1,nsym_ltgk read(unt,*,ERR=10) sym_idx, OneIrr%mat(:,:,isym) ABI_CHECK(sym_idx==irp,"sym_idx/=irp!") ! Matrix elements on file are in the form (rho, theta) with theta given in degrees. call cmplx_sphcart(OneIrr%mat(:,:,isym),from="Sphere",units="Degrees") OneIrr%trace(isym) = get_trace(OneIrr%mat(:,:,isym)) end do end do end do close(unt) RETURN ! ! Handle IO-error. 10 ierr=1 close(unt) RETURN end subroutine init_groupk_from_file !!*** !---------------------------------------------------------------------- !!****f* m_ptgroups/destroy_irrep_0D !! NAME !! destroy_irrep_0D !! !! FUNCTION !! Deallocate all memory allocated in the irrep_t datatype. !! !! PARENTS !! m_ptgroups !! !! CHILDREN !! destroy_irrep !! !! SOURCE subroutine destroy_irrep_0D(Irrep) use defs_basis !This section has been created automatically by the script Abilint (TD). !Do not modify the following lines by hand. #undef ABI_FUNC #define ABI_FUNC 'destroy_irrep_0D' !End of the abilint section implicit none !Arguments ------------------------------------ type(irrep_t),intent(inout) :: Irrep ! ********************************************************************* !@irrep_t if (allocated(Irrep%trace)) then ABI_FREE(Irrep%trace) end if if (allocated(Irrep%mat)) then ABI_FREE(Irrep%mat) end if end subroutine destroy_irrep_0D !!*** !---------------------------------------------------------------------- !!****f* m_ptgroups/destroy_irrep_1D !! NAME !! destroy_irrep_1D !! !! FUNCTION !! Deallocate all memory allocated in the irrep_t datatype. !! !! PARENTS !! !! CHILDREN !! destroy_irrep !! !! SOURCE subroutine destroy_irrep_1D(Irrep) use defs_basis !This section has been created automatically by the script Abilint (TD). !Do not modify the following lines by hand. #undef ABI_FUNC #define ABI_FUNC 'destroy_irrep_1D' !End of the abilint section implicit none !Arguments ------------------------------------ type(irrep_t),intent(inout) :: Irrep(:) !Local variables------------------------------- integer :: irp ! ********************************************************************* do irp=1,SIZE(Irrep) call destroy_irrep_0D(Irrep(irp)) end do end subroutine destroy_irrep_1D !!*** !---------------------------------------------------------------------- !!****f* m_ptgroups/copy_irrep !! NAME !! copy_irrep !! !! FUNCTION !! Perform a copy of a set of irrep_t datatypes. Optionally one can multiply !! by a phase factor. !! !! PARENTS !! m_esymm !! !! CHILDREN !! destroy_irrep !! !! SOURCE subroutine copy_irrep(In_irreps,Out_irreps,phase_fact) use defs_basis !This section has been created automatically by the script Abilint (TD). !Do not modify the following lines by hand. #undef ABI_FUNC #define ABI_FUNC 'copy_irrep' !End of the abilint section implicit none !Arguments ------------------------------------ type(irrep_t),intent(in) :: In_irreps(:) type(irrep_t),intent(inout) :: Out_irreps(:) complex(dpc),optional,intent(in) :: phase_fact(:) !Local variables------------------------------- !scalars integer :: irp,dim1,dim2,in_nsym,in_dim,isym character(len=500) :: msg !arrays complex(dpc) :: my_phase_fact(In_irreps(1)%nsym) ! ********************************************************************* !@irrep_t dim1 = SIZE( In_irreps) dim2 = SIZE(Out_irreps) if (dim1/=dim2) then msg = " irreps to be copied have different dimension" MSG_ERROR(msg) end if my_phase_fact=cone if (PRESENT(phase_fact)) then my_phase_fact=phase_fact if (SIZE(phase_fact) /= In_irreps(1)%nsym) then msg = " irreps to be copied have different dimension" MSG_ERROR(msg) end if end if do irp=1,dim1 in_dim = In_irreps(irp)%dim in_nsym = In_irreps(irp)%nsym call init_irrep(Out_irreps(irp),in_nsym,in_dim) Out_irreps(irp)%name = In_irreps(irp)%name do isym=1,in_nsym Out_irreps(irp)%mat(:,:,isym) = In_irreps(irp)%mat(:,:,isym) * my_phase_fact(isym) Out_irreps(irp)%trace(isym) = get_trace(Out_irreps(irp)%mat(:,:,isym)) end do end do end subroutine copy_irrep !!*** !---------------------------------------------------------------------- !!****f* m_ptgroups/init_irrep !! NAME !! alloc_irrep !! !! FUNCTION !! Initialize an instance of the irrep_t datatype. !! !! INPUTS !! nsym=The number of symmetries. !! irr_dim=The dimension of the irrep. !! [irr_name]=The name of theirrep. "???" is used if not given !! !! OUTPUT !! Irrep<irrep_t>= !! !! PARENTS !! !! CHILDREN !! !! SOURCE subroutine init_irrep(Irrep,nsym,irr_dim,irr_name) use defs_basis !This section has been created automatically by the script Abilint (TD). !Do not modify the following lines by hand. #undef ABI_FUNC #define ABI_FUNC 'init_irrep' !End of the abilint section implicit none !Arguments ------------------------------------ !scalars integer,intent(in) :: nsym !arrays integer,intent(in) :: irr_dim character(len=*),optional,intent(in) :: irr_name type(irrep_t),intent(inout) :: Irrep !Local variables------------------------------- !character(len=500) :: msg ! ********************************************************************* !@irrep_t Irrep%dim = irr_dim Irrep%nsym = nsym Irrep%name = "???" if (PRESENT(irr_name)) Irrep%name = irr_name ABI_MALLOC(Irrep%mat,(irr_dim,irr_dim,nsym)) Irrep%mat = czero ABI_MALLOC(Irrep%trace,(nsym)) Irrep%trace = czero end subroutine init_irrep !!*** !---------------------------------------------------------------------- !!****f* m_ptgroups/sum_irreps !! NAME !! sum_irreps !! !! FUNCTION !! !! INPUTS !! !! OUTPUT !! !! PARENTS !! !! CHILDREN !! !! SOURCE function sum_irreps(Irrep1,Irrep2,ii,jj,kk,ll) result(res) use defs_basis !This section has been created automatically by the script Abilint (TD). !Do not modify the following lines by hand. #undef ABI_FUNC #define ABI_FUNC 'sum_irreps' !End of the abilint section implicit none !Arguments ------------------------------------ !scalars integer,intent(in) :: ii,jj,kk,ll !arrays type(irrep_t),intent(in) :: Irrep1,Irrep2 complex(dpc) :: res !Local variables------------------------------- integer :: isym,nsym,ierr !character(len=500) :: msg ! ********************************************************************* ierr=0; res = czero nsym = Irrep1%nsym if (nsym /= Irrep2%nsym) then MSG_WARNING("Irreps have different nsym") ierr=ierr+1 end if if (Irrep1%dim /= Irrep2%dim) then MSG_WARNING("Irreps have different dimensions") write(std_out,*)Irrep1%dim,Irrep2%dim ierr=ierr+1 end if if (ii>Irrep2%dim .or. jj>Irrep2%dim .or. & & kk>Irrep1%dim .or. ll>Irrep1%dim) then MSG_WARNING("Wrong indeces") write(std_out,*)ii,Irrep2%dim,jj,Irrep2%dim,kk>Irrep1%dim,ll,Irrep1%dim ierr=ierr+1 end if if (ierr/=0) RETURN do isym=1,nsym res = res + DCONJG(Irrep1%mat(ii,jj,isym)) * Irrep2%mat(kk,ll,isym) end do end function sum_irreps !!*** !---------------------------------------------------------------------- !!****f* m_ptgroups/destroy_group_k !! NAME !! destroy_group_k !! !! FUNCTION !! Deallocate all memory allocate in the group_k_t. !! !! PARENTS !! !! CHILDREN !! destroy_irrep !! !! SOURCE subroutine destroy_group_k(Gk) use defs_basis !This section has been created automatically by the script Abilint (TD). !Do not modify the following lines by hand. #undef ABI_FUNC #define ABI_FUNC 'destroy_group_k' !End of the abilint section implicit none !Arguments ------------------------------------ !scalars !arrays type(group_k_t),intent(inout) :: Gk ! ************************************************************************* ! integer if (allocated(Gk%class_ids)) then ABI_FREE(Gk%class_ids) end if if (allocated(Gk%sym)) then ABI_FREE(Gk%sym) end if !real if (allocated(Gk%tnons)) then ABI_FREE(Gk%tnons) end if !character if (allocated(Gk%class_names)) then ABI_FREE(Gk%class_names) end if !type if (allocated(Gk%Irreps)) then call destroy_irrep(Gk%Irreps) ABI_DT_FREE(Gk%Irreps) end if end subroutine destroy_group_k END MODULE m_ptgroups !!***
gpl-3.0
doslab/gcc-designated-initializer-support-cpp
gcc/testsuite/gfortran.dg/namelist_39.f90
8
1360
! { dg-do run { target fd_truncate } } ! PR33421 and PR33253 Weird quotation of namelist output of character arrays ! Test case from Toon Moone, adapted by Jerry DeLisle <jvdelisle@gcc.gnu.org> ! Long names used to test line_buffer feature is working. program test implicit none character(len=45) :: b01234567890123456789012345678901234567890123456789012345678901(3) namelist /nam/ b01234567890123456789012345678901234567890123456789012345678901 b01234567890123456789012345678901234567890123456789012345678901 = 'x' open(99) write(99,'(4(a,/),a)') "&NAM", & " b01234567890123456789012345678901234567890123456789012345678901(1)=' AAP NOOT MIES WIM ZUS JET',", & " b01234567890123456789012345678901234567890123456789012345678901(2)='SURF.PRESSURE',", & " b01234567890123456789012345678901234567890123456789012345678901(3)='APEKOOL',", & " /" rewind(99) read(99,nml=nam) close(99,status="delete") if (b01234567890123456789012345678901234567890123456789012345678901(1).ne.& " AAP NOOT MIES WIM ZUS JET ") call abort if (b01234567890123456789012345678901234567890123456789012345678901(2).ne.& "SURF.PRESSURE ") call abort if (b01234567890123456789012345678901234567890123456789012345678901(3).ne.& "APEKOOL ") call abort end program test
gpl-2.0
jjones-cavium/gcc
libgfortran/generated/_sqrt_c8.F90
15
1485
! Copyright 2002, 2007, 2009 Free Software Foundation, Inc. ! Contributed by Paul Brook <paul@nowt.org> ! !This file is part of the GNU Fortran 95 runtime library (libgfortran). ! !GNU libgfortran is free software; you can redistribute it and/or !modify it under the terms of the GNU General Public !License as published by the Free Software Foundation; either !version 3 of the License, or (at your option) any later version. !GNU libgfortran is distributed in the hope that it will be useful, !but WITHOUT ANY WARRANTY; without even the implied warranty of !MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the !GNU General Public License for more details. ! !Under Section 7 of GPL version 3, you are granted additional !permissions described in the GCC Runtime Library Exception, version !3.1, as published by the Free Software Foundation. ! !You should have received a copy of the GNU General Public License and !a copy of the GCC Runtime Library Exception along with this program; !see the files COPYING3 and COPYING.RUNTIME respectively. If not, see !<http://www.gnu.org/licenses/>. ! !This file is machine generated. #include "config.h" #include "kinds.inc" #include "c99_protos.inc" #if defined (HAVE_GFC_COMPLEX_8) #ifdef HAVE_CSQRT elemental function _gfortran_specific__sqrt_c8 (parm) complex (kind=8), intent (in) :: parm complex (kind=8) :: _gfortran_specific__sqrt_c8 _gfortran_specific__sqrt_c8 = sqrt (parm) end function #endif #endif
gpl-2.0
stephenR/gcc-fpp
gcc/testsuite/gfortran.dg/external_procedures_1.f90
185
1089
! { dg-do compile } ! { dg-options "-std=f95" } ! ! This tests the patch for PR25024. ! PR25024 - The external attribute for subroutine a would cause an ICE. subroutine A () EXTERNAL A ! { dg-error "EXTERNAL attribute conflicts with SUBROUTINE" } END function ext (y) ! { dg-error "EXTERNAL attribute conflicts with FUNCTION" } real ext, y external ext !ext = y * y end function ext function ext1 (y) real ext1, y external z ! OK no conflict ext1 = y * y end function ext1 program main real ext, inval external ext ! OK, valid external reference. external main ! { dg-error "PROGRAM attribute conflicts with EXTERNAL" } interface function ext1 (y) real ext1, y external ext1 end function ext1 ! { dg-error "Duplicate EXTERNAL attribute" } end interface inval = 1.0 print *, ext(inval) print *, ext1(inval) print *, inv(inval) contains function inv (y) ! { dg-error "EXTERNAL attribute conflicts with FUNCTION" } real inv, y external inv !inv = y * y * y end function inv end program main
gpl-2.0
sungsujo/nacl-llvm-branches.llvm-gcc-trunk
libgfortran/generated/_dim_i8.F90
11
1716
! Copyright 2002 Free Software Foundation, Inc. ! Contributed by Paul Brook <paul@nowt.org> ! !This file is part of the GNU Fortran 95 runtime library (libgfortran). ! !GNU libgfortran is free software; you can redistribute it and/or !modify it under the terms of the GNU General Public !License as published by the Free Software Foundation; either !version 2 of the License, or (at your option) any later version. !In addition to the permissions in the GNU General Public License, the !Free Software Foundation gives you unlimited permission to link the !compiled version of this file into combinations with other programs, !and to distribute those combinations without any restriction coming !from the use of this file. (The General Public License restrictions !do apply in other respects; for example, they cover modification of !the file, and distribution when not linked into a combine !executable.) ! !GNU libgfortran is distributed in the hope that it will be useful, !but WITHOUT ANY WARRANTY; without even the implied warranty of !MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the !GNU General Public License for more details. ! !You should have received a copy of the GNU General Public !License along with libgfortran; see the file COPYING. If not, !write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, !Boston, MA 02110-1301, USA. ! !This file is machine generated. #include "config.h" #include "kinds.inc" #include "c99_protos.inc" #if defined (HAVE_GFC_INTEGER_8) elemental function specific__dim_i8 (p1, p2) integer (kind=8), intent (in) :: p1, p2 integer (kind=8) :: specific__dim_i8 specific__dim_i8 = dim (p1, p2) end function #endif
gpl-2.0
wilmarcardonac/hypermcmc
lapack-3.5.0/SRC/cuncsd.f
22
22483
*> \brief \b CUNCSD * * =========== DOCUMENTATION =========== * * Online html documentation available at * http://www.netlib.org/lapack/explore-html/ * *> \htmlonly *> Download CUNCSD + dependencies *> <a href="http://www.netlib.org/cgi-bin/netlibfiles.tgz?format=tgz&filename=/lapack/lapack_routine/cuncsd.f"> *> [TGZ]</a> *> <a href="http://www.netlib.org/cgi-bin/netlibfiles.zip?format=zip&filename=/lapack/lapack_routine/cuncsd.f"> *> [ZIP]</a> *> <a href="http://www.netlib.org/cgi-bin/netlibfiles.txt?format=txt&filename=/lapack/lapack_routine/cuncsd.f"> *> [TXT]</a> *> \endhtmlonly * * Definition: * =========== * * RECURSIVE SUBROUTINE CUNCSD( JOBU1, JOBU2, JOBV1T, JOBV2T, TRANS, * SIGNS, M, P, Q, X11, LDX11, X12, * LDX12, X21, LDX21, X22, LDX22, THETA, * U1, LDU1, U2, LDU2, V1T, LDV1T, V2T, * LDV2T, WORK, LWORK, RWORK, LRWORK, * IWORK, INFO ) * * .. Scalar Arguments .. * CHARACTER JOBU1, JOBU2, JOBV1T, JOBV2T, SIGNS, TRANS * INTEGER INFO, LDU1, LDU2, LDV1T, LDV2T, LDX11, LDX12, * $ LDX21, LDX22, LRWORK, LWORK, M, P, Q * .. * .. Array Arguments .. * INTEGER IWORK( * ) * REAL THETA( * ) * REAL RWORK( * ) * COMPLEX U1( LDU1, * ), U2( LDU2, * ), V1T( LDV1T, * ), * $ V2T( LDV2T, * ), WORK( * ), X11( LDX11, * ), * $ X12( LDX12, * ), X21( LDX21, * ), X22( LDX22, * $ * ) * .. * * *> \par Purpose: * ============= *> *> \verbatim *> *> CUNCSD computes the CS decomposition of an M-by-M partitioned *> unitary matrix X: *> *> [ I 0 0 | 0 0 0 ] *> [ 0 C 0 | 0 -S 0 ] *> [ X11 | X12 ] [ U1 | ] [ 0 0 0 | 0 0 -I ] [ V1 | ]**H *> X = [-----------] = [---------] [---------------------] [---------] . *> [ X21 | X22 ] [ | U2 ] [ 0 0 0 | I 0 0 ] [ | V2 ] *> [ 0 S 0 | 0 C 0 ] *> [ 0 0 I | 0 0 0 ] *> *> X11 is P-by-Q. The unitary matrices U1, U2, V1, and V2 are P-by-P, *> (M-P)-by-(M-P), Q-by-Q, and (M-Q)-by-(M-Q), respectively. C and S are *> R-by-R nonnegative diagonal matrices satisfying C^2 + S^2 = I, in *> which R = MIN(P,M-P,Q,M-Q). *> \endverbatim * * Arguments: * ========== * *> \param[in] JOBU1 *> \verbatim *> JOBU1 is CHARACTER *> = 'Y': U1 is computed; *> otherwise: U1 is not computed. *> \endverbatim *> *> \param[in] JOBU2 *> \verbatim *> JOBU2 is CHARACTER *> = 'Y': U2 is computed; *> otherwise: U2 is not computed. *> \endverbatim *> *> \param[in] JOBV1T *> \verbatim *> JOBV1T is CHARACTER *> = 'Y': V1T is computed; *> otherwise: V1T is not computed. *> \endverbatim *> *> \param[in] JOBV2T *> \verbatim *> JOBV2T is CHARACTER *> = 'Y': V2T is computed; *> otherwise: V2T is not computed. *> \endverbatim *> *> \param[in] TRANS *> \verbatim *> TRANS is CHARACTER *> = 'T': X, U1, U2, V1T, and V2T are stored in row-major *> order; *> otherwise: X, U1, U2, V1T, and V2T are stored in column- *> major order. *> \endverbatim *> *> \param[in] SIGNS *> \verbatim *> SIGNS is CHARACTER *> = 'O': The lower-left block is made nonpositive (the *> "other" convention); *> otherwise: The upper-right block is made nonpositive (the *> "default" convention). *> \endverbatim *> *> \param[in] M *> \verbatim *> M is INTEGER *> The number of rows and columns in X. *> \endverbatim *> *> \param[in] P *> \verbatim *> P is INTEGER *> The number of rows in X11 and X12. 0 <= P <= M. *> \endverbatim *> *> \param[in] Q *> \verbatim *> Q is INTEGER *> The number of columns in X11 and X21. 0 <= Q <= M. *> \endverbatim *> *> \param[in,out] X11 *> \verbatim *> X11 is COMPLEX array, dimension (LDX11,Q) *> On entry, part of the unitary matrix whose CSD is desired. *> \endverbatim *> *> \param[in] LDX11 *> \verbatim *> LDX11 is INTEGER *> The leading dimension of X11. LDX11 >= MAX(1,P). *> \endverbatim *> *> \param[in,out] X12 *> \verbatim *> X12 is COMPLEX array, dimension (LDX12,M-Q) *> On entry, part of the unitary matrix whose CSD is desired. *> \endverbatim *> *> \param[in] LDX12 *> \verbatim *> LDX12 is INTEGER *> The leading dimension of X12. LDX12 >= MAX(1,P). *> \endverbatim *> *> \param[in,out] X21 *> \verbatim *> X21 is COMPLEX array, dimension (LDX21,Q) *> On entry, part of the unitary matrix whose CSD is desired. *> \endverbatim *> *> \param[in] LDX21 *> \verbatim *> LDX21 is INTEGER *> The leading dimension of X11. LDX21 >= MAX(1,M-P). *> \endverbatim *> *> \param[in,out] X22 *> \verbatim *> X22 is COMPLEX array, dimension (LDX22,M-Q) *> On entry, part of the unitary matrix whose CSD is desired. *> \endverbatim *> *> \param[in] LDX22 *> \verbatim *> LDX22 is INTEGER *> The leading dimension of X11. LDX22 >= MAX(1,M-P). *> \endverbatim *> *> \param[out] THETA *> \verbatim *> THETA is REAL array, dimension (R), in which R = *> MIN(P,M-P,Q,M-Q). *> C = DIAG( COS(THETA(1)), ... , COS(THETA(R)) ) and *> S = DIAG( SIN(THETA(1)), ... , SIN(THETA(R)) ). *> \endverbatim *> *> \param[out] U1 *> \verbatim *> U1 is COMPLEX array, dimension (P) *> If JOBU1 = 'Y', U1 contains the P-by-P unitary matrix U1. *> \endverbatim *> *> \param[in] LDU1 *> \verbatim *> LDU1 is INTEGER *> The leading dimension of U1. If JOBU1 = 'Y', LDU1 >= *> MAX(1,P). *> \endverbatim *> *> \param[out] U2 *> \verbatim *> U2 is COMPLEX array, dimension (M-P) *> If JOBU2 = 'Y', U2 contains the (M-P)-by-(M-P) unitary *> matrix U2. *> \endverbatim *> *> \param[in] LDU2 *> \verbatim *> LDU2 is INTEGER *> The leading dimension of U2. If JOBU2 = 'Y', LDU2 >= *> MAX(1,M-P). *> \endverbatim *> *> \param[out] V1T *> \verbatim *> V1T is COMPLEX array, dimension (Q) *> If JOBV1T = 'Y', V1T contains the Q-by-Q matrix unitary *> matrix V1**H. *> \endverbatim *> *> \param[in] LDV1T *> \verbatim *> LDV1T is INTEGER *> The leading dimension of V1T. If JOBV1T = 'Y', LDV1T >= *> MAX(1,Q). *> \endverbatim *> *> \param[out] V2T *> \verbatim *> V2T is COMPLEX array, dimension (M-Q) *> If JOBV2T = 'Y', V2T contains the (M-Q)-by-(M-Q) unitary *> matrix V2**H. *> \endverbatim *> *> \param[in] LDV2T *> \verbatim *> LDV2T is INTEGER *> The leading dimension of V2T. If JOBV2T = 'Y', LDV2T >= *> MAX(1,M-Q). *> \endverbatim *> *> \param[out] WORK *> \verbatim *> WORK is COMPLEX array, dimension (MAX(1,LWORK)) *> On exit, if INFO = 0, WORK(1) returns the optimal LWORK. *> \endverbatim *> *> \param[in] LWORK *> \verbatim *> LWORK is INTEGER *> The dimension of the array WORK. *> *> If LWORK = -1, then a workspace query is assumed; the routine *> only calculates the optimal size of the WORK array, returns *> this value as the first entry of the work array, and no error *> message related to LWORK is issued by XERBLA. *> \endverbatim *> *> \param[out] RWORK *> \verbatim *> RWORK is REAL array, dimension MAX(1,LRWORK) *> On exit, if INFO = 0, RWORK(1) returns the optimal LRWORK. *> If INFO > 0 on exit, RWORK(2:R) contains the values PHI(1), *> ..., PHI(R-1) that, together with THETA(1), ..., THETA(R), *> define the matrix in intermediate bidiagonal-block form *> remaining after nonconvergence. INFO specifies the number *> of nonzero PHI's. *> \endverbatim *> *> \param[in] LRWORK *> \verbatim *> LRWORK is INTEGER *> The dimension of the array RWORK. *> *> If LRWORK = -1, then a workspace query is assumed; the routine *> only calculates the optimal size of the RWORK array, returns *> this value as the first entry of the work array, and no error *> message related to LRWORK is issued by XERBLA. *> \endverbatim *> *> \param[out] IWORK *> \verbatim *> IWORK is INTEGER array, dimension (M-MIN(P,M-P,Q,M-Q)) *> \endverbatim *> *> \param[out] INFO *> \verbatim *> INFO is INTEGER *> = 0: successful exit. *> < 0: if INFO = -i, the i-th argument had an illegal value. *> > 0: CBBCSD did not converge. See the description of RWORK *> above for details. *> \endverbatim * *> \par References: * ================ *> *> [1] Brian D. Sutton. Computing the complete CS decomposition. Numer. *> Algorithms, 50(1):33-65, 2009. * * Authors: * ======== * *> \author Univ. of Tennessee *> \author Univ. of California Berkeley *> \author Univ. of Colorado Denver *> \author NAG Ltd. * *> \date November 2013 * *> \ingroup complexOTHERcomputational * * ===================================================================== RECURSIVE SUBROUTINE CUNCSD( JOBU1, JOBU2, JOBV1T, JOBV2T, TRANS, $ SIGNS, M, P, Q, X11, LDX11, X12, $ LDX12, X21, LDX21, X22, LDX22, THETA, $ U1, LDU1, U2, LDU2, V1T, LDV1T, V2T, $ LDV2T, WORK, LWORK, RWORK, LRWORK, $ IWORK, INFO ) * * -- LAPACK computational routine (version 3.5.0) -- * -- LAPACK is a software package provided by Univ. of Tennessee, -- * -- Univ. of California Berkeley, Univ. of Colorado Denver and NAG Ltd..-- * November 2013 * * .. Scalar Arguments .. CHARACTER JOBU1, JOBU2, JOBV1T, JOBV2T, SIGNS, TRANS INTEGER INFO, LDU1, LDU2, LDV1T, LDV2T, LDX11, LDX12, $ LDX21, LDX22, LRWORK, LWORK, M, P, Q * .. * .. Array Arguments .. INTEGER IWORK( * ) REAL THETA( * ) REAL RWORK( * ) COMPLEX U1( LDU1, * ), U2( LDU2, * ), V1T( LDV1T, * ), $ V2T( LDV2T, * ), WORK( * ), X11( LDX11, * ), $ X12( LDX12, * ), X21( LDX21, * ), X22( LDX22, $ * ) * .. * * =================================================================== * * .. Parameters .. COMPLEX ONE, ZERO PARAMETER ( ONE = (1.0E0,0.0E0), $ ZERO = (0.0E0,0.0E0) ) * .. * .. Local Scalars .. CHARACTER TRANST, SIGNST INTEGER CHILDINFO, I, IB11D, IB11E, IB12D, IB12E, $ IB21D, IB21E, IB22D, IB22E, IBBCSD, IORBDB, $ IORGLQ, IORGQR, IPHI, ITAUP1, ITAUP2, ITAUQ1, $ ITAUQ2, J, LBBCSDWORK, LBBCSDWORKMIN, $ LBBCSDWORKOPT, LORBDBWORK, LORBDBWORKMIN, $ LORBDBWORKOPT, LORGLQWORK, LORGLQWORKMIN, $ LORGLQWORKOPT, LORGQRWORK, LORGQRWORKMIN, $ LORGQRWORKOPT, LWORKMIN, LWORKOPT, P1, Q1 LOGICAL COLMAJOR, DEFAULTSIGNS, LQUERY, WANTU1, WANTU2, $ WANTV1T, WANTV2T INTEGER LRWORKMIN, LRWORKOPT LOGICAL LRQUERY * .. * .. External Subroutines .. EXTERNAL XERBLA, CBBCSD, CLACPY, CLAPMR, CLAPMT, CLASCL, $ CLASET, CUNBDB, CUNGLQ, CUNGQR * .. * .. External Functions .. LOGICAL LSAME EXTERNAL LSAME * .. * .. Intrinsic Functions INTRINSIC COS, INT, MAX, MIN, SIN * .. * .. Executable Statements .. * * Test input arguments * INFO = 0 WANTU1 = LSAME( JOBU1, 'Y' ) WANTU2 = LSAME( JOBU2, 'Y' ) WANTV1T = LSAME( JOBV1T, 'Y' ) WANTV2T = LSAME( JOBV2T, 'Y' ) COLMAJOR = .NOT. LSAME( TRANS, 'T' ) DEFAULTSIGNS = .NOT. LSAME( SIGNS, 'O' ) LQUERY = LWORK .EQ. -1 LRQUERY = LRWORK .EQ. -1 IF( M .LT. 0 ) THEN INFO = -7 ELSE IF( P .LT. 0 .OR. P .GT. M ) THEN INFO = -8 ELSE IF( Q .LT. 0 .OR. Q .GT. M ) THEN INFO = -9 ELSE IF ( COLMAJOR .AND. LDX11 .LT. MAX( 1, P ) ) THEN INFO = -11 ELSE IF (.NOT. COLMAJOR .AND. LDX11 .LT. MAX( 1, Q ) ) THEN INFO = -11 ELSE IF (COLMAJOR .AND. LDX12 .LT. MAX( 1, P ) ) THEN INFO = -13 ELSE IF (.NOT. COLMAJOR .AND. LDX12 .LT. MAX( 1, M-Q ) ) THEN INFO = -13 ELSE IF (COLMAJOR .AND. LDX21 .LT. MAX( 1, M-P ) ) THEN INFO = -15 ELSE IF (.NOT. COLMAJOR .AND. LDX21 .LT. MAX( 1, Q ) ) THEN INFO = -15 ELSE IF (COLMAJOR .AND. LDX22 .LT. MAX( 1, M-P ) ) THEN INFO = -17 ELSE IF (.NOT. COLMAJOR .AND. LDX22 .LT. MAX( 1, M-Q ) ) THEN INFO = -17 ELSE IF( WANTU1 .AND. LDU1 .LT. P ) THEN INFO = -20 ELSE IF( WANTU2 .AND. LDU2 .LT. M-P ) THEN INFO = -22 ELSE IF( WANTV1T .AND. LDV1T .LT. Q ) THEN INFO = -24 ELSE IF( WANTV2T .AND. LDV2T .LT. M-Q ) THEN INFO = -26 END IF * * Work with transpose if convenient * IF( INFO .EQ. 0 .AND. MIN( P, M-P ) .LT. MIN( Q, M-Q ) ) THEN IF( COLMAJOR ) THEN TRANST = 'T' ELSE TRANST = 'N' END IF IF( DEFAULTSIGNS ) THEN SIGNST = 'O' ELSE SIGNST = 'D' END IF CALL CUNCSD( JOBV1T, JOBV2T, JOBU1, JOBU2, TRANST, SIGNST, M, $ Q, P, X11, LDX11, X21, LDX21, X12, LDX12, X22, $ LDX22, THETA, V1T, LDV1T, V2T, LDV2T, U1, LDU1, $ U2, LDU2, WORK, LWORK, RWORK, LRWORK, IWORK, $ INFO ) RETURN END IF * * Work with permutation [ 0 I; I 0 ] * X * [ 0 I; I 0 ] if * convenient * IF( INFO .EQ. 0 .AND. M-Q .LT. Q ) THEN IF( DEFAULTSIGNS ) THEN SIGNST = 'O' ELSE SIGNST = 'D' END IF CALL CUNCSD( JOBU2, JOBU1, JOBV2T, JOBV1T, TRANS, SIGNST, M, $ M-P, M-Q, X22, LDX22, X21, LDX21, X12, LDX12, X11, $ LDX11, THETA, U2, LDU2, U1, LDU1, V2T, LDV2T, V1T, $ LDV1T, WORK, LWORK, RWORK, LRWORK, IWORK, INFO ) RETURN END IF * * Compute workspace * IF( INFO .EQ. 0 ) THEN * * Real workspace * IPHI = 2 IB11D = IPHI + MAX( 1, Q - 1 ) IB11E = IB11D + MAX( 1, Q ) IB12D = IB11E + MAX( 1, Q - 1 ) IB12E = IB12D + MAX( 1, Q ) IB21D = IB12E + MAX( 1, Q - 1 ) IB21E = IB21D + MAX( 1, Q ) IB22D = IB21E + MAX( 1, Q - 1 ) IB22E = IB22D + MAX( 1, Q ) IBBCSD = IB22E + MAX( 1, Q - 1 ) CALL CBBCSD( JOBU1, JOBU2, JOBV1T, JOBV2T, TRANS, M, P, Q, $ THETA, THETA, U1, LDU1, U2, LDU2, V1T, LDV1T, $ V2T, LDV2T, THETA, THETA, THETA, THETA, THETA, $ THETA, THETA, THETA, RWORK, -1, CHILDINFO ) LBBCSDWORKOPT = INT( RWORK(1) ) LBBCSDWORKMIN = LBBCSDWORKOPT LRWORKOPT = IBBCSD + LBBCSDWORKOPT - 1 LRWORKMIN = IBBCSD + LBBCSDWORKMIN - 1 RWORK(1) = LRWORKOPT * * Complex workspace * ITAUP1 = 2 ITAUP2 = ITAUP1 + MAX( 1, P ) ITAUQ1 = ITAUP2 + MAX( 1, M - P ) ITAUQ2 = ITAUQ1 + MAX( 1, Q ) IORGQR = ITAUQ2 + MAX( 1, M - Q ) CALL CUNGQR( M-Q, M-Q, M-Q, 0, MAX(1,M-Q), U1, WORK, -1, $ CHILDINFO ) LORGQRWORKOPT = INT( WORK(1) ) LORGQRWORKMIN = MAX( 1, M - Q ) IORGLQ = ITAUQ2 + MAX( 1, M - Q ) CALL CUNGLQ( M-Q, M-Q, M-Q, 0, MAX(1,M-Q), U1, WORK, -1, $ CHILDINFO ) LORGLQWORKOPT = INT( WORK(1) ) LORGLQWORKMIN = MAX( 1, M - Q ) IORBDB = ITAUQ2 + MAX( 1, M - Q ) CALL CUNBDB( TRANS, SIGNS, M, P, Q, X11, LDX11, X12, LDX12, $ X21, LDX21, X22, LDX22, THETA, THETA, U1, U2, $ V1T, V2T, WORK, -1, CHILDINFO ) LORBDBWORKOPT = INT( WORK(1) ) LORBDBWORKMIN = LORBDBWORKOPT LWORKOPT = MAX( IORGQR + LORGQRWORKOPT, IORGLQ + LORGLQWORKOPT, $ IORBDB + LORBDBWORKOPT ) - 1 LWORKMIN = MAX( IORGQR + LORGQRWORKMIN, IORGLQ + LORGLQWORKMIN, $ IORBDB + LORBDBWORKMIN ) - 1 WORK(1) = MAX(LWORKOPT,LWORKMIN) * IF( LWORK .LT. LWORKMIN $ .AND. .NOT. ( LQUERY .OR. LRQUERY ) ) THEN INFO = -22 ELSE IF( LRWORK .LT. LRWORKMIN $ .AND. .NOT. ( LQUERY .OR. LRQUERY ) ) THEN INFO = -24 ELSE LORGQRWORK = LWORK - IORGQR + 1 LORGLQWORK = LWORK - IORGLQ + 1 LORBDBWORK = LWORK - IORBDB + 1 LBBCSDWORK = LRWORK - IBBCSD + 1 END IF END IF * * Abort if any illegal arguments * IF( INFO .NE. 0 ) THEN CALL XERBLA( 'CUNCSD', -INFO ) RETURN ELSE IF( LQUERY .OR. LRQUERY ) THEN RETURN END IF * * Transform to bidiagonal block form * CALL CUNBDB( TRANS, SIGNS, M, P, Q, X11, LDX11, X12, LDX12, X21, $ LDX21, X22, LDX22, THETA, RWORK(IPHI), WORK(ITAUP1), $ WORK(ITAUP2), WORK(ITAUQ1), WORK(ITAUQ2), $ WORK(IORBDB), LORBDBWORK, CHILDINFO ) * * Accumulate Householder reflectors * IF( COLMAJOR ) THEN IF( WANTU1 .AND. P .GT. 0 ) THEN CALL CLACPY( 'L', P, Q, X11, LDX11, U1, LDU1 ) CALL CUNGQR( P, P, Q, U1, LDU1, WORK(ITAUP1), WORK(IORGQR), $ LORGQRWORK, INFO) END IF IF( WANTU2 .AND. M-P .GT. 0 ) THEN CALL CLACPY( 'L', M-P, Q, X21, LDX21, U2, LDU2 ) CALL CUNGQR( M-P, M-P, Q, U2, LDU2, WORK(ITAUP2), $ WORK(IORGQR), LORGQRWORK, INFO ) END IF IF( WANTV1T .AND. Q .GT. 0 ) THEN CALL CLACPY( 'U', Q-1, Q-1, X11(1,2), LDX11, V1T(2,2), $ LDV1T ) V1T(1, 1) = ONE DO J = 2, Q V1T(1,J) = ZERO V1T(J,1) = ZERO END DO CALL CUNGLQ( Q-1, Q-1, Q-1, V1T(2,2), LDV1T, WORK(ITAUQ1), $ WORK(IORGLQ), LORGLQWORK, INFO ) END IF IF( WANTV2T .AND. M-Q .GT. 0 ) THEN CALL CLACPY( 'U', P, M-Q, X12, LDX12, V2T, LDV2T ) IF( M-P .GT. Q ) THEN CALL CLACPY( 'U', M-P-Q, M-P-Q, X22(Q+1,P+1), LDX22, $ V2T(P+1,P+1), LDV2T ) END IF IF( M .GT. Q ) THEN CALL CUNGLQ( M-Q, M-Q, M-Q, V2T, LDV2T, WORK(ITAUQ2), $ WORK(IORGLQ), LORGLQWORK, INFO ) END IF END IF ELSE IF( WANTU1 .AND. P .GT. 0 ) THEN CALL CLACPY( 'U', Q, P, X11, LDX11, U1, LDU1 ) CALL CUNGLQ( P, P, Q, U1, LDU1, WORK(ITAUP1), WORK(IORGLQ), $ LORGLQWORK, INFO) END IF IF( WANTU2 .AND. M-P .GT. 0 ) THEN CALL CLACPY( 'U', Q, M-P, X21, LDX21, U2, LDU2 ) CALL CUNGLQ( M-P, M-P, Q, U2, LDU2, WORK(ITAUP2), $ WORK(IORGLQ), LORGLQWORK, INFO ) END IF IF( WANTV1T .AND. Q .GT. 0 ) THEN CALL CLACPY( 'L', Q-1, Q-1, X11(2,1), LDX11, V1T(2,2), $ LDV1T ) V1T(1, 1) = ONE DO J = 2, Q V1T(1,J) = ZERO V1T(J,1) = ZERO END DO CALL CUNGQR( Q-1, Q-1, Q-1, V1T(2,2), LDV1T, WORK(ITAUQ1), $ WORK(IORGQR), LORGQRWORK, INFO ) END IF IF( WANTV2T .AND. M-Q .GT. 0 ) THEN P1 = MIN( P+1, M ) Q1 = MIN( Q+1, M ) CALL CLACPY( 'L', M-Q, P, X12, LDX12, V2T, LDV2T ) IF ( M .GT. P+Q ) THEN CALL CLACPY( 'L', M-P-Q, M-P-Q, X22(P1,Q1), LDX22, $ V2T(P+1,P+1), LDV2T ) END IF CALL CUNGQR( M-Q, M-Q, M-Q, V2T, LDV2T, WORK(ITAUQ2), $ WORK(IORGQR), LORGQRWORK, INFO ) END IF END IF * * Compute the CSD of the matrix in bidiagonal-block form * CALL CBBCSD( JOBU1, JOBU2, JOBV1T, JOBV2T, TRANS, M, P, Q, THETA, $ RWORK(IPHI), U1, LDU1, U2, LDU2, V1T, LDV1T, V2T, $ LDV2T, RWORK(IB11D), RWORK(IB11E), RWORK(IB12D), $ RWORK(IB12E), RWORK(IB21D), RWORK(IB21E), $ RWORK(IB22D), RWORK(IB22E), RWORK(IBBCSD), $ LBBCSDWORK, INFO ) * * Permute rows and columns to place identity submatrices in top- * left corner of (1,1)-block and/or bottom-right corner of (1,2)- * block and/or bottom-right corner of (2,1)-block and/or top-left * corner of (2,2)-block * IF( Q .GT. 0 .AND. WANTU2 ) THEN DO I = 1, Q IWORK(I) = M - P - Q + I END DO DO I = Q + 1, M - P IWORK(I) = I - Q END DO IF( COLMAJOR ) THEN CALL CLAPMT( .FALSE., M-P, M-P, U2, LDU2, IWORK ) ELSE CALL CLAPMR( .FALSE., M-P, M-P, U2, LDU2, IWORK ) END IF END IF IF( M .GT. 0 .AND. WANTV2T ) THEN DO I = 1, P IWORK(I) = M - P - Q + I END DO DO I = P + 1, M - Q IWORK(I) = I - P END DO IF( .NOT. COLMAJOR ) THEN CALL CLAPMT( .FALSE., M-Q, M-Q, V2T, LDV2T, IWORK ) ELSE CALL CLAPMR( .FALSE., M-Q, M-Q, V2T, LDV2T, IWORK ) END IF END IF * RETURN * * End CUNCSD * END
gpl-2.0
QEF/q-e
XClib/dft_setting_params.f90
2
3954
! ! Copyright (C) 2020 Quantum ESPRESSO group ! This file is distributed under the terms of the ! GNU General Public License. See the file `License' ! in the root directory of the present distribution, ! or http://www.gnu.org/copyleft/gpl.txt . ! !-------------------------------------------------------------------- MODULE dft_setting_params !---------------------------------------------------------------- !! Parameters that define the XC functionals. ! USE kind_l, ONLY: DP #if defined(__LIBXC) USE xc_f03_lib_m #endif ! IMPLICIT NONE ! SAVE ! CHARACTER(LEN=32) :: dft = 'not set' !! Full name of the XC functional INTEGER, PARAMETER :: notset = -1 !! Value of indexes that have not been set yet ! LOGICAL :: is_libxc(6) = .FALSE. !! \(\text{is_libxc(i)}=TRUE\) if the i-th term of the input !! functional is from Libxc ! LOGICAL :: libxc_initialized(6) = .FALSE. !! TRUE if libxc functionals have been initialized ! #if defined(__LIBXC) TYPE(xc_f03_func_t) :: xc_func(6) !! pointers to libxc functional structs TYPE(xc_f03_func_info_t) :: xc_info(6) !! pointers to libxc info structs INTEGER :: libxc_flags(6,0:15) = notset !! flags related to specific features of libxc functionals !! (see Libxc doc) INTEGER :: n_ext_params(6) = 0 !! number of external parameters for each functional REAL(DP) :: par_list(6,50) !! list of external parameters LOGICAL :: xc_kind_error = .FALSE. !! some Libxc dfts are currently not usable in QE (for example !! kinetic dfts). If one of them is detected this variable is !! set to TRUE. #endif ! LOGICAL :: exx_started = .FALSE. !! TRUE if Exact Exchange is active REAL(DP) :: exx_fraction = 0.0_DP !! Exact Exchange fraction parameter ! INTEGER :: iexch = notset !! LDA exchange index INTEGER :: icorr = notset !! LDA correlation index REAL(DP) :: finite_size_cell_volume = -1._DP !! Cell volume parameter for finite size correction REAL(DP) :: rho_threshold_lda = 1.E-10_DP !! Threshold value for the density in LDA ! INTEGER :: igcx = notset !! GGA exchange index INTEGER :: igcc = notset !! GGA correlation index REAL(DP) :: rho_threshold_gga = 1.E-6_DP !! Threshold value for the density in GGA REAL(DP) :: grho_threshold_gga = 1.E-10_DP !! Threshold value for the density gradient in GGA REAL(DP) :: screening_parameter !! Screening parameter for PBE exchange REAL(DP) :: gau_parameter !! Gaussian parameter for PBE exchange ! INTEGER :: imeta = notset !! MGGA exchange index INTEGER :: imetac = notset !! MGGA correlation index REAL(DP) :: rho_threshold_mgga = 1.E-12_DP !! Threshold value for the density in MGGA REAL(DP) :: grho2_threshold_mgga = 1.E-24_DP !! Threshold value for the density gradient (square modulus) in MGGA REAL(DP) :: tau_threshold_mgga = 1.0E-12_DP !! Threshold value for the density laplacian in MGGA ! ! LOGICAL :: islda = .FALSE. !! TRUE if the functional is LDA only LOGICAL :: isgradient = .FALSE. !! TRUE if the functional is GGA LOGICAL :: has_finite_size_correction = .FALSE. !! TRUE if finite size correction is present LOGICAL :: finite_size_cell_volume_set = .FALSE. !! TRUE if the cell volume has been set for finite size correction. LOGICAL :: ismeta = .FALSE. !! TRUE if the functional is MGGA LOGICAL :: ishybrid = .FALSE. !! TRUE if the functional is hybrid LOGICAL :: scan_exx = .FALSE. !! TRUE if SCAN0 functional is active ! LOGICAL :: discard_input_dft = .FALSE. !! TRUE if input DFT can be overwritten INTEGER :: beeftype = -1 !! Index for BEEF functional INTEGER :: beefvdw = 0 !! Index for vdw term of BEEF ! END MODULE dft_setting_params
gpl-2.0
markusappel/McCode
support/common/pgplot/src/pgqtxt.f
6
2267
C*PGQTXT -- find bounding box of text string C%void cpgqtxt(float x, float y, float angle, float fjust, \ C% const char *text, float *xbox, float *ybox); C+ SUBROUTINE PGQTXT (X, Y, ANGLE, FJUST, TEXT, XBOX, YBOX) REAL X, Y, ANGLE, FJUST CHARACTER*(*) TEXT REAL XBOX(4), YBOX(4) C C This routine returns a bounding box for a text string. Instead C of drawing the string as routine PGPTXT does, it returns in XBOX C and YBOX the coordinates of the corners of a rectangle parallel C to the string baseline that just encloses the string. The four C corners are in the order: lower left, upper left, upper right, C lower right (where left and right refer to the first and last C characters in the string). C C If the string is blank or contains no drawable characters, all C four elements of XBOX and YBOX are assigned the starting point C of the string, (X,Y). C C Arguments: C X, Y, ANGLE, FJUST, TEXT (input) : these arguments are the same as C the corrresponding arguments in PGPTXT. C XBOX, YBOX (output) : arrays of dimension 4; on output, they C contain the world coordinates of the bounding C box in (XBOX(1), YBOX(1)), ..., (XBOX(4), YBOX(4)). C-- C 12-Sep-1993 - new routine [TJP]. C 8-Nov-1994 - return something for blank string [TJP]. C 14-Jan-1997 - additional explanation [TJP]. C----------------------------------------------------------------------- INCLUDE 'pgplot.inc' LOGICAL PGNOTO INTEGER I, L, GRTRIM REAL D, XP, YP, XPBOX(4), YPBOX(4), XOFFS, YOFFS C IF (PGNOTO('PGQTXT')) RETURN C L = GRTRIM(TEXT) IF (L.LE.0) THEN DO 15 I=1,4 XBOX(I) = X YBOX(I) = Y 15 CONTINUE ELSE D = 0.0 IF (FJUST.NE.0.0) CALL GRLEN(TEXT(1:L),D) XOFFS = PGXORG(PGID) - D*FJUST*COS(ANGLE/57.29578) YOFFS = PGYORG(PGID) - D*FJUST*SIN(ANGLE/57.29578) XP = X*PGXSCL(PGID) + XOFFS YP = Y*PGYSCL(PGID) + YOFFS CALL GRQTXT(ANGLE, XP, YP, TEXT(1:L), XPBOX, YPBOX) DO 25 I=1,4 XBOX(I) = (XPBOX(I) - PGXORG(PGID))/PGXSCL(PGID) YBOX(I) = (YPBOX(I) - PGYORG(PGID))/PGYSCL(PGID) 25 CONTINUE END IF END
gpl-2.0
wilmarcardonac/hypermcmc
lapack-3.5.0/SRC/zgbtf2.f
24
8142
*> \brief \b ZGBTF2 computes the LU factorization of a general band matrix using the unblocked version of the algorithm. * * =========== DOCUMENTATION =========== * * Online html documentation available at * http://www.netlib.org/lapack/explore-html/ * *> \htmlonly *> Download ZGBTF2 + dependencies *> <a href="http://www.netlib.org/cgi-bin/netlibfiles.tgz?format=tgz&filename=/lapack/lapack_routine/zgbtf2.f"> *> [TGZ]</a> *> <a href="http://www.netlib.org/cgi-bin/netlibfiles.zip?format=zip&filename=/lapack/lapack_routine/zgbtf2.f"> *> [ZIP]</a> *> <a href="http://www.netlib.org/cgi-bin/netlibfiles.txt?format=txt&filename=/lapack/lapack_routine/zgbtf2.f"> *> [TXT]</a> *> \endhtmlonly * * Definition: * =========== * * SUBROUTINE ZGBTF2( M, N, KL, KU, AB, LDAB, IPIV, INFO ) * * .. Scalar Arguments .. * INTEGER INFO, KL, KU, LDAB, M, N * .. * .. Array Arguments .. * INTEGER IPIV( * ) * COMPLEX*16 AB( LDAB, * ) * .. * * *> \par Purpose: * ============= *> *> \verbatim *> *> ZGBTF2 computes an LU factorization of a complex m-by-n band matrix *> A using partial pivoting with row interchanges. *> *> This is the unblocked version of the algorithm, calling Level 2 BLAS. *> \endverbatim * * Arguments: * ========== * *> \param[in] M *> \verbatim *> M is INTEGER *> The number of rows of the matrix A. M >= 0. *> \endverbatim *> *> \param[in] N *> \verbatim *> N is INTEGER *> The number of columns of the matrix A. N >= 0. *> \endverbatim *> *> \param[in] KL *> \verbatim *> KL is INTEGER *> The number of subdiagonals within the band of A. KL >= 0. *> \endverbatim *> *> \param[in] KU *> \verbatim *> KU is INTEGER *> The number of superdiagonals within the band of A. KU >= 0. *> \endverbatim *> *> \param[in,out] AB *> \verbatim *> AB is COMPLEX*16 array, dimension (LDAB,N) *> On entry, the matrix A in band storage, in rows KL+1 to *> 2*KL+KU+1; rows 1 to KL of the array need not be set. *> The j-th column of A is stored in the j-th column of the *> array AB as follows: *> AB(kl+ku+1+i-j,j) = A(i,j) for max(1,j-ku)<=i<=min(m,j+kl) *> *> On exit, details of the factorization: U is stored as an *> upper triangular band matrix with KL+KU superdiagonals in *> rows 1 to KL+KU+1, and the multipliers used during the *> factorization are stored in rows KL+KU+2 to 2*KL+KU+1. *> See below for further details. *> \endverbatim *> *> \param[in] LDAB *> \verbatim *> LDAB is INTEGER *> The leading dimension of the array AB. LDAB >= 2*KL+KU+1. *> \endverbatim *> *> \param[out] IPIV *> \verbatim *> IPIV is INTEGER array, dimension (min(M,N)) *> The pivot indices; for 1 <= i <= min(M,N), row i of the *> matrix was interchanged with row IPIV(i). *> \endverbatim *> *> \param[out] INFO *> \verbatim *> INFO is INTEGER *> = 0: successful exit *> < 0: if INFO = -i, the i-th argument had an illegal value *> > 0: if INFO = +i, U(i,i) is exactly zero. The factorization *> has been completed, but the factor U is exactly *> singular, and division by zero will occur if it is used *> to solve a system of equations. *> \endverbatim * * Authors: * ======== * *> \author Univ. of Tennessee *> \author Univ. of California Berkeley *> \author Univ. of Colorado Denver *> \author NAG Ltd. * *> \date September 2012 * *> \ingroup complex16GBcomputational * *> \par Further Details: * ===================== *> *> \verbatim *> *> The band storage scheme is illustrated by the following example, when *> M = N = 6, KL = 2, KU = 1: *> *> On entry: On exit: *> *> * * * + + + * * * u14 u25 u36 *> * * + + + + * * u13 u24 u35 u46 *> * a12 a23 a34 a45 a56 * u12 u23 u34 u45 u56 *> a11 a22 a33 a44 a55 a66 u11 u22 u33 u44 u55 u66 *> a21 a32 a43 a54 a65 * m21 m32 m43 m54 m65 * *> a31 a42 a53 a64 * * m31 m42 m53 m64 * * *> *> Array elements marked * are not used by the routine; elements marked *> + need not be set on entry, but are required by the routine to store *> elements of U, because of fill-in resulting from the row *> interchanges. *> \endverbatim *> * ===================================================================== SUBROUTINE ZGBTF2( M, N, KL, KU, AB, LDAB, IPIV, INFO ) * * -- LAPACK computational routine (version 3.4.2) -- * -- LAPACK is a software package provided by Univ. of Tennessee, -- * -- Univ. of California Berkeley, Univ. of Colorado Denver and NAG Ltd..-- * September 2012 * * .. Scalar Arguments .. INTEGER INFO, KL, KU, LDAB, M, N * .. * .. Array Arguments .. INTEGER IPIV( * ) COMPLEX*16 AB( LDAB, * ) * .. * * ===================================================================== * * .. Parameters .. COMPLEX*16 ONE, ZERO PARAMETER ( ONE = ( 1.0D+0, 0.0D+0 ), $ ZERO = ( 0.0D+0, 0.0D+0 ) ) * .. * .. Local Scalars .. INTEGER I, J, JP, JU, KM, KV * .. * .. External Functions .. INTEGER IZAMAX EXTERNAL IZAMAX * .. * .. External Subroutines .. EXTERNAL XERBLA, ZGERU, ZSCAL, ZSWAP * .. * .. Intrinsic Functions .. INTRINSIC MAX, MIN * .. * .. Executable Statements .. * * KV is the number of superdiagonals in the factor U, allowing for * fill-in. * KV = KU + KL * * Test the input parameters. * INFO = 0 IF( M.LT.0 ) THEN INFO = -1 ELSE IF( N.LT.0 ) THEN INFO = -2 ELSE IF( KL.LT.0 ) THEN INFO = -3 ELSE IF( KU.LT.0 ) THEN INFO = -4 ELSE IF( LDAB.LT.KL+KV+1 ) THEN INFO = -6 END IF IF( INFO.NE.0 ) THEN CALL XERBLA( 'ZGBTF2', -INFO ) RETURN END IF * * Quick return if possible * IF( M.EQ.0 .OR. N.EQ.0 ) $ RETURN * * Gaussian elimination with partial pivoting * * Set fill-in elements in columns KU+2 to KV to zero. * DO 20 J = KU + 2, MIN( KV, N ) DO 10 I = KV - J + 2, KL AB( I, J ) = ZERO 10 CONTINUE 20 CONTINUE * * JU is the index of the last column affected by the current stage * of the factorization. * JU = 1 * DO 40 J = 1, MIN( M, N ) * * Set fill-in elements in column J+KV to zero. * IF( J+KV.LE.N ) THEN DO 30 I = 1, KL AB( I, J+KV ) = ZERO 30 CONTINUE END IF * * Find pivot and test for singularity. KM is the number of * subdiagonal elements in the current column. * KM = MIN( KL, M-J ) JP = IZAMAX( KM+1, AB( KV+1, J ), 1 ) IPIV( J ) = JP + J - 1 IF( AB( KV+JP, J ).NE.ZERO ) THEN JU = MAX( JU, MIN( J+KU+JP-1, N ) ) * * Apply interchange to columns J to JU. * IF( JP.NE.1 ) $ CALL ZSWAP( JU-J+1, AB( KV+JP, J ), LDAB-1, $ AB( KV+1, J ), LDAB-1 ) IF( KM.GT.0 ) THEN * * Compute multipliers. * CALL ZSCAL( KM, ONE / AB( KV+1, J ), AB( KV+2, J ), 1 ) * * Update trailing submatrix within the band. * IF( JU.GT.J ) $ CALL ZGERU( KM, JU-J, -ONE, AB( KV+2, J ), 1, $ AB( KV, J+1 ), LDAB-1, AB( KV+1, J+1 ), $ LDAB-1 ) END IF ELSE * * If pivot is zero, set INFO to the index of the pivot * unless a zero pivot has already been found. * IF( INFO.EQ.0 ) $ INFO = J END IF 40 CONTINUE RETURN * * End of ZGBTF2 * END
gpl-2.0
wilmarcardonac/hypermcmc
lapack-3.5.0/SRC/cposvx.f
28
16696
*> \brief <b> CPOSVX computes the solution to system of linear equations A * X = B for PO matrices</b> * * =========== DOCUMENTATION =========== * * Online html documentation available at * http://www.netlib.org/lapack/explore-html/ * *> \htmlonly *> Download CPOSVX + dependencies *> <a href="http://www.netlib.org/cgi-bin/netlibfiles.tgz?format=tgz&filename=/lapack/lapack_routine/cposvx.f"> *> [TGZ]</a> *> <a href="http://www.netlib.org/cgi-bin/netlibfiles.zip?format=zip&filename=/lapack/lapack_routine/cposvx.f"> *> [ZIP]</a> *> <a href="http://www.netlib.org/cgi-bin/netlibfiles.txt?format=txt&filename=/lapack/lapack_routine/cposvx.f"> *> [TXT]</a> *> \endhtmlonly * * Definition: * =========== * * SUBROUTINE CPOSVX( FACT, UPLO, N, NRHS, A, LDA, AF, LDAF, EQUED, * S, B, LDB, X, LDX, RCOND, FERR, BERR, WORK, * RWORK, INFO ) * * .. Scalar Arguments .. * CHARACTER EQUED, FACT, UPLO * INTEGER INFO, LDA, LDAF, LDB, LDX, N, NRHS * REAL RCOND * .. * .. Array Arguments .. * REAL BERR( * ), FERR( * ), RWORK( * ), S( * ) * COMPLEX A( LDA, * ), AF( LDAF, * ), B( LDB, * ), * $ WORK( * ), X( LDX, * ) * .. * * *> \par Purpose: * ============= *> *> \verbatim *> *> CPOSVX uses the Cholesky factorization A = U**H*U or A = L*L**H to *> compute the solution to a complex system of linear equations *> A * X = B, *> where A is an N-by-N Hermitian positive definite matrix and X and B *> are N-by-NRHS matrices. *> *> Error bounds on the solution and a condition estimate are also *> provided. *> \endverbatim * *> \par Description: * ================= *> *> \verbatim *> *> The following steps are performed: *> *> 1. If FACT = 'E', real scaling factors are computed to equilibrate *> the system: *> diag(S) * A * diag(S) * inv(diag(S)) * X = diag(S) * B *> Whether or not the system will be equilibrated depends on the *> scaling of the matrix A, but if equilibration is used, A is *> overwritten by diag(S)*A*diag(S) and B by diag(S)*B. *> *> 2. If FACT = 'N' or 'E', the Cholesky decomposition is used to *> factor the matrix A (after equilibration if FACT = 'E') as *> A = U**H* U, if UPLO = 'U', or *> A = L * L**H, if UPLO = 'L', *> where U is an upper triangular matrix and L is a lower triangular *> matrix. *> *> 3. If the leading i-by-i principal minor is not positive definite, *> then the routine returns with INFO = i. Otherwise, the factored *> form of A is used to estimate the condition number of the matrix *> A. If the reciprocal of the condition number is less than machine *> precision, INFO = N+1 is returned as a warning, but the routine *> still goes on to solve for X and compute error bounds as *> described below. *> *> 4. The system of equations is solved for X using the factored form *> of A. *> *> 5. Iterative refinement is applied to improve the computed solution *> matrix and calculate error bounds and backward error estimates *> for it. *> *> 6. If equilibration was used, the matrix X is premultiplied by *> diag(S) so that it solves the original system before *> equilibration. *> \endverbatim * * Arguments: * ========== * *> \param[in] FACT *> \verbatim *> FACT is CHARACTER*1 *> Specifies whether or not the factored form of the matrix A is *> supplied on entry, and if not, whether the matrix A should be *> equilibrated before it is factored. *> = 'F': On entry, AF contains the factored form of A. *> If EQUED = 'Y', the matrix A has been equilibrated *> with scaling factors given by S. A and AF will not *> be modified. *> = 'N': The matrix A will be copied to AF and factored. *> = 'E': The matrix A will be equilibrated if necessary, then *> copied to AF and factored. *> \endverbatim *> *> \param[in] UPLO *> \verbatim *> UPLO is CHARACTER*1 *> = 'U': Upper triangle of A is stored; *> = 'L': Lower triangle of A is stored. *> \endverbatim *> *> \param[in] N *> \verbatim *> N is INTEGER *> The number of linear equations, i.e., the order of the *> matrix A. N >= 0. *> \endverbatim *> *> \param[in] NRHS *> \verbatim *> NRHS is INTEGER *> The number of right hand sides, i.e., the number of columns *> of the matrices B and X. NRHS >= 0. *> \endverbatim *> *> \param[in,out] A *> \verbatim *> A is COMPLEX array, dimension (LDA,N) *> On entry, the Hermitian matrix A, except if FACT = 'F' and *> EQUED = 'Y', then A must contain the equilibrated matrix *> diag(S)*A*diag(S). If UPLO = 'U', the leading *> N-by-N upper triangular part of A contains the upper *> triangular part of the matrix A, and the strictly lower *> triangular part of A is not referenced. If UPLO = 'L', the *> leading N-by-N lower triangular part of A contains the lower *> triangular part of the matrix A, and the strictly upper *> triangular part of A is not referenced. A is not modified if *> FACT = 'F' or 'N', or if FACT = 'E' and EQUED = 'N' on exit. *> *> On exit, if FACT = 'E' and EQUED = 'Y', A is overwritten by *> diag(S)*A*diag(S). *> \endverbatim *> *> \param[in] LDA *> \verbatim *> LDA is INTEGER *> The leading dimension of the array A. LDA >= max(1,N). *> \endverbatim *> *> \param[in,out] AF *> \verbatim *> AF is COMPLEX array, dimension (LDAF,N) *> If FACT = 'F', then AF is an input argument and on entry *> contains the triangular factor U or L from the Cholesky *> factorization A = U**H*U or A = L*L**H, in the same storage *> format as A. If EQUED .ne. 'N', then AF is the factored form *> of the equilibrated matrix diag(S)*A*diag(S). *> *> If FACT = 'N', then AF is an output argument and on exit *> returns the triangular factor U or L from the Cholesky *> factorization A = U**H*U or A = L*L**H of the original *> matrix A. *> *> If FACT = 'E', then AF is an output argument and on exit *> returns the triangular factor U or L from the Cholesky *> factorization A = U**H*U or A = L*L**H of the equilibrated *> matrix A (see the description of A for the form of the *> equilibrated matrix). *> \endverbatim *> *> \param[in] LDAF *> \verbatim *> LDAF is INTEGER *> The leading dimension of the array AF. LDAF >= max(1,N). *> \endverbatim *> *> \param[in,out] EQUED *> \verbatim *> EQUED is CHARACTER*1 *> Specifies the form of equilibration that was done. *> = 'N': No equilibration (always true if FACT = 'N'). *> = 'Y': Equilibration was done, i.e., A has been replaced by *> diag(S) * A * diag(S). *> EQUED is an input argument if FACT = 'F'; otherwise, it is an *> output argument. *> \endverbatim *> *> \param[in,out] S *> \verbatim *> S is REAL array, dimension (N) *> The scale factors for A; not accessed if EQUED = 'N'. S is *> an input argument if FACT = 'F'; otherwise, S is an output *> argument. If FACT = 'F' and EQUED = 'Y', each element of S *> must be positive. *> \endverbatim *> *> \param[in,out] B *> \verbatim *> B is COMPLEX array, dimension (LDB,NRHS) *> On entry, the N-by-NRHS righthand side matrix B. *> On exit, if EQUED = 'N', B is not modified; if EQUED = 'Y', *> B is overwritten by diag(S) * B. *> \endverbatim *> *> \param[in] LDB *> \verbatim *> LDB is INTEGER *> The leading dimension of the array B. LDB >= max(1,N). *> \endverbatim *> *> \param[out] X *> \verbatim *> X is COMPLEX array, dimension (LDX,NRHS) *> If INFO = 0 or INFO = N+1, the N-by-NRHS solution matrix X to *> the original system of equations. Note that if EQUED = 'Y', *> A and B are modified on exit, and the solution to the *> equilibrated system is inv(diag(S))*X. *> \endverbatim *> *> \param[in] LDX *> \verbatim *> LDX is INTEGER *> The leading dimension of the array X. LDX >= max(1,N). *> \endverbatim *> *> \param[out] RCOND *> \verbatim *> RCOND is REAL *> The estimate of the reciprocal condition number of the matrix *> A after equilibration (if done). If RCOND is less than the *> machine precision (in particular, if RCOND = 0), the matrix *> is singular to working precision. This condition is *> indicated by a return code of INFO > 0. *> \endverbatim *> *> \param[out] FERR *> \verbatim *> FERR is REAL array, dimension (NRHS) *> The estimated forward error bound for each solution vector *> X(j) (the j-th column of the solution matrix X). *> If XTRUE is the true solution corresponding to X(j), FERR(j) *> is an estimated upper bound for the magnitude of the largest *> element in (X(j) - XTRUE) divided by the magnitude of the *> largest element in X(j). The estimate is as reliable as *> the estimate for RCOND, and is almost always a slight *> overestimate of the true error. *> \endverbatim *> *> \param[out] BERR *> \verbatim *> BERR is REAL array, dimension (NRHS) *> The componentwise relative backward error of each solution *> vector X(j) (i.e., the smallest relative change in *> any element of A or B that makes X(j) an exact solution). *> \endverbatim *> *> \param[out] WORK *> \verbatim *> WORK is COMPLEX array, dimension (2*N) *> \endverbatim *> *> \param[out] RWORK *> \verbatim *> RWORK is REAL array, dimension (N) *> \endverbatim *> *> \param[out] INFO *> \verbatim *> INFO is INTEGER *> = 0: successful exit *> < 0: if INFO = -i, the i-th argument had an illegal value *> > 0: if INFO = i, and i is *> <= N: the leading minor of order i of A is *> not positive definite, so the factorization *> could not be completed, and the solution has not *> been computed. RCOND = 0 is returned. *> = N+1: U is nonsingular, but RCOND is less than machine *> precision, meaning that the matrix is singular *> to working precision. Nevertheless, the *> solution and error bounds are computed because *> there are a number of situations where the *> computed solution can be more accurate than the *> value of RCOND would suggest. *> \endverbatim * * Authors: * ======== * *> \author Univ. of Tennessee *> \author Univ. of California Berkeley *> \author Univ. of Colorado Denver *> \author NAG Ltd. * *> \date April 2012 * *> \ingroup complexPOsolve * * ===================================================================== SUBROUTINE CPOSVX( FACT, UPLO, N, NRHS, A, LDA, AF, LDAF, EQUED, $ S, B, LDB, X, LDX, RCOND, FERR, BERR, WORK, $ RWORK, INFO ) * * -- LAPACK driver routine (version 3.4.1) -- * -- LAPACK is a software package provided by Univ. of Tennessee, -- * -- Univ. of California Berkeley, Univ. of Colorado Denver and NAG Ltd..-- * April 2012 * * .. Scalar Arguments .. CHARACTER EQUED, FACT, UPLO INTEGER INFO, LDA, LDAF, LDB, LDX, N, NRHS REAL RCOND * .. * .. Array Arguments .. REAL BERR( * ), FERR( * ), RWORK( * ), S( * ) COMPLEX A( LDA, * ), AF( LDAF, * ), B( LDB, * ), $ WORK( * ), X( LDX, * ) * .. * * ===================================================================== * * .. Parameters .. REAL ZERO, ONE PARAMETER ( ZERO = 0.0E+0, ONE = 1.0E+0 ) * .. * .. Local Scalars .. LOGICAL EQUIL, NOFACT, RCEQU INTEGER I, INFEQU, J REAL AMAX, ANORM, BIGNUM, SCOND, SMAX, SMIN, SMLNUM * .. * .. External Functions .. LOGICAL LSAME REAL CLANHE, SLAMCH EXTERNAL LSAME, CLANHE, SLAMCH * .. * .. External Subroutines .. EXTERNAL CLACPY, CLAQHE, CPOCON, CPOEQU, CPORFS, CPOTRF, $ CPOTRS, XERBLA * .. * .. Intrinsic Functions .. INTRINSIC MAX, MIN * .. * .. Executable Statements .. * INFO = 0 NOFACT = LSAME( FACT, 'N' ) EQUIL = LSAME( FACT, 'E' ) IF( NOFACT .OR. EQUIL ) THEN EQUED = 'N' RCEQU = .FALSE. ELSE RCEQU = LSAME( EQUED, 'Y' ) SMLNUM = SLAMCH( 'Safe minimum' ) BIGNUM = ONE / SMLNUM END IF * * Test the input parameters. * IF( .NOT.NOFACT .AND. .NOT.EQUIL .AND. .NOT.LSAME( FACT, 'F' ) ) $ THEN INFO = -1 ELSE IF( .NOT.LSAME( UPLO, 'U' ) .AND. .NOT.LSAME( UPLO, 'L' ) ) $ THEN INFO = -2 ELSE IF( N.LT.0 ) THEN INFO = -3 ELSE IF( NRHS.LT.0 ) THEN INFO = -4 ELSE IF( LDA.LT.MAX( 1, N ) ) THEN INFO = -6 ELSE IF( LDAF.LT.MAX( 1, N ) ) THEN INFO = -8 ELSE IF( LSAME( FACT, 'F' ) .AND. .NOT. $ ( RCEQU .OR. LSAME( EQUED, 'N' ) ) ) THEN INFO = -9 ELSE IF( RCEQU ) THEN SMIN = BIGNUM SMAX = ZERO DO 10 J = 1, N SMIN = MIN( SMIN, S( J ) ) SMAX = MAX( SMAX, S( J ) ) 10 CONTINUE IF( SMIN.LE.ZERO ) THEN INFO = -10 ELSE IF( N.GT.0 ) THEN SCOND = MAX( SMIN, SMLNUM ) / MIN( SMAX, BIGNUM ) ELSE SCOND = ONE END IF END IF IF( INFO.EQ.0 ) THEN IF( LDB.LT.MAX( 1, N ) ) THEN INFO = -12 ELSE IF( LDX.LT.MAX( 1, N ) ) THEN INFO = -14 END IF END IF END IF * IF( INFO.NE.0 ) THEN CALL XERBLA( 'CPOSVX', -INFO ) RETURN END IF * IF( EQUIL ) THEN * * Compute row and column scalings to equilibrate the matrix A. * CALL CPOEQU( N, A, LDA, S, SCOND, AMAX, INFEQU ) IF( INFEQU.EQ.0 ) THEN * * Equilibrate the matrix. * CALL CLAQHE( UPLO, N, A, LDA, S, SCOND, AMAX, EQUED ) RCEQU = LSAME( EQUED, 'Y' ) END IF END IF * * Scale the right hand side. * IF( RCEQU ) THEN DO 30 J = 1, NRHS DO 20 I = 1, N B( I, J ) = S( I )*B( I, J ) 20 CONTINUE 30 CONTINUE END IF * IF( NOFACT .OR. EQUIL ) THEN * * Compute the Cholesky factorization A = U**H *U or A = L*L**H. * CALL CLACPY( UPLO, N, N, A, LDA, AF, LDAF ) CALL CPOTRF( UPLO, N, AF, LDAF, INFO ) * * Return if INFO is non-zero. * IF( INFO.GT.0 )THEN RCOND = ZERO RETURN END IF END IF * * Compute the norm of the matrix A. * ANORM = CLANHE( '1', UPLO, N, A, LDA, RWORK ) * * Compute the reciprocal of the condition number of A. * CALL CPOCON( UPLO, N, AF, LDAF, ANORM, RCOND, WORK, RWORK, INFO ) * * Compute the solution matrix X. * CALL CLACPY( 'Full', N, NRHS, B, LDB, X, LDX ) CALL CPOTRS( UPLO, N, NRHS, AF, LDAF, X, LDX, INFO ) * * Use iterative refinement to improve the computed solution and * compute error bounds and backward error estimates for it. * CALL CPORFS( UPLO, N, NRHS, A, LDA, AF, LDAF, B, LDB, X, LDX, $ FERR, BERR, WORK, RWORK, INFO ) * * Transform the solution matrix X to a solution of the original * system. * IF( RCEQU ) THEN DO 50 J = 1, NRHS DO 40 I = 1, N X( I, J ) = S( I )*X( I, J ) 40 CONTINUE 50 CONTINUE DO 60 J = 1, NRHS FERR( J ) = FERR( J ) / SCOND 60 CONTINUE END IF * * Set INFO = N+1 if the matrix is singular to working precision. * IF( RCOND.LT.SLAMCH( 'Epsilon' ) ) $ INFO = N + 1 * RETURN * * End of CPOSVX * END
gpl-2.0
wilmarcardonac/hypermcmc
lapack-3.5.0/SRC/ztrttp.f
24
4817
*> \brief \b ZTRTTP copies a triangular matrix from the standard full format (TR) to the standard packed format (TP). * * =========== DOCUMENTATION =========== * * Online html documentation available at * http://www.netlib.org/lapack/explore-html/ * *> \htmlonly *> Download ZTRTTP + dependencies *> <a href="http://www.netlib.org/cgi-bin/netlibfiles.tgz?format=tgz&filename=/lapack/lapack_routine/ztrttp.f"> *> [TGZ]</a> *> <a href="http://www.netlib.org/cgi-bin/netlibfiles.zip?format=zip&filename=/lapack/lapack_routine/ztrttp.f"> *> [ZIP]</a> *> <a href="http://www.netlib.org/cgi-bin/netlibfiles.txt?format=txt&filename=/lapack/lapack_routine/ztrttp.f"> *> [TXT]</a> *> \endhtmlonly * * Definition: * =========== * * SUBROUTINE ZTRTTP( UPLO, N, A, LDA, AP, INFO ) * * .. Scalar Arguments .. * CHARACTER UPLO * INTEGER INFO, N, LDA * .. * .. Array Arguments .. * COMPLEX*16 A( LDA, * ), AP( * ) * .. * * *> \par Purpose: * ============= *> *> \verbatim *> *> ZTRTTP copies a triangular matrix A from full format (TR) to standard *> packed format (TP). *> \endverbatim * * Arguments: * ========== * *> \param[in] UPLO *> \verbatim *> UPLO is CHARACTER*1 *> = 'U': A is upper triangular; *> = 'L': A is lower triangular. *> \endverbatim *> *> \param[in] N *> \verbatim *> N is INTEGER *> The order of the matrices AP and A. N >= 0. *> \endverbatim *> *> \param[in] A *> \verbatim *> A is COMPLEX*16 array, dimension (LDA,N) *> On entry, the triangular matrix A. If UPLO = 'U', the leading *> N-by-N upper triangular part of A contains the upper *> triangular part of the matrix A, and the strictly lower *> triangular part of A is not referenced. If UPLO = 'L', the *> leading N-by-N lower triangular part of A contains the lower *> triangular part of the matrix A, and the strictly upper *> triangular part of A is not referenced. *> \endverbatim *> *> \param[in] LDA *> \verbatim *> LDA is INTEGER *> The leading dimension of the array A. LDA >= max(1,N). *> \endverbatim *> *> \param[out] AP *> \verbatim *> AP is COMPLEX*16 array, dimension ( N*(N+1)/2 ), *> On exit, the upper or lower triangular matrix A, packed *> columnwise in a linear array. The j-th column of A is stored *> in the array AP as follows: *> if UPLO = 'U', AP(i + (j-1)*j/2) = A(i,j) for 1<=i<=j; *> if UPLO = 'L', AP(i + (j-1)*(2n-j)/2) = A(i,j) for j<=i<=n. *> \endverbatim *> *> \param[out] INFO *> \verbatim *> INFO is INTEGER *> = 0: successful exit *> < 0: if INFO = -i, the i-th argument had an illegal value *> \endverbatim * * Authors: * ======== * *> \author Univ. of Tennessee *> \author Univ. of California Berkeley *> \author Univ. of Colorado Denver *> \author NAG Ltd. * *> \date September 2012 * *> \ingroup complex16OTHERcomputational * * ===================================================================== SUBROUTINE ZTRTTP( UPLO, N, A, LDA, AP, INFO ) * * -- LAPACK computational routine (version 3.4.2) -- * -- LAPACK is a software package provided by Univ. of Tennessee, -- * -- Univ. of California Berkeley, Univ. of Colorado Denver and NAG Ltd..-- * September 2012 * * .. Scalar Arguments .. CHARACTER UPLO INTEGER INFO, N, LDA * .. * .. Array Arguments .. COMPLEX*16 A( LDA, * ), AP( * ) * .. * * ===================================================================== * * .. Parameters .. * .. * .. Local Scalars .. LOGICAL LOWER INTEGER I, J, K * .. * .. External Functions .. LOGICAL LSAME EXTERNAL LSAME * .. * .. External Subroutines .. EXTERNAL XERBLA * .. * .. Executable Statements .. * * Test the input parameters. * INFO = 0 LOWER = LSAME( UPLO, 'L' ) IF( .NOT.LOWER .AND. .NOT.LSAME( UPLO, 'U' ) ) THEN INFO = -1 ELSE IF( N.LT.0 ) THEN INFO = -2 ELSE IF( LDA.LT.MAX( 1, N ) ) THEN INFO = -4 END IF IF( INFO.NE.0 ) THEN CALL XERBLA( 'ZTRTTP', -INFO ) RETURN END IF * IF( LOWER ) THEN K = 0 DO J = 1, N DO I = J, N K = K + 1 AP( K ) = A( I, J ) END DO END DO ELSE K = 0 DO J = 1, N DO I = 1, J K = K + 1 AP( K ) = A( I, J ) END DO END DO END IF * * RETURN * * End of ZTRTTP * END
gpl-2.0
linzhaoming/origin
vendor/gonum.org/v1/gonum/lapack/internal/testdata/dlasqtest/dlasq3.f
59
12810
*> \brief \b DLASQ3 checks for deflation, computes a shift and calls dqds. Used by sbdsqr. * * =========== DOCUMENTATION =========== * * Online html documentation available at * http://www.netlib.org/lapack/explore-html/ * *> \htmlonly *> Download DLASQ3 + dependencies *> <a href="http://www.netlib.org/cgi-bin/netlibfiles.tgz?format=tgz&filename=/lapack/lapack_routine/dlasq3.f"> *> [TGZ]</a> *> <a href="http://www.netlib.org/cgi-bin/netlibfiles.zip?format=zip&filename=/lapack/lapack_routine/dlasq3.f"> *> [ZIP]</a> *> <a href="http://www.netlib.org/cgi-bin/netlibfiles.txt?format=txt&filename=/lapack/lapack_routine/dlasq3.f"> *> [TXT]</a> *> \endhtmlonly * * Definition: * =========== * * SUBROUTINE DLASQ3( I0, N0, Z, PP, DMIN, SIGMA, DESIG, QMAX, NFAIL, * ITER, NDIV, IEEE, TTYPE, DMIN1, DMIN2, DN, DN1, * DN2, G, TAU ) * * .. Scalar Arguments .. * LOGICAL IEEE * INTEGER I0, ITER, N0, NDIV, NFAIL, PP * DOUBLE PRECISION DESIG, DMIN, DMIN1, DMIN2, DN, DN1, DN2, G, * $ QMAX, SIGMA, TAU * .. * .. Array Arguments .. * DOUBLE PRECISION Z( * ) * .. * * *> \par Purpose: * ============= *> *> \verbatim *> *> DLASQ3 checks for deflation, computes a shift (TAU) and calls dqds. *> In case of failure it changes shifts, and tries again until output *> is positive. *> \endverbatim * * Arguments: * ========== * *> \param[in] I0 *> \verbatim *> I0 is INTEGER *> First index. *> \endverbatim *> *> \param[in,out] N0 *> \verbatim *> N0 is INTEGER *> Last index. *> \endverbatim *> *> \param[in] Z *> \verbatim *> Z is DOUBLE PRECISION array, dimension ( 4*N ) *> Z holds the qd array. *> \endverbatim *> *> \param[in,out] PP *> \verbatim *> PP is INTEGER *> PP=0 for ping, PP=1 for pong. *> PP=2 indicates that flipping was applied to the Z array *> and that the initial tests for deflation should not be *> performed. *> \endverbatim *> *> \param[out] DMIN *> \verbatim *> DMIN is DOUBLE PRECISION *> Minimum value of d. *> \endverbatim *> *> \param[out] SIGMA *> \verbatim *> SIGMA is DOUBLE PRECISION *> Sum of shifts used in current segment. *> \endverbatim *> *> \param[in,out] DESIG *> \verbatim *> DESIG is DOUBLE PRECISION *> Lower order part of SIGMA *> \endverbatim *> *> \param[in] QMAX *> \verbatim *> QMAX is DOUBLE PRECISION *> Maximum value of q. *> \endverbatim *> *> \param[out] NFAIL *> \verbatim *> NFAIL is INTEGER *> Number of times shift was too big. *> \endverbatim *> *> \param[out] ITER *> \verbatim *> ITER is INTEGER *> Number of iterations. *> \endverbatim *> *> \param[out] NDIV *> \verbatim *> NDIV is INTEGER *> Number of divisions. *> \endverbatim *> *> \param[in] IEEE *> \verbatim *> IEEE is LOGICAL *> Flag for IEEE or non IEEE arithmetic (passed to DLASQ5). *> \endverbatim *> *> \param[in,out] TTYPE *> \verbatim *> TTYPE is INTEGER *> Shift type. *> \endverbatim *> *> \param[in,out] DMIN1 *> \verbatim *> DMIN1 is DOUBLE PRECISION *> \endverbatim *> *> \param[in,out] DMIN2 *> \verbatim *> DMIN2 is DOUBLE PRECISION *> \endverbatim *> *> \param[in,out] DN *> \verbatim *> DN is DOUBLE PRECISION *> \endverbatim *> *> \param[in,out] DN1 *> \verbatim *> DN1 is DOUBLE PRECISION *> \endverbatim *> *> \param[in,out] DN2 *> \verbatim *> DN2 is DOUBLE PRECISION *> \endverbatim *> *> \param[in,out] G *> \verbatim *> G is DOUBLE PRECISION *> \endverbatim *> *> \param[in,out] TAU *> \verbatim *> TAU is DOUBLE PRECISION *> *> These are passed as arguments in order to save their values *> between calls to DLASQ3. *> \endverbatim * * Authors: * ======== * *> \author Univ. of Tennessee *> \author Univ. of California Berkeley *> \author Univ. of Colorado Denver *> \author NAG Ltd. * *> \date September 2012 * *> \ingroup auxOTHERcomputational * * ===================================================================== SUBROUTINE DLASQ3( I0, N0, Z, PP, DMIN, SIGMA, DESIG, QMAX, NFAIL, $ ITER, NDIV, IEEE, TTYPE, DMIN1, DMIN2, DN, DN1, $ DN2, G, TAU ) * * -- LAPACK computational routine (version 3.4.2) -- * -- LAPACK is a software package provided by Univ. of Tennessee, -- * -- Univ. of California Berkeley, Univ. of Colorado Denver and NAG Ltd..-- * September 2012 * * .. Scalar Arguments .. LOGICAL IEEE INTEGER I0, ITER, N0, NDIV, NFAIL, PP DOUBLE PRECISION DESIG, DMIN, DMIN1, DMIN2, DN, DN1, DN2, G, $ QMAX, SIGMA, TAU * .. * .. Array Arguments .. DOUBLE PRECISION Z( * ) * .. * * ===================================================================== * * .. Parameters .. DOUBLE PRECISION CBIAS PARAMETER ( CBIAS = 1.50D0 ) DOUBLE PRECISION ZERO, QURTR, HALF, ONE, TWO, HUNDRD PARAMETER ( ZERO = 0.0D0, QURTR = 0.250D0, HALF = 0.5D0, $ ONE = 1.0D0, TWO = 2.0D0, HUNDRD = 100.0D0 ) * .. * .. Local Scalars .. INTEGER IPN4, J4, N0IN, NN, TTYPE DOUBLE PRECISION EPS, S, T, TEMP, TOL, TOL2 * .. * .. External Subroutines .. EXTERNAL DLASQ4, DLASQ5, DLASQ6 * .. * .. External Function .. DOUBLE PRECISION DLAMCH LOGICAL DISNAN EXTERNAL DISNAN, DLAMCH * .. * .. Intrinsic Functions .. INTRINSIC ABS, MAX, MIN, SQRT * .. * .. Executable Statements .. * N0IN = N0 EPS = DLAMCH( 'Precision' ) TOL = EPS*HUNDRD TOL2 = TOL**2 * * Check for deflation. * 10 CONTINUE * IF( N0.LT.I0 ) $ RETURN IF( N0.EQ.I0 ) $ GO TO 20 NN = 4*N0 + PP IF( N0.EQ.( I0+1 ) ) $ GO TO 40 * * Check whether E(N0-1) is negligible, 1 eigenvalue. * IF( Z( NN-5 ).GT.TOL2*( SIGMA+Z( NN-3 ) ) .AND. $ Z( NN-2*PP-4 ).GT.TOL2*Z( NN-7 ) ) $ GO TO 30 * 20 CONTINUE * Z( 4*N0-3 ) = Z( 4*N0+PP-3 ) + SIGMA N0 = N0 - 1 GO TO 10 * * Check whether E(N0-2) is negligible, 2 eigenvalues. * 30 CONTINUE * IF( Z( NN-9 ).GT.TOL2*SIGMA .AND. $ Z( NN-2*PP-8 ).GT.TOL2*Z( NN-11 ) ) $ GO TO 50 * 40 CONTINUE * IF( Z( NN-3 ).GT.Z( NN-7 ) ) THEN S = Z( NN-3 ) Z( NN-3 ) = Z( NN-7 ) Z( NN-7 ) = S END IF T = HALF*( ( Z( NN-7 )-Z( NN-3 ) )+Z( NN-5 ) ) IF( Z( NN-5 ).GT.Z( NN-3 )*TOL2.AND.T.NE.ZERO ) THEN S = Z( NN-3 )*( Z( NN-5 ) / T ) IF( S.LE.T ) THEN S = Z( NN-3 )*( Z( NN-5 ) / $ ( T*( ONE+SQRT( ONE+S / T ) ) ) ) ELSE S = Z( NN-3 )*( Z( NN-5 ) / ( T+SQRT( T )*SQRT( T+S ) ) ) END IF T = Z( NN-7 ) + ( S+Z( NN-5 ) ) Z( NN-3 ) = Z( NN-3 )*( Z( NN-7 ) / T ) Z( NN-7 ) = T END IF Z( 4*N0-7 ) = Z( NN-7 ) + SIGMA Z( 4*N0-3 ) = Z( NN-3 ) + SIGMA N0 = N0 - 2 GO TO 10 * 50 CONTINUE IF( PP.EQ.2 ) $ PP = 0 * * Reverse the qd-array, if warranted. * IF( DMIN.LE.ZERO .OR. N0.LT.N0IN ) THEN IF( CBIAS*Z( 4*I0+PP-3 ).LT.Z( 4*N0+PP-3 ) ) THEN IPN4 = 4*( I0+N0 ) DO 60 J4 = 4*I0, 2*( I0+N0-1 ), 4 TEMP = Z( J4-3 ) Z( J4-3 ) = Z( IPN4-J4-3 ) Z( IPN4-J4-3 ) = TEMP TEMP = Z( J4-2 ) Z( J4-2 ) = Z( IPN4-J4-2 ) Z( IPN4-J4-2 ) = TEMP TEMP = Z( J4-1 ) Z( J4-1 ) = Z( IPN4-J4-5 ) Z( IPN4-J4-5 ) = TEMP TEMP = Z( J4 ) Z( J4 ) = Z( IPN4-J4-4 ) Z( IPN4-J4-4 ) = TEMP 60 CONTINUE IF( N0-I0.LE.4 ) THEN Z( 4*N0+PP-1 ) = Z( 4*I0+PP-1 ) Z( 4*N0-PP ) = Z( 4*I0-PP ) END IF DMIN2 = MIN( DMIN2, Z( 4*N0+PP-1 ) ) Z( 4*N0+PP-1 ) = MIN( Z( 4*N0+PP-1 ), Z( 4*I0+PP-1 ), $ Z( 4*I0+PP+3 ) ) Z( 4*N0-PP ) = MIN( Z( 4*N0-PP ), Z( 4*I0-PP ), $ Z( 4*I0-PP+4 ) ) QMAX = MAX( QMAX, Z( 4*I0+PP-3 ), Z( 4*I0+PP+1 ) ) DMIN = -ZERO END IF END IF * * Choose a shift. * ! Print out DLASQ4 test cases write(4,*) "{" write(4,'(9999(g0))',advance="no") "z: []float64{" do i = 1, NN write (4,'(99999(e24.16,a))',advance="no") z(i), "," end do write (4,*) "}," write (4,*) "i0: ", I0, "," write (4,*) "n0: ", N0, "," write (4,*) "pp: ", PP, "," write (4,*) "n0in: ", N0IN, "," write (4,*) "dmin: ", DMIN, "," write (4,*) "dmin1:", DMIN1, "," write (4,*) "dmin2:", DMIN2, "," write (4,*) "dn: ", DN, "," write (4,*) "dn1: ", DN1, "," write (4,*) "dn2: ", DN2, "," write (4,*) "tau: ", TAU, "," write (4,*) "ttype: ", TTYPE, "," write (4,*) "g: ", G, "," CALL DLASQ4( I0, N0, Z, PP, N0IN, DMIN, DMIN1, DMIN2, DN, DN1, $ DN2, TAU, TTYPE, G ) write(4,'(9999(g0))',advance="no") "zOut: []float64{" do i = 1, NN write (4,'(99999(e24.16,a))',advance="no") z(i), "," end do write (4,*) "}," write (4,*) "tauOut: ", TAU, "," write (4,*) "ttypeOut: ", TTYPE, "," write (4,*) "gOut: ", G, "," write (4,*) "}," * * Call dqds until DMIN > 0. * 70 CONTINUE * write(5,*) "{" write(5,'(9999(g0))',advance="no") "z: []float64{" do i = 1, NN write (5,'(99999(e24.16,a))',advance="no") z(i), "," end do write (5,*) "}," write (5,*) "i0: ", I0, "," write (5,*) "n0: ", N0, "," write (5,*) "pp: ", PP, "," write (5,*) "tau: ", TAU, "," write (5,*) "sigma: ", SIGMA, "," write (5,*) "dmin: ", DMIN, "," write (5,*) "dmin1:", DMIN1, "," write (5,*) "dmin2:", DMIN2, "," write (5,*) "dn: ", DN, "," write (5,*) "dnm1: ", DN1, "," write (5,*) "dnm2: ", DN2, "," CALL DLASQ5( I0, N0, Z, PP, TAU, SIGMA, DMIN, DMIN1, DMIN2, DN, $ DN1, DN2, IEEE, EPS ) write (5,*) "i0Out: ", I0, "," write (5,*) "n0Out: ", N0, "," write (5,*) "ppOut: ", PP, "," write (5,*) "tauOut: ", TAU, "," write (5,*) "sigmaOut: ", SIGMA, "," write (5,*) "dminOut: ", DMIN, "," write (5,*) "dmin1Out:", DMIN1, "," write (5,*) "dmin2Out:", DMIN2, "," write (5,*) "dnOut: ", DN, "," write (5,*) "dnm1Out: ", DN1, "," write (5,*) "dnm2Out: ", DN2, "," write (5,*) "}," * NDIV = NDIV + ( N0-I0+2 ) ITER = ITER + 1 * * Check status. * IF( DMIN.GE.ZERO .AND. DMIN1.GE.ZERO ) THEN * * Success. * GO TO 90 * ELSE IF( DMIN.LT.ZERO .AND. DMIN1.GT.ZERO .AND. $ Z( 4*( N0-1 )-PP ).LT.TOL*( SIGMA+DN1 ) .AND. $ ABS( DN ).LT.TOL*SIGMA ) THEN * * Convergence hidden by negative DN. * Z( 4*( N0-1 )-PP+2 ) = ZERO DMIN = ZERO GO TO 90 ELSE IF( DMIN.LT.ZERO ) THEN * * TAU too big. Select new TAU and try again. * NFAIL = NFAIL + 1 IF( TTYPE.LT.-22 ) THEN * * Failed twice. Play it safe. * TAU = ZERO ELSE IF( DMIN1.GT.ZERO ) THEN * * Late failure. Gives excellent shift. * TAU = ( TAU+DMIN )*( ONE-TWO*EPS ) TTYPE = TTYPE - 11 ELSE * * Early failure. Divide by 4. * TAU = QURTR*TAU TTYPE = TTYPE - 12 END IF GO TO 70 ELSE IF( DISNAN( DMIN ) ) THEN * * NaN. * IF( TAU.EQ.ZERO ) THEN GO TO 80 ELSE TAU = ZERO GO TO 70 END IF ELSE * * Possible underflow. Play it safe. * GO TO 80 END IF * * Risk of underflow. * 80 CONTINUE CALL DLASQ6( I0, N0, Z, PP, DMIN, DMIN1, DMIN2, DN, DN1, DN2 ) NDIV = NDIV + ( N0-I0+2 ) ITER = ITER + 1 TAU = ZERO * 90 CONTINUE IF( TAU.LT.SIGMA ) THEN DESIG = DESIG + TAU T = SIGMA + DESIG DESIG = DESIG - ( T-SIGMA ) ELSE T = SIGMA + TAU DESIG = SIGMA - ( T-TAU ) + DESIG END IF SIGMA = T * RETURN * * End of DLASQ3 * END
apache-2.0
wilmarcardonac/hypermcmc
lapack-3.5.0/SRC/zgeqr2p.f
19
5226
*> \brief \b ZGEQR2P computes the QR factorization of a general rectangular matrix with non-negative diagonal elements using an unblocked algorithm. * * =========== DOCUMENTATION =========== * * Online html documentation available at * http://www.netlib.org/lapack/explore-html/ * *> \htmlonly *> Download ZGEQR2P + dependencies *> <a href="http://www.netlib.org/cgi-bin/netlibfiles.tgz?format=tgz&filename=/lapack/lapack_routine/zgeqr2p.f"> *> [TGZ]</a> *> <a href="http://www.netlib.org/cgi-bin/netlibfiles.zip?format=zip&filename=/lapack/lapack_routine/zgeqr2p.f"> *> [ZIP]</a> *> <a href="http://www.netlib.org/cgi-bin/netlibfiles.txt?format=txt&filename=/lapack/lapack_routine/zgeqr2p.f"> *> [TXT]</a> *> \endhtmlonly * * Definition: * =========== * * SUBROUTINE ZGEQR2P( M, N, A, LDA, TAU, WORK, INFO ) * * .. Scalar Arguments .. * INTEGER INFO, LDA, M, N * .. * .. Array Arguments .. * COMPLEX*16 A( LDA, * ), TAU( * ), WORK( * ) * .. * * *> \par Purpose: * ============= *> *> \verbatim *> *> ZGEQR2P computes a QR factorization of a complex m by n matrix A: *> A = Q * R. *> \endverbatim * * Arguments: * ========== * *> \param[in] M *> \verbatim *> M is INTEGER *> The number of rows of the matrix A. M >= 0. *> \endverbatim *> *> \param[in] N *> \verbatim *> N is INTEGER *> The number of columns of the matrix A. N >= 0. *> \endverbatim *> *> \param[in,out] A *> \verbatim *> A is COMPLEX*16 array, dimension (LDA,N) *> On entry, the m by n matrix A. *> On exit, the elements on and above the diagonal of the array *> contain the min(m,n) by n upper trapezoidal matrix R (R is *> upper triangular if m >= n); the elements below the diagonal, *> with the array TAU, represent the unitary matrix Q as a *> product of elementary reflectors (see Further Details). *> \endverbatim *> *> \param[in] LDA *> \verbatim *> LDA is INTEGER *> The leading dimension of the array A. LDA >= max(1,M). *> \endverbatim *> *> \param[out] TAU *> \verbatim *> TAU is COMPLEX*16 array, dimension (min(M,N)) *> The scalar factors of the elementary reflectors (see Further *> Details). *> \endverbatim *> *> \param[out] WORK *> \verbatim *> WORK is COMPLEX*16 array, dimension (N) *> \endverbatim *> *> \param[out] INFO *> \verbatim *> INFO is INTEGER *> = 0: successful exit *> < 0: if INFO = -i, the i-th argument had an illegal value *> \endverbatim * * Authors: * ======== * *> \author Univ. of Tennessee *> \author Univ. of California Berkeley *> \author Univ. of Colorado Denver *> \author NAG Ltd. * *> \date September 2012 * *> \ingroup complex16GEcomputational * *> \par Further Details: * ===================== *> *> \verbatim *> *> The matrix Q is represented as a product of elementary reflectors *> *> Q = H(1) H(2) . . . H(k), where k = min(m,n). *> *> Each H(i) has the form *> *> H(i) = I - tau * v * v**H *> *> where tau is a complex scalar, and v is a complex vector with *> v(1:i-1) = 0 and v(i) = 1; v(i+1:m) is stored on exit in A(i+1:m,i), *> and tau in TAU(i). *> \endverbatim *> * ===================================================================== SUBROUTINE ZGEQR2P( M, N, A, LDA, TAU, WORK, INFO ) * * -- LAPACK computational routine (version 3.4.2) -- * -- LAPACK is a software package provided by Univ. of Tennessee, -- * -- Univ. of California Berkeley, Univ. of Colorado Denver and NAG Ltd..-- * September 2012 * * .. Scalar Arguments .. INTEGER INFO, LDA, M, N * .. * .. Array Arguments .. COMPLEX*16 A( LDA, * ), TAU( * ), WORK( * ) * .. * * ===================================================================== * * .. Parameters .. COMPLEX*16 ONE PARAMETER ( ONE = ( 1.0D+0, 0.0D+0 ) ) * .. * .. Local Scalars .. INTEGER I, K COMPLEX*16 ALPHA * .. * .. External Subroutines .. EXTERNAL XERBLA, ZLARF, ZLARFGP * .. * .. Intrinsic Functions .. INTRINSIC DCONJG, MAX, MIN * .. * .. Executable Statements .. * * Test the input arguments * INFO = 0 IF( M.LT.0 ) THEN INFO = -1 ELSE IF( N.LT.0 ) THEN INFO = -2 ELSE IF( LDA.LT.MAX( 1, M ) ) THEN INFO = -4 END IF IF( INFO.NE.0 ) THEN CALL XERBLA( 'ZGEQR2P', -INFO ) RETURN END IF * K = MIN( M, N ) * DO 10 I = 1, K * * Generate elementary reflector H(i) to annihilate A(i+1:m,i) * CALL ZLARFGP( M-I+1, A( I, I ), A( MIN( I+1, M ), I ), 1, $ TAU( I ) ) IF( I.LT.N ) THEN * * Apply H(i)**H to A(i:m,i+1:n) from the left * ALPHA = A( I, I ) A( I, I ) = ONE CALL ZLARF( 'Left', M-I+1, N-I, A( I, I ), 1, $ DCONJG( TAU( I ) ), A( I, I+1 ), LDA, WORK ) A( I, I ) = ALPHA END IF 10 CONTINUE RETURN * * End of ZGEQR2P * END
gpl-2.0
wilmarcardonac/hypermcmc
lapack-3.5.0/TESTING/LIN/derrqrtp.f
31
6965
*> \brief \b DERRQRTP * * =========== DOCUMENTATION =========== * * Online html documentation available at * http://www.netlib.org/lapack/explore-html/ * * Definition: * =========== * * SUBROUTINE DERRQRTP( PATH, NUNIT ) * * .. Scalar Arguments .. * CHARACTER*3 PATH * INTEGER NUNIT * .. * * *> \par Purpose: * ============= *> *> \verbatim *> *> DERRQRTP tests the error exits for the REAL routines *> that use the QRT decomposition of a triangular-pentagonal matrix. *> \endverbatim * * Arguments: * ========== * *> \param[in] PATH *> \verbatim *> PATH is CHARACTER*3 *> The LAPACK path name for the routines to be tested. *> \endverbatim *> *> \param[in] NUNIT *> \verbatim *> NUNIT is INTEGER *> The unit number for output. *> \endverbatim * * Authors: * ======== * *> \author Univ. of Tennessee *> \author Univ. of California Berkeley *> \author Univ. of Colorado Denver *> \author NAG Ltd. * *> \date November 2011 * *> \ingroup double_lin * * ===================================================================== SUBROUTINE DERRQRTP( PATH, NUNIT ) IMPLICIT NONE * * -- LAPACK test routine (version 3.4.0) -- * -- LAPACK is a software package provided by Univ. of Tennessee, -- * -- Univ. of California Berkeley, Univ. of Colorado Denver and NAG Ltd..-- * November 2011 * * .. Scalar Arguments .. CHARACTER*3 PATH INTEGER NUNIT * .. * * ===================================================================== * * .. Parameters .. INTEGER NMAX PARAMETER ( NMAX = 2 ) * .. * .. Local Scalars .. INTEGER I, INFO, J * .. * .. Local Arrays .. DOUBLE PRECISION A( NMAX, NMAX ), T( NMAX, NMAX ), W( NMAX ), $ B( NMAX, NMAX ), C( NMAX, NMAX ) * .. * .. External Subroutines .. EXTERNAL ALAESM, CHKXER, DTPQRT2, DTPQRT, $ DTPMQRT * .. * .. Scalars in Common .. LOGICAL LERR, OK CHARACTER*32 SRNAMT INTEGER INFOT, NOUT * .. * .. Common blocks .. COMMON / INFOC / INFOT, NOUT, OK, LERR COMMON / SRNAMC / SRNAMT * .. * .. Intrinsic Functions .. INTRINSIC DBLE * .. * .. Executable Statements .. * NOUT = NUNIT WRITE( NOUT, FMT = * ) * * Set the variables to innocuous values. * DO J = 1, NMAX DO I = 1, NMAX A( I, J ) = 1.D0 / DBLE( I+J ) C( I, J ) = 1.D0 / DBLE( I+J ) T( I, J ) = 1.D0 / DBLE( I+J ) END DO W( J ) = 0.0 END DO OK = .TRUE. * * Error exits for TPQRT factorization * * DTPQRT * SRNAMT = 'DTPQRT' INFOT = 1 CALL DTPQRT( -1, 1, 0, 1, A, 1, B, 1, T, 1, W, INFO ) CALL CHKXER( 'DTPQRT', INFOT, NOUT, LERR, OK ) INFOT = 2 CALL DTPQRT( 1, -1, 0, 1, A, 1, B, 1, T, 1, W, INFO ) CALL CHKXER( 'DTPQRT', INFOT, NOUT, LERR, OK ) INFOT = 3 CALL DTPQRT( 0, 1, -1, 1, A, 1, B, 1, T, 1, W, INFO ) CALL CHKXER( 'DTPQRT', INFOT, NOUT, LERR, OK ) INFOT = 3 CALL DTPQRT( 0, 1, 1, 1, A, 1, B, 1, T, 1, W, INFO ) CALL CHKXER( 'DTPQRT', INFOT, NOUT, LERR, OK ) INFOT = 4 CALL DTPQRT( 0, 1, 0, 0, A, 1, B, 1, T, 1, W, INFO ) CALL CHKXER( 'DTPQRT', INFOT, NOUT, LERR, OK ) INFOT = 4 CALL DTPQRT( 0, 1, 0, 2, A, 1, B, 1, T, 1, W, INFO ) CALL CHKXER( 'DTPQRT', INFOT, NOUT, LERR, OK ) INFOT = 6 CALL DTPQRT( 1, 2, 0, 2, A, 1, B, 1, T, 1, W, INFO ) CALL CHKXER( 'DTPQRT', INFOT, NOUT, LERR, OK ) INFOT = 8 CALL DTPQRT( 2, 1, 0, 1, A, 1, B, 1, T, 1, W, INFO ) CALL CHKXER( 'DTPQRT', INFOT, NOUT, LERR, OK ) INFOT = 10 CALL DTPQRT( 2, 2, 1, 2, A, 2, B, 2, T, 1, W, INFO ) CALL CHKXER( 'DTPQRT', INFOT, NOUT, LERR, OK ) * * DTPQRT2 * SRNAMT = 'DTPQRT2' INFOT = 1 CALL DTPQRT2( -1, 0, 0, A, 1, B, 1, T, 1, INFO ) CALL CHKXER( 'DTPQRT2', INFOT, NOUT, LERR, OK ) INFOT = 2 CALL DTPQRT2( 0, -1, 0, A, 1, B, 1, T, 1, INFO ) CALL CHKXER( 'DTPQRT2', INFOT, NOUT, LERR, OK ) INFOT = 3 CALL DTPQRT2( 0, 0, -1, A, 1, B, 1, T, 1, INFO ) CALL CHKXER( 'DTPQRT2', INFOT, NOUT, LERR, OK ) INFOT = 5 CALL DTPQRT2( 2, 2, 0, A, 1, B, 2, T, 2, INFO ) CALL CHKXER( 'DTPQRT2', INFOT, NOUT, LERR, OK ) INFOT = 7 CALL DTPQRT2( 2, 2, 0, A, 2, B, 1, T, 2, INFO ) CALL CHKXER( 'DTPQRT2', INFOT, NOUT, LERR, OK ) INFOT = 9 CALL DTPQRT2( 2, 2, 0, A, 2, B, 2, T, 1, INFO ) CALL CHKXER( 'DTPQRT2', INFOT, NOUT, LERR, OK ) * * DTPMQRT * SRNAMT = 'DTPMQRT' INFOT = 1 CALL DTPMQRT( '/', 'N', 0, 0, 0, 0, 1, A, 1, T, 1, B, 1, C, 1, $ W, INFO ) CALL CHKXER( 'DTPMQRT', INFOT, NOUT, LERR, OK ) INFOT = 2 CALL DTPMQRT( 'L', '/', 0, 0, 0, 0, 1, A, 1, T, 1, B, 1, C, 1, $ W, INFO ) CALL CHKXER( 'DTPMQRT', INFOT, NOUT, LERR, OK ) INFOT = 3 CALL DTPMQRT( 'L', 'N', -1, 0, 0, 0, 1, A, 1, T, 1, B, 1, C, 1, $ W, INFO ) CALL CHKXER( 'DTPMQRT', INFOT, NOUT, LERR, OK ) INFOT = 4 CALL DTPMQRT( 'L', 'N', 0, -1, 0, 0, 1, A, 1, T, 1, B, 1, C, 1, $ W, INFO ) CALL CHKXER( 'DTPMQRT', INFOT, NOUT, LERR, OK ) INFOT = 5 CALL DTPMQRT( 'L', 'N', 0, 0, -1, 0, 1, A, 1, T, 1, B, 1, C, 1, $ W, INFO ) INFOT = 6 CALL DTPMQRT( 'L', 'N', 0, 0, 0, -1, 1, A, 1, T, 1, B, 1, C, 1, $ W, INFO ) CALL CHKXER( 'DTPMQRT', INFOT, NOUT, LERR, OK ) INFOT = 7 CALL DTPMQRT( 'L', 'N', 0, 0, 0, 0, 0, A, 1, T, 1, B, 1, C, 1, $ W, INFO ) CALL CHKXER( 'DTPMQRT', INFOT, NOUT, LERR, OK ) INFOT = 9 CALL DTPMQRT( 'R', 'N', 1, 2, 1, 1, 1, A, 1, T, 1, B, 1, C, 1, $ W, INFO ) CALL CHKXER( 'DTPMQRT', INFOT, NOUT, LERR, OK ) INFOT = 9 CALL DTPMQRT( 'L', 'N', 2, 1, 1, 1, 1, A, 1, T, 1, B, 1, C, 1, $ W, INFO ) CALL CHKXER( 'DTPMQRT', INFOT, NOUT, LERR, OK ) INFOT = 11 CALL DTPMQRT( 'R', 'N', 1, 1, 1, 1, 1, A, 1, T, 0, B, 1, C, 1, $ W, INFO ) CALL CHKXER( 'DTPMQRT', INFOT, NOUT, LERR, OK ) INFOT = 13 CALL DTPMQRT( 'L', 'N', 1, 1, 1, 1, 1, A, 1, T, 1, B, 0, C, 1, $ W, INFO ) CALL CHKXER( 'DTPMQRT', INFOT, NOUT, LERR, OK ) INFOT = 15 CALL DTPMQRT( 'L', 'N', 1, 1, 1, 1, 1, A, 1, T, 1, B, 1, C, 0, $ W, INFO ) CALL CHKXER( 'DTPMQRT', INFOT, NOUT, LERR, OK ) * * Print a summary line. * CALL ALAESM( PATH, OK, NOUT ) * RETURN * * End of DERRQRT * END
gpl-2.0
wilmarcardonac/hypermcmc
lapack-3.5.0/SRC/cbdsqr.f
20
25968
*> \brief \b CBDSQR * * =========== DOCUMENTATION =========== * * Online html documentation available at * http://www.netlib.org/lapack/explore-html/ * *> \htmlonly *> Download CBDSQR + dependencies *> <a href="http://www.netlib.org/cgi-bin/netlibfiles.tgz?format=tgz&filename=/lapack/lapack_routine/cbdsqr.f"> *> [TGZ]</a> *> <a href="http://www.netlib.org/cgi-bin/netlibfiles.zip?format=zip&filename=/lapack/lapack_routine/cbdsqr.f"> *> [ZIP]</a> *> <a href="http://www.netlib.org/cgi-bin/netlibfiles.txt?format=txt&filename=/lapack/lapack_routine/cbdsqr.f"> *> [TXT]</a> *> \endhtmlonly * * Definition: * =========== * * SUBROUTINE CBDSQR( UPLO, N, NCVT, NRU, NCC, D, E, VT, LDVT, U, * LDU, C, LDC, RWORK, INFO ) * * .. Scalar Arguments .. * CHARACTER UPLO * INTEGER INFO, LDC, LDU, LDVT, N, NCC, NCVT, NRU * .. * .. Array Arguments .. * REAL D( * ), E( * ), RWORK( * ) * COMPLEX C( LDC, * ), U( LDU, * ), VT( LDVT, * ) * .. * * *> \par Purpose: * ============= *> *> \verbatim *> *> CBDSQR computes the singular values and, optionally, the right and/or *> left singular vectors from the singular value decomposition (SVD) of *> a real N-by-N (upper or lower) bidiagonal matrix B using the implicit *> zero-shift QR algorithm. The SVD of B has the form *> *> B = Q * S * P**H *> *> where S is the diagonal matrix of singular values, Q is an orthogonal *> matrix of left singular vectors, and P is an orthogonal matrix of *> right singular vectors. If left singular vectors are requested, this *> subroutine actually returns U*Q instead of Q, and, if right singular *> vectors are requested, this subroutine returns P**H*VT instead of *> P**H, for given complex input matrices U and VT. When U and VT are *> the unitary matrices that reduce a general matrix A to bidiagonal *> form: A = U*B*VT, as computed by CGEBRD, then *> *> A = (U*Q) * S * (P**H*VT) *> *> is the SVD of A. Optionally, the subroutine may also compute Q**H*C *> for a given complex input matrix C. *> *> See "Computing Small Singular Values of Bidiagonal Matrices With *> Guaranteed High Relative Accuracy," by J. Demmel and W. Kahan, *> LAPACK Working Note #3 (or SIAM J. Sci. Statist. Comput. vol. 11, *> no. 5, pp. 873-912, Sept 1990) and *> "Accurate singular values and differential qd algorithms," by *> B. Parlett and V. Fernando, Technical Report CPAM-554, Mathematics *> Department, University of California at Berkeley, July 1992 *> for a detailed description of the algorithm. *> \endverbatim * * Arguments: * ========== * *> \param[in] UPLO *> \verbatim *> UPLO is CHARACTER*1 *> = 'U': B is upper bidiagonal; *> = 'L': B is lower bidiagonal. *> \endverbatim *> *> \param[in] N *> \verbatim *> N is INTEGER *> The order of the matrix B. N >= 0. *> \endverbatim *> *> \param[in] NCVT *> \verbatim *> NCVT is INTEGER *> The number of columns of the matrix VT. NCVT >= 0. *> \endverbatim *> *> \param[in] NRU *> \verbatim *> NRU is INTEGER *> The number of rows of the matrix U. NRU >= 0. *> \endverbatim *> *> \param[in] NCC *> \verbatim *> NCC is INTEGER *> The number of columns of the matrix C. NCC >= 0. *> \endverbatim *> *> \param[in,out] D *> \verbatim *> D is REAL array, dimension (N) *> On entry, the n diagonal elements of the bidiagonal matrix B. *> On exit, if INFO=0, the singular values of B in decreasing *> order. *> \endverbatim *> *> \param[in,out] E *> \verbatim *> E is REAL array, dimension (N-1) *> On entry, the N-1 offdiagonal elements of the bidiagonal *> matrix B. *> On exit, if INFO = 0, E is destroyed; if INFO > 0, D and E *> will contain the diagonal and superdiagonal elements of a *> bidiagonal matrix orthogonally equivalent to the one given *> as input. *> \endverbatim *> *> \param[in,out] VT *> \verbatim *> VT is COMPLEX array, dimension (LDVT, NCVT) *> On entry, an N-by-NCVT matrix VT. *> On exit, VT is overwritten by P**H * VT. *> Not referenced if NCVT = 0. *> \endverbatim *> *> \param[in] LDVT *> \verbatim *> LDVT is INTEGER *> The leading dimension of the array VT. *> LDVT >= max(1,N) if NCVT > 0; LDVT >= 1 if NCVT = 0. *> \endverbatim *> *> \param[in,out] U *> \verbatim *> U is COMPLEX array, dimension (LDU, N) *> On entry, an NRU-by-N matrix U. *> On exit, U is overwritten by U * Q. *> Not referenced if NRU = 0. *> \endverbatim *> *> \param[in] LDU *> \verbatim *> LDU is INTEGER *> The leading dimension of the array U. LDU >= max(1,NRU). *> \endverbatim *> *> \param[in,out] C *> \verbatim *> C is COMPLEX array, dimension (LDC, NCC) *> On entry, an N-by-NCC matrix C. *> On exit, C is overwritten by Q**H * C. *> Not referenced if NCC = 0. *> \endverbatim *> *> \param[in] LDC *> \verbatim *> LDC is INTEGER *> The leading dimension of the array C. *> LDC >= max(1,N) if NCC > 0; LDC >=1 if NCC = 0. *> \endverbatim *> *> \param[out] RWORK *> \verbatim *> RWORK is REAL array, dimension (2*N) *> if NCVT = NRU = NCC = 0, (max(1, 4*N-4)) otherwise *> \endverbatim *> *> \param[out] INFO *> \verbatim *> INFO is INTEGER *> = 0: successful exit *> < 0: If INFO = -i, the i-th argument had an illegal value *> > 0: the algorithm did not converge; D and E contain the *> elements of a bidiagonal matrix which is orthogonally *> similar to the input matrix B; if INFO = i, i *> elements of E have not converged to zero. *> \endverbatim * *> \par Internal Parameters: * ========================= *> *> \verbatim *> TOLMUL REAL, default = max(10,min(100,EPS**(-1/8))) *> TOLMUL controls the convergence criterion of the QR loop. *> If it is positive, TOLMUL*EPS is the desired relative *> precision in the computed singular values. *> If it is negative, abs(TOLMUL*EPS*sigma_max) is the *> desired absolute accuracy in the computed singular *> values (corresponds to relative accuracy *> abs(TOLMUL*EPS) in the largest singular value. *> abs(TOLMUL) should be between 1 and 1/EPS, and preferably *> between 10 (for fast convergence) and .1/EPS *> (for there to be some accuracy in the results). *> Default is to lose at either one eighth or 2 of the *> available decimal digits in each computed singular value *> (whichever is smaller). *> *> MAXITR INTEGER, default = 6 *> MAXITR controls the maximum number of passes of the *> algorithm through its inner loop. The algorithms stops *> (and so fails to converge) if the number of passes *> through the inner loop exceeds MAXITR*N**2. *> \endverbatim * * Authors: * ======== * *> \author Univ. of Tennessee *> \author Univ. of California Berkeley *> \author Univ. of Colorado Denver *> \author NAG Ltd. * *> \date November 2011 * *> \ingroup complexOTHERcomputational * * ===================================================================== SUBROUTINE CBDSQR( UPLO, N, NCVT, NRU, NCC, D, E, VT, LDVT, U, $ LDU, C, LDC, RWORK, INFO ) * * -- LAPACK computational routine (version 3.4.0) -- * -- LAPACK is a software package provided by Univ. of Tennessee, -- * -- Univ. of California Berkeley, Univ. of Colorado Denver and NAG Ltd..-- * November 2011 * * .. Scalar Arguments .. CHARACTER UPLO INTEGER INFO, LDC, LDU, LDVT, N, NCC, NCVT, NRU * .. * .. Array Arguments .. REAL D( * ), E( * ), RWORK( * ) COMPLEX C( LDC, * ), U( LDU, * ), VT( LDVT, * ) * .. * * ===================================================================== * * .. Parameters .. REAL ZERO PARAMETER ( ZERO = 0.0E0 ) REAL ONE PARAMETER ( ONE = 1.0E0 ) REAL NEGONE PARAMETER ( NEGONE = -1.0E0 ) REAL HNDRTH PARAMETER ( HNDRTH = 0.01E0 ) REAL TEN PARAMETER ( TEN = 10.0E0 ) REAL HNDRD PARAMETER ( HNDRD = 100.0E0 ) REAL MEIGTH PARAMETER ( MEIGTH = -0.125E0 ) INTEGER MAXITR PARAMETER ( MAXITR = 6 ) * .. * .. Local Scalars .. LOGICAL LOWER, ROTATE INTEGER I, IDIR, ISUB, ITER, J, LL, LLL, M, MAXIT, NM1, $ NM12, NM13, OLDLL, OLDM REAL ABSE, ABSS, COSL, COSR, CS, EPS, F, G, H, MU, $ OLDCS, OLDSN, R, SHIFT, SIGMN, SIGMX, SINL, $ SINR, SLL, SMAX, SMIN, SMINL, SMINOA, $ SN, THRESH, TOL, TOLMUL, UNFL * .. * .. External Functions .. LOGICAL LSAME REAL SLAMCH EXTERNAL LSAME, SLAMCH * .. * .. External Subroutines .. EXTERNAL CLASR, CSROT, CSSCAL, CSWAP, SLARTG, SLAS2, $ SLASQ1, SLASV2, XERBLA * .. * .. Intrinsic Functions .. INTRINSIC ABS, MAX, MIN, REAL, SIGN, SQRT * .. * .. Executable Statements .. * * Test the input parameters. * INFO = 0 LOWER = LSAME( UPLO, 'L' ) IF( .NOT.LSAME( UPLO, 'U' ) .AND. .NOT.LOWER ) THEN INFO = -1 ELSE IF( N.LT.0 ) THEN INFO = -2 ELSE IF( NCVT.LT.0 ) THEN INFO = -3 ELSE IF( NRU.LT.0 ) THEN INFO = -4 ELSE IF( NCC.LT.0 ) THEN INFO = -5 ELSE IF( ( NCVT.EQ.0 .AND. LDVT.LT.1 ) .OR. $ ( NCVT.GT.0 .AND. LDVT.LT.MAX( 1, N ) ) ) THEN INFO = -9 ELSE IF( LDU.LT.MAX( 1, NRU ) ) THEN INFO = -11 ELSE IF( ( NCC.EQ.0 .AND. LDC.LT.1 ) .OR. $ ( NCC.GT.0 .AND. LDC.LT.MAX( 1, N ) ) ) THEN INFO = -13 END IF IF( INFO.NE.0 ) THEN CALL XERBLA( 'CBDSQR', -INFO ) RETURN END IF IF( N.EQ.0 ) $ RETURN IF( N.EQ.1 ) $ GO TO 160 * * ROTATE is true if any singular vectors desired, false otherwise * ROTATE = ( NCVT.GT.0 ) .OR. ( NRU.GT.0 ) .OR. ( NCC.GT.0 ) * * If no singular vectors desired, use qd algorithm * IF( .NOT.ROTATE ) THEN CALL SLASQ1( N, D, E, RWORK, INFO ) * * If INFO equals 2, dqds didn't finish, try to finish * IF( INFO .NE. 2 ) RETURN INFO = 0 END IF * NM1 = N - 1 NM12 = NM1 + NM1 NM13 = NM12 + NM1 IDIR = 0 * * Get machine constants * EPS = SLAMCH( 'Epsilon' ) UNFL = SLAMCH( 'Safe minimum' ) * * If matrix lower bidiagonal, rotate to be upper bidiagonal * by applying Givens rotations on the left * IF( LOWER ) THEN DO 10 I = 1, N - 1 CALL SLARTG( D( I ), E( I ), CS, SN, R ) D( I ) = R E( I ) = SN*D( I+1 ) D( I+1 ) = CS*D( I+1 ) RWORK( I ) = CS RWORK( NM1+I ) = SN 10 CONTINUE * * Update singular vectors if desired * IF( NRU.GT.0 ) $ CALL CLASR( 'R', 'V', 'F', NRU, N, RWORK( 1 ), RWORK( N ), $ U, LDU ) IF( NCC.GT.0 ) $ CALL CLASR( 'L', 'V', 'F', N, NCC, RWORK( 1 ), RWORK( N ), $ C, LDC ) END IF * * Compute singular values to relative accuracy TOL * (By setting TOL to be negative, algorithm will compute * singular values to absolute accuracy ABS(TOL)*norm(input matrix)) * TOLMUL = MAX( TEN, MIN( HNDRD, EPS**MEIGTH ) ) TOL = TOLMUL*EPS * * Compute approximate maximum, minimum singular values * SMAX = ZERO DO 20 I = 1, N SMAX = MAX( SMAX, ABS( D( I ) ) ) 20 CONTINUE DO 30 I = 1, N - 1 SMAX = MAX( SMAX, ABS( E( I ) ) ) 30 CONTINUE SMINL = ZERO IF( TOL.GE.ZERO ) THEN * * Relative accuracy desired * SMINOA = ABS( D( 1 ) ) IF( SMINOA.EQ.ZERO ) $ GO TO 50 MU = SMINOA DO 40 I = 2, N MU = ABS( D( I ) )*( MU / ( MU+ABS( E( I-1 ) ) ) ) SMINOA = MIN( SMINOA, MU ) IF( SMINOA.EQ.ZERO ) $ GO TO 50 40 CONTINUE 50 CONTINUE SMINOA = SMINOA / SQRT( REAL( N ) ) THRESH = MAX( TOL*SMINOA, MAXITR*N*N*UNFL ) ELSE * * Absolute accuracy desired * THRESH = MAX( ABS( TOL )*SMAX, MAXITR*N*N*UNFL ) END IF * * Prepare for main iteration loop for the singular values * (MAXIT is the maximum number of passes through the inner * loop permitted before nonconvergence signalled.) * MAXIT = MAXITR*N*N ITER = 0 OLDLL = -1 OLDM = -1 * * M points to last element of unconverged part of matrix * M = N * * Begin main iteration loop * 60 CONTINUE * * Check for convergence or exceeding iteration count * IF( M.LE.1 ) $ GO TO 160 IF( ITER.GT.MAXIT ) $ GO TO 200 * * Find diagonal block of matrix to work on * IF( TOL.LT.ZERO .AND. ABS( D( M ) ).LE.THRESH ) $ D( M ) = ZERO SMAX = ABS( D( M ) ) SMIN = SMAX DO 70 LLL = 1, M - 1 LL = M - LLL ABSS = ABS( D( LL ) ) ABSE = ABS( E( LL ) ) IF( TOL.LT.ZERO .AND. ABSS.LE.THRESH ) $ D( LL ) = ZERO IF( ABSE.LE.THRESH ) $ GO TO 80 SMIN = MIN( SMIN, ABSS ) SMAX = MAX( SMAX, ABSS, ABSE ) 70 CONTINUE LL = 0 GO TO 90 80 CONTINUE E( LL ) = ZERO * * Matrix splits since E(LL) = 0 * IF( LL.EQ.M-1 ) THEN * * Convergence of bottom singular value, return to top of loop * M = M - 1 GO TO 60 END IF 90 CONTINUE LL = LL + 1 * * E(LL) through E(M-1) are nonzero, E(LL-1) is zero * IF( LL.EQ.M-1 ) THEN * * 2 by 2 block, handle separately * CALL SLASV2( D( M-1 ), E( M-1 ), D( M ), SIGMN, SIGMX, SINR, $ COSR, SINL, COSL ) D( M-1 ) = SIGMX E( M-1 ) = ZERO D( M ) = SIGMN * * Compute singular vectors, if desired * IF( NCVT.GT.0 ) $ CALL CSROT( NCVT, VT( M-1, 1 ), LDVT, VT( M, 1 ), LDVT, $ COSR, SINR ) IF( NRU.GT.0 ) $ CALL CSROT( NRU, U( 1, M-1 ), 1, U( 1, M ), 1, COSL, SINL ) IF( NCC.GT.0 ) $ CALL CSROT( NCC, C( M-1, 1 ), LDC, C( M, 1 ), LDC, COSL, $ SINL ) M = M - 2 GO TO 60 END IF * * If working on new submatrix, choose shift direction * (from larger end diagonal element towards smaller) * IF( LL.GT.OLDM .OR. M.LT.OLDLL ) THEN IF( ABS( D( LL ) ).GE.ABS( D( M ) ) ) THEN * * Chase bulge from top (big end) to bottom (small end) * IDIR = 1 ELSE * * Chase bulge from bottom (big end) to top (small end) * IDIR = 2 END IF END IF * * Apply convergence tests * IF( IDIR.EQ.1 ) THEN * * Run convergence test in forward direction * First apply standard test to bottom of matrix * IF( ABS( E( M-1 ) ).LE.ABS( TOL )*ABS( D( M ) ) .OR. $ ( TOL.LT.ZERO .AND. ABS( E( M-1 ) ).LE.THRESH ) ) THEN E( M-1 ) = ZERO GO TO 60 END IF * IF( TOL.GE.ZERO ) THEN * * If relative accuracy desired, * apply convergence criterion forward * MU = ABS( D( LL ) ) SMINL = MU DO 100 LLL = LL, M - 1 IF( ABS( E( LLL ) ).LE.TOL*MU ) THEN E( LLL ) = ZERO GO TO 60 END IF MU = ABS( D( LLL+1 ) )*( MU / ( MU+ABS( E( LLL ) ) ) ) SMINL = MIN( SMINL, MU ) 100 CONTINUE END IF * ELSE * * Run convergence test in backward direction * First apply standard test to top of matrix * IF( ABS( E( LL ) ).LE.ABS( TOL )*ABS( D( LL ) ) .OR. $ ( TOL.LT.ZERO .AND. ABS( E( LL ) ).LE.THRESH ) ) THEN E( LL ) = ZERO GO TO 60 END IF * IF( TOL.GE.ZERO ) THEN * * If relative accuracy desired, * apply convergence criterion backward * MU = ABS( D( M ) ) SMINL = MU DO 110 LLL = M - 1, LL, -1 IF( ABS( E( LLL ) ).LE.TOL*MU ) THEN E( LLL ) = ZERO GO TO 60 END IF MU = ABS( D( LLL ) )*( MU / ( MU+ABS( E( LLL ) ) ) ) SMINL = MIN( SMINL, MU ) 110 CONTINUE END IF END IF OLDLL = LL OLDM = M * * Compute shift. First, test if shifting would ruin relative * accuracy, and if so set the shift to zero. * IF( TOL.GE.ZERO .AND. N*TOL*( SMINL / SMAX ).LE. $ MAX( EPS, HNDRTH*TOL ) ) THEN * * Use a zero shift to avoid loss of relative accuracy * SHIFT = ZERO ELSE * * Compute the shift from 2-by-2 block at end of matrix * IF( IDIR.EQ.1 ) THEN SLL = ABS( D( LL ) ) CALL SLAS2( D( M-1 ), E( M-1 ), D( M ), SHIFT, R ) ELSE SLL = ABS( D( M ) ) CALL SLAS2( D( LL ), E( LL ), D( LL+1 ), SHIFT, R ) END IF * * Test if shift negligible, and if so set to zero * IF( SLL.GT.ZERO ) THEN IF( ( SHIFT / SLL )**2.LT.EPS ) $ SHIFT = ZERO END IF END IF * * Increment iteration count * ITER = ITER + M - LL * * If SHIFT = 0, do simplified QR iteration * IF( SHIFT.EQ.ZERO ) THEN IF( IDIR.EQ.1 ) THEN * * Chase bulge from top to bottom * Save cosines and sines for later singular vector updates * CS = ONE OLDCS = ONE DO 120 I = LL, M - 1 CALL SLARTG( D( I )*CS, E( I ), CS, SN, R ) IF( I.GT.LL ) $ E( I-1 ) = OLDSN*R CALL SLARTG( OLDCS*R, D( I+1 )*SN, OLDCS, OLDSN, D( I ) ) RWORK( I-LL+1 ) = CS RWORK( I-LL+1+NM1 ) = SN RWORK( I-LL+1+NM12 ) = OLDCS RWORK( I-LL+1+NM13 ) = OLDSN 120 CONTINUE H = D( M )*CS D( M ) = H*OLDCS E( M-1 ) = H*OLDSN * * Update singular vectors * IF( NCVT.GT.0 ) $ CALL CLASR( 'L', 'V', 'F', M-LL+1, NCVT, RWORK( 1 ), $ RWORK( N ), VT( LL, 1 ), LDVT ) IF( NRU.GT.0 ) $ CALL CLASR( 'R', 'V', 'F', NRU, M-LL+1, RWORK( NM12+1 ), $ RWORK( NM13+1 ), U( 1, LL ), LDU ) IF( NCC.GT.0 ) $ CALL CLASR( 'L', 'V', 'F', M-LL+1, NCC, RWORK( NM12+1 ), $ RWORK( NM13+1 ), C( LL, 1 ), LDC ) * * Test convergence * IF( ABS( E( M-1 ) ).LE.THRESH ) $ E( M-1 ) = ZERO * ELSE * * Chase bulge from bottom to top * Save cosines and sines for later singular vector updates * CS = ONE OLDCS = ONE DO 130 I = M, LL + 1, -1 CALL SLARTG( D( I )*CS, E( I-1 ), CS, SN, R ) IF( I.LT.M ) $ E( I ) = OLDSN*R CALL SLARTG( OLDCS*R, D( I-1 )*SN, OLDCS, OLDSN, D( I ) ) RWORK( I-LL ) = CS RWORK( I-LL+NM1 ) = -SN RWORK( I-LL+NM12 ) = OLDCS RWORK( I-LL+NM13 ) = -OLDSN 130 CONTINUE H = D( LL )*CS D( LL ) = H*OLDCS E( LL ) = H*OLDSN * * Update singular vectors * IF( NCVT.GT.0 ) $ CALL CLASR( 'L', 'V', 'B', M-LL+1, NCVT, RWORK( NM12+1 ), $ RWORK( NM13+1 ), VT( LL, 1 ), LDVT ) IF( NRU.GT.0 ) $ CALL CLASR( 'R', 'V', 'B', NRU, M-LL+1, RWORK( 1 ), $ RWORK( N ), U( 1, LL ), LDU ) IF( NCC.GT.0 ) $ CALL CLASR( 'L', 'V', 'B', M-LL+1, NCC, RWORK( 1 ), $ RWORK( N ), C( LL, 1 ), LDC ) * * Test convergence * IF( ABS( E( LL ) ).LE.THRESH ) $ E( LL ) = ZERO END IF ELSE * * Use nonzero shift * IF( IDIR.EQ.1 ) THEN * * Chase bulge from top to bottom * Save cosines and sines for later singular vector updates * F = ( ABS( D( LL ) )-SHIFT )* $ ( SIGN( ONE, D( LL ) )+SHIFT / D( LL ) ) G = E( LL ) DO 140 I = LL, M - 1 CALL SLARTG( F, G, COSR, SINR, R ) IF( I.GT.LL ) $ E( I-1 ) = R F = COSR*D( I ) + SINR*E( I ) E( I ) = COSR*E( I ) - SINR*D( I ) G = SINR*D( I+1 ) D( I+1 ) = COSR*D( I+1 ) CALL SLARTG( F, G, COSL, SINL, R ) D( I ) = R F = COSL*E( I ) + SINL*D( I+1 ) D( I+1 ) = COSL*D( I+1 ) - SINL*E( I ) IF( I.LT.M-1 ) THEN G = SINL*E( I+1 ) E( I+1 ) = COSL*E( I+1 ) END IF RWORK( I-LL+1 ) = COSR RWORK( I-LL+1+NM1 ) = SINR RWORK( I-LL+1+NM12 ) = COSL RWORK( I-LL+1+NM13 ) = SINL 140 CONTINUE E( M-1 ) = F * * Update singular vectors * IF( NCVT.GT.0 ) $ CALL CLASR( 'L', 'V', 'F', M-LL+1, NCVT, RWORK( 1 ), $ RWORK( N ), VT( LL, 1 ), LDVT ) IF( NRU.GT.0 ) $ CALL CLASR( 'R', 'V', 'F', NRU, M-LL+1, RWORK( NM12+1 ), $ RWORK( NM13+1 ), U( 1, LL ), LDU ) IF( NCC.GT.0 ) $ CALL CLASR( 'L', 'V', 'F', M-LL+1, NCC, RWORK( NM12+1 ), $ RWORK( NM13+1 ), C( LL, 1 ), LDC ) * * Test convergence * IF( ABS( E( M-1 ) ).LE.THRESH ) $ E( M-1 ) = ZERO * ELSE * * Chase bulge from bottom to top * Save cosines and sines for later singular vector updates * F = ( ABS( D( M ) )-SHIFT )*( SIGN( ONE, D( M ) )+SHIFT / $ D( M ) ) G = E( M-1 ) DO 150 I = M, LL + 1, -1 CALL SLARTG( F, G, COSR, SINR, R ) IF( I.LT.M ) $ E( I ) = R F = COSR*D( I ) + SINR*E( I-1 ) E( I-1 ) = COSR*E( I-1 ) - SINR*D( I ) G = SINR*D( I-1 ) D( I-1 ) = COSR*D( I-1 ) CALL SLARTG( F, G, COSL, SINL, R ) D( I ) = R F = COSL*E( I-1 ) + SINL*D( I-1 ) D( I-1 ) = COSL*D( I-1 ) - SINL*E( I-1 ) IF( I.GT.LL+1 ) THEN G = SINL*E( I-2 ) E( I-2 ) = COSL*E( I-2 ) END IF RWORK( I-LL ) = COSR RWORK( I-LL+NM1 ) = -SINR RWORK( I-LL+NM12 ) = COSL RWORK( I-LL+NM13 ) = -SINL 150 CONTINUE E( LL ) = F * * Test convergence * IF( ABS( E( LL ) ).LE.THRESH ) $ E( LL ) = ZERO * * Update singular vectors if desired * IF( NCVT.GT.0 ) $ CALL CLASR( 'L', 'V', 'B', M-LL+1, NCVT, RWORK( NM12+1 ), $ RWORK( NM13+1 ), VT( LL, 1 ), LDVT ) IF( NRU.GT.0 ) $ CALL CLASR( 'R', 'V', 'B', NRU, M-LL+1, RWORK( 1 ), $ RWORK( N ), U( 1, LL ), LDU ) IF( NCC.GT.0 ) $ CALL CLASR( 'L', 'V', 'B', M-LL+1, NCC, RWORK( 1 ), $ RWORK( N ), C( LL, 1 ), LDC ) END IF END IF * * QR iteration finished, go back and check convergence * GO TO 60 * * All singular values converged, so make them positive * 160 CONTINUE DO 170 I = 1, N IF( D( I ).LT.ZERO ) THEN D( I ) = -D( I ) * * Change sign of singular vectors, if desired * IF( NCVT.GT.0 ) $ CALL CSSCAL( NCVT, NEGONE, VT( I, 1 ), LDVT ) END IF 170 CONTINUE * * Sort the singular values into decreasing order (insertion sort on * singular values, but only one transposition per singular vector) * DO 190 I = 1, N - 1 * * Scan for smallest D(I) * ISUB = 1 SMIN = D( 1 ) DO 180 J = 2, N + 1 - I IF( D( J ).LE.SMIN ) THEN ISUB = J SMIN = D( J ) END IF 180 CONTINUE IF( ISUB.NE.N+1-I ) THEN * * Swap singular values and vectors * D( ISUB ) = D( N+1-I ) D( N+1-I ) = SMIN IF( NCVT.GT.0 ) $ CALL CSWAP( NCVT, VT( ISUB, 1 ), LDVT, VT( N+1-I, 1 ), $ LDVT ) IF( NRU.GT.0 ) $ CALL CSWAP( NRU, U( 1, ISUB ), 1, U( 1, N+1-I ), 1 ) IF( NCC.GT.0 ) $ CALL CSWAP( NCC, C( ISUB, 1 ), LDC, C( N+1-I, 1 ), LDC ) END IF 190 CONTINUE GO TO 220 * * Maximum number of iterations exceeded, failure to converge * 200 CONTINUE INFO = 0 DO 210 I = 1, N - 1 IF( E( I ).NE.ZERO ) $ INFO = INFO + 1 210 CONTINUE 220 CONTINUE RETURN * * End of CBDSQR * END
gpl-2.0
QEF/q-e
Modules/parameters.f90
2
1025
! ! Copyright (C) 2001-2020 Quantum ESPRESSO group ! This file is distributed under the terms of the ! GNU General Public License. See the file `License' ! in the root directory of the present distribution, ! or http://www.gnu.org/copyleft/gpl.txt . ! ! MODULE parameters ! !! Upper limits on k-points, atoms and supercell size. ! IMPLICIT NONE SAVE INTEGER, PARAMETER :: npk = 40000 !! max number of k-points INTEGER, PARAMETER :: ntypx = 10 !! max number of different types of atom INTEGER, PARAMETER :: nsx = ntypx !! max number of atomic species (CP) INTEGER, PARAMETER :: natx = 50 !! max number of atoms for DFT+U+V calculations INTEGER, PARAMETER :: sc_size = 1 !! Defines the supercell in DFT+U+V as composed by the unit cells located !! by (n1,n2,n3) in primitive vectors base with \(-\text{sc_size} \leq ni !! \leq \text{sc_size}\) and \((2\text{sc_size}+1)^3\) is the number of cells. INTEGER, PARAMETER :: nsolx = 10 !! max number of solvents (RISM) END MODULE parameters
gpl-2.0
wilmarcardonac/hypermcmc
lapack-3.5.0/TESTING/EIG/zdrgev.f
29
34076
*> \brief \b ZDRGEV * * =========== DOCUMENTATION =========== * * Online html documentation available at * http://www.netlib.org/lapack/explore-html/ * * Definition: * =========== * * SUBROUTINE ZDRGEV( NSIZES, NN, NTYPES, DOTYPE, ISEED, THRESH, * NOUNIT, A, LDA, B, S, T, Q, LDQ, Z, QE, LDQE, * ALPHA, BETA, ALPHA1, BETA1, WORK, LWORK, RWORK, * RESULT, INFO ) * * .. Scalar Arguments .. * INTEGER INFO, LDA, LDQ, LDQE, LWORK, NOUNIT, NSIZES, * $ NTYPES * DOUBLE PRECISION THRESH * .. * .. Array Arguments .. * LOGICAL DOTYPE( * ) * INTEGER ISEED( 4 ), NN( * ) * DOUBLE PRECISION RESULT( * ), RWORK( * ) * COMPLEX*16 A( LDA, * ), ALPHA( * ), ALPHA1( * ), * $ B( LDA, * ), BETA( * ), BETA1( * ), * $ Q( LDQ, * ), QE( LDQE, * ), S( LDA, * ), * $ T( LDA, * ), WORK( * ), Z( LDQ, * ) * .. * * *> \par Purpose: * ============= *> *> \verbatim *> *> ZDRGEV checks the nonsymmetric generalized eigenvalue problem driver *> routine ZGGEV. *> *> ZGGEV computes for a pair of n-by-n nonsymmetric matrices (A,B) the *> generalized eigenvalues and, optionally, the left and right *> eigenvectors. *> *> A generalized eigenvalue for a pair of matrices (A,B) is a scalar w *> or a ratio alpha/beta = w, such that A - w*B is singular. It is *> usually represented as the pair (alpha,beta), as there is reasonalbe *> interpretation for beta=0, and even for both being zero. *> *> A right generalized eigenvector corresponding to a generalized *> eigenvalue w for a pair of matrices (A,B) is a vector r such that *> (A - wB) * r = 0. A left generalized eigenvector is a vector l such *> that l**H * (A - wB) = 0, where l**H is the conjugate-transpose of l. *> *> When ZDRGEV is called, a number of matrix "sizes" ("n's") and a *> number of matrix "types" are specified. For each size ("n") *> and each type of matrix, a pair of matrices (A, B) will be generated *> and used for testing. For each matrix pair, the following tests *> will be performed and compared with the threshhold THRESH. *> *> Results from ZGGEV: *> *> (1) max over all left eigenvalue/-vector pairs (alpha/beta,l) of *> *> | VL**H * (beta A - alpha B) |/( ulp max(|beta A|, |alpha B|) ) *> *> where VL**H is the conjugate-transpose of VL. *> *> (2) | |VL(i)| - 1 | / ulp and whether largest component real *> *> VL(i) denotes the i-th column of VL. *> *> (3) max over all left eigenvalue/-vector pairs (alpha/beta,r) of *> *> | (beta A - alpha B) * VR | / ( ulp max(|beta A|, |alpha B|) ) *> *> (4) | |VR(i)| - 1 | / ulp and whether largest component real *> *> VR(i) denotes the i-th column of VR. *> *> (5) W(full) = W(partial) *> W(full) denotes the eigenvalues computed when both l and r *> are also computed, and W(partial) denotes the eigenvalues *> computed when only W, only W and r, or only W and l are *> computed. *> *> (6) VL(full) = VL(partial) *> VL(full) denotes the left eigenvectors computed when both l *> and r are computed, and VL(partial) denotes the result *> when only l is computed. *> *> (7) VR(full) = VR(partial) *> VR(full) denotes the right eigenvectors computed when both l *> and r are also computed, and VR(partial) denotes the result *> when only l is computed. *> *> *> Test Matrices *> ---- -------- *> *> The sizes of the test matrices are specified by an array *> NN(1:NSIZES); the value of each element NN(j) specifies one size. *> The "types" are specified by a logical array DOTYPE( 1:NTYPES ); if *> DOTYPE(j) is .TRUE., then matrix type "j" will be generated. *> Currently, the list of possible types is: *> *> (1) ( 0, 0 ) (a pair of zero matrices) *> *> (2) ( I, 0 ) (an identity and a zero matrix) *> *> (3) ( 0, I ) (an identity and a zero matrix) *> *> (4) ( I, I ) (a pair of identity matrices) *> *> t t *> (5) ( J , J ) (a pair of transposed Jordan blocks) *> *> t ( I 0 ) *> (6) ( X, Y ) where X = ( J 0 ) and Y = ( t ) *> ( 0 I ) ( 0 J ) *> and I is a k x k identity and J a (k+1)x(k+1) *> Jordan block; k=(N-1)/2 *> *> (7) ( D, I ) where D is diag( 0, 1,..., N-1 ) (a diagonal *> matrix with those diagonal entries.) *> (8) ( I, D ) *> *> (9) ( big*D, small*I ) where "big" is near overflow and small=1/big *> *> (10) ( small*D, big*I ) *> *> (11) ( big*I, small*D ) *> *> (12) ( small*I, big*D ) *> *> (13) ( big*D, big*I ) *> *> (14) ( small*D, small*I ) *> *> (15) ( D1, D2 ) where D1 is diag( 0, 0, 1, ..., N-3, 0 ) and *> D2 is diag( 0, N-3, N-4,..., 1, 0, 0 ) *> t t *> (16) Q ( J , J ) Z where Q and Z are random orthogonal matrices. *> *> (17) Q ( T1, T2 ) Z where T1 and T2 are upper triangular matrices *> with random O(1) entries above the diagonal *> and diagonal entries diag(T1) = *> ( 0, 0, 1, ..., N-3, 0 ) and diag(T2) = *> ( 0, N-3, N-4,..., 1, 0, 0 ) *> *> (18) Q ( T1, T2 ) Z diag(T1) = ( 0, 0, 1, 1, s, ..., s, 0 ) *> diag(T2) = ( 0, 1, 0, 1,..., 1, 0 ) *> s = machine precision. *> *> (19) Q ( T1, T2 ) Z diag(T1)=( 0,0,1,1, 1-d, ..., 1-(N-5)*d=s, 0 ) *> diag(T2) = ( 0, 1, 0, 1, ..., 1, 0 ) *> *> N-5 *> (20) Q ( T1, T2 ) Z diag(T1)=( 0, 0, 1, 1, a, ..., a =s, 0 ) *> diag(T2) = ( 0, 1, 0, 1, ..., 1, 0, 0 ) *> *> (21) Q ( T1, T2 ) Z diag(T1)=( 0, 0, 1, r1, r2, ..., r(N-4), 0 ) *> diag(T2) = ( 0, 1, 0, 1, ..., 1, 0, 0 ) *> where r1,..., r(N-4) are random. *> *> (22) Q ( big*T1, small*T2 ) Z diag(T1) = ( 0, 0, 1, ..., N-3, 0 ) *> diag(T2) = ( 0, 1, ..., 1, 0, 0 ) *> *> (23) Q ( small*T1, big*T2 ) Z diag(T1) = ( 0, 0, 1, ..., N-3, 0 ) *> diag(T2) = ( 0, 1, ..., 1, 0, 0 ) *> *> (24) Q ( small*T1, small*T2 ) Z diag(T1) = ( 0, 0, 1, ..., N-3, 0 ) *> diag(T2) = ( 0, 1, ..., 1, 0, 0 ) *> *> (25) Q ( big*T1, big*T2 ) Z diag(T1) = ( 0, 0, 1, ..., N-3, 0 ) *> diag(T2) = ( 0, 1, ..., 1, 0, 0 ) *> *> (26) Q ( T1, T2 ) Z where T1 and T2 are random upper-triangular *> matrices. *> *> \endverbatim * * Arguments: * ========== * *> \param[in] NSIZES *> \verbatim *> NSIZES is INTEGER *> The number of sizes of matrices to use. If it is zero, *> ZDRGES does nothing. NSIZES >= 0. *> \endverbatim *> *> \param[in] NN *> \verbatim *> NN is INTEGER array, dimension (NSIZES) *> An array containing the sizes to be used for the matrices. *> Zero values will be skipped. NN >= 0. *> \endverbatim *> *> \param[in] NTYPES *> \verbatim *> NTYPES is INTEGER *> The number of elements in DOTYPE. If it is zero, ZDRGEV *> does nothing. It must be at least zero. If it is MAXTYP+1 *> and NSIZES is 1, then an additional type, MAXTYP+1 is *> defined, which is to use whatever matrix is in A. This *> is only useful if DOTYPE(1:MAXTYP) is .FALSE. and *> DOTYPE(MAXTYP+1) is .TRUE. . *> \endverbatim *> *> \param[in] DOTYPE *> \verbatim *> DOTYPE is LOGICAL array, dimension (NTYPES) *> If DOTYPE(j) is .TRUE., then for each size in NN a *> matrix of that size and of type j will be generated. *> If NTYPES is smaller than the maximum number of types *> defined (PARAMETER MAXTYP), then types NTYPES+1 through *> MAXTYP will not be generated. If NTYPES is larger *> than MAXTYP, DOTYPE(MAXTYP+1) through DOTYPE(NTYPES) *> will be ignored. *> \endverbatim *> *> \param[in,out] ISEED *> \verbatim *> ISEED is INTEGER array, dimension (4) *> On entry ISEED specifies the seed of the random number *> generator. The array elements should be between 0 and 4095; *> if not they will be reduced mod 4096. Also, ISEED(4) must *> be odd. The random number generator uses a linear *> congruential sequence limited to small integers, and so *> should produce machine independent random numbers. The *> values of ISEED are changed on exit, and can be used in the *> next call to ZDRGES to continue the same random number *> sequence. *> \endverbatim *> *> \param[in] THRESH *> \verbatim *> THRESH is DOUBLE PRECISION *> A test will count as "failed" if the "error", computed as *> described above, exceeds THRESH. Note that the error is *> scaled to be O(1), so THRESH should be a reasonably small *> multiple of 1, e.g., 10 or 100. In particular, it should *> not depend on the precision (single vs. double) or the size *> of the matrix. It must be at least zero. *> \endverbatim *> *> \param[in] NOUNIT *> \verbatim *> NOUNIT is INTEGER *> The FORTRAN unit number for printing out error messages *> (e.g., if a routine returns IERR not equal to 0.) *> \endverbatim *> *> \param[in,out] A *> \verbatim *> A is COMPLEX*16 array, dimension(LDA, max(NN)) *> Used to hold the original A matrix. Used as input only *> if NTYPES=MAXTYP+1, DOTYPE(1:MAXTYP)=.FALSE., and *> DOTYPE(MAXTYP+1)=.TRUE. *> \endverbatim *> *> \param[in] LDA *> \verbatim *> LDA is INTEGER *> The leading dimension of A, B, S, and T. *> It must be at least 1 and at least max( NN ). *> \endverbatim *> *> \param[in,out] B *> \verbatim *> B is COMPLEX*16 array, dimension(LDA, max(NN)) *> Used to hold the original B matrix. Used as input only *> if NTYPES=MAXTYP+1, DOTYPE(1:MAXTYP)=.FALSE., and *> DOTYPE(MAXTYP+1)=.TRUE. *> \endverbatim *> *> \param[out] S *> \verbatim *> S is COMPLEX*16 array, dimension (LDA, max(NN)) *> The Schur form matrix computed from A by ZGGEV. On exit, S *> contains the Schur form matrix corresponding to the matrix *> in A. *> \endverbatim *> *> \param[out] T *> \verbatim *> T is COMPLEX*16 array, dimension (LDA, max(NN)) *> The upper triangular matrix computed from B by ZGGEV. *> \endverbatim *> *> \param[out] Q *> \verbatim *> Q is COMPLEX*16 array, dimension (LDQ, max(NN)) *> The (left) eigenvectors matrix computed by ZGGEV. *> \endverbatim *> *> \param[in] LDQ *> \verbatim *> LDQ is INTEGER *> The leading dimension of Q and Z. It must *> be at least 1 and at least max( NN ). *> \endverbatim *> *> \param[out] Z *> \verbatim *> Z is COMPLEX*16 array, dimension( LDQ, max(NN) ) *> The (right) orthogonal matrix computed by ZGGEV. *> \endverbatim *> *> \param[out] QE *> \verbatim *> QE is COMPLEX*16 array, dimension( LDQ, max(NN) ) *> QE holds the computed right or left eigenvectors. *> \endverbatim *> *> \param[in] LDQE *> \verbatim *> LDQE is INTEGER *> The leading dimension of QE. LDQE >= max(1,max(NN)). *> \endverbatim *> *> \param[out] ALPHA *> \verbatim *> ALPHA is COMPLEX*16 array, dimension (max(NN)) *> \endverbatim *> *> \param[out] BETA *> \verbatim *> BETA is COMPLEX*16 array, dimension (max(NN)) *> *> The generalized eigenvalues of (A,B) computed by ZGGEV. *> ( ALPHAR(k)+ALPHAI(k)*i ) / BETA(k) is the k-th *> generalized eigenvalue of A and B. *> \endverbatim *> *> \param[out] ALPHA1 *> \verbatim *> ALPHA1 is COMPLEX*16 array, dimension (max(NN)) *> \endverbatim *> *> \param[out] BETA1 *> \verbatim *> BETA1 is COMPLEX*16 array, dimension (max(NN)) *> *> Like ALPHAR, ALPHAI, BETA, these arrays contain the *> eigenvalues of A and B, but those computed when ZGGEV only *> computes a partial eigendecomposition, i.e. not the *> eigenvalues and left and right eigenvectors. *> \endverbatim *> *> \param[out] WORK *> \verbatim *> WORK is COMPLEX*16 array, dimension (LWORK) *> \endverbatim *> *> \param[in] LWORK *> \verbatim *> LWORK is INTEGER *> The number of entries in WORK. LWORK >= N*(N+1) *> \endverbatim *> *> \param[out] RWORK *> \verbatim *> RWORK is DOUBLE PRECISION array, dimension (8*N) *> Real workspace. *> \endverbatim *> *> \param[out] RESULT *> \verbatim *> RESULT is DOUBLE PRECISION array, dimension (2) *> The values computed by the tests described above. *> The values are currently limited to 1/ulp, to avoid overflow. *> \endverbatim *> *> \param[out] INFO *> \verbatim *> INFO is INTEGER *> = 0: successful exit *> < 0: if INFO = -i, the i-th argument had an illegal value. *> > 0: A routine returned an error code. INFO is the *> absolute value of the INFO value returned. *> \endverbatim * * Authors: * ======== * *> \author Univ. of Tennessee *> \author Univ. of California Berkeley *> \author Univ. of Colorado Denver *> \author NAG Ltd. * *> \date November 2011 * *> \ingroup complex16_eig * * ===================================================================== SUBROUTINE ZDRGEV( NSIZES, NN, NTYPES, DOTYPE, ISEED, THRESH, $ NOUNIT, A, LDA, B, S, T, Q, LDQ, Z, QE, LDQE, $ ALPHA, BETA, ALPHA1, BETA1, WORK, LWORK, RWORK, $ RESULT, INFO ) * * -- LAPACK test routine (version 3.4.0) -- * -- LAPACK is a software package provided by Univ. of Tennessee, -- * -- Univ. of California Berkeley, Univ. of Colorado Denver and NAG Ltd..-- * November 2011 * * .. Scalar Arguments .. INTEGER INFO, LDA, LDQ, LDQE, LWORK, NOUNIT, NSIZES, $ NTYPES DOUBLE PRECISION THRESH * .. * .. Array Arguments .. LOGICAL DOTYPE( * ) INTEGER ISEED( 4 ), NN( * ) DOUBLE PRECISION RESULT( * ), RWORK( * ) COMPLEX*16 A( LDA, * ), ALPHA( * ), ALPHA1( * ), $ B( LDA, * ), BETA( * ), BETA1( * ), $ Q( LDQ, * ), QE( LDQE, * ), S( LDA, * ), $ T( LDA, * ), WORK( * ), Z( LDQ, * ) * .. * * ===================================================================== * * .. Parameters .. DOUBLE PRECISION ZERO, ONE PARAMETER ( ZERO = 0.0D+0, ONE = 1.0D+0 ) COMPLEX*16 CZERO, CONE PARAMETER ( CZERO = ( 0.0D+0, 0.0D+0 ), $ CONE = ( 1.0D+0, 0.0D+0 ) ) INTEGER MAXTYP PARAMETER ( MAXTYP = 26 ) * .. * .. Local Scalars .. LOGICAL BADNN INTEGER I, IADD, IERR, IN, J, JC, JR, JSIZE, JTYPE, $ MAXWRK, MINWRK, MTYPES, N, N1, NB, NERRS, $ NMATS, NMAX, NTESTT DOUBLE PRECISION SAFMAX, SAFMIN, ULP, ULPINV COMPLEX*16 CTEMP * .. * .. Local Arrays .. LOGICAL LASIGN( MAXTYP ), LBSIGN( MAXTYP ) INTEGER IOLDSD( 4 ), KADD( 6 ), KAMAGN( MAXTYP ), $ KATYPE( MAXTYP ), KAZERO( MAXTYP ), $ KBMAGN( MAXTYP ), KBTYPE( MAXTYP ), $ KBZERO( MAXTYP ), KCLASS( MAXTYP ), $ KTRIAN( MAXTYP ), KZ1( 6 ), KZ2( 6 ) DOUBLE PRECISION RMAGN( 0: 3 ) * .. * .. External Functions .. INTEGER ILAENV DOUBLE PRECISION DLAMCH COMPLEX*16 ZLARND EXTERNAL ILAENV, DLAMCH, ZLARND * .. * .. External Subroutines .. EXTERNAL ALASVM, DLABAD, XERBLA, ZGET52, ZGGEV, ZLACPY, $ ZLARFG, ZLASET, ZLATM4, ZUNM2R * .. * .. Intrinsic Functions .. INTRINSIC ABS, DBLE, DCONJG, MAX, MIN, SIGN * .. * .. Data statements .. DATA KCLASS / 15*1, 10*2, 1*3 / DATA KZ1 / 0, 1, 2, 1, 3, 3 / DATA KZ2 / 0, 0, 1, 2, 1, 1 / DATA KADD / 0, 0, 0, 0, 3, 2 / DATA KATYPE / 0, 1, 0, 1, 2, 3, 4, 1, 4, 4, 1, 1, 4, $ 4, 4, 2, 4, 5, 8, 7, 9, 4*4, 0 / DATA KBTYPE / 0, 0, 1, 1, 2, -3, 1, 4, 1, 1, 4, 4, $ 1, 1, -4, 2, -4, 8*8, 0 / DATA KAZERO / 6*1, 2, 1, 2*2, 2*1, 2*2, 3, 1, 3, $ 4*5, 4*3, 1 / DATA KBZERO / 6*1, 1, 2, 2*1, 2*2, 2*1, 4, 1, 4, $ 4*6, 4*4, 1 / DATA KAMAGN / 8*1, 2, 3, 2, 3, 2, 3, 7*1, 2, 3, 3, $ 2, 1 / DATA KBMAGN / 8*1, 3, 2, 3, 2, 2, 3, 7*1, 3, 2, 3, $ 2, 1 / DATA KTRIAN / 16*0, 10*1 / DATA LASIGN / 6*.FALSE., .TRUE., .FALSE., 2*.TRUE., $ 2*.FALSE., 3*.TRUE., .FALSE., .TRUE., $ 3*.FALSE., 5*.TRUE., .FALSE. / DATA LBSIGN / 7*.FALSE., .TRUE., 2*.FALSE., $ 2*.TRUE., 2*.FALSE., .TRUE., .FALSE., .TRUE., $ 9*.FALSE. / * .. * .. Executable Statements .. * * Check for errors * INFO = 0 * BADNN = .FALSE. NMAX = 1 DO 10 J = 1, NSIZES NMAX = MAX( NMAX, NN( J ) ) IF( NN( J ).LT.0 ) $ BADNN = .TRUE. 10 CONTINUE * IF( NSIZES.LT.0 ) THEN INFO = -1 ELSE IF( BADNN ) THEN INFO = -2 ELSE IF( NTYPES.LT.0 ) THEN INFO = -3 ELSE IF( THRESH.LT.ZERO ) THEN INFO = -6 ELSE IF( LDA.LE.1 .OR. LDA.LT.NMAX ) THEN INFO = -9 ELSE IF( LDQ.LE.1 .OR. LDQ.LT.NMAX ) THEN INFO = -14 ELSE IF( LDQE.LE.1 .OR. LDQE.LT.NMAX ) THEN INFO = -17 END IF * * Compute workspace * (Note: Comments in the code beginning "Workspace:" describe the * minimal amount of workspace needed at that point in the code, * as well as the preferred amount for good performance. * NB refers to the optimal block size for the immediately * following subroutine, as returned by ILAENV. * MINWRK = 1 IF( INFO.EQ.0 .AND. LWORK.GE.1 ) THEN MINWRK = NMAX*( NMAX+1 ) NB = MAX( 1, ILAENV( 1, 'ZGEQRF', ' ', NMAX, NMAX, -1, -1 ), $ ILAENV( 1, 'ZUNMQR', 'LC', NMAX, NMAX, NMAX, -1 ), $ ILAENV( 1, 'ZUNGQR', ' ', NMAX, NMAX, NMAX, -1 ) ) MAXWRK = MAX( 2*NMAX, NMAX*( NB+1 ), NMAX*( NMAX+1 ) ) WORK( 1 ) = MAXWRK END IF * IF( LWORK.LT.MINWRK ) $ INFO = -23 * IF( INFO.NE.0 ) THEN CALL XERBLA( 'ZDRGEV', -INFO ) RETURN END IF * * Quick return if possible * IF( NSIZES.EQ.0 .OR. NTYPES.EQ.0 ) $ RETURN * ULP = DLAMCH( 'Precision' ) SAFMIN = DLAMCH( 'Safe minimum' ) SAFMIN = SAFMIN / ULP SAFMAX = ONE / SAFMIN CALL DLABAD( SAFMIN, SAFMAX ) ULPINV = ONE / ULP * * The values RMAGN(2:3) depend on N, see below. * RMAGN( 0 ) = ZERO RMAGN( 1 ) = ONE * * Loop over sizes, types * NTESTT = 0 NERRS = 0 NMATS = 0 * DO 220 JSIZE = 1, NSIZES N = NN( JSIZE ) N1 = MAX( 1, N ) RMAGN( 2 ) = SAFMAX*ULP / DBLE( N1 ) RMAGN( 3 ) = SAFMIN*ULPINV*N1 * IF( NSIZES.NE.1 ) THEN MTYPES = MIN( MAXTYP, NTYPES ) ELSE MTYPES = MIN( MAXTYP+1, NTYPES ) END IF * DO 210 JTYPE = 1, MTYPES IF( .NOT.DOTYPE( JTYPE ) ) $ GO TO 210 NMATS = NMATS + 1 * * Save ISEED in case of an error. * DO 20 J = 1, 4 IOLDSD( J ) = ISEED( J ) 20 CONTINUE * * Generate test matrices A and B * * Description of control parameters: * * KZLASS: =1 means w/o rotation, =2 means w/ rotation, * =3 means random. * KATYPE: the "type" to be passed to ZLATM4 for computing A. * KAZERO: the pattern of zeros on the diagonal for A: * =1: ( xxx ), =2: (0, xxx ) =3: ( 0, 0, xxx, 0 ), * =4: ( 0, xxx, 0, 0 ), =5: ( 0, 0, 1, xxx, 0 ), * =6: ( 0, 1, 0, xxx, 0 ). (xxx means a string of * non-zero entries.) * KAMAGN: the magnitude of the matrix: =0: zero, =1: O(1), * =2: large, =3: small. * LASIGN: .TRUE. if the diagonal elements of A are to be * multiplied by a random magnitude 1 number. * KBTYPE, KBZERO, KBMAGN, LBSIGN: the same, but for B. * KTRIAN: =0: don't fill in the upper triangle, =1: do. * KZ1, KZ2, KADD: used to implement KAZERO and KBZERO. * RMAGN: used to implement KAMAGN and KBMAGN. * IF( MTYPES.GT.MAXTYP ) $ GO TO 100 IERR = 0 IF( KCLASS( JTYPE ).LT.3 ) THEN * * Generate A (w/o rotation) * IF( ABS( KATYPE( JTYPE ) ).EQ.3 ) THEN IN = 2*( ( N-1 ) / 2 ) + 1 IF( IN.NE.N ) $ CALL ZLASET( 'Full', N, N, CZERO, CZERO, A, LDA ) ELSE IN = N END IF CALL ZLATM4( KATYPE( JTYPE ), IN, KZ1( KAZERO( JTYPE ) ), $ KZ2( KAZERO( JTYPE ) ), LASIGN( JTYPE ), $ RMAGN( KAMAGN( JTYPE ) ), ULP, $ RMAGN( KTRIAN( JTYPE )*KAMAGN( JTYPE ) ), 2, $ ISEED, A, LDA ) IADD = KADD( KAZERO( JTYPE ) ) IF( IADD.GT.0 .AND. IADD.LE.N ) $ A( IADD, IADD ) = RMAGN( KAMAGN( JTYPE ) ) * * Generate B (w/o rotation) * IF( ABS( KBTYPE( JTYPE ) ).EQ.3 ) THEN IN = 2*( ( N-1 ) / 2 ) + 1 IF( IN.NE.N ) $ CALL ZLASET( 'Full', N, N, CZERO, CZERO, B, LDA ) ELSE IN = N END IF CALL ZLATM4( KBTYPE( JTYPE ), IN, KZ1( KBZERO( JTYPE ) ), $ KZ2( KBZERO( JTYPE ) ), LBSIGN( JTYPE ), $ RMAGN( KBMAGN( JTYPE ) ), ONE, $ RMAGN( KTRIAN( JTYPE )*KBMAGN( JTYPE ) ), 2, $ ISEED, B, LDA ) IADD = KADD( KBZERO( JTYPE ) ) IF( IADD.NE.0 .AND. IADD.LE.N ) $ B( IADD, IADD ) = RMAGN( KBMAGN( JTYPE ) ) * IF( KCLASS( JTYPE ).EQ.2 .AND. N.GT.0 ) THEN * * Include rotations * * Generate Q, Z as Householder transformations times * a diagonal matrix. * DO 40 JC = 1, N - 1 DO 30 JR = JC, N Q( JR, JC ) = ZLARND( 3, ISEED ) Z( JR, JC ) = ZLARND( 3, ISEED ) 30 CONTINUE CALL ZLARFG( N+1-JC, Q( JC, JC ), Q( JC+1, JC ), 1, $ WORK( JC ) ) WORK( 2*N+JC ) = SIGN( ONE, DBLE( Q( JC, JC ) ) ) Q( JC, JC ) = CONE CALL ZLARFG( N+1-JC, Z( JC, JC ), Z( JC+1, JC ), 1, $ WORK( N+JC ) ) WORK( 3*N+JC ) = SIGN( ONE, DBLE( Z( JC, JC ) ) ) Z( JC, JC ) = CONE 40 CONTINUE CTEMP = ZLARND( 3, ISEED ) Q( N, N ) = CONE WORK( N ) = CZERO WORK( 3*N ) = CTEMP / ABS( CTEMP ) CTEMP = ZLARND( 3, ISEED ) Z( N, N ) = CONE WORK( 2*N ) = CZERO WORK( 4*N ) = CTEMP / ABS( CTEMP ) * * Apply the diagonal matrices * DO 60 JC = 1, N DO 50 JR = 1, N A( JR, JC ) = WORK( 2*N+JR )* $ DCONJG( WORK( 3*N+JC ) )* $ A( JR, JC ) B( JR, JC ) = WORK( 2*N+JR )* $ DCONJG( WORK( 3*N+JC ) )* $ B( JR, JC ) 50 CONTINUE 60 CONTINUE CALL ZUNM2R( 'L', 'N', N, N, N-1, Q, LDQ, WORK, A, $ LDA, WORK( 2*N+1 ), IERR ) IF( IERR.NE.0 ) $ GO TO 90 CALL ZUNM2R( 'R', 'C', N, N, N-1, Z, LDQ, WORK( N+1 ), $ A, LDA, WORK( 2*N+1 ), IERR ) IF( IERR.NE.0 ) $ GO TO 90 CALL ZUNM2R( 'L', 'N', N, N, N-1, Q, LDQ, WORK, B, $ LDA, WORK( 2*N+1 ), IERR ) IF( IERR.NE.0 ) $ GO TO 90 CALL ZUNM2R( 'R', 'C', N, N, N-1, Z, LDQ, WORK( N+1 ), $ B, LDA, WORK( 2*N+1 ), IERR ) IF( IERR.NE.0 ) $ GO TO 90 END IF ELSE * * Random matrices * DO 80 JC = 1, N DO 70 JR = 1, N A( JR, JC ) = RMAGN( KAMAGN( JTYPE ) )* $ ZLARND( 4, ISEED ) B( JR, JC ) = RMAGN( KBMAGN( JTYPE ) )* $ ZLARND( 4, ISEED ) 70 CONTINUE 80 CONTINUE END IF * 90 CONTINUE * IF( IERR.NE.0 ) THEN WRITE( NOUNIT, FMT = 9999 )'Generator', IERR, N, JTYPE, $ IOLDSD INFO = ABS( IERR ) RETURN END IF * 100 CONTINUE * DO 110 I = 1, 7 RESULT( I ) = -ONE 110 CONTINUE * * Call ZGGEV to compute eigenvalues and eigenvectors. * CALL ZLACPY( ' ', N, N, A, LDA, S, LDA ) CALL ZLACPY( ' ', N, N, B, LDA, T, LDA ) CALL ZGGEV( 'V', 'V', N, S, LDA, T, LDA, ALPHA, BETA, Q, $ LDQ, Z, LDQ, WORK, LWORK, RWORK, IERR ) IF( IERR.NE.0 .AND. IERR.NE.N+1 ) THEN RESULT( 1 ) = ULPINV WRITE( NOUNIT, FMT = 9999 )'ZGGEV1', IERR, N, JTYPE, $ IOLDSD INFO = ABS( IERR ) GO TO 190 END IF * * Do the tests (1) and (2) * CALL ZGET52( .TRUE., N, A, LDA, B, LDA, Q, LDQ, ALPHA, BETA, $ WORK, RWORK, RESULT( 1 ) ) IF( RESULT( 2 ).GT.THRESH ) THEN WRITE( NOUNIT, FMT = 9998 )'Left', 'ZGGEV1', $ RESULT( 2 ), N, JTYPE, IOLDSD END IF * * Do the tests (3) and (4) * CALL ZGET52( .FALSE., N, A, LDA, B, LDA, Z, LDQ, ALPHA, $ BETA, WORK, RWORK, RESULT( 3 ) ) IF( RESULT( 4 ).GT.THRESH ) THEN WRITE( NOUNIT, FMT = 9998 )'Right', 'ZGGEV1', $ RESULT( 4 ), N, JTYPE, IOLDSD END IF * * Do test (5) * CALL ZLACPY( ' ', N, N, A, LDA, S, LDA ) CALL ZLACPY( ' ', N, N, B, LDA, T, LDA ) CALL ZGGEV( 'N', 'N', N, S, LDA, T, LDA, ALPHA1, BETA1, Q, $ LDQ, Z, LDQ, WORK, LWORK, RWORK, IERR ) IF( IERR.NE.0 .AND. IERR.NE.N+1 ) THEN RESULT( 1 ) = ULPINV WRITE( NOUNIT, FMT = 9999 )'ZGGEV2', IERR, N, JTYPE, $ IOLDSD INFO = ABS( IERR ) GO TO 190 END IF * DO 120 J = 1, N IF( ALPHA( J ).NE.ALPHA1( J ) .OR. BETA( J ).NE. $ BETA1( J ) )RESULT( 5 ) = ULPINV 120 CONTINUE * * Do test (6): Compute eigenvalues and left eigenvectors, * and test them * CALL ZLACPY( ' ', N, N, A, LDA, S, LDA ) CALL ZLACPY( ' ', N, N, B, LDA, T, LDA ) CALL ZGGEV( 'V', 'N', N, S, LDA, T, LDA, ALPHA1, BETA1, QE, $ LDQE, Z, LDQ, WORK, LWORK, RWORK, IERR ) IF( IERR.NE.0 .AND. IERR.NE.N+1 ) THEN RESULT( 1 ) = ULPINV WRITE( NOUNIT, FMT = 9999 )'ZGGEV3', IERR, N, JTYPE, $ IOLDSD INFO = ABS( IERR ) GO TO 190 END IF * DO 130 J = 1, N IF( ALPHA( J ).NE.ALPHA1( J ) .OR. BETA( J ).NE. $ BETA1( J ) )RESULT( 6 ) = ULPINV 130 CONTINUE * DO 150 J = 1, N DO 140 JC = 1, N IF( Q( J, JC ).NE.QE( J, JC ) ) $ RESULT( 6 ) = ULPINV 140 CONTINUE 150 CONTINUE * * Do test (7): Compute eigenvalues and right eigenvectors, * and test them * CALL ZLACPY( ' ', N, N, A, LDA, S, LDA ) CALL ZLACPY( ' ', N, N, B, LDA, T, LDA ) CALL ZGGEV( 'N', 'V', N, S, LDA, T, LDA, ALPHA1, BETA1, Q, $ LDQ, QE, LDQE, WORK, LWORK, RWORK, IERR ) IF( IERR.NE.0 .AND. IERR.NE.N+1 ) THEN RESULT( 1 ) = ULPINV WRITE( NOUNIT, FMT = 9999 )'ZGGEV4', IERR, N, JTYPE, $ IOLDSD INFO = ABS( IERR ) GO TO 190 END IF * DO 160 J = 1, N IF( ALPHA( J ).NE.ALPHA1( J ) .OR. BETA( J ).NE. $ BETA1( J ) )RESULT( 7 ) = ULPINV 160 CONTINUE * DO 180 J = 1, N DO 170 JC = 1, N IF( Z( J, JC ).NE.QE( J, JC ) ) $ RESULT( 7 ) = ULPINV 170 CONTINUE 180 CONTINUE * * End of Loop -- Check for RESULT(j) > THRESH * 190 CONTINUE * NTESTT = NTESTT + 7 * * Print out tests which fail. * DO 200 JR = 1, 7 IF( RESULT( JR ).GE.THRESH ) THEN * * If this is the first test to fail, * print a header to the data file. * IF( NERRS.EQ.0 ) THEN WRITE( NOUNIT, FMT = 9997 )'ZGV' * * Matrix types * WRITE( NOUNIT, FMT = 9996 ) WRITE( NOUNIT, FMT = 9995 ) WRITE( NOUNIT, FMT = 9994 )'Orthogonal' * * Tests performed * WRITE( NOUNIT, FMT = 9993 ) * END IF NERRS = NERRS + 1 IF( RESULT( JR ).LT.10000.0D0 ) THEN WRITE( NOUNIT, FMT = 9992 )N, JTYPE, IOLDSD, JR, $ RESULT( JR ) ELSE WRITE( NOUNIT, FMT = 9991 )N, JTYPE, IOLDSD, JR, $ RESULT( JR ) END IF END IF 200 CONTINUE * 210 CONTINUE 220 CONTINUE * * Summary * CALL ALASVM( 'ZGV', NOUNIT, NERRS, NTESTT, 0 ) * WORK( 1 ) = MAXWRK * RETURN * 9999 FORMAT( ' ZDRGEV: ', A, ' returned INFO=', I6, '.', / 3X, 'N=', $ I6, ', JTYPE=', I6, ', ISEED=(', 3( I5, ',' ), I5, ')' ) * 9998 FORMAT( ' ZDRGEV: ', A, ' Eigenvectors from ', A, ' incorrectly ', $ 'normalized.', / ' Bits of error=', 0P, G10.3, ',', 3X, $ 'N=', I4, ', JTYPE=', I3, ', ISEED=(', 3( I4, ',' ), I5, $ ')' ) * 9997 FORMAT( / 1X, A3, ' -- Complex Generalized eigenvalue problem ', $ 'driver' ) * 9996 FORMAT( ' Matrix types (see ZDRGEV for details): ' ) * 9995 FORMAT( ' Special Matrices:', 23X, $ '(J''=transposed Jordan block)', $ / ' 1=(0,0) 2=(I,0) 3=(0,I) 4=(I,I) 5=(J'',J'') ', $ '6=(diag(J'',I), diag(I,J''))', / ' Diagonal Matrices: ( ', $ 'D=diag(0,1,2,...) )', / ' 7=(D,I) 9=(large*D, small*I', $ ') 11=(large*I, small*D) 13=(large*D, large*I)', / $ ' 8=(I,D) 10=(small*D, large*I) 12=(small*I, large*D) ', $ ' 14=(small*D, small*I)', / ' 15=(D, reversed D)' ) 9994 FORMAT( ' Matrices Rotated by Random ', A, ' Matrices U, V:', $ / ' 16=Transposed Jordan Blocks 19=geometric ', $ 'alpha, beta=0,1', / ' 17=arithm. alpha&beta ', $ ' 20=arithmetic alpha, beta=0,1', / ' 18=clustered ', $ 'alpha, beta=0,1 21=random alpha, beta=0,1', $ / ' Large & Small Matrices:', / ' 22=(large, small) ', $ '23=(small,large) 24=(small,small) 25=(large,large)', $ / ' 26=random O(1) matrices.' ) * 9993 FORMAT( / ' Tests performed: ', $ / ' 1 = max | ( b A - a B )''*l | / const.,', $ / ' 2 = | |VR(i)| - 1 | / ulp,', $ / ' 3 = max | ( b A - a B )*r | / const.', $ / ' 4 = | |VL(i)| - 1 | / ulp,', $ / ' 5 = 0 if W same no matter if r or l computed,', $ / ' 6 = 0 if l same no matter if l computed,', $ / ' 7 = 0 if r same no matter if r computed,', / 1X ) 9992 FORMAT( ' Matrix order=', I5, ', type=', I2, ', seed=', $ 4( I4, ',' ), ' result ', I2, ' is', 0P, F8.2 ) 9991 FORMAT( ' Matrix order=', I5, ', type=', I2, ', seed=', $ 4( I4, ',' ), ' result ', I2, ' is', 1P, D10.3 ) * * End of ZDRGEV * END
gpl-2.0
QEF/q-e
KCW/src/kcw_allocate_q.f90
2
1648
! ! Copyright (C) 2003-2021 Quantum ESPRESSO group ! This file is distributed under the terms of the ! GNU General Public License. See the file `License' ! in the root directory of the present distribution, ! or http://www.gnu.org/copyleft/gpl.txt . ! ! !----------------------------------------------------------------------- subroutine kcw_allocate_q !----------------------------------------------------------------------- ! ! Dynamical allocation of arrays: quantities needed for the linear ! response problem ! USE ions_base, ONLY : nat USE wvfct, ONLY : nbnd, npwx USE noncollin_module, ONLY : npol, nspin_mag USE fft_base, ONLY : dfftp USE wavefunctions, ONLY : evc USE becmod, ONLY : allocate_bec_type, becp USE uspp, ONLY : nkb, okvan USE qpoint, ONLY : nksq, eigqts USE lrus, ONLY : becp1 USE eqv, ONLY : dpsi, evq, dmuxc, dvpsi USE control_lr, ONLY : lgamma ! IMPLICIT NONE INTEGER :: ik ! IF (lgamma) THEN ! q=0 : evq is a pointer to evc evq => evc ELSE ! q/=0 : evq is allocated and calculated at point k+q ALLOCATE (evq(npwx*npol,nbnd)) ENDIF ! ALLOCATE (dvpsi(npwx*npol,nbnd)) ALLOCATE (dpsi(npwx*npol,nbnd)) ALLOCATE (dmuxc(dfftp%nnr,nspin_mag,nspin_mag)) ! CALL allocate_bec_type ( nkb, nbnd, becp ) IF (okvan) THEN ALLOCATE (eigqts(nat)) ALLOCATE (becp1(nksq)) DO ik = 1,nksq CALL allocate_bec_type ( nkb, nbnd, becp1(ik) ) ENDDO ENDIF ! RETURN ! end subroutine kcw_allocate_q
gpl-2.0
wilmarcardonac/hypermcmc
lapack-3.5.0/TESTING/LIN/schkgb.f
32
25373
*> \brief \b SCHKGB * * =========== DOCUMENTATION =========== * * Online html documentation available at * http://www.netlib.org/lapack/explore-html/ * * Definition: * =========== * * SUBROUTINE SCHKGB( DOTYPE, NM, MVAL, NN, NVAL, NNB, NBVAL, NNS, * NSVAL, THRESH, TSTERR, A, LA, AFAC, LAFAC, B, * X, XACT, WORK, RWORK, IWORK, NOUT ) * * .. Scalar Arguments .. * LOGICAL TSTERR * INTEGER LA, LAFAC, NM, NN, NNB, NNS, NOUT * REAL THRESH * .. * .. Array Arguments .. * LOGICAL DOTYPE( * ) * INTEGER IWORK( * ), MVAL( * ), NBVAL( * ), NSVAL( * ), * $ NVAL( * ) * REAL A( * ), AFAC( * ), B( * ), RWORK( * ), * $ WORK( * ), X( * ), XACT( * ) * .. * * *> \par Purpose: * ============= *> *> \verbatim *> *> SCHKGB tests SGBTRF, -TRS, -RFS, and -CON *> \endverbatim * * Arguments: * ========== * *> \param[in] DOTYPE *> \verbatim *> DOTYPE is LOGICAL array, dimension (NTYPES) *> The matrix types to be used for testing. Matrices of type j *> (for 1 <= j <= NTYPES) are used for testing if DOTYPE(j) = *> .TRUE.; if DOTYPE(j) = .FALSE., then type j is not used. *> \endverbatim *> *> \param[in] NM *> \verbatim *> NM is INTEGER *> The number of values of M contained in the vector MVAL. *> \endverbatim *> *> \param[in] MVAL *> \verbatim *> MVAL is INTEGER array, dimension (NM) *> The values of the matrix row dimension M. *> \endverbatim *> *> \param[in] NN *> \verbatim *> NN is INTEGER *> The number of values of N contained in the vector NVAL. *> \endverbatim *> *> \param[in] NVAL *> \verbatim *> NVAL is INTEGER array, dimension (NN) *> The values of the matrix column dimension N. *> \endverbatim *> *> \param[in] NNB *> \verbatim *> NNB is INTEGER *> The number of values of NB contained in the vector NBVAL. *> \endverbatim *> *> \param[in] NBVAL *> \verbatim *> NBVAL is INTEGER array, dimension (NNB) *> The values of the blocksize NB. *> \endverbatim *> *> \param[in] NNS *> \verbatim *> NNS is INTEGER *> The number of values of NRHS contained in the vector NSVAL. *> \endverbatim *> *> \param[in] NSVAL *> \verbatim *> NSVAL is INTEGER array, dimension (NNS) *> The values of the number of right hand sides NRHS. *> \endverbatim *> *> \param[in] THRESH *> \verbatim *> THRESH is REAL *> The threshold value for the test ratios. A result is *> included in the output file if RESULT >= THRESH. To have *> every test ratio printed, use THRESH = 0. *> \endverbatim *> *> \param[in] TSTERR *> \verbatim *> TSTERR is LOGICAL *> Flag that indicates whether error exits are to be tested. *> \endverbatim *> *> \param[out] A *> \verbatim *> A is REAL array, dimension (LA) *> \endverbatim *> *> \param[in] LA *> \verbatim *> LA is INTEGER *> The length of the array A. LA >= (KLMAX+KUMAX+1)*NMAX *> where KLMAX is the largest entry in the local array KLVAL, *> KUMAX is the largest entry in the local array KUVAL and *> NMAX is the largest entry in the input array NVAL. *> \endverbatim *> *> \param[out] AFAC *> \verbatim *> AFAC is REAL array, dimension (LAFAC) *> \endverbatim *> *> \param[in] LAFAC *> \verbatim *> LAFAC is INTEGER *> The length of the array AFAC. LAFAC >= (2*KLMAX+KUMAX+1)*NMAX *> where KLMAX is the largest entry in the local array KLVAL, *> KUMAX is the largest entry in the local array KUVAL and *> NMAX is the largest entry in the input array NVAL. *> \endverbatim *> *> \param[out] B *> \verbatim *> B is REAL array, dimension (NMAX*NSMAX) *> where NSMAX is the largest entry in NSVAL. *> \endverbatim *> *> \param[out] X *> \verbatim *> X is REAL array, dimension (NMAX*NSMAX) *> \endverbatim *> *> \param[out] XACT *> \verbatim *> XACT is REAL array, dimension (NMAX*NSMAX) *> \endverbatim *> *> \param[out] WORK *> \verbatim *> WORK is REAL array, dimension *> (NMAX*max(3,NSMAX,NMAX)) *> \endverbatim *> *> \param[out] RWORK *> \verbatim *> RWORK is REAL array, dimension *> (max(NMAX,2*NSMAX)) *> \endverbatim *> *> \param[out] IWORK *> \verbatim *> IWORK is INTEGER array, dimension (2*NMAX) *> \endverbatim *> *> \param[in] NOUT *> \verbatim *> NOUT is INTEGER *> The unit number for output. *> \endverbatim * * Authors: * ======== * *> \author Univ. of Tennessee *> \author Univ. of California Berkeley *> \author Univ. of Colorado Denver *> \author NAG Ltd. * *> \date November 2011 * *> \ingroup single_lin * * ===================================================================== SUBROUTINE SCHKGB( DOTYPE, NM, MVAL, NN, NVAL, NNB, NBVAL, NNS, $ NSVAL, THRESH, TSTERR, A, LA, AFAC, LAFAC, B, $ X, XACT, WORK, RWORK, IWORK, NOUT ) * * -- LAPACK test routine (version 3.4.0) -- * -- LAPACK is a software package provided by Univ. of Tennessee, -- * -- Univ. of California Berkeley, Univ. of Colorado Denver and NAG Ltd..-- * November 2011 * * .. Scalar Arguments .. LOGICAL TSTERR INTEGER LA, LAFAC, NM, NN, NNB, NNS, NOUT REAL THRESH * .. * .. Array Arguments .. LOGICAL DOTYPE( * ) INTEGER IWORK( * ), MVAL( * ), NBVAL( * ), NSVAL( * ), $ NVAL( * ) REAL A( * ), AFAC( * ), B( * ), RWORK( * ), $ WORK( * ), X( * ), XACT( * ) * .. * * ===================================================================== * * .. Parameters .. REAL ONE, ZERO PARAMETER ( ONE = 1.0E+0, ZERO = 0.0E+0 ) INTEGER NTYPES, NTESTS PARAMETER ( NTYPES = 8, NTESTS = 7 ) INTEGER NBW, NTRAN PARAMETER ( NBW = 4, NTRAN = 3 ) * .. * .. Local Scalars .. LOGICAL TRFCON, ZEROT CHARACTER DIST, NORM, TRANS, TYPE, XTYPE CHARACTER*3 PATH INTEGER I, I1, I2, IKL, IKU, IM, IMAT, IN, INB, INFO, $ IOFF, IRHS, ITRAN, IZERO, J, K, KL, KOFF, KU, $ LDA, LDAFAC, LDB, M, MODE, N, NB, NERRS, NFAIL, $ NIMAT, NKL, NKU, NRHS, NRUN REAL AINVNM, ANORM, ANORMI, ANORMO, CNDNUM, RCOND, $ RCONDC, RCONDI, RCONDO * .. * .. Local Arrays .. CHARACTER TRANSS( NTRAN ) INTEGER ISEED( 4 ), ISEEDY( 4 ), KLVAL( NBW ), $ KUVAL( NBW ) REAL RESULT( NTESTS ) * .. * .. External Functions .. REAL SGET06, SLANGB, SLANGE EXTERNAL SGET06, SLANGB, SLANGE * .. * .. External Subroutines .. EXTERNAL ALAERH, ALAHD, ALASUM, SCOPY, SERRGE, SGBCON, $ SGBRFS, SGBT01, SGBT02, SGBT05, SGBTRF, SGBTRS, $ SGET04, SLACPY, SLARHS, SLASET, SLATB4, SLATMS, $ XLAENV * .. * .. Intrinsic Functions .. INTRINSIC MAX, MIN * .. * .. Scalars in Common .. LOGICAL LERR, OK CHARACTER*32 SRNAMT INTEGER INFOT, NUNIT * .. * .. Common blocks .. COMMON / INFOC / INFOT, NUNIT, OK, LERR COMMON / SRNAMC / SRNAMT * .. * .. Data statements .. DATA ISEEDY / 1988, 1989, 1990, 1991 / , $ TRANSS / 'N', 'T', 'C' / * .. * .. Executable Statements .. * * Initialize constants and the random number seed. * PATH( 1: 1 ) = 'Single precision' PATH( 2: 3 ) = 'GB' NRUN = 0 NFAIL = 0 NERRS = 0 DO 10 I = 1, 4 ISEED( I ) = ISEEDY( I ) 10 CONTINUE * * Test the error exits * IF( TSTERR ) $ CALL SERRGE( PATH, NOUT ) INFOT = 0 CALL XLAENV( 2, 2 ) * * Initialize the first value for the lower and upper bandwidths. * KLVAL( 1 ) = 0 KUVAL( 1 ) = 0 * * Do for each value of M in MVAL * DO 160 IM = 1, NM M = MVAL( IM ) * * Set values to use for the lower bandwidth. * KLVAL( 2 ) = M + ( M+1 ) / 4 * * KLVAL( 2 ) = MAX( M-1, 0 ) * KLVAL( 3 ) = ( 3*M-1 ) / 4 KLVAL( 4 ) = ( M+1 ) / 4 * * Do for each value of N in NVAL * DO 150 IN = 1, NN N = NVAL( IN ) XTYPE = 'N' * * Set values to use for the upper bandwidth. * KUVAL( 2 ) = N + ( N+1 ) / 4 * * KUVAL( 2 ) = MAX( N-1, 0 ) * KUVAL( 3 ) = ( 3*N-1 ) / 4 KUVAL( 4 ) = ( N+1 ) / 4 * * Set limits on the number of loop iterations. * NKL = MIN( M+1, 4 ) IF( N.EQ.0 ) $ NKL = 2 NKU = MIN( N+1, 4 ) IF( M.EQ.0 ) $ NKU = 2 NIMAT = NTYPES IF( M.LE.0 .OR. N.LE.0 ) $ NIMAT = 1 * DO 140 IKL = 1, NKL * * Do for KL = 0, (5*M+1)/4, (3M-1)/4, and (M+1)/4. This * order makes it easier to skip redundant values for small * values of M. * KL = KLVAL( IKL ) DO 130 IKU = 1, NKU * * Do for KU = 0, (5*N+1)/4, (3N-1)/4, and (N+1)/4. This * order makes it easier to skip redundant values for * small values of N. * KU = KUVAL( IKU ) * * Check that A and AFAC are big enough to generate this * matrix. * LDA = KL + KU + 1 LDAFAC = 2*KL + KU + 1 IF( ( LDA*N ).GT.LA .OR. ( LDAFAC*N ).GT.LAFAC ) THEN IF( NFAIL.EQ.0 .AND. NERRS.EQ.0 ) $ CALL ALAHD( NOUT, PATH ) IF( N*( KL+KU+1 ).GT.LA ) THEN WRITE( NOUT, FMT = 9999 )LA, M, N, KL, KU, $ N*( KL+KU+1 ) NERRS = NERRS + 1 END IF IF( N*( 2*KL+KU+1 ).GT.LAFAC ) THEN WRITE( NOUT, FMT = 9998 )LAFAC, M, N, KL, KU, $ N*( 2*KL+KU+1 ) NERRS = NERRS + 1 END IF GO TO 130 END IF * DO 120 IMAT = 1, NIMAT * * Do the tests only if DOTYPE( IMAT ) is true. * IF( .NOT.DOTYPE( IMAT ) ) $ GO TO 120 * * Skip types 2, 3, or 4 if the matrix size is too * small. * ZEROT = IMAT.GE.2 .AND. IMAT.LE.4 IF( ZEROT .AND. N.LT.IMAT-1 ) $ GO TO 120 * IF( .NOT.ZEROT .OR. .NOT.DOTYPE( 1 ) ) THEN * * Set up parameters with SLATB4 and generate a * test matrix with SLATMS. * CALL SLATB4( PATH, IMAT, M, N, TYPE, KL, KU, $ ANORM, MODE, CNDNUM, DIST ) * KOFF = MAX( 1, KU+2-N ) DO 20 I = 1, KOFF - 1 A( I ) = ZERO 20 CONTINUE SRNAMT = 'SLATMS' CALL SLATMS( M, N, DIST, ISEED, TYPE, RWORK, $ MODE, CNDNUM, ANORM, KL, KU, 'Z', $ A( KOFF ), LDA, WORK, INFO ) * * Check the error code from SLATMS. * IF( INFO.NE.0 ) THEN CALL ALAERH( PATH, 'SLATMS', INFO, 0, ' ', M, $ N, KL, KU, -1, IMAT, NFAIL, $ NERRS, NOUT ) GO TO 120 END IF ELSE IF( IZERO.GT.0 ) THEN * * Use the same matrix for types 3 and 4 as for * type 2 by copying back the zeroed out column. * CALL SCOPY( I2-I1+1, B, 1, A( IOFF+I1 ), 1 ) END IF * * For types 2, 3, and 4, zero one or more columns of * the matrix to test that INFO is returned correctly. * IZERO = 0 IF( ZEROT ) THEN IF( IMAT.EQ.2 ) THEN IZERO = 1 ELSE IF( IMAT.EQ.3 ) THEN IZERO = MIN( M, N ) ELSE IZERO = MIN( M, N ) / 2 + 1 END IF IOFF = ( IZERO-1 )*LDA IF( IMAT.LT.4 ) THEN * * Store the column to be zeroed out in B. * I1 = MAX( 1, KU+2-IZERO ) I2 = MIN( KL+KU+1, KU+1+( M-IZERO ) ) CALL SCOPY( I2-I1+1, A( IOFF+I1 ), 1, B, 1 ) * DO 30 I = I1, I2 A( IOFF+I ) = ZERO 30 CONTINUE ELSE DO 50 J = IZERO, N DO 40 I = MAX( 1, KU+2-J ), $ MIN( KL+KU+1, KU+1+( M-J ) ) A( IOFF+I ) = ZERO 40 CONTINUE IOFF = IOFF + LDA 50 CONTINUE END IF END IF * * These lines, if used in place of the calls in the * loop over INB, cause the code to bomb on a Sun * SPARCstation. * * ANORMO = SLANGB( 'O', N, KL, KU, A, LDA, RWORK ) * ANORMI = SLANGB( 'I', N, KL, KU, A, LDA, RWORK ) * * Do for each blocksize in NBVAL * DO 110 INB = 1, NNB NB = NBVAL( INB ) CALL XLAENV( 1, NB ) * * Compute the LU factorization of the band matrix. * IF( M.GT.0 .AND. N.GT.0 ) $ CALL SLACPY( 'Full', KL+KU+1, N, A, LDA, $ AFAC( KL+1 ), LDAFAC ) SRNAMT = 'SGBTRF' CALL SGBTRF( M, N, KL, KU, AFAC, LDAFAC, IWORK, $ INFO ) * * Check error code from SGBTRF. * IF( INFO.NE.IZERO ) $ CALL ALAERH( PATH, 'SGBTRF', INFO, IZERO, $ ' ', M, N, KL, KU, NB, IMAT, $ NFAIL, NERRS, NOUT ) TRFCON = .FALSE. * *+ TEST 1 * Reconstruct matrix from factors and compute * residual. * CALL SGBT01( M, N, KL, KU, A, LDA, AFAC, LDAFAC, $ IWORK, WORK, RESULT( 1 ) ) * * Print information about the tests so far that * did not pass the threshold. * IF( RESULT( 1 ).GE.THRESH ) THEN IF( NFAIL.EQ.0 .AND. NERRS.EQ.0 ) $ CALL ALAHD( NOUT, PATH ) WRITE( NOUT, FMT = 9997 )M, N, KL, KU, NB, $ IMAT, 1, RESULT( 1 ) NFAIL = NFAIL + 1 END IF NRUN = NRUN + 1 * * Skip the remaining tests if this is not the * first block size or if M .ne. N. * IF( INB.GT.1 .OR. M.NE.N ) $ GO TO 110 * ANORMO = SLANGB( 'O', N, KL, KU, A, LDA, RWORK ) ANORMI = SLANGB( 'I', N, KL, KU, A, LDA, RWORK ) * IF( INFO.EQ.0 ) THEN * * Form the inverse of A so we can get a good * estimate of CNDNUM = norm(A) * norm(inv(A)). * LDB = MAX( 1, N ) CALL SLASET( 'Full', N, N, ZERO, ONE, WORK, $ LDB ) SRNAMT = 'SGBTRS' CALL SGBTRS( 'No transpose', N, KL, KU, N, $ AFAC, LDAFAC, IWORK, WORK, LDB, $ INFO ) * * Compute the 1-norm condition number of A. * AINVNM = SLANGE( 'O', N, N, WORK, LDB, $ RWORK ) IF( ANORMO.LE.ZERO .OR. AINVNM.LE.ZERO ) THEN RCONDO = ONE ELSE RCONDO = ( ONE / ANORMO ) / AINVNM END IF * * Compute the infinity-norm condition number of * A. * AINVNM = SLANGE( 'I', N, N, WORK, LDB, $ RWORK ) IF( ANORMI.LE.ZERO .OR. AINVNM.LE.ZERO ) THEN RCONDI = ONE ELSE RCONDI = ( ONE / ANORMI ) / AINVNM END IF ELSE * * Do only the condition estimate if INFO.NE.0. * TRFCON = .TRUE. RCONDO = ZERO RCONDI = ZERO END IF * * Skip the solve tests if the matrix is singular. * IF( TRFCON ) $ GO TO 90 * DO 80 IRHS = 1, NNS NRHS = NSVAL( IRHS ) XTYPE = 'N' * DO 70 ITRAN = 1, NTRAN TRANS = TRANSS( ITRAN ) IF( ITRAN.EQ.1 ) THEN RCONDC = RCONDO NORM = 'O' ELSE RCONDC = RCONDI NORM = 'I' END IF * *+ TEST 2: * Solve and compute residual for A * X = B. * SRNAMT = 'SLARHS' CALL SLARHS( PATH, XTYPE, ' ', TRANS, N, $ N, KL, KU, NRHS, A, LDA, $ XACT, LDB, B, LDB, ISEED, $ INFO ) XTYPE = 'C' CALL SLACPY( 'Full', N, NRHS, B, LDB, X, $ LDB ) * SRNAMT = 'SGBTRS' CALL SGBTRS( TRANS, N, KL, KU, NRHS, AFAC, $ LDAFAC, IWORK, X, LDB, INFO ) * * Check error code from SGBTRS. * IF( INFO.NE.0 ) $ CALL ALAERH( PATH, 'SGBTRS', INFO, 0, $ TRANS, N, N, KL, KU, -1, $ IMAT, NFAIL, NERRS, NOUT ) * CALL SLACPY( 'Full', N, NRHS, B, LDB, $ WORK, LDB ) CALL SGBT02( TRANS, M, N, KL, KU, NRHS, A, $ LDA, X, LDB, WORK, LDB, $ RESULT( 2 ) ) * *+ TEST 3: * Check solution from generated exact * solution. * CALL SGET04( N, NRHS, X, LDB, XACT, LDB, $ RCONDC, RESULT( 3 ) ) * *+ TESTS 4, 5, 6: * Use iterative refinement to improve the * solution. * SRNAMT = 'SGBRFS' CALL SGBRFS( TRANS, N, KL, KU, NRHS, A, $ LDA, AFAC, LDAFAC, IWORK, B, $ LDB, X, LDB, RWORK, $ RWORK( NRHS+1 ), WORK, $ IWORK( N+1 ), INFO ) * * Check error code from SGBRFS. * IF( INFO.NE.0 ) $ CALL ALAERH( PATH, 'SGBRFS', INFO, 0, $ TRANS, N, N, KL, KU, NRHS, $ IMAT, NFAIL, NERRS, NOUT ) * CALL SGET04( N, NRHS, X, LDB, XACT, LDB, $ RCONDC, RESULT( 4 ) ) CALL SGBT05( TRANS, N, KL, KU, NRHS, A, $ LDA, B, LDB, X, LDB, XACT, $ LDB, RWORK, RWORK( NRHS+1 ), $ RESULT( 5 ) ) DO 60 K = 2, 6 IF( RESULT( K ).GE.THRESH ) THEN IF( NFAIL.EQ.0 .AND. NERRS.EQ.0 ) $ CALL ALAHD( NOUT, PATH ) WRITE( NOUT, FMT = 9996 )TRANS, N, $ KL, KU, NRHS, IMAT, K, $ RESULT( K ) NFAIL = NFAIL + 1 END IF 60 CONTINUE NRUN = NRUN + 5 70 CONTINUE 80 CONTINUE * *+ TEST 7: * Get an estimate of RCOND = 1/CNDNUM. * 90 CONTINUE DO 100 ITRAN = 1, 2 IF( ITRAN.EQ.1 ) THEN ANORM = ANORMO RCONDC = RCONDO NORM = 'O' ELSE ANORM = ANORMI RCONDC = RCONDI NORM = 'I' END IF SRNAMT = 'SGBCON' CALL SGBCON( NORM, N, KL, KU, AFAC, LDAFAC, $ IWORK, ANORM, RCOND, WORK, $ IWORK( N+1 ), INFO ) * * Check error code from SGBCON. * IF( INFO.NE.0 ) $ CALL ALAERH( PATH, 'SGBCON', INFO, 0, $ NORM, N, N, KL, KU, -1, IMAT, $ NFAIL, NERRS, NOUT ) * RESULT( 7 ) = SGET06( RCOND, RCONDC ) * * Print information about the tests that did * not pass the threshold. * IF( RESULT( 7 ).GE.THRESH ) THEN IF( NFAIL.EQ.0 .AND. NERRS.EQ.0 ) $ CALL ALAHD( NOUT, PATH ) WRITE( NOUT, FMT = 9995 )NORM, N, KL, KU, $ IMAT, 7, RESULT( 7 ) NFAIL = NFAIL + 1 END IF NRUN = NRUN + 1 100 CONTINUE * 110 CONTINUE 120 CONTINUE 130 CONTINUE 140 CONTINUE 150 CONTINUE 160 CONTINUE * * Print a summary of the results. * CALL ALASUM( PATH, NOUT, NFAIL, NRUN, NERRS ) * 9999 FORMAT( ' *** In SCHKGB, LA=', I5, ' is too small for M=', I5, $ ', N=', I5, ', KL=', I4, ', KU=', I4, $ / ' ==> Increase LA to at least ', I5 ) 9998 FORMAT( ' *** In SCHKGB, LAFAC=', I5, ' is too small for M=', I5, $ ', N=', I5, ', KL=', I4, ', KU=', I4, $ / ' ==> Increase LAFAC to at least ', I5 ) 9997 FORMAT( ' M =', I5, ', N =', I5, ', KL=', I5, ', KU=', I5, $ ', NB =', I4, ', type ', I1, ', test(', I1, ')=', G12.5 ) 9996 FORMAT( ' TRANS=''', A1, ''', N=', I5, ', KL=', I5, ', KU=', I5, $ ', NRHS=', I3, ', type ', I1, ', test(', I1, ')=', G12.5 ) 9995 FORMAT( ' NORM =''', A1, ''', N=', I5, ', KL=', I5, ', KU=', I5, $ ',', 10X, ' type ', I1, ', test(', I1, ')=', G12.5 ) * RETURN * * End of SCHKGB * END
gpl-2.0
wilmarcardonac/hypermcmc
ranlib/src/src-splitted/genf.f90
2
1782
REAL FUNCTION genf(dfn,dfd) !********************************************************************** ! ! REAL FUNCTION GENF( DFN, DFD ) ! GENerate random deviate from the F distribution ! ! ! Function ! ! ! Generates a random deviate from the F (variance ratio) ! distribution with DFN degrees of freedom in the numerator ! and DFD degrees of freedom in the denominator. ! ! ! Arguments ! ! ! DFN --> Numerator degrees of freedom ! (Must be positive) ! REAL DFN ! DFD --> Denominator degrees of freedom ! (Must be positive) ! REAL DFD ! ! ! Method ! ! ! Directly generates ratio of chisquare variates ! !********************************************************************** ! .. Scalar Arguments .. REAL dfd,dfn ! .. ! .. Local Scalars .. REAL xden,xnum ! .. ! .. External Functions .. REAL genchi EXTERNAL genchi ! .. ! .. Executable Statements .. IF (.NOT. (dfn.LE.0.0.OR.dfd.LE.0.0)) GO TO 10 WRITE (*,*) 'Degrees of freedom nonpositive in GENF - abort!' WRITE (*,*) 'DFN value: ',dfn,'DFD value: ',dfd STOP 'Degrees of freedom nonpositive in GENF - abort!' 10 xnum = genchi(dfn)/dfn ! GENF = ( GENCHI( DFN ) / DFN ) / ( GENCHI( DFD ) / DFD ) xden = genchi(dfd)/dfd IF (.NOT. (xden.LE. (1.0E-38*xnum))) GO TO 20 WRITE (*,*) ' GENF - generated numbers would cause overflow' WRITE (*,*) ' Numerator ',xnum,' Denominator ',xden WRITE (*,*) ' GENF returning 1.0E38' genf = 1.0E38 GO TO 30 20 genf = xnum/xden 30 RETURN END
gpl-2.0
wilmarcardonac/hypermcmc
lapack-3.5.0/SRC/dpftrs.f
29
8451
*> \brief \b DPFTRS * * =========== DOCUMENTATION =========== * * Online html documentation available at * http://www.netlib.org/lapack/explore-html/ * *> \htmlonly *> Download DPFTRS + dependencies *> <a href="http://www.netlib.org/cgi-bin/netlibfiles.tgz?format=tgz&filename=/lapack/lapack_routine/dpftrs.f"> *> [TGZ]</a> *> <a href="http://www.netlib.org/cgi-bin/netlibfiles.zip?format=zip&filename=/lapack/lapack_routine/dpftrs.f"> *> [ZIP]</a> *> <a href="http://www.netlib.org/cgi-bin/netlibfiles.txt?format=txt&filename=/lapack/lapack_routine/dpftrs.f"> *> [TXT]</a> *> \endhtmlonly * * Definition: * =========== * * SUBROUTINE DPFTRS( TRANSR, UPLO, N, NRHS, A, B, LDB, INFO ) * * .. Scalar Arguments .. * CHARACTER TRANSR, UPLO * INTEGER INFO, LDB, N, NRHS * .. * .. Array Arguments .. * DOUBLE PRECISION A( 0: * ), B( LDB, * ) * .. * * *> \par Purpose: * ============= *> *> \verbatim *> *> DPFTRS solves a system of linear equations A*X = B with a symmetric *> positive definite matrix A using the Cholesky factorization *> A = U**T*U or A = L*L**T computed by DPFTRF. *> \endverbatim * * Arguments: * ========== * *> \param[in] TRANSR *> \verbatim *> TRANSR is CHARACTER*1 *> = 'N': The Normal TRANSR of RFP A is stored; *> = 'T': The Transpose TRANSR of RFP A is stored. *> \endverbatim *> *> \param[in] UPLO *> \verbatim *> UPLO is CHARACTER*1 *> = 'U': Upper triangle of RFP A is stored; *> = 'L': Lower triangle of RFP A is stored. *> \endverbatim *> *> \param[in] N *> \verbatim *> N is INTEGER *> The order of the matrix A. N >= 0. *> \endverbatim *> *> \param[in] NRHS *> \verbatim *> NRHS is INTEGER *> The number of right hand sides, i.e., the number of columns *> of the matrix B. NRHS >= 0. *> \endverbatim *> *> \param[in] A *> \verbatim *> A is DOUBLE PRECISION array, dimension ( N*(N+1)/2 ). *> The triangular factor U or L from the Cholesky factorization *> of RFP A = U**T*U or RFP A = L*L**T, as computed by DPFTRF. *> See note below for more details about RFP A. *> \endverbatim *> *> \param[in,out] B *> \verbatim *> B is DOUBLE PRECISION array, dimension (LDB,NRHS) *> On entry, the right hand side matrix B. *> On exit, the solution matrix X. *> \endverbatim *> *> \param[in] LDB *> \verbatim *> LDB is INTEGER *> The leading dimension of the array B. LDB >= max(1,N). *> \endverbatim *> *> \param[out] INFO *> \verbatim *> INFO is INTEGER *> = 0: successful exit *> < 0: if INFO = -i, the i-th argument had an illegal value *> \endverbatim * * Authors: * ======== * *> \author Univ. of Tennessee *> \author Univ. of California Berkeley *> \author Univ. of Colorado Denver *> \author NAG Ltd. * *> \date November 2011 * *> \ingroup doubleOTHERcomputational * *> \par Further Details: * ===================== *> *> \verbatim *> *> We first consider Rectangular Full Packed (RFP) Format when N is *> even. We give an example where N = 6. *> *> AP is Upper AP is Lower *> *> 00 01 02 03 04 05 00 *> 11 12 13 14 15 10 11 *> 22 23 24 25 20 21 22 *> 33 34 35 30 31 32 33 *> 44 45 40 41 42 43 44 *> 55 50 51 52 53 54 55 *> *> *> Let TRANSR = 'N'. RFP holds AP as follows: *> For UPLO = 'U' the upper trapezoid A(0:5,0:2) consists of the last *> three columns of AP upper. The lower triangle A(4:6,0:2) consists of *> the transpose of the first three columns of AP upper. *> For UPLO = 'L' the lower trapezoid A(1:6,0:2) consists of the first *> three columns of AP lower. The upper triangle A(0:2,0:2) consists of *> the transpose of the last three columns of AP lower. *> This covers the case N even and TRANSR = 'N'. *> *> RFP A RFP A *> *> 03 04 05 33 43 53 *> 13 14 15 00 44 54 *> 23 24 25 10 11 55 *> 33 34 35 20 21 22 *> 00 44 45 30 31 32 *> 01 11 55 40 41 42 *> 02 12 22 50 51 52 *> *> Now let TRANSR = 'T'. RFP A in both UPLO cases is just the *> transpose of RFP A above. One therefore gets: *> *> *> RFP A RFP A *> *> 03 13 23 33 00 01 02 33 00 10 20 30 40 50 *> 04 14 24 34 44 11 12 43 44 11 21 31 41 51 *> 05 15 25 35 45 55 22 53 54 55 22 32 42 52 *> *> *> We then consider Rectangular Full Packed (RFP) Format when N is *> odd. We give an example where N = 5. *> *> AP is Upper AP is Lower *> *> 00 01 02 03 04 00 *> 11 12 13 14 10 11 *> 22 23 24 20 21 22 *> 33 34 30 31 32 33 *> 44 40 41 42 43 44 *> *> *> Let TRANSR = 'N'. RFP holds AP as follows: *> For UPLO = 'U' the upper trapezoid A(0:4,0:2) consists of the last *> three columns of AP upper. The lower triangle A(3:4,0:1) consists of *> the transpose of the first two columns of AP upper. *> For UPLO = 'L' the lower trapezoid A(0:4,0:2) consists of the first *> three columns of AP lower. The upper triangle A(0:1,1:2) consists of *> the transpose of the last two columns of AP lower. *> This covers the case N odd and TRANSR = 'N'. *> *> RFP A RFP A *> *> 02 03 04 00 33 43 *> 12 13 14 10 11 44 *> 22 23 24 20 21 22 *> 00 33 34 30 31 32 *> 01 11 44 40 41 42 *> *> Now let TRANSR = 'T'. RFP A in both UPLO cases is just the *> transpose of RFP A above. One therefore gets: *> *> RFP A RFP A *> *> 02 12 22 00 01 00 10 20 30 40 50 *> 03 13 23 33 11 33 11 21 31 41 51 *> 04 14 24 34 44 43 44 22 32 42 52 *> \endverbatim *> * ===================================================================== SUBROUTINE DPFTRS( TRANSR, UPLO, N, NRHS, A, B, LDB, INFO ) * * -- LAPACK computational routine (version 3.4.0) -- * -- LAPACK is a software package provided by Univ. of Tennessee, -- * -- Univ. of California Berkeley, Univ. of Colorado Denver and NAG Ltd..-- * November 2011 * * .. Scalar Arguments .. CHARACTER TRANSR, UPLO INTEGER INFO, LDB, N, NRHS * .. * .. Array Arguments .. DOUBLE PRECISION A( 0: * ), B( LDB, * ) * .. * * ===================================================================== * * .. Parameters .. DOUBLE PRECISION ONE PARAMETER ( ONE = 1.0D+0 ) * .. * .. Local Scalars .. LOGICAL LOWER, NORMALTRANSR * .. * .. External Functions .. LOGICAL LSAME EXTERNAL LSAME * .. * .. External Subroutines .. EXTERNAL XERBLA, DTFSM * .. * .. Intrinsic Functions .. INTRINSIC MAX * .. * .. Executable Statements .. * * Test the input parameters. * INFO = 0 NORMALTRANSR = LSAME( TRANSR, 'N' ) LOWER = LSAME( UPLO, 'L' ) IF( .NOT.NORMALTRANSR .AND. .NOT.LSAME( TRANSR, 'T' ) ) THEN INFO = -1 ELSE IF( .NOT.LOWER .AND. .NOT.LSAME( UPLO, 'U' ) ) THEN INFO = -2 ELSE IF( N.LT.0 ) THEN INFO = -3 ELSE IF( NRHS.LT.0 ) THEN INFO = -4 ELSE IF( LDB.LT.MAX( 1, N ) ) THEN INFO = -7 END IF IF( INFO.NE.0 ) THEN CALL XERBLA( 'DPFTRS', -INFO ) RETURN END IF * * Quick return if possible * IF( N.EQ.0 .OR. NRHS.EQ.0 ) $ RETURN * * start execution: there are two triangular solves * IF( LOWER ) THEN CALL DTFSM( TRANSR, 'L', UPLO, 'N', 'N', N, NRHS, ONE, A, B, $ LDB ) CALL DTFSM( TRANSR, 'L', UPLO, 'T', 'N', N, NRHS, ONE, A, B, $ LDB ) ELSE CALL DTFSM( TRANSR, 'L', UPLO, 'T', 'N', N, NRHS, ONE, A, B, $ LDB ) CALL DTFSM( TRANSR, 'L', UPLO, 'N', 'N', N, NRHS, ONE, A, B, $ LDB ) END IF * RETURN * * End of DPFTRS * END
gpl-2.0
wilmarcardonac/hypermcmc
lapack-3.5.0/TESTING/EIG/cget38.f
32
15905
*> \brief \b CGET38 * * =========== DOCUMENTATION =========== * * Online html documentation available at * http://www.netlib.org/lapack/explore-html/ * * Definition: * =========== * * SUBROUTINE CGET38( RMAX, LMAX, NINFO, KNT, NIN ) * * .. Scalar Arguments .. * INTEGER KNT, NIN * .. * .. Array Arguments .. * INTEGER LMAX( 3 ), NINFO( 3 ) * REAL RMAX( 3 ) * .. * * *> \par Purpose: * ============= *> *> \verbatim *> *> CGET38 tests CTRSEN, a routine for estimating condition numbers of a *> cluster of eigenvalues and/or its associated right invariant subspace *> *> The test matrices are read from a file with logical unit number NIN. *> \endverbatim * * Arguments: * ========== * *> \param[out] RMAX *> \verbatim *> RMAX is REAL array, dimension (3) *> Values of the largest test ratios. *> RMAX(1) = largest residuals from CHST01 or comparing *> different calls to CTRSEN *> RMAX(2) = largest error in reciprocal condition *> numbers taking their conditioning into account *> RMAX(3) = largest error in reciprocal condition *> numbers not taking their conditioning into *> account (may be larger than RMAX(2)) *> \endverbatim *> *> \param[out] LMAX *> \verbatim *> LMAX is INTEGER array, dimension (3) *> LMAX(i) is example number where largest test ratio *> RMAX(i) is achieved. Also: *> If CGEHRD returns INFO nonzero on example i, LMAX(1)=i *> If CHSEQR returns INFO nonzero on example i, LMAX(2)=i *> If CTRSEN returns INFO nonzero on example i, LMAX(3)=i *> \endverbatim *> *> \param[out] NINFO *> \verbatim *> NINFO is INTEGER array, dimension (3) *> NINFO(1) = No. of times CGEHRD returned INFO nonzero *> NINFO(2) = No. of times CHSEQR returned INFO nonzero *> NINFO(3) = No. of times CTRSEN returned INFO nonzero *> \endverbatim *> *> \param[out] KNT *> \verbatim *> KNT is INTEGER *> Total number of examples tested. *> \endverbatim *> *> \param[in] NIN *> \verbatim *> NIN is INTEGER *> Input logical unit number. *> \endverbatim * * Authors: * ======== * *> \author Univ. of Tennessee *> \author Univ. of California Berkeley *> \author Univ. of Colorado Denver *> \author NAG Ltd. * *> \date November 2011 * *> \ingroup complex_eig * * ===================================================================== SUBROUTINE CGET38( RMAX, LMAX, NINFO, KNT, NIN ) * * -- LAPACK test routine (version 3.4.0) -- * -- LAPACK is a software package provided by Univ. of Tennessee, -- * -- Univ. of California Berkeley, Univ. of Colorado Denver and NAG Ltd..-- * November 2011 * * .. Scalar Arguments .. INTEGER KNT, NIN * .. * .. Array Arguments .. INTEGER LMAX( 3 ), NINFO( 3 ) REAL RMAX( 3 ) * .. * * ===================================================================== * * .. Parameters .. INTEGER LDT, LWORK PARAMETER ( LDT = 20, LWORK = 2*LDT*( 10+LDT ) ) REAL ZERO, ONE, TWO PARAMETER ( ZERO = 0.0E+0, ONE = 1.0E+0, TWO = 2.0E+0 ) REAL EPSIN PARAMETER ( EPSIN = 5.9605E-8 ) COMPLEX CZERO PARAMETER ( CZERO = ( 0.0E+0, 0.0E+0 ) ) * .. * .. Local Scalars .. INTEGER I, INFO, ISCL, ISRT, ITMP, J, KMIN, M, N, NDIM REAL BIGNUM, EPS, S, SEP, SEPIN, SEPTMP, SIN, $ SMLNUM, STMP, TNRM, TOL, TOLIN, V, VMAX, VMIN, $ VMUL * .. * .. Local Arrays .. LOGICAL SELECT( LDT ) INTEGER IPNT( LDT ), ISELEC( LDT ) REAL RESULT( 2 ), RWORK( LDT ), VAL( 3 ), $ WSRT( LDT ) COMPLEX Q( LDT, LDT ), QSAV( LDT, LDT ), $ QTMP( LDT, LDT ), T( LDT, LDT ), $ TMP( LDT, LDT ), TSAV( LDT, LDT ), $ TSAV1( LDT, LDT ), TTMP( LDT, LDT ), W( LDT ), $ WORK( LWORK ), WTMP( LDT ) * .. * .. External Functions .. REAL CLANGE, SLAMCH EXTERNAL CLANGE, SLAMCH * .. * .. External Subroutines .. EXTERNAL CGEHRD, CHSEQR, CHST01, CLACPY, CSSCAL, CTRSEN, $ CUNGHR, SLABAD * .. * .. Intrinsic Functions .. INTRINSIC AIMAG, MAX, REAL, SQRT * .. * .. Executable Statements .. * EPS = SLAMCH( 'P' ) SMLNUM = SLAMCH( 'S' ) / EPS BIGNUM = ONE / SMLNUM CALL SLABAD( SMLNUM, BIGNUM ) * * EPSIN = 2**(-24) = precision to which input data computed * EPS = MAX( EPS, EPSIN ) RMAX( 1 ) = ZERO RMAX( 2 ) = ZERO RMAX( 3 ) = ZERO LMAX( 1 ) = 0 LMAX( 2 ) = 0 LMAX( 3 ) = 0 KNT = 0 NINFO( 1 ) = 0 NINFO( 2 ) = 0 NINFO( 3 ) = 0 VAL( 1 ) = SQRT( SMLNUM ) VAL( 2 ) = ONE VAL( 3 ) = SQRT( SQRT( BIGNUM ) ) * * Read input data until N=0. Assume input eigenvalues are sorted * lexicographically (increasing by real part, then decreasing by * imaginary part) * 10 CONTINUE READ( NIN, FMT = * )N, NDIM, ISRT IF( N.EQ.0 ) $ RETURN READ( NIN, FMT = * )( ISELEC( I ), I = 1, NDIM ) DO 20 I = 1, N READ( NIN, FMT = * )( TMP( I, J ), J = 1, N ) 20 CONTINUE READ( NIN, FMT = * )SIN, SEPIN * TNRM = CLANGE( 'M', N, N, TMP, LDT, RWORK ) DO 200 ISCL = 1, 3 * * Scale input matrix * KNT = KNT + 1 CALL CLACPY( 'F', N, N, TMP, LDT, T, LDT ) VMUL = VAL( ISCL ) DO 30 I = 1, N CALL CSSCAL( N, VMUL, T( 1, I ), 1 ) 30 CONTINUE IF( TNRM.EQ.ZERO ) $ VMUL = ONE CALL CLACPY( 'F', N, N, T, LDT, TSAV, LDT ) * * Compute Schur form * CALL CGEHRD( N, 1, N, T, LDT, WORK( 1 ), WORK( N+1 ), LWORK-N, $ INFO ) IF( INFO.NE.0 ) THEN LMAX( 1 ) = KNT NINFO( 1 ) = NINFO( 1 ) + 1 GO TO 200 END IF * * Generate unitary matrix * CALL CLACPY( 'L', N, N, T, LDT, Q, LDT ) CALL CUNGHR( N, 1, N, Q, LDT, WORK( 1 ), WORK( N+1 ), LWORK-N, $ INFO ) * * Compute Schur form * DO 50 J = 1, N - 2 DO 40 I = J + 2, N T( I, J ) = CZERO 40 CONTINUE 50 CONTINUE CALL CHSEQR( 'S', 'V', N, 1, N, T, LDT, W, Q, LDT, WORK, LWORK, $ INFO ) IF( INFO.NE.0 ) THEN LMAX( 2 ) = KNT NINFO( 2 ) = NINFO( 2 ) + 1 GO TO 200 END IF * * Sort, select eigenvalues * DO 60 I = 1, N IPNT( I ) = I SELECT( I ) = .FALSE. 60 CONTINUE IF( ISRT.EQ.0 ) THEN DO 70 I = 1, N WSRT( I ) = REAL( W( I ) ) 70 CONTINUE ELSE DO 80 I = 1, N WSRT( I ) = AIMAG( W( I ) ) 80 CONTINUE END IF DO 100 I = 1, N - 1 KMIN = I VMIN = WSRT( I ) DO 90 J = I + 1, N IF( WSRT( J ).LT.VMIN ) THEN KMIN = J VMIN = WSRT( J ) END IF 90 CONTINUE WSRT( KMIN ) = WSRT( I ) WSRT( I ) = VMIN ITMP = IPNT( I ) IPNT( I ) = IPNT( KMIN ) IPNT( KMIN ) = ITMP 100 CONTINUE DO 110 I = 1, NDIM SELECT( IPNT( ISELEC( I ) ) ) = .TRUE. 110 CONTINUE * * Compute condition numbers * CALL CLACPY( 'F', N, N, Q, LDT, QSAV, LDT ) CALL CLACPY( 'F', N, N, T, LDT, TSAV1, LDT ) CALL CTRSEN( 'B', 'V', SELECT, N, T, LDT, Q, LDT, WTMP, M, S, $ SEP, WORK, LWORK, INFO ) IF( INFO.NE.0 ) THEN LMAX( 3 ) = KNT NINFO( 3 ) = NINFO( 3 ) + 1 GO TO 200 END IF SEPTMP = SEP / VMUL STMP = S * * Compute residuals * CALL CHST01( N, 1, N, TSAV, LDT, T, LDT, Q, LDT, WORK, LWORK, $ RWORK, RESULT ) VMAX = MAX( RESULT( 1 ), RESULT( 2 ) ) IF( VMAX.GT.RMAX( 1 ) ) THEN RMAX( 1 ) = VMAX IF( NINFO( 1 ).EQ.0 ) $ LMAX( 1 ) = KNT END IF * * Compare condition number for eigenvalue cluster * taking its condition number into account * V = MAX( TWO*REAL( N )*EPS*TNRM, SMLNUM ) IF( TNRM.EQ.ZERO ) $ V = ONE IF( V.GT.SEPTMP ) THEN TOL = ONE ELSE TOL = V / SEPTMP END IF IF( V.GT.SEPIN ) THEN TOLIN = ONE ELSE TOLIN = V / SEPIN END IF TOL = MAX( TOL, SMLNUM / EPS ) TOLIN = MAX( TOLIN, SMLNUM / EPS ) IF( EPS*( SIN-TOLIN ).GT.STMP+TOL ) THEN VMAX = ONE / EPS ELSE IF( SIN-TOLIN.GT.STMP+TOL ) THEN VMAX = ( SIN-TOLIN ) / ( STMP+TOL ) ELSE IF( SIN+TOLIN.LT.EPS*( STMP-TOL ) ) THEN VMAX = ONE / EPS ELSE IF( SIN+TOLIN.LT.STMP-TOL ) THEN VMAX = ( STMP-TOL ) / ( SIN+TOLIN ) ELSE VMAX = ONE END IF IF( VMAX.GT.RMAX( 2 ) ) THEN RMAX( 2 ) = VMAX IF( NINFO( 2 ).EQ.0 ) $ LMAX( 2 ) = KNT END IF * * Compare condition numbers for invariant subspace * taking its condition number into account * IF( V.GT.SEPTMP*STMP ) THEN TOL = SEPTMP ELSE TOL = V / STMP END IF IF( V.GT.SEPIN*SIN ) THEN TOLIN = SEPIN ELSE TOLIN = V / SIN END IF TOL = MAX( TOL, SMLNUM / EPS ) TOLIN = MAX( TOLIN, SMLNUM / EPS ) IF( EPS*( SEPIN-TOLIN ).GT.SEPTMP+TOL ) THEN VMAX = ONE / EPS ELSE IF( SEPIN-TOLIN.GT.SEPTMP+TOL ) THEN VMAX = ( SEPIN-TOLIN ) / ( SEPTMP+TOL ) ELSE IF( SEPIN+TOLIN.LT.EPS*( SEPTMP-TOL ) ) THEN VMAX = ONE / EPS ELSE IF( SEPIN+TOLIN.LT.SEPTMP-TOL ) THEN VMAX = ( SEPTMP-TOL ) / ( SEPIN+TOLIN ) ELSE VMAX = ONE END IF IF( VMAX.GT.RMAX( 2 ) ) THEN RMAX( 2 ) = VMAX IF( NINFO( 2 ).EQ.0 ) $ LMAX( 2 ) = KNT END IF * * Compare condition number for eigenvalue cluster * without taking its condition number into account * IF( SIN.LE.REAL( 2*N )*EPS .AND. STMP.LE.REAL( 2*N )*EPS ) THEN VMAX = ONE ELSE IF( EPS*SIN.GT.STMP ) THEN VMAX = ONE / EPS ELSE IF( SIN.GT.STMP ) THEN VMAX = SIN / STMP ELSE IF( SIN.LT.EPS*STMP ) THEN VMAX = ONE / EPS ELSE IF( SIN.LT.STMP ) THEN VMAX = STMP / SIN ELSE VMAX = ONE END IF IF( VMAX.GT.RMAX( 3 ) ) THEN RMAX( 3 ) = VMAX IF( NINFO( 3 ).EQ.0 ) $ LMAX( 3 ) = KNT END IF * * Compare condition numbers for invariant subspace * without taking its condition number into account * IF( SEPIN.LE.V .AND. SEPTMP.LE.V ) THEN VMAX = ONE ELSE IF( EPS*SEPIN.GT.SEPTMP ) THEN VMAX = ONE / EPS ELSE IF( SEPIN.GT.SEPTMP ) THEN VMAX = SEPIN / SEPTMP ELSE IF( SEPIN.LT.EPS*SEPTMP ) THEN VMAX = ONE / EPS ELSE IF( SEPIN.LT.SEPTMP ) THEN VMAX = SEPTMP / SEPIN ELSE VMAX = ONE END IF IF( VMAX.GT.RMAX( 3 ) ) THEN RMAX( 3 ) = VMAX IF( NINFO( 3 ).EQ.0 ) $ LMAX( 3 ) = KNT END IF * * Compute eigenvalue condition number only and compare * Update Q * VMAX = ZERO CALL CLACPY( 'F', N, N, TSAV1, LDT, TTMP, LDT ) CALL CLACPY( 'F', N, N, QSAV, LDT, QTMP, LDT ) SEPTMP = -ONE STMP = -ONE CALL CTRSEN( 'E', 'V', SELECT, N, TTMP, LDT, QTMP, LDT, WTMP, $ M, STMP, SEPTMP, WORK, LWORK, INFO ) IF( INFO.NE.0 ) THEN LMAX( 3 ) = KNT NINFO( 3 ) = NINFO( 3 ) + 1 GO TO 200 END IF IF( S.NE.STMP ) $ VMAX = ONE / EPS IF( -ONE.NE.SEPTMP ) $ VMAX = ONE / EPS DO 130 I = 1, N DO 120 J = 1, N IF( TTMP( I, J ).NE.T( I, J ) ) $ VMAX = ONE / EPS IF( QTMP( I, J ).NE.Q( I, J ) ) $ VMAX = ONE / EPS 120 CONTINUE 130 CONTINUE * * Compute invariant subspace condition number only and compare * Update Q * CALL CLACPY( 'F', N, N, TSAV1, LDT, TTMP, LDT ) CALL CLACPY( 'F', N, N, QSAV, LDT, QTMP, LDT ) SEPTMP = -ONE STMP = -ONE CALL CTRSEN( 'V', 'V', SELECT, N, TTMP, LDT, QTMP, LDT, WTMP, $ M, STMP, SEPTMP, WORK, LWORK, INFO ) IF( INFO.NE.0 ) THEN LMAX( 3 ) = KNT NINFO( 3 ) = NINFO( 3 ) + 1 GO TO 200 END IF IF( -ONE.NE.STMP ) $ VMAX = ONE / EPS IF( SEP.NE.SEPTMP ) $ VMAX = ONE / EPS DO 150 I = 1, N DO 140 J = 1, N IF( TTMP( I, J ).NE.T( I, J ) ) $ VMAX = ONE / EPS IF( QTMP( I, J ).NE.Q( I, J ) ) $ VMAX = ONE / EPS 140 CONTINUE 150 CONTINUE * * Compute eigenvalue condition number only and compare * Do not update Q * CALL CLACPY( 'F', N, N, TSAV1, LDT, TTMP, LDT ) CALL CLACPY( 'F', N, N, QSAV, LDT, QTMP, LDT ) SEPTMP = -ONE STMP = -ONE CALL CTRSEN( 'E', 'N', SELECT, N, TTMP, LDT, QTMP, LDT, WTMP, $ M, STMP, SEPTMP, WORK, LWORK, INFO ) IF( INFO.NE.0 ) THEN LMAX( 3 ) = KNT NINFO( 3 ) = NINFO( 3 ) + 1 GO TO 200 END IF IF( S.NE.STMP ) $ VMAX = ONE / EPS IF( -ONE.NE.SEPTMP ) $ VMAX = ONE / EPS DO 170 I = 1, N DO 160 J = 1, N IF( TTMP( I, J ).NE.T( I, J ) ) $ VMAX = ONE / EPS IF( QTMP( I, J ).NE.QSAV( I, J ) ) $ VMAX = ONE / EPS 160 CONTINUE 170 CONTINUE * * Compute invariant subspace condition number only and compare * Do not update Q * CALL CLACPY( 'F', N, N, TSAV1, LDT, TTMP, LDT ) CALL CLACPY( 'F', N, N, QSAV, LDT, QTMP, LDT ) SEPTMP = -ONE STMP = -ONE CALL CTRSEN( 'V', 'N', SELECT, N, TTMP, LDT, QTMP, LDT, WTMP, $ M, STMP, SEPTMP, WORK, LWORK, INFO ) IF( INFO.NE.0 ) THEN LMAX( 3 ) = KNT NINFO( 3 ) = NINFO( 3 ) + 1 GO TO 200 END IF IF( -ONE.NE.STMP ) $ VMAX = ONE / EPS IF( SEP.NE.SEPTMP ) $ VMAX = ONE / EPS DO 190 I = 1, N DO 180 J = 1, N IF( TTMP( I, J ).NE.T( I, J ) ) $ VMAX = ONE / EPS IF( QTMP( I, J ).NE.QSAV( I, J ) ) $ VMAX = ONE / EPS 180 CONTINUE 190 CONTINUE IF( VMAX.GT.RMAX( 1 ) ) THEN RMAX( 1 ) = VMAX IF( NINFO( 1 ).EQ.0 ) $ LMAX( 1 ) = KNT END IF 200 CONTINUE GO TO 10 * * End of CGET38 * END
gpl-2.0
linzhaoming/origin
vendor/github.com/gonum/lapack/internal/testdata/dlasqtest/ilaenv.f
129
18298
*> \brief \b ILAENV * * =========== DOCUMENTATION =========== * * Online html documentation available at * http://www.netlib.org/lapack/explore-html/ * *> \htmlonly *> Download ILAENV + dependencies *> <a href="http://www.netlib.org/cgi-bin/netlibfiles.tgz?format=tgz&filename=/lapack/lapack_routine/ilaenv.f"> *> [TGZ]</a> *> <a href="http://www.netlib.org/cgi-bin/netlibfiles.zip?format=zip&filename=/lapack/lapack_routine/ilaenv.f"> *> [ZIP]</a> *> <a href="http://www.netlib.org/cgi-bin/netlibfiles.txt?format=txt&filename=/lapack/lapack_routine/ilaenv.f"> *> [TXT]</a> *> \endhtmlonly * * Definition: * =========== * * INTEGER FUNCTION ILAENV( ISPEC, NAME, OPTS, N1, N2, N3, N4 ) * * .. Scalar Arguments .. * CHARACTER*( * ) NAME, OPTS * INTEGER ISPEC, N1, N2, N3, N4 * .. * * *> \par Purpose: * ============= *> *> \verbatim *> *> ILAENV is called from the LAPACK routines to choose problem-dependent *> parameters for the local environment. See ISPEC for a description of *> the parameters. *> *> ILAENV returns an INTEGER *> if ILAENV >= 0: ILAENV returns the value of the parameter specified by ISPEC *> if ILAENV < 0: if ILAENV = -k, the k-th argument had an illegal value. *> *> This version provides a set of parameters which should give good, *> but not optimal, performance on many of the currently available *> computers. Users are encouraged to modify this subroutine to set *> the tuning parameters for their particular machine using the option *> and problem size information in the arguments. *> *> This routine will not function correctly if it is converted to all *> lower case. Converting it to all upper case is allowed. *> \endverbatim * * Arguments: * ========== * *> \param[in] ISPEC *> \verbatim *> ISPEC is INTEGER *> Specifies the parameter to be returned as the value of *> ILAENV. *> = 1: the optimal blocksize; if this value is 1, an unblocked *> algorithm will give the best performance. *> = 2: the minimum block size for which the block routine *> should be used; if the usable block size is less than *> this value, an unblocked routine should be used. *> = 3: the crossover point (in a block routine, for N less *> than this value, an unblocked routine should be used) *> = 4: the number of shifts, used in the nonsymmetric *> eigenvalue routines (DEPRECATED) *> = 5: the minimum column dimension for blocking to be used; *> rectangular blocks must have dimension at least k by m, *> where k is given by ILAENV(2,...) and m by ILAENV(5,...) *> = 6: the crossover point for the SVD (when reducing an m by n *> matrix to bidiagonal form, if max(m,n)/min(m,n) exceeds *> this value, a QR factorization is used first to reduce *> the matrix to a triangular form.) *> = 7: the number of processors *> = 8: the crossover point for the multishift QR method *> for nonsymmetric eigenvalue problems (DEPRECATED) *> = 9: maximum size of the subproblems at the bottom of the *> computation tree in the divide-and-conquer algorithm *> (used by xGELSD and xGESDD) *> =10: ieee NaN arithmetic can be trusted not to trap *> =11: infinity arithmetic can be trusted not to trap *> 12 <= ISPEC <= 16: *> xHSEQR or one of its subroutines, *> see IPARMQ for detailed explanation *> \endverbatim *> *> \param[in] NAME *> \verbatim *> NAME is CHARACTER*(*) *> The name of the calling subroutine, in either upper case or *> lower case. *> \endverbatim *> *> \param[in] OPTS *> \verbatim *> OPTS is CHARACTER*(*) *> The character options to the subroutine NAME, concatenated *> into a single character string. For example, UPLO = 'U', *> TRANS = 'T', and DIAG = 'N' for a triangular routine would *> be specified as OPTS = 'UTN'. *> \endverbatim *> *> \param[in] N1 *> \verbatim *> N1 is INTEGER *> \endverbatim *> *> \param[in] N2 *> \verbatim *> N2 is INTEGER *> \endverbatim *> *> \param[in] N3 *> \verbatim *> N3 is INTEGER *> \endverbatim *> *> \param[in] N4 *> \verbatim *> N4 is INTEGER *> Problem dimensions for the subroutine NAME; these may not all *> be required. *> \endverbatim * * Authors: * ======== * *> \author Univ. of Tennessee *> \author Univ. of California Berkeley *> \author Univ. of Colorado Denver *> \author NAG Ltd. * *> \date November 2011 * *> \ingroup auxOTHERauxiliary * *> \par Further Details: * ===================== *> *> \verbatim *> *> The following conventions have been used when calling ILAENV from the *> LAPACK routines: *> 1) OPTS is a concatenation of all of the character options to *> subroutine NAME, in the same order that they appear in the *> argument list for NAME, even if they are not used in determining *> the value of the parameter specified by ISPEC. *> 2) The problem dimensions N1, N2, N3, N4 are specified in the order *> that they appear in the argument list for NAME. N1 is used *> first, N2 second, and so on, and unused problem dimensions are *> passed a value of -1. *> 3) The parameter value returned by ILAENV is checked for validity in *> the calling subroutine. For example, ILAENV is used to retrieve *> the optimal blocksize for STRTRI as follows: *> *> NB = ILAENV( 1, 'STRTRI', UPLO // DIAG, N, -1, -1, -1 ) *> IF( NB.LE.1 ) NB = MAX( 1, N ) *> \endverbatim *> * ===================================================================== INTEGER FUNCTION ILAENV( ISPEC, NAME, OPTS, N1, N2, N3, N4 ) * * -- LAPACK auxiliary routine (version 3.4.0) -- * -- LAPACK is a software package provided by Univ. of Tennessee, -- * -- Univ. of California Berkeley, Univ. of Colorado Denver and NAG Ltd..-- * November 2011 * * .. Scalar Arguments .. CHARACTER*( * ) NAME, OPTS INTEGER ISPEC, N1, N2, N3, N4 * .. * * ===================================================================== * * .. Local Scalars .. INTEGER I, IC, IZ, NB, NBMIN, NX LOGICAL CNAME, SNAME CHARACTER C1*1, C2*2, C4*2, C3*3, SUBNAM*6 * .. * .. Intrinsic Functions .. INTRINSIC CHAR, ICHAR, INT, MIN, REAL * .. * .. External Functions .. INTEGER IEEECK, IPARMQ EXTERNAL IEEECK, IPARMQ * .. * .. Executable Statements .. * GO TO ( 10, 10, 10, 80, 90, 100, 110, 120, $ 130, 140, 150, 160, 160, 160, 160, 160 )ISPEC * * Invalid value for ISPEC * ILAENV = -1 RETURN * 10 CONTINUE * * Convert NAME to upper case if the first character is lower case. * ILAENV = 1 SUBNAM = NAME IC = ICHAR( SUBNAM( 1: 1 ) ) IZ = ICHAR( 'Z' ) IF( IZ.EQ.90 .OR. IZ.EQ.122 ) THEN * * ASCII character set * IF( IC.GE.97 .AND. IC.LE.122 ) THEN SUBNAM( 1: 1 ) = CHAR( IC-32 ) DO 20 I = 2, 6 IC = ICHAR( SUBNAM( I: I ) ) IF( IC.GE.97 .AND. IC.LE.122 ) $ SUBNAM( I: I ) = CHAR( IC-32 ) 20 CONTINUE END IF * ELSE IF( IZ.EQ.233 .OR. IZ.EQ.169 ) THEN * * EBCDIC character set * IF( ( IC.GE.129 .AND. IC.LE.137 ) .OR. $ ( IC.GE.145 .AND. IC.LE.153 ) .OR. $ ( IC.GE.162 .AND. IC.LE.169 ) ) THEN SUBNAM( 1: 1 ) = CHAR( IC+64 ) DO 30 I = 2, 6 IC = ICHAR( SUBNAM( I: I ) ) IF( ( IC.GE.129 .AND. IC.LE.137 ) .OR. $ ( IC.GE.145 .AND. IC.LE.153 ) .OR. $ ( IC.GE.162 .AND. IC.LE.169 ) )SUBNAM( I: $ I ) = CHAR( IC+64 ) 30 CONTINUE END IF * ELSE IF( IZ.EQ.218 .OR. IZ.EQ.250 ) THEN * * Prime machines: ASCII+128 * IF( IC.GE.225 .AND. IC.LE.250 ) THEN SUBNAM( 1: 1 ) = CHAR( IC-32 ) DO 40 I = 2, 6 IC = ICHAR( SUBNAM( I: I ) ) IF( IC.GE.225 .AND. IC.LE.250 ) $ SUBNAM( I: I ) = CHAR( IC-32 ) 40 CONTINUE END IF END IF * C1 = SUBNAM( 1: 1 ) SNAME = C1.EQ.'S' .OR. C1.EQ.'D' CNAME = C1.EQ.'C' .OR. C1.EQ.'Z' IF( .NOT.( CNAME .OR. SNAME ) ) $ RETURN C2 = SUBNAM( 2: 3 ) C3 = SUBNAM( 4: 6 ) C4 = C3( 2: 3 ) * GO TO ( 50, 60, 70 )ISPEC * 50 CONTINUE * * ISPEC = 1: block size * * In these examples, separate code is provided for setting NB for * real and complex. We assume that NB will take the same value in * single or double precision. * NB = 1 * IF( C2.EQ.'GE' ) THEN IF( C3.EQ.'TRF' ) THEN IF( SNAME ) THEN NB = 64 ELSE NB = 64 END IF ELSE IF( C3.EQ.'QRF' .OR. C3.EQ.'RQF' .OR. C3.EQ.'LQF' .OR. $ C3.EQ.'QLF' ) THEN IF( SNAME ) THEN NB = 32 ELSE NB = 32 END IF ELSE IF( C3.EQ.'HRD' ) THEN IF( SNAME ) THEN NB = 32 ELSE NB = 32 END IF ELSE IF( C3.EQ.'BRD' ) THEN IF( SNAME ) THEN NB = 32 ELSE NB = 32 END IF ELSE IF( C3.EQ.'TRI' ) THEN IF( SNAME ) THEN NB = 64 ELSE NB = 64 END IF END IF ELSE IF( C2.EQ.'PO' ) THEN IF( C3.EQ.'TRF' ) THEN IF( SNAME ) THEN NB = 64 ELSE NB = 64 END IF END IF ELSE IF( C2.EQ.'SY' ) THEN IF( C3.EQ.'TRF' ) THEN IF( SNAME ) THEN NB = 64 ELSE NB = 64 END IF ELSE IF( SNAME .AND. C3.EQ.'TRD' ) THEN NB = 32 ELSE IF( SNAME .AND. C3.EQ.'GST' ) THEN NB = 64 END IF ELSE IF( CNAME .AND. C2.EQ.'HE' ) THEN IF( C3.EQ.'TRF' ) THEN NB = 64 ELSE IF( C3.EQ.'TRD' ) THEN NB = 32 ELSE IF( C3.EQ.'GST' ) THEN NB = 64 END IF ELSE IF( SNAME .AND. C2.EQ.'OR' ) THEN IF( C3( 1: 1 ).EQ.'G' ) THEN IF( C4.EQ.'QR' .OR. C4.EQ.'RQ' .OR. C4.EQ.'LQ' .OR. C4.EQ. $ 'QL' .OR. C4.EQ.'HR' .OR. C4.EQ.'TR' .OR. C4.EQ.'BR' ) $ THEN NB = 32 END IF ELSE IF( C3( 1: 1 ).EQ.'M' ) THEN IF( C4.EQ.'QR' .OR. C4.EQ.'RQ' .OR. C4.EQ.'LQ' .OR. C4.EQ. $ 'QL' .OR. C4.EQ.'HR' .OR. C4.EQ.'TR' .OR. C4.EQ.'BR' ) $ THEN NB = 32 END IF END IF ELSE IF( CNAME .AND. C2.EQ.'UN' ) THEN IF( C3( 1: 1 ).EQ.'G' ) THEN IF( C4.EQ.'QR' .OR. C4.EQ.'RQ' .OR. C4.EQ.'LQ' .OR. C4.EQ. $ 'QL' .OR. C4.EQ.'HR' .OR. C4.EQ.'TR' .OR. C4.EQ.'BR' ) $ THEN NB = 32 END IF ELSE IF( C3( 1: 1 ).EQ.'M' ) THEN IF( C4.EQ.'QR' .OR. C4.EQ.'RQ' .OR. C4.EQ.'LQ' .OR. C4.EQ. $ 'QL' .OR. C4.EQ.'HR' .OR. C4.EQ.'TR' .OR. C4.EQ.'BR' ) $ THEN NB = 32 END IF END IF ELSE IF( C2.EQ.'GB' ) THEN IF( C3.EQ.'TRF' ) THEN IF( SNAME ) THEN IF( N4.LE.64 ) THEN NB = 1 ELSE NB = 32 END IF ELSE IF( N4.LE.64 ) THEN NB = 1 ELSE NB = 32 END IF END IF END IF ELSE IF( C2.EQ.'PB' ) THEN IF( C3.EQ.'TRF' ) THEN IF( SNAME ) THEN IF( N2.LE.64 ) THEN NB = 1 ELSE NB = 32 END IF ELSE IF( N2.LE.64 ) THEN NB = 1 ELSE NB = 32 END IF END IF END IF ELSE IF( C2.EQ.'TR' ) THEN IF( C3.EQ.'TRI' ) THEN IF( SNAME ) THEN NB = 64 ELSE NB = 64 END IF END IF ELSE IF( C2.EQ.'LA' ) THEN IF( C3.EQ.'UUM' ) THEN IF( SNAME ) THEN NB = 64 ELSE NB = 64 END IF END IF ELSE IF( SNAME .AND. C2.EQ.'ST' ) THEN IF( C3.EQ.'EBZ' ) THEN NB = 1 END IF END IF ILAENV = NB RETURN * 60 CONTINUE * * ISPEC = 2: minimum block size * NBMIN = 2 IF( C2.EQ.'GE' ) THEN IF( C3.EQ.'QRF' .OR. C3.EQ.'RQF' .OR. C3.EQ.'LQF' .OR. C3.EQ. $ 'QLF' ) THEN IF( SNAME ) THEN NBMIN = 2 ELSE NBMIN = 2 END IF ELSE IF( C3.EQ.'HRD' ) THEN IF( SNAME ) THEN NBMIN = 2 ELSE NBMIN = 2 END IF ELSE IF( C3.EQ.'BRD' ) THEN IF( SNAME ) THEN NBMIN = 2 ELSE NBMIN = 2 END IF ELSE IF( C3.EQ.'TRI' ) THEN IF( SNAME ) THEN NBMIN = 2 ELSE NBMIN = 2 END IF END IF ELSE IF( C2.EQ.'SY' ) THEN IF( C3.EQ.'TRF' ) THEN IF( SNAME ) THEN NBMIN = 8 ELSE NBMIN = 8 END IF ELSE IF( SNAME .AND. C3.EQ.'TRD' ) THEN NBMIN = 2 END IF ELSE IF( CNAME .AND. C2.EQ.'HE' ) THEN IF( C3.EQ.'TRD' ) THEN NBMIN = 2 END IF ELSE IF( SNAME .AND. C2.EQ.'OR' ) THEN IF( C3( 1: 1 ).EQ.'G' ) THEN IF( C4.EQ.'QR' .OR. C4.EQ.'RQ' .OR. C4.EQ.'LQ' .OR. C4.EQ. $ 'QL' .OR. C4.EQ.'HR' .OR. C4.EQ.'TR' .OR. C4.EQ.'BR' ) $ THEN NBMIN = 2 END IF ELSE IF( C3( 1: 1 ).EQ.'M' ) THEN IF( C4.EQ.'QR' .OR. C4.EQ.'RQ' .OR. C4.EQ.'LQ' .OR. C4.EQ. $ 'QL' .OR. C4.EQ.'HR' .OR. C4.EQ.'TR' .OR. C4.EQ.'BR' ) $ THEN NBMIN = 2 END IF END IF ELSE IF( CNAME .AND. C2.EQ.'UN' ) THEN IF( C3( 1: 1 ).EQ.'G' ) THEN IF( C4.EQ.'QR' .OR. C4.EQ.'RQ' .OR. C4.EQ.'LQ' .OR. C4.EQ. $ 'QL' .OR. C4.EQ.'HR' .OR. C4.EQ.'TR' .OR. C4.EQ.'BR' ) $ THEN NBMIN = 2 END IF ELSE IF( C3( 1: 1 ).EQ.'M' ) THEN IF( C4.EQ.'QR' .OR. C4.EQ.'RQ' .OR. C4.EQ.'LQ' .OR. C4.EQ. $ 'QL' .OR. C4.EQ.'HR' .OR. C4.EQ.'TR' .OR. C4.EQ.'BR' ) $ THEN NBMIN = 2 END IF END IF END IF ILAENV = NBMIN RETURN * 70 CONTINUE * * ISPEC = 3: crossover point * NX = 0 IF( C2.EQ.'GE' ) THEN IF( C3.EQ.'QRF' .OR. C3.EQ.'RQF' .OR. C3.EQ.'LQF' .OR. C3.EQ. $ 'QLF' ) THEN IF( SNAME ) THEN NX = 128 ELSE NX = 128 END IF ELSE IF( C3.EQ.'HRD' ) THEN IF( SNAME ) THEN NX = 128 ELSE NX = 128 END IF ELSE IF( C3.EQ.'BRD' ) THEN IF( SNAME ) THEN NX = 128 ELSE NX = 128 END IF END IF ELSE IF( C2.EQ.'SY' ) THEN IF( SNAME .AND. C3.EQ.'TRD' ) THEN NX = 32 END IF ELSE IF( CNAME .AND. C2.EQ.'HE' ) THEN IF( C3.EQ.'TRD' ) THEN NX = 32 END IF ELSE IF( SNAME .AND. C2.EQ.'OR' ) THEN IF( C3( 1: 1 ).EQ.'G' ) THEN IF( C4.EQ.'QR' .OR. C4.EQ.'RQ' .OR. C4.EQ.'LQ' .OR. C4.EQ. $ 'QL' .OR. C4.EQ.'HR' .OR. C4.EQ.'TR' .OR. C4.EQ.'BR' ) $ THEN NX = 128 END IF END IF ELSE IF( CNAME .AND. C2.EQ.'UN' ) THEN IF( C3( 1: 1 ).EQ.'G' ) THEN IF( C4.EQ.'QR' .OR. C4.EQ.'RQ' .OR. C4.EQ.'LQ' .OR. C4.EQ. $ 'QL' .OR. C4.EQ.'HR' .OR. C4.EQ.'TR' .OR. C4.EQ.'BR' ) $ THEN NX = 128 END IF END IF END IF ILAENV = NX RETURN * 80 CONTINUE * * ISPEC = 4: number of shifts (used by xHSEQR) * ILAENV = 6 RETURN * 90 CONTINUE * * ISPEC = 5: minimum column dimension (not used) * ILAENV = 2 RETURN * 100 CONTINUE * * ISPEC = 6: crossover point for SVD (used by xGELSS and xGESVD) * ILAENV = INT( REAL( MIN( N1, N2 ) )*1.6E0 ) RETURN * 110 CONTINUE * * ISPEC = 7: number of processors (not used) * ILAENV = 1 RETURN * 120 CONTINUE * * ISPEC = 8: crossover point for multishift (used by xHSEQR) * ILAENV = 50 RETURN * 130 CONTINUE * * ISPEC = 9: maximum size of the subproblems at the bottom of the * computation tree in the divide-and-conquer algorithm * (used by xGELSD and xGESDD) * ILAENV = 25 RETURN * 140 CONTINUE * * ISPEC = 10: ieee NaN arithmetic can be trusted not to trap * * ILAENV = 0 ILAENV = 1 IF( ILAENV.EQ.1 ) THEN ILAENV = IEEECK( 1, 0.0, 1.0 ) END IF RETURN * 150 CONTINUE * * ISPEC = 11: infinity arithmetic can be trusted not to trap * * ILAENV = 0 ILAENV = 1 IF( ILAENV.EQ.1 ) THEN ILAENV = IEEECK( 0, 0.0, 1.0 ) END IF RETURN * 160 CONTINUE * * 12 <= ISPEC <= 16: xHSEQR or one of its subroutines. * ILAENV = IPARMQ( ISPEC, NAME, OPTS, N1, N2, N3, N4 ) RETURN * * End of ILAENV * END
apache-2.0
pts-eduardoacuna/pachy-learning
vendor/gonum.org/v1/gonum/lapack/internal/testdata/dlasqtest/ilaenv.f
129
18298
*> \brief \b ILAENV * * =========== DOCUMENTATION =========== * * Online html documentation available at * http://www.netlib.org/lapack/explore-html/ * *> \htmlonly *> Download ILAENV + dependencies *> <a href="http://www.netlib.org/cgi-bin/netlibfiles.tgz?format=tgz&filename=/lapack/lapack_routine/ilaenv.f"> *> [TGZ]</a> *> <a href="http://www.netlib.org/cgi-bin/netlibfiles.zip?format=zip&filename=/lapack/lapack_routine/ilaenv.f"> *> [ZIP]</a> *> <a href="http://www.netlib.org/cgi-bin/netlibfiles.txt?format=txt&filename=/lapack/lapack_routine/ilaenv.f"> *> [TXT]</a> *> \endhtmlonly * * Definition: * =========== * * INTEGER FUNCTION ILAENV( ISPEC, NAME, OPTS, N1, N2, N3, N4 ) * * .. Scalar Arguments .. * CHARACTER*( * ) NAME, OPTS * INTEGER ISPEC, N1, N2, N3, N4 * .. * * *> \par Purpose: * ============= *> *> \verbatim *> *> ILAENV is called from the LAPACK routines to choose problem-dependent *> parameters for the local environment. See ISPEC for a description of *> the parameters. *> *> ILAENV returns an INTEGER *> if ILAENV >= 0: ILAENV returns the value of the parameter specified by ISPEC *> if ILAENV < 0: if ILAENV = -k, the k-th argument had an illegal value. *> *> This version provides a set of parameters which should give good, *> but not optimal, performance on many of the currently available *> computers. Users are encouraged to modify this subroutine to set *> the tuning parameters for their particular machine using the option *> and problem size information in the arguments. *> *> This routine will not function correctly if it is converted to all *> lower case. Converting it to all upper case is allowed. *> \endverbatim * * Arguments: * ========== * *> \param[in] ISPEC *> \verbatim *> ISPEC is INTEGER *> Specifies the parameter to be returned as the value of *> ILAENV. *> = 1: the optimal blocksize; if this value is 1, an unblocked *> algorithm will give the best performance. *> = 2: the minimum block size for which the block routine *> should be used; if the usable block size is less than *> this value, an unblocked routine should be used. *> = 3: the crossover point (in a block routine, for N less *> than this value, an unblocked routine should be used) *> = 4: the number of shifts, used in the nonsymmetric *> eigenvalue routines (DEPRECATED) *> = 5: the minimum column dimension for blocking to be used; *> rectangular blocks must have dimension at least k by m, *> where k is given by ILAENV(2,...) and m by ILAENV(5,...) *> = 6: the crossover point for the SVD (when reducing an m by n *> matrix to bidiagonal form, if max(m,n)/min(m,n) exceeds *> this value, a QR factorization is used first to reduce *> the matrix to a triangular form.) *> = 7: the number of processors *> = 8: the crossover point for the multishift QR method *> for nonsymmetric eigenvalue problems (DEPRECATED) *> = 9: maximum size of the subproblems at the bottom of the *> computation tree in the divide-and-conquer algorithm *> (used by xGELSD and xGESDD) *> =10: ieee NaN arithmetic can be trusted not to trap *> =11: infinity arithmetic can be trusted not to trap *> 12 <= ISPEC <= 16: *> xHSEQR or one of its subroutines, *> see IPARMQ for detailed explanation *> \endverbatim *> *> \param[in] NAME *> \verbatim *> NAME is CHARACTER*(*) *> The name of the calling subroutine, in either upper case or *> lower case. *> \endverbatim *> *> \param[in] OPTS *> \verbatim *> OPTS is CHARACTER*(*) *> The character options to the subroutine NAME, concatenated *> into a single character string. For example, UPLO = 'U', *> TRANS = 'T', and DIAG = 'N' for a triangular routine would *> be specified as OPTS = 'UTN'. *> \endverbatim *> *> \param[in] N1 *> \verbatim *> N1 is INTEGER *> \endverbatim *> *> \param[in] N2 *> \verbatim *> N2 is INTEGER *> \endverbatim *> *> \param[in] N3 *> \verbatim *> N3 is INTEGER *> \endverbatim *> *> \param[in] N4 *> \verbatim *> N4 is INTEGER *> Problem dimensions for the subroutine NAME; these may not all *> be required. *> \endverbatim * * Authors: * ======== * *> \author Univ. of Tennessee *> \author Univ. of California Berkeley *> \author Univ. of Colorado Denver *> \author NAG Ltd. * *> \date November 2011 * *> \ingroup auxOTHERauxiliary * *> \par Further Details: * ===================== *> *> \verbatim *> *> The following conventions have been used when calling ILAENV from the *> LAPACK routines: *> 1) OPTS is a concatenation of all of the character options to *> subroutine NAME, in the same order that they appear in the *> argument list for NAME, even if they are not used in determining *> the value of the parameter specified by ISPEC. *> 2) The problem dimensions N1, N2, N3, N4 are specified in the order *> that they appear in the argument list for NAME. N1 is used *> first, N2 second, and so on, and unused problem dimensions are *> passed a value of -1. *> 3) The parameter value returned by ILAENV is checked for validity in *> the calling subroutine. For example, ILAENV is used to retrieve *> the optimal blocksize for STRTRI as follows: *> *> NB = ILAENV( 1, 'STRTRI', UPLO // DIAG, N, -1, -1, -1 ) *> IF( NB.LE.1 ) NB = MAX( 1, N ) *> \endverbatim *> * ===================================================================== INTEGER FUNCTION ILAENV( ISPEC, NAME, OPTS, N1, N2, N3, N4 ) * * -- LAPACK auxiliary routine (version 3.4.0) -- * -- LAPACK is a software package provided by Univ. of Tennessee, -- * -- Univ. of California Berkeley, Univ. of Colorado Denver and NAG Ltd..-- * November 2011 * * .. Scalar Arguments .. CHARACTER*( * ) NAME, OPTS INTEGER ISPEC, N1, N2, N3, N4 * .. * * ===================================================================== * * .. Local Scalars .. INTEGER I, IC, IZ, NB, NBMIN, NX LOGICAL CNAME, SNAME CHARACTER C1*1, C2*2, C4*2, C3*3, SUBNAM*6 * .. * .. Intrinsic Functions .. INTRINSIC CHAR, ICHAR, INT, MIN, REAL * .. * .. External Functions .. INTEGER IEEECK, IPARMQ EXTERNAL IEEECK, IPARMQ * .. * .. Executable Statements .. * GO TO ( 10, 10, 10, 80, 90, 100, 110, 120, $ 130, 140, 150, 160, 160, 160, 160, 160 )ISPEC * * Invalid value for ISPEC * ILAENV = -1 RETURN * 10 CONTINUE * * Convert NAME to upper case if the first character is lower case. * ILAENV = 1 SUBNAM = NAME IC = ICHAR( SUBNAM( 1: 1 ) ) IZ = ICHAR( 'Z' ) IF( IZ.EQ.90 .OR. IZ.EQ.122 ) THEN * * ASCII character set * IF( IC.GE.97 .AND. IC.LE.122 ) THEN SUBNAM( 1: 1 ) = CHAR( IC-32 ) DO 20 I = 2, 6 IC = ICHAR( SUBNAM( I: I ) ) IF( IC.GE.97 .AND. IC.LE.122 ) $ SUBNAM( I: I ) = CHAR( IC-32 ) 20 CONTINUE END IF * ELSE IF( IZ.EQ.233 .OR. IZ.EQ.169 ) THEN * * EBCDIC character set * IF( ( IC.GE.129 .AND. IC.LE.137 ) .OR. $ ( IC.GE.145 .AND. IC.LE.153 ) .OR. $ ( IC.GE.162 .AND. IC.LE.169 ) ) THEN SUBNAM( 1: 1 ) = CHAR( IC+64 ) DO 30 I = 2, 6 IC = ICHAR( SUBNAM( I: I ) ) IF( ( IC.GE.129 .AND. IC.LE.137 ) .OR. $ ( IC.GE.145 .AND. IC.LE.153 ) .OR. $ ( IC.GE.162 .AND. IC.LE.169 ) )SUBNAM( I: $ I ) = CHAR( IC+64 ) 30 CONTINUE END IF * ELSE IF( IZ.EQ.218 .OR. IZ.EQ.250 ) THEN * * Prime machines: ASCII+128 * IF( IC.GE.225 .AND. IC.LE.250 ) THEN SUBNAM( 1: 1 ) = CHAR( IC-32 ) DO 40 I = 2, 6 IC = ICHAR( SUBNAM( I: I ) ) IF( IC.GE.225 .AND. IC.LE.250 ) $ SUBNAM( I: I ) = CHAR( IC-32 ) 40 CONTINUE END IF END IF * C1 = SUBNAM( 1: 1 ) SNAME = C1.EQ.'S' .OR. C1.EQ.'D' CNAME = C1.EQ.'C' .OR. C1.EQ.'Z' IF( .NOT.( CNAME .OR. SNAME ) ) $ RETURN C2 = SUBNAM( 2: 3 ) C3 = SUBNAM( 4: 6 ) C4 = C3( 2: 3 ) * GO TO ( 50, 60, 70 )ISPEC * 50 CONTINUE * * ISPEC = 1: block size * * In these examples, separate code is provided for setting NB for * real and complex. We assume that NB will take the same value in * single or double precision. * NB = 1 * IF( C2.EQ.'GE' ) THEN IF( C3.EQ.'TRF' ) THEN IF( SNAME ) THEN NB = 64 ELSE NB = 64 END IF ELSE IF( C3.EQ.'QRF' .OR. C3.EQ.'RQF' .OR. C3.EQ.'LQF' .OR. $ C3.EQ.'QLF' ) THEN IF( SNAME ) THEN NB = 32 ELSE NB = 32 END IF ELSE IF( C3.EQ.'HRD' ) THEN IF( SNAME ) THEN NB = 32 ELSE NB = 32 END IF ELSE IF( C3.EQ.'BRD' ) THEN IF( SNAME ) THEN NB = 32 ELSE NB = 32 END IF ELSE IF( C3.EQ.'TRI' ) THEN IF( SNAME ) THEN NB = 64 ELSE NB = 64 END IF END IF ELSE IF( C2.EQ.'PO' ) THEN IF( C3.EQ.'TRF' ) THEN IF( SNAME ) THEN NB = 64 ELSE NB = 64 END IF END IF ELSE IF( C2.EQ.'SY' ) THEN IF( C3.EQ.'TRF' ) THEN IF( SNAME ) THEN NB = 64 ELSE NB = 64 END IF ELSE IF( SNAME .AND. C3.EQ.'TRD' ) THEN NB = 32 ELSE IF( SNAME .AND. C3.EQ.'GST' ) THEN NB = 64 END IF ELSE IF( CNAME .AND. C2.EQ.'HE' ) THEN IF( C3.EQ.'TRF' ) THEN NB = 64 ELSE IF( C3.EQ.'TRD' ) THEN NB = 32 ELSE IF( C3.EQ.'GST' ) THEN NB = 64 END IF ELSE IF( SNAME .AND. C2.EQ.'OR' ) THEN IF( C3( 1: 1 ).EQ.'G' ) THEN IF( C4.EQ.'QR' .OR. C4.EQ.'RQ' .OR. C4.EQ.'LQ' .OR. C4.EQ. $ 'QL' .OR. C4.EQ.'HR' .OR. C4.EQ.'TR' .OR. C4.EQ.'BR' ) $ THEN NB = 32 END IF ELSE IF( C3( 1: 1 ).EQ.'M' ) THEN IF( C4.EQ.'QR' .OR. C4.EQ.'RQ' .OR. C4.EQ.'LQ' .OR. C4.EQ. $ 'QL' .OR. C4.EQ.'HR' .OR. C4.EQ.'TR' .OR. C4.EQ.'BR' ) $ THEN NB = 32 END IF END IF ELSE IF( CNAME .AND. C2.EQ.'UN' ) THEN IF( C3( 1: 1 ).EQ.'G' ) THEN IF( C4.EQ.'QR' .OR. C4.EQ.'RQ' .OR. C4.EQ.'LQ' .OR. C4.EQ. $ 'QL' .OR. C4.EQ.'HR' .OR. C4.EQ.'TR' .OR. C4.EQ.'BR' ) $ THEN NB = 32 END IF ELSE IF( C3( 1: 1 ).EQ.'M' ) THEN IF( C4.EQ.'QR' .OR. C4.EQ.'RQ' .OR. C4.EQ.'LQ' .OR. C4.EQ. $ 'QL' .OR. C4.EQ.'HR' .OR. C4.EQ.'TR' .OR. C4.EQ.'BR' ) $ THEN NB = 32 END IF END IF ELSE IF( C2.EQ.'GB' ) THEN IF( C3.EQ.'TRF' ) THEN IF( SNAME ) THEN IF( N4.LE.64 ) THEN NB = 1 ELSE NB = 32 END IF ELSE IF( N4.LE.64 ) THEN NB = 1 ELSE NB = 32 END IF END IF END IF ELSE IF( C2.EQ.'PB' ) THEN IF( C3.EQ.'TRF' ) THEN IF( SNAME ) THEN IF( N2.LE.64 ) THEN NB = 1 ELSE NB = 32 END IF ELSE IF( N2.LE.64 ) THEN NB = 1 ELSE NB = 32 END IF END IF END IF ELSE IF( C2.EQ.'TR' ) THEN IF( C3.EQ.'TRI' ) THEN IF( SNAME ) THEN NB = 64 ELSE NB = 64 END IF END IF ELSE IF( C2.EQ.'LA' ) THEN IF( C3.EQ.'UUM' ) THEN IF( SNAME ) THEN NB = 64 ELSE NB = 64 END IF END IF ELSE IF( SNAME .AND. C2.EQ.'ST' ) THEN IF( C3.EQ.'EBZ' ) THEN NB = 1 END IF END IF ILAENV = NB RETURN * 60 CONTINUE * * ISPEC = 2: minimum block size * NBMIN = 2 IF( C2.EQ.'GE' ) THEN IF( C3.EQ.'QRF' .OR. C3.EQ.'RQF' .OR. C3.EQ.'LQF' .OR. C3.EQ. $ 'QLF' ) THEN IF( SNAME ) THEN NBMIN = 2 ELSE NBMIN = 2 END IF ELSE IF( C3.EQ.'HRD' ) THEN IF( SNAME ) THEN NBMIN = 2 ELSE NBMIN = 2 END IF ELSE IF( C3.EQ.'BRD' ) THEN IF( SNAME ) THEN NBMIN = 2 ELSE NBMIN = 2 END IF ELSE IF( C3.EQ.'TRI' ) THEN IF( SNAME ) THEN NBMIN = 2 ELSE NBMIN = 2 END IF END IF ELSE IF( C2.EQ.'SY' ) THEN IF( C3.EQ.'TRF' ) THEN IF( SNAME ) THEN NBMIN = 8 ELSE NBMIN = 8 END IF ELSE IF( SNAME .AND. C3.EQ.'TRD' ) THEN NBMIN = 2 END IF ELSE IF( CNAME .AND. C2.EQ.'HE' ) THEN IF( C3.EQ.'TRD' ) THEN NBMIN = 2 END IF ELSE IF( SNAME .AND. C2.EQ.'OR' ) THEN IF( C3( 1: 1 ).EQ.'G' ) THEN IF( C4.EQ.'QR' .OR. C4.EQ.'RQ' .OR. C4.EQ.'LQ' .OR. C4.EQ. $ 'QL' .OR. C4.EQ.'HR' .OR. C4.EQ.'TR' .OR. C4.EQ.'BR' ) $ THEN NBMIN = 2 END IF ELSE IF( C3( 1: 1 ).EQ.'M' ) THEN IF( C4.EQ.'QR' .OR. C4.EQ.'RQ' .OR. C4.EQ.'LQ' .OR. C4.EQ. $ 'QL' .OR. C4.EQ.'HR' .OR. C4.EQ.'TR' .OR. C4.EQ.'BR' ) $ THEN NBMIN = 2 END IF END IF ELSE IF( CNAME .AND. C2.EQ.'UN' ) THEN IF( C3( 1: 1 ).EQ.'G' ) THEN IF( C4.EQ.'QR' .OR. C4.EQ.'RQ' .OR. C4.EQ.'LQ' .OR. C4.EQ. $ 'QL' .OR. C4.EQ.'HR' .OR. C4.EQ.'TR' .OR. C4.EQ.'BR' ) $ THEN NBMIN = 2 END IF ELSE IF( C3( 1: 1 ).EQ.'M' ) THEN IF( C4.EQ.'QR' .OR. C4.EQ.'RQ' .OR. C4.EQ.'LQ' .OR. C4.EQ. $ 'QL' .OR. C4.EQ.'HR' .OR. C4.EQ.'TR' .OR. C4.EQ.'BR' ) $ THEN NBMIN = 2 END IF END IF END IF ILAENV = NBMIN RETURN * 70 CONTINUE * * ISPEC = 3: crossover point * NX = 0 IF( C2.EQ.'GE' ) THEN IF( C3.EQ.'QRF' .OR. C3.EQ.'RQF' .OR. C3.EQ.'LQF' .OR. C3.EQ. $ 'QLF' ) THEN IF( SNAME ) THEN NX = 128 ELSE NX = 128 END IF ELSE IF( C3.EQ.'HRD' ) THEN IF( SNAME ) THEN NX = 128 ELSE NX = 128 END IF ELSE IF( C3.EQ.'BRD' ) THEN IF( SNAME ) THEN NX = 128 ELSE NX = 128 END IF END IF ELSE IF( C2.EQ.'SY' ) THEN IF( SNAME .AND. C3.EQ.'TRD' ) THEN NX = 32 END IF ELSE IF( CNAME .AND. C2.EQ.'HE' ) THEN IF( C3.EQ.'TRD' ) THEN NX = 32 END IF ELSE IF( SNAME .AND. C2.EQ.'OR' ) THEN IF( C3( 1: 1 ).EQ.'G' ) THEN IF( C4.EQ.'QR' .OR. C4.EQ.'RQ' .OR. C4.EQ.'LQ' .OR. C4.EQ. $ 'QL' .OR. C4.EQ.'HR' .OR. C4.EQ.'TR' .OR. C4.EQ.'BR' ) $ THEN NX = 128 END IF END IF ELSE IF( CNAME .AND. C2.EQ.'UN' ) THEN IF( C3( 1: 1 ).EQ.'G' ) THEN IF( C4.EQ.'QR' .OR. C4.EQ.'RQ' .OR. C4.EQ.'LQ' .OR. C4.EQ. $ 'QL' .OR. C4.EQ.'HR' .OR. C4.EQ.'TR' .OR. C4.EQ.'BR' ) $ THEN NX = 128 END IF END IF END IF ILAENV = NX RETURN * 80 CONTINUE * * ISPEC = 4: number of shifts (used by xHSEQR) * ILAENV = 6 RETURN * 90 CONTINUE * * ISPEC = 5: minimum column dimension (not used) * ILAENV = 2 RETURN * 100 CONTINUE * * ISPEC = 6: crossover point for SVD (used by xGELSS and xGESVD) * ILAENV = INT( REAL( MIN( N1, N2 ) )*1.6E0 ) RETURN * 110 CONTINUE * * ISPEC = 7: number of processors (not used) * ILAENV = 1 RETURN * 120 CONTINUE * * ISPEC = 8: crossover point for multishift (used by xHSEQR) * ILAENV = 50 RETURN * 130 CONTINUE * * ISPEC = 9: maximum size of the subproblems at the bottom of the * computation tree in the divide-and-conquer algorithm * (used by xGELSD and xGESDD) * ILAENV = 25 RETURN * 140 CONTINUE * * ISPEC = 10: ieee NaN arithmetic can be trusted not to trap * * ILAENV = 0 ILAENV = 1 IF( ILAENV.EQ.1 ) THEN ILAENV = IEEECK( 1, 0.0, 1.0 ) END IF RETURN * 150 CONTINUE * * ISPEC = 11: infinity arithmetic can be trusted not to trap * * ILAENV = 0 ILAENV = 1 IF( ILAENV.EQ.1 ) THEN ILAENV = IEEECK( 0, 0.0, 1.0 ) END IF RETURN * 160 CONTINUE * * 12 <= ISPEC <= 16: xHSEQR or one of its subroutines. * ILAENV = IPARMQ( ISPEC, NAME, OPTS, N1, N2, N3, N4 ) RETURN * * End of ILAENV * END
gpl-3.0
wilmarcardonac/hypermcmc
lapack-3.5.0/TESTING/EIG/sstt22.f
32
7054
*> \brief \b SSTT22 * * =========== DOCUMENTATION =========== * * Online html documentation available at * http://www.netlib.org/lapack/explore-html/ * * Definition: * =========== * * SUBROUTINE SSTT22( N, M, KBAND, AD, AE, SD, SE, U, LDU, WORK, * LDWORK, RESULT ) * * .. Scalar Arguments .. * INTEGER KBAND, LDU, LDWORK, M, N * .. * .. Array Arguments .. * REAL AD( * ), AE( * ), RESULT( 2 ), SD( * ), * $ SE( * ), U( LDU, * ), WORK( LDWORK, * ) * .. * * *> \par Purpose: * ============= *> *> \verbatim *> *> SSTT22 checks a set of M eigenvalues and eigenvectors, *> *> A U = U S *> *> where A is symmetric tridiagonal, the columns of U are orthogonal, *> and S is diagonal (if KBAND=0) or symmetric tridiagonal (if KBAND=1). *> Two tests are performed: *> *> RESULT(1) = | U' A U - S | / ( |A| m ulp ) *> *> RESULT(2) = | I - U'U | / ( m ulp ) *> \endverbatim * * Arguments: * ========== * *> \param[in] N *> \verbatim *> N is INTEGER *> The size of the matrix. If it is zero, SSTT22 does nothing. *> It must be at least zero. *> \endverbatim *> *> \param[in] M *> \verbatim *> M is INTEGER *> The number of eigenpairs to check. If it is zero, SSTT22 *> does nothing. It must be at least zero. *> \endverbatim *> *> \param[in] KBAND *> \verbatim *> KBAND is INTEGER *> The bandwidth of the matrix S. It may only be zero or one. *> If zero, then S is diagonal, and SE is not referenced. If *> one, then S is symmetric tri-diagonal. *> \endverbatim *> *> \param[in] AD *> \verbatim *> AD is REAL array, dimension (N) *> The diagonal of the original (unfactored) matrix A. A is *> assumed to be symmetric tridiagonal. *> \endverbatim *> *> \param[in] AE *> \verbatim *> AE is REAL array, dimension (N) *> The off-diagonal of the original (unfactored) matrix A. A *> is assumed to be symmetric tridiagonal. AE(1) is ignored, *> AE(2) is the (1,2) and (2,1) element, etc. *> \endverbatim *> *> \param[in] SD *> \verbatim *> SD is REAL array, dimension (N) *> The diagonal of the (symmetric tri-) diagonal matrix S. *> \endverbatim *> *> \param[in] SE *> \verbatim *> SE is REAL array, dimension (N) *> The off-diagonal of the (symmetric tri-) diagonal matrix S. *> Not referenced if KBSND=0. If KBAND=1, then AE(1) is *> ignored, SE(2) is the (1,2) and (2,1) element, etc. *> \endverbatim *> *> \param[in] U *> \verbatim *> U is REAL array, dimension (LDU, N) *> The orthogonal matrix in the decomposition. *> \endverbatim *> *> \param[in] LDU *> \verbatim *> LDU is INTEGER *> The leading dimension of U. LDU must be at least N. *> \endverbatim *> *> \param[out] WORK *> \verbatim *> WORK is REAL array, dimension (LDWORK, M+1) *> \endverbatim *> *> \param[in] LDWORK *> \verbatim *> LDWORK is INTEGER *> The leading dimension of WORK. LDWORK must be at least *> max(1,M). *> \endverbatim *> *> \param[out] RESULT *> \verbatim *> RESULT is REAL array, dimension (2) *> The values computed by the two tests described above. The *> values are currently limited to 1/ulp, to avoid overflow. *> \endverbatim * * Authors: * ======== * *> \author Univ. of Tennessee *> \author Univ. of California Berkeley *> \author Univ. of Colorado Denver *> \author NAG Ltd. * *> \date November 2011 * *> \ingroup single_eig * * ===================================================================== SUBROUTINE SSTT22( N, M, KBAND, AD, AE, SD, SE, U, LDU, WORK, $ LDWORK, RESULT ) * * -- LAPACK test routine (version 3.4.0) -- * -- LAPACK is a software package provided by Univ. of Tennessee, -- * -- Univ. of California Berkeley, Univ. of Colorado Denver and NAG Ltd..-- * November 2011 * * .. Scalar Arguments .. INTEGER KBAND, LDU, LDWORK, M, N * .. * .. Array Arguments .. REAL AD( * ), AE( * ), RESULT( 2 ), SD( * ), $ SE( * ), U( LDU, * ), WORK( LDWORK, * ) * .. * * ===================================================================== * * .. Parameters .. REAL ZERO, ONE PARAMETER ( ZERO = 0.0E0, ONE = 1.0E0 ) * .. * .. Local Scalars .. INTEGER I, J, K REAL ANORM, AUKJ, ULP, UNFL, WNORM * .. * .. External Functions .. REAL SLAMCH, SLANGE, SLANSY EXTERNAL SLAMCH, SLANGE, SLANSY * .. * .. External Subroutines .. EXTERNAL SGEMM * .. * .. Intrinsic Functions .. INTRINSIC ABS, MAX, MIN, REAL * .. * .. Executable Statements .. * RESULT( 1 ) = ZERO RESULT( 2 ) = ZERO IF( N.LE.0 .OR. M.LE.0 ) $ RETURN * UNFL = SLAMCH( 'Safe minimum' ) ULP = SLAMCH( 'Epsilon' ) * * Do Test 1 * * Compute the 1-norm of A. * IF( N.GT.1 ) THEN ANORM = ABS( AD( 1 ) ) + ABS( AE( 1 ) ) DO 10 J = 2, N - 1 ANORM = MAX( ANORM, ABS( AD( J ) )+ABS( AE( J ) )+ $ ABS( AE( J-1 ) ) ) 10 CONTINUE ANORM = MAX( ANORM, ABS( AD( N ) )+ABS( AE( N-1 ) ) ) ELSE ANORM = ABS( AD( 1 ) ) END IF ANORM = MAX( ANORM, UNFL ) * * Norm of U'AU - S * DO 40 I = 1, M DO 30 J = 1, M WORK( I, J ) = ZERO DO 20 K = 1, N AUKJ = AD( K )*U( K, J ) IF( K.NE.N ) $ AUKJ = AUKJ + AE( K )*U( K+1, J ) IF( K.NE.1 ) $ AUKJ = AUKJ + AE( K-1 )*U( K-1, J ) WORK( I, J ) = WORK( I, J ) + U( K, I )*AUKJ 20 CONTINUE 30 CONTINUE WORK( I, I ) = WORK( I, I ) - SD( I ) IF( KBAND.EQ.1 ) THEN IF( I.NE.1 ) $ WORK( I, I-1 ) = WORK( I, I-1 ) - SE( I-1 ) IF( I.NE.N ) $ WORK( I, I+1 ) = WORK( I, I+1 ) - SE( I ) END IF 40 CONTINUE * WNORM = SLANSY( '1', 'L', M, WORK, M, WORK( 1, M+1 ) ) * IF( ANORM.GT.WNORM ) THEN RESULT( 1 ) = ( WNORM / ANORM ) / ( M*ULP ) ELSE IF( ANORM.LT.ONE ) THEN RESULT( 1 ) = ( MIN( WNORM, M*ANORM ) / ANORM ) / ( M*ULP ) ELSE RESULT( 1 ) = MIN( WNORM / ANORM, REAL( M ) ) / ( M*ULP ) END IF END IF * * Do Test 2 * * Compute U'U - I * CALL SGEMM( 'T', 'N', M, M, N, ONE, U, LDU, U, LDU, ZERO, WORK, $ M ) * DO 50 J = 1, M WORK( J, J ) = WORK( J, J ) - ONE 50 CONTINUE * RESULT( 2 ) = MIN( REAL( M ), SLANGE( '1', M, M, WORK, M, WORK( 1, $ M+1 ) ) ) / ( M*ULP ) * RETURN * * End of SSTT22 * END
gpl-2.0
wilmarcardonac/hypermcmc
lapack-3.5.0/SRC/zlanhp.f
26
8330
*> \brief \b ZLANHP returns the value of the 1-norm, or the Frobenius norm, or the infinity norm, or the element of largest absolute value of a complex Hermitian matrix supplied in packed form. * * =========== DOCUMENTATION =========== * * Online html documentation available at * http://www.netlib.org/lapack/explore-html/ * *> \htmlonly *> Download ZLANHP + dependencies *> <a href="http://www.netlib.org/cgi-bin/netlibfiles.tgz?format=tgz&filename=/lapack/lapack_routine/zlanhp.f"> *> [TGZ]</a> *> <a href="http://www.netlib.org/cgi-bin/netlibfiles.zip?format=zip&filename=/lapack/lapack_routine/zlanhp.f"> *> [ZIP]</a> *> <a href="http://www.netlib.org/cgi-bin/netlibfiles.txt?format=txt&filename=/lapack/lapack_routine/zlanhp.f"> *> [TXT]</a> *> \endhtmlonly * * Definition: * =========== * * DOUBLE PRECISION FUNCTION ZLANHP( NORM, UPLO, N, AP, WORK ) * * .. Scalar Arguments .. * CHARACTER NORM, UPLO * INTEGER N * .. * .. Array Arguments .. * DOUBLE PRECISION WORK( * ) * COMPLEX*16 AP( * ) * .. * * *> \par Purpose: * ============= *> *> \verbatim *> *> ZLANHP returns the value of the one norm, or the Frobenius norm, or *> the infinity norm, or the element of largest absolute value of a *> complex hermitian matrix A, supplied in packed form. *> \endverbatim *> *> \return ZLANHP *> \verbatim *> *> ZLANHP = ( max(abs(A(i,j))), NORM = 'M' or 'm' *> ( *> ( norm1(A), NORM = '1', 'O' or 'o' *> ( *> ( normI(A), NORM = 'I' or 'i' *> ( *> ( normF(A), NORM = 'F', 'f', 'E' or 'e' *> *> where norm1 denotes the one norm of a matrix (maximum column sum), *> normI denotes the infinity norm of a matrix (maximum row sum) and *> normF denotes the Frobenius norm of a matrix (square root of sum of *> squares). Note that max(abs(A(i,j))) is not a consistent matrix norm. *> \endverbatim * * Arguments: * ========== * *> \param[in] NORM *> \verbatim *> NORM is CHARACTER*1 *> Specifies the value to be returned in ZLANHP as described *> above. *> \endverbatim *> *> \param[in] UPLO *> \verbatim *> UPLO is CHARACTER*1 *> Specifies whether the upper or lower triangular part of the *> hermitian matrix A is supplied. *> = 'U': Upper triangular part of A is supplied *> = 'L': Lower triangular part of A is supplied *> \endverbatim *> *> \param[in] N *> \verbatim *> N is INTEGER *> The order of the matrix A. N >= 0. When N = 0, ZLANHP is *> set to zero. *> \endverbatim *> *> \param[in] AP *> \verbatim *> AP is COMPLEX*16 array, dimension (N*(N+1)/2) *> The upper or lower triangle of the hermitian matrix A, packed *> columnwise in a linear array. The j-th column of A is stored *> in the array AP as follows: *> if UPLO = 'U', AP(i + (j-1)*j/2) = A(i,j) for 1<=i<=j; *> if UPLO = 'L', AP(i + (j-1)*(2n-j)/2) = A(i,j) for j<=i<=n. *> Note that the imaginary parts of the diagonal elements need *> not be set and are assumed to be zero. *> \endverbatim *> *> \param[out] WORK *> \verbatim *> WORK is DOUBLE PRECISION array, dimension (MAX(1,LWORK)), *> where LWORK >= N when NORM = 'I' or '1' or 'O'; otherwise, *> WORK is not referenced. *> \endverbatim * * Authors: * ======== * *> \author Univ. of Tennessee *> \author Univ. of California Berkeley *> \author Univ. of Colorado Denver *> \author NAG Ltd. * *> \date September 2012 * *> \ingroup complex16OTHERauxiliary * * ===================================================================== DOUBLE PRECISION FUNCTION ZLANHP( NORM, UPLO, N, AP, WORK ) * * -- LAPACK auxiliary routine (version 3.4.2) -- * -- LAPACK is a software package provided by Univ. of Tennessee, -- * -- Univ. of California Berkeley, Univ. of Colorado Denver and NAG Ltd..-- * September 2012 * * .. Scalar Arguments .. CHARACTER NORM, UPLO INTEGER N * .. * .. Array Arguments .. DOUBLE PRECISION WORK( * ) COMPLEX*16 AP( * ) * .. * * ===================================================================== * * .. Parameters .. DOUBLE PRECISION ONE, ZERO PARAMETER ( ONE = 1.0D+0, ZERO = 0.0D+0 ) * .. * .. Local Scalars .. INTEGER I, J, K DOUBLE PRECISION ABSA, SCALE, SUM, VALUE * .. * .. External Functions .. LOGICAL LSAME, DISNAN EXTERNAL LSAME, DISNAN * .. * .. External Subroutines .. EXTERNAL ZLASSQ * .. * .. Intrinsic Functions .. INTRINSIC ABS, DBLE, SQRT * .. * .. Executable Statements .. * IF( N.EQ.0 ) THEN VALUE = ZERO ELSE IF( LSAME( NORM, 'M' ) ) THEN * * Find max(abs(A(i,j))). * VALUE = ZERO IF( LSAME( UPLO, 'U' ) ) THEN K = 0 DO 20 J = 1, N DO 10 I = K + 1, K + J - 1 SUM = ABS( AP( I ) ) IF( VALUE .LT. SUM .OR. DISNAN( SUM ) ) VALUE = SUM 10 CONTINUE K = K + J SUM = ABS( DBLE( AP( K ) ) ) IF( VALUE .LT. SUM .OR. DISNAN( SUM ) ) VALUE = SUM 20 CONTINUE ELSE K = 1 DO 40 J = 1, N SUM = ABS( DBLE( AP( K ) ) ) IF( VALUE .LT. SUM .OR. DISNAN( SUM ) ) VALUE = SUM DO 30 I = K + 1, K + N - J SUM = ABS( AP( I ) ) IF( VALUE .LT. SUM .OR. DISNAN( SUM ) ) VALUE = SUM 30 CONTINUE K = K + N - J + 1 40 CONTINUE END IF ELSE IF( ( LSAME( NORM, 'I' ) ) .OR. ( LSAME( NORM, 'O' ) ) .OR. $ ( NORM.EQ.'1' ) ) THEN * * Find normI(A) ( = norm1(A), since A is hermitian). * VALUE = ZERO K = 1 IF( LSAME( UPLO, 'U' ) ) THEN DO 60 J = 1, N SUM = ZERO DO 50 I = 1, J - 1 ABSA = ABS( AP( K ) ) SUM = SUM + ABSA WORK( I ) = WORK( I ) + ABSA K = K + 1 50 CONTINUE WORK( J ) = SUM + ABS( DBLE( AP( K ) ) ) K = K + 1 60 CONTINUE DO 70 I = 1, N SUM = WORK( I ) IF( VALUE .LT. SUM .OR. DISNAN( SUM ) ) VALUE = SUM 70 CONTINUE ELSE DO 80 I = 1, N WORK( I ) = ZERO 80 CONTINUE DO 100 J = 1, N SUM = WORK( J ) + ABS( DBLE( AP( K ) ) ) K = K + 1 DO 90 I = J + 1, N ABSA = ABS( AP( K ) ) SUM = SUM + ABSA WORK( I ) = WORK( I ) + ABSA K = K + 1 90 CONTINUE IF( VALUE .LT. SUM .OR. DISNAN( SUM ) ) VALUE = SUM 100 CONTINUE END IF ELSE IF( ( LSAME( NORM, 'F' ) ) .OR. ( LSAME( NORM, 'E' ) ) ) THEN * * Find normF(A). * SCALE = ZERO SUM = ONE K = 2 IF( LSAME( UPLO, 'U' ) ) THEN DO 110 J = 2, N CALL ZLASSQ( J-1, AP( K ), 1, SCALE, SUM ) K = K + J 110 CONTINUE ELSE DO 120 J = 1, N - 1 CALL ZLASSQ( N-J, AP( K ), 1, SCALE, SUM ) K = K + N - J + 1 120 CONTINUE END IF SUM = 2*SUM K = 1 DO 130 I = 1, N IF( DBLE( AP( K ) ).NE.ZERO ) THEN ABSA = ABS( DBLE( AP( K ) ) ) IF( SCALE.LT.ABSA ) THEN SUM = ONE + SUM*( SCALE / ABSA )**2 SCALE = ABSA ELSE SUM = SUM + ( ABSA / SCALE )**2 END IF END IF IF( LSAME( UPLO, 'U' ) ) THEN K = K + I + 1 ELSE K = K + N - I + 1 END IF 130 CONTINUE VALUE = SCALE*SQRT( SUM ) END IF * ZLANHP = VALUE RETURN * * End of ZLANHP * END
gpl-2.0
wilmarcardonac/hypermcmc
lapack-3.5.0/SRC/cgetrs.f
29
6059
*> \brief \b CGETRS * * =========== DOCUMENTATION =========== * * Online html documentation available at * http://www.netlib.org/lapack/explore-html/ * *> \htmlonly *> Download CGETRS + dependencies *> <a href="http://www.netlib.org/cgi-bin/netlibfiles.tgz?format=tgz&filename=/lapack/lapack_routine/cgetrs.f"> *> [TGZ]</a> *> <a href="http://www.netlib.org/cgi-bin/netlibfiles.zip?format=zip&filename=/lapack/lapack_routine/cgetrs.f"> *> [ZIP]</a> *> <a href="http://www.netlib.org/cgi-bin/netlibfiles.txt?format=txt&filename=/lapack/lapack_routine/cgetrs.f"> *> [TXT]</a> *> \endhtmlonly * * Definition: * =========== * * SUBROUTINE CGETRS( TRANS, N, NRHS, A, LDA, IPIV, B, LDB, INFO ) * * .. Scalar Arguments .. * CHARACTER TRANS * INTEGER INFO, LDA, LDB, N, NRHS * .. * .. Array Arguments .. * INTEGER IPIV( * ) * COMPLEX A( LDA, * ), B( LDB, * ) * .. * * *> \par Purpose: * ============= *> *> \verbatim *> *> CGETRS solves a system of linear equations *> A * X = B, A**T * X = B, or A**H * X = B *> with a general N-by-N matrix A using the LU factorization computed *> by CGETRF. *> \endverbatim * * Arguments: * ========== * *> \param[in] TRANS *> \verbatim *> TRANS is CHARACTER*1 *> Specifies the form of the system of equations: *> = 'N': A * X = B (No transpose) *> = 'T': A**T * X = B (Transpose) *> = 'C': A**H * X = B (Conjugate transpose) *> \endverbatim *> *> \param[in] N *> \verbatim *> N is INTEGER *> The order of the matrix A. N >= 0. *> \endverbatim *> *> \param[in] NRHS *> \verbatim *> NRHS is INTEGER *> The number of right hand sides, i.e., the number of columns *> of the matrix B. NRHS >= 0. *> \endverbatim *> *> \param[in] A *> \verbatim *> A is COMPLEX array, dimension (LDA,N) *> The factors L and U from the factorization A = P*L*U *> as computed by CGETRF. *> \endverbatim *> *> \param[in] LDA *> \verbatim *> LDA is INTEGER *> The leading dimension of the array A. LDA >= max(1,N). *> \endverbatim *> *> \param[in] IPIV *> \verbatim *> IPIV is INTEGER array, dimension (N) *> The pivot indices from CGETRF; for 1<=i<=N, row i of the *> matrix was interchanged with row IPIV(i). *> \endverbatim *> *> \param[in,out] B *> \verbatim *> B is COMPLEX array, dimension (LDB,NRHS) *> On entry, the right hand side matrix B. *> On exit, the solution matrix X. *> \endverbatim *> *> \param[in] LDB *> \verbatim *> LDB is INTEGER *> The leading dimension of the array B. LDB >= max(1,N). *> \endverbatim *> *> \param[out] INFO *> \verbatim *> INFO is INTEGER *> = 0: successful exit *> < 0: if INFO = -i, the i-th argument had an illegal value *> \endverbatim * * Authors: * ======== * *> \author Univ. of Tennessee *> \author Univ. of California Berkeley *> \author Univ. of Colorado Denver *> \author NAG Ltd. * *> \date November 2011 * *> \ingroup complexGEcomputational * * ===================================================================== SUBROUTINE CGETRS( TRANS, N, NRHS, A, LDA, IPIV, B, LDB, INFO ) * * -- LAPACK computational routine (version 3.4.0) -- * -- LAPACK is a software package provided by Univ. of Tennessee, -- * -- Univ. of California Berkeley, Univ. of Colorado Denver and NAG Ltd..-- * November 2011 * * .. Scalar Arguments .. CHARACTER TRANS INTEGER INFO, LDA, LDB, N, NRHS * .. * .. Array Arguments .. INTEGER IPIV( * ) COMPLEX A( LDA, * ), B( LDB, * ) * .. * * ===================================================================== * * .. Parameters .. COMPLEX ONE PARAMETER ( ONE = ( 1.0E+0, 0.0E+0 ) ) * .. * .. Local Scalars .. LOGICAL NOTRAN * .. * .. External Functions .. LOGICAL LSAME EXTERNAL LSAME * .. * .. External Subroutines .. EXTERNAL CLASWP, CTRSM, XERBLA * .. * .. Intrinsic Functions .. INTRINSIC MAX * .. * .. Executable Statements .. * * Test the input parameters. * INFO = 0 NOTRAN = LSAME( TRANS, 'N' ) IF( .NOT.NOTRAN .AND. .NOT.LSAME( TRANS, 'T' ) .AND. .NOT. $ LSAME( TRANS, 'C' ) ) THEN INFO = -1 ELSE IF( N.LT.0 ) THEN INFO = -2 ELSE IF( NRHS.LT.0 ) THEN INFO = -3 ELSE IF( LDA.LT.MAX( 1, N ) ) THEN INFO = -5 ELSE IF( LDB.LT.MAX( 1, N ) ) THEN INFO = -8 END IF IF( INFO.NE.0 ) THEN CALL XERBLA( 'CGETRS', -INFO ) RETURN END IF * * Quick return if possible * IF( N.EQ.0 .OR. NRHS.EQ.0 ) $ RETURN * IF( NOTRAN ) THEN * * Solve A * X = B. * * Apply row interchanges to the right hand sides. * CALL CLASWP( NRHS, B, LDB, 1, N, IPIV, 1 ) * * Solve L*X = B, overwriting B with X. * CALL CTRSM( 'Left', 'Lower', 'No transpose', 'Unit', N, NRHS, $ ONE, A, LDA, B, LDB ) * * Solve U*X = B, overwriting B with X. * CALL CTRSM( 'Left', 'Upper', 'No transpose', 'Non-unit', N, $ NRHS, ONE, A, LDA, B, LDB ) ELSE * * Solve A**T * X = B or A**H * X = B. * * Solve U**T *X = B or U**H *X = B, overwriting B with X. * CALL CTRSM( 'Left', 'Upper', TRANS, 'Non-unit', N, NRHS, ONE, $ A, LDA, B, LDB ) * * Solve L**T *X = B, or L**H *X = B overwriting B with X. * CALL CTRSM( 'Left', 'Lower', TRANS, 'Unit', N, NRHS, ONE, A, $ LDA, B, LDB ) * * Apply row interchanges to the solution vectors. * CALL CLASWP( NRHS, B, LDB, 1, N, IPIV, -1 ) END IF * RETURN * * End of CGETRS * END
gpl-2.0
wilmarcardonac/hypermcmc
lapack-3.5.0/BLAS/SRC/dcabs1.f
30
1299
*> \brief \b DCABS1 * * =========== DOCUMENTATION =========== * * Online html documentation available at * http://www.netlib.org/lapack/explore-html/ * * Definition: * =========== * * DOUBLE PRECISION FUNCTION DCABS1(Z) * * .. Scalar Arguments .. * COMPLEX*16 Z * .. * .. * * *> \par Purpose: * ============= *> *> \verbatim *> *> DCABS1 computes absolute value of a double complex number *> \endverbatim * * Authors: * ======== * *> \author Univ. of Tennessee *> \author Univ. of California Berkeley *> \author Univ. of Colorado Denver *> \author NAG Ltd. * *> \date November 2011 * *> \ingroup double_blas_level1 * * ===================================================================== DOUBLE PRECISION FUNCTION DCABS1(Z) * * -- Reference BLAS level1 routine (version 3.4.0) -- * -- Reference BLAS is a software package provided by Univ. of Tennessee, -- * -- Univ. of California Berkeley, Univ. of Colorado Denver and NAG Ltd..-- * November 2011 * * .. Scalar Arguments .. COMPLEX*16 Z * .. * .. * ===================================================================== * * .. Intrinsic Functions .. INTRINSIC ABS,DBLE,DIMAG * DCABS1 = ABS(DBLE(Z)) + ABS(DIMAG(Z)) RETURN END
gpl-2.0
wilmarcardonac/hypermcmc
lapack-3.5.0/TESTING/LIN/slattb.f
32
22039
*> \brief \b SLATTB * * =========== DOCUMENTATION =========== * * Online html documentation available at * http://www.netlib.org/lapack/explore-html/ * * Definition: * =========== * * SUBROUTINE SLATTB( IMAT, UPLO, TRANS, DIAG, ISEED, N, KD, AB, * LDAB, B, WORK, INFO ) * * .. Scalar Arguments .. * CHARACTER DIAG, TRANS, UPLO * INTEGER IMAT, INFO, KD, LDAB, N * .. * .. Array Arguments .. * INTEGER ISEED( 4 ) * REAL AB( LDAB, * ), B( * ), WORK( * ) * .. * * *> \par Purpose: * ============= *> *> \verbatim *> *> SLATTB generates a triangular test matrix in 2-dimensional storage. *> IMAT and UPLO uniquely specify the properties of the test matrix, *> which is returned in the array A. *> \endverbatim * * Arguments: * ========== * *> \param[in] IMAT *> \verbatim *> IMAT is INTEGER *> An integer key describing which matrix to generate for this *> path. *> \endverbatim *> *> \param[in] UPLO *> \verbatim *> UPLO is CHARACTER*1 *> Specifies whether the matrix A will be upper or lower *> triangular. *> = 'U': Upper triangular *> = 'L': Lower triangular *> \endverbatim *> *> \param[in] TRANS *> \verbatim *> TRANS is CHARACTER*1 *> Specifies whether the matrix or its transpose will be used. *> = 'N': No transpose *> = 'T': Transpose *> = 'C': Conjugate transpose (= transpose) *> \endverbatim *> *> \param[out] DIAG *> \verbatim *> DIAG is CHARACTER*1 *> Specifies whether or not the matrix A is unit triangular. *> = 'N': Non-unit triangular *> = 'U': Unit triangular *> \endverbatim *> *> \param[in,out] ISEED *> \verbatim *> ISEED is INTEGER array, dimension (4) *> The seed vector for the random number generator (used in *> SLATMS). Modified on exit. *> \endverbatim *> *> \param[in] N *> \verbatim *> N is INTEGER *> The order of the matrix to be generated. *> \endverbatim *> *> \param[in] KD *> \verbatim *> KD is INTEGER *> The number of superdiagonals or subdiagonals of the banded *> triangular matrix A. KD >= 0. *> \endverbatim *> *> \param[out] AB *> \verbatim *> AB is REAL array, dimension (LDAB,N) *> The upper or lower triangular banded matrix A, stored in the *> first KD+1 rows of AB. Let j be a column of A, 1<=j<=n. *> If UPLO = 'U', AB(kd+1+i-j,j) = A(i,j) for max(1,j-kd)<=i<=j. *> If UPLO = 'L', AB(1+i-j,j) = A(i,j) for j<=i<=min(n,j+kd). *> \endverbatim *> *> \param[in] LDAB *> \verbatim *> LDAB is INTEGER *> The leading dimension of the array AB. LDAB >= KD+1. *> \endverbatim *> *> \param[out] B *> \verbatim *> B is REAL array, dimension (N) *> \endverbatim *> *> \param[out] WORK *> \verbatim *> WORK is REAL array, dimension (2*N) *> \endverbatim *> *> \param[out] INFO *> \verbatim *> INFO is INTEGER *> = 0: successful exit *> < 0: if INFO = -k, the k-th argument had an illegal value *> \endverbatim * * Authors: * ======== * *> \author Univ. of Tennessee *> \author Univ. of California Berkeley *> \author Univ. of Colorado Denver *> \author NAG Ltd. * *> \date November 2011 * *> \ingroup single_lin * * ===================================================================== SUBROUTINE SLATTB( IMAT, UPLO, TRANS, DIAG, ISEED, N, KD, AB, $ LDAB, B, WORK, INFO ) * * -- LAPACK test routine (version 3.4.0) -- * -- LAPACK is a software package provided by Univ. of Tennessee, -- * -- Univ. of California Berkeley, Univ. of Colorado Denver and NAG Ltd..-- * November 2011 * * .. Scalar Arguments .. CHARACTER DIAG, TRANS, UPLO INTEGER IMAT, INFO, KD, LDAB, N * .. * .. Array Arguments .. INTEGER ISEED( 4 ) REAL AB( LDAB, * ), B( * ), WORK( * ) * .. * * ===================================================================== * * .. Parameters .. REAL ONE, TWO, ZERO PARAMETER ( ONE = 1.0E+0, TWO = 2.0E+0, ZERO = 0.0E+0 ) * .. * .. Local Scalars .. LOGICAL UPPER CHARACTER DIST, PACKIT, TYPE CHARACTER*3 PATH INTEGER I, IOFF, IY, J, JCOUNT, KL, KU, LENJ, MODE REAL ANORM, BIGNUM, BNORM, BSCAL, CNDNUM, PLUS1, $ PLUS2, REXP, SFAC, SMLNUM, STAR1, TEXP, TLEFT, $ TNORM, TSCAL, ULP, UNFL * .. * .. External Functions .. LOGICAL LSAME INTEGER ISAMAX REAL SLAMCH, SLARND EXTERNAL LSAME, ISAMAX, SLAMCH, SLARND * .. * .. External Subroutines .. EXTERNAL SCOPY, SLABAD, SLARNV, SLATB4, SLATMS, SSCAL, $ SSWAP * .. * .. Intrinsic Functions .. INTRINSIC ABS, MAX, MIN, REAL, SIGN, SQRT * .. * .. Executable Statements .. * PATH( 1: 1 ) = 'Single precision' PATH( 2: 3 ) = 'TB' UNFL = SLAMCH( 'Safe minimum' ) ULP = SLAMCH( 'Epsilon' )*SLAMCH( 'Base' ) SMLNUM = UNFL BIGNUM = ( ONE-ULP ) / SMLNUM CALL SLABAD( SMLNUM, BIGNUM ) IF( ( IMAT.GE.6 .AND. IMAT.LE.9 ) .OR. IMAT.EQ.17 ) THEN DIAG = 'U' ELSE DIAG = 'N' END IF INFO = 0 * * Quick return if N.LE.0. * IF( N.LE.0 ) $ RETURN * * Call SLATB4 to set parameters for SLATMS. * UPPER = LSAME( UPLO, 'U' ) IF( UPPER ) THEN CALL SLATB4( PATH, IMAT, N, N, TYPE, KL, KU, ANORM, MODE, $ CNDNUM, DIST ) KU = KD IOFF = 1 + MAX( 0, KD-N+1 ) KL = 0 PACKIT = 'Q' ELSE CALL SLATB4( PATH, -IMAT, N, N, TYPE, KL, KU, ANORM, MODE, $ CNDNUM, DIST ) KL = KD IOFF = 1 KU = 0 PACKIT = 'B' END IF * * IMAT <= 5: Non-unit triangular matrix * IF( IMAT.LE.5 ) THEN CALL SLATMS( N, N, DIST, ISEED, TYPE, B, MODE, CNDNUM, ANORM, $ KL, KU, PACKIT, AB( IOFF, 1 ), LDAB, WORK, INFO ) * * IMAT > 5: Unit triangular matrix * The diagonal is deliberately set to something other than 1. * * IMAT = 6: Matrix is the identity * ELSE IF( IMAT.EQ.6 ) THEN IF( UPPER ) THEN DO 20 J = 1, N DO 10 I = MAX( 1, KD+2-J ), KD AB( I, J ) = ZERO 10 CONTINUE AB( KD+1, J ) = J 20 CONTINUE ELSE DO 40 J = 1, N AB( 1, J ) = J DO 30 I = 2, MIN( KD+1, N-J+1 ) AB( I, J ) = ZERO 30 CONTINUE 40 CONTINUE END IF * * IMAT > 6: Non-trivial unit triangular matrix * * A unit triangular matrix T with condition CNDNUM is formed. * In this version, T only has bandwidth 2, the rest of it is zero. * ELSE IF( IMAT.LE.9 ) THEN TNORM = SQRT( CNDNUM ) * * Initialize AB to zero. * IF( UPPER ) THEN DO 60 J = 1, N DO 50 I = MAX( 1, KD+2-J ), KD AB( I, J ) = ZERO 50 CONTINUE AB( KD+1, J ) = REAL( J ) 60 CONTINUE ELSE DO 80 J = 1, N DO 70 I = 2, MIN( KD+1, N-J+1 ) AB( I, J ) = ZERO 70 CONTINUE AB( 1, J ) = REAL( J ) 80 CONTINUE END IF * * Special case: T is tridiagonal. Set every other offdiagonal * so that the matrix has norm TNORM+1. * IF( KD.EQ.1 ) THEN IF( UPPER ) THEN AB( 1, 2 ) = SIGN( TNORM, SLARND( 2, ISEED ) ) LENJ = ( N-3 ) / 2 CALL SLARNV( 2, ISEED, LENJ, WORK ) DO 90 J = 1, LENJ AB( 1, 2*( J+1 ) ) = TNORM*WORK( J ) 90 CONTINUE ELSE AB( 2, 1 ) = SIGN( TNORM, SLARND( 2, ISEED ) ) LENJ = ( N-3 ) / 2 CALL SLARNV( 2, ISEED, LENJ, WORK ) DO 100 J = 1, LENJ AB( 2, 2*J+1 ) = TNORM*WORK( J ) 100 CONTINUE END IF ELSE IF( KD.GT.1 ) THEN * * Form a unit triangular matrix T with condition CNDNUM. T is * given by * | 1 + * | * | 1 + | * T = | 1 + * | * | 1 + | * | 1 + * | * | 1 + | * | . . . | * Each element marked with a '*' is formed by taking the product * of the adjacent elements marked with '+'. The '*'s can be * chosen freely, and the '+'s are chosen so that the inverse of * T will have elements of the same magnitude as T. * * The two offdiagonals of T are stored in WORK. * STAR1 = SIGN( TNORM, SLARND( 2, ISEED ) ) SFAC = SQRT( TNORM ) PLUS1 = SIGN( SFAC, SLARND( 2, ISEED ) ) DO 110 J = 1, N, 2 PLUS2 = STAR1 / PLUS1 WORK( J ) = PLUS1 WORK( N+J ) = STAR1 IF( J+1.LE.N ) THEN WORK( J+1 ) = PLUS2 WORK( N+J+1 ) = ZERO PLUS1 = STAR1 / PLUS2 * * Generate a new *-value with norm between sqrt(TNORM) * and TNORM. * REXP = SLARND( 2, ISEED ) IF( REXP.LT.ZERO ) THEN STAR1 = -SFAC**( ONE-REXP ) ELSE STAR1 = SFAC**( ONE+REXP ) END IF END IF 110 CONTINUE * * Copy the tridiagonal T to AB. * IF( UPPER ) THEN CALL SCOPY( N-1, WORK, 1, AB( KD, 2 ), LDAB ) CALL SCOPY( N-2, WORK( N+1 ), 1, AB( KD-1, 3 ), LDAB ) ELSE CALL SCOPY( N-1, WORK, 1, AB( 2, 1 ), LDAB ) CALL SCOPY( N-2, WORK( N+1 ), 1, AB( 3, 1 ), LDAB ) END IF END IF * * IMAT > 9: Pathological test cases. These triangular matrices * are badly scaled or badly conditioned, so when used in solving a * triangular system they may cause overflow in the solution vector. * ELSE IF( IMAT.EQ.10 ) THEN * * Type 10: Generate a triangular matrix with elements between * -1 and 1. Give the diagonal norm 2 to make it well-conditioned. * Make the right hand side large so that it requires scaling. * IF( UPPER ) THEN DO 120 J = 1, N LENJ = MIN( J, KD+1 ) CALL SLARNV( 2, ISEED, LENJ, AB( KD+2-LENJ, J ) ) AB( KD+1, J ) = SIGN( TWO, AB( KD+1, J ) ) 120 CONTINUE ELSE DO 130 J = 1, N LENJ = MIN( N-J+1, KD+1 ) IF( LENJ.GT.0 ) $ CALL SLARNV( 2, ISEED, LENJ, AB( 1, J ) ) AB( 1, J ) = SIGN( TWO, AB( 1, J ) ) 130 CONTINUE END IF * * Set the right hand side so that the largest value is BIGNUM. * CALL SLARNV( 2, ISEED, N, B ) IY = ISAMAX( N, B, 1 ) BNORM = ABS( B( IY ) ) BSCAL = BIGNUM / MAX( ONE, BNORM ) CALL SSCAL( N, BSCAL, B, 1 ) * ELSE IF( IMAT.EQ.11 ) THEN * * Type 11: Make the first diagonal element in the solve small to * cause immediate overflow when dividing by T(j,j). * In type 11, the offdiagonal elements are small (CNORM(j) < 1). * CALL SLARNV( 2, ISEED, N, B ) TSCAL = ONE / REAL( KD+1 ) IF( UPPER ) THEN DO 140 J = 1, N LENJ = MIN( J, KD+1 ) CALL SLARNV( 2, ISEED, LENJ, AB( KD+2-LENJ, J ) ) CALL SSCAL( LENJ-1, TSCAL, AB( KD+2-LENJ, J ), 1 ) AB( KD+1, J ) = SIGN( ONE, AB( KD+1, J ) ) 140 CONTINUE AB( KD+1, N ) = SMLNUM*AB( KD+1, N ) ELSE DO 150 J = 1, N LENJ = MIN( N-J+1, KD+1 ) CALL SLARNV( 2, ISEED, LENJ, AB( 1, J ) ) IF( LENJ.GT.1 ) $ CALL SSCAL( LENJ-1, TSCAL, AB( 2, J ), 1 ) AB( 1, J ) = SIGN( ONE, AB( 1, J ) ) 150 CONTINUE AB( 1, 1 ) = SMLNUM*AB( 1, 1 ) END IF * ELSE IF( IMAT.EQ.12 ) THEN * * Type 12: Make the first diagonal element in the solve small to * cause immediate overflow when dividing by T(j,j). * In type 12, the offdiagonal elements are O(1) (CNORM(j) > 1). * CALL SLARNV( 2, ISEED, N, B ) IF( UPPER ) THEN DO 160 J = 1, N LENJ = MIN( J, KD+1 ) CALL SLARNV( 2, ISEED, LENJ, AB( KD+2-LENJ, J ) ) AB( KD+1, J ) = SIGN( ONE, AB( KD+1, J ) ) 160 CONTINUE AB( KD+1, N ) = SMLNUM*AB( KD+1, N ) ELSE DO 170 J = 1, N LENJ = MIN( N-J+1, KD+1 ) CALL SLARNV( 2, ISEED, LENJ, AB( 1, J ) ) AB( 1, J ) = SIGN( ONE, AB( 1, J ) ) 170 CONTINUE AB( 1, 1 ) = SMLNUM*AB( 1, 1 ) END IF * ELSE IF( IMAT.EQ.13 ) THEN * * Type 13: T is diagonal with small numbers on the diagonal to * make the growth factor underflow, but a small right hand side * chosen so that the solution does not overflow. * IF( UPPER ) THEN JCOUNT = 1 DO 190 J = N, 1, -1 DO 180 I = MAX( 1, KD+1-( J-1 ) ), KD AB( I, J ) = ZERO 180 CONTINUE IF( JCOUNT.LE.2 ) THEN AB( KD+1, J ) = SMLNUM ELSE AB( KD+1, J ) = ONE END IF JCOUNT = JCOUNT + 1 IF( JCOUNT.GT.4 ) $ JCOUNT = 1 190 CONTINUE ELSE JCOUNT = 1 DO 210 J = 1, N DO 200 I = 2, MIN( N-J+1, KD+1 ) AB( I, J ) = ZERO 200 CONTINUE IF( JCOUNT.LE.2 ) THEN AB( 1, J ) = SMLNUM ELSE AB( 1, J ) = ONE END IF JCOUNT = JCOUNT + 1 IF( JCOUNT.GT.4 ) $ JCOUNT = 1 210 CONTINUE END IF * * Set the right hand side alternately zero and small. * IF( UPPER ) THEN B( 1 ) = ZERO DO 220 I = N, 2, -2 B( I ) = ZERO B( I-1 ) = SMLNUM 220 CONTINUE ELSE B( N ) = ZERO DO 230 I = 1, N - 1, 2 B( I ) = ZERO B( I+1 ) = SMLNUM 230 CONTINUE END IF * ELSE IF( IMAT.EQ.14 ) THEN * * Type 14: Make the diagonal elements small to cause gradual * overflow when dividing by T(j,j). To control the amount of * scaling needed, the matrix is bidiagonal. * TEXP = ONE / REAL( KD+1 ) TSCAL = SMLNUM**TEXP CALL SLARNV( 2, ISEED, N, B ) IF( UPPER ) THEN DO 250 J = 1, N DO 240 I = MAX( 1, KD+2-J ), KD AB( I, J ) = ZERO 240 CONTINUE IF( J.GT.1 .AND. KD.GT.0 ) $ AB( KD, J ) = -ONE AB( KD+1, J ) = TSCAL 250 CONTINUE B( N ) = ONE ELSE DO 270 J = 1, N DO 260 I = 3, MIN( N-J+1, KD+1 ) AB( I, J ) = ZERO 260 CONTINUE IF( J.LT.N .AND. KD.GT.0 ) $ AB( 2, J ) = -ONE AB( 1, J ) = TSCAL 270 CONTINUE B( 1 ) = ONE END IF * ELSE IF( IMAT.EQ.15 ) THEN * * Type 15: One zero diagonal element. * IY = N / 2 + 1 IF( UPPER ) THEN DO 280 J = 1, N LENJ = MIN( J, KD+1 ) CALL SLARNV( 2, ISEED, LENJ, AB( KD+2-LENJ, J ) ) IF( J.NE.IY ) THEN AB( KD+1, J ) = SIGN( TWO, AB( KD+1, J ) ) ELSE AB( KD+1, J ) = ZERO END IF 280 CONTINUE ELSE DO 290 J = 1, N LENJ = MIN( N-J+1, KD+1 ) CALL SLARNV( 2, ISEED, LENJ, AB( 1, J ) ) IF( J.NE.IY ) THEN AB( 1, J ) = SIGN( TWO, AB( 1, J ) ) ELSE AB( 1, J ) = ZERO END IF 290 CONTINUE END IF CALL SLARNV( 2, ISEED, N, B ) CALL SSCAL( N, TWO, B, 1 ) * ELSE IF( IMAT.EQ.16 ) THEN * * Type 16: Make the offdiagonal elements large to cause overflow * when adding a column of T. In the non-transposed case, the * matrix is constructed to cause overflow when adding a column in * every other step. * TSCAL = UNFL / ULP TSCAL = ( ONE-ULP ) / TSCAL DO 310 J = 1, N DO 300 I = 1, KD + 1 AB( I, J ) = ZERO 300 CONTINUE 310 CONTINUE TEXP = ONE IF( KD.GT.0 ) THEN IF( UPPER ) THEN DO 330 J = N, 1, -KD DO 320 I = J, MAX( 1, J-KD+1 ), -2 AB( 1+( J-I ), I ) = -TSCAL / REAL( KD+2 ) AB( KD+1, I ) = ONE B( I ) = TEXP*( ONE-ULP ) IF( I.GT.MAX( 1, J-KD+1 ) ) THEN AB( 2+( J-I ), I-1 ) = -( TSCAL / REAL( KD+2 ) ) $ / REAL( KD+3 ) AB( KD+1, I-1 ) = ONE B( I-1 ) = TEXP*REAL( ( KD+1 )*( KD+1 )+KD ) END IF TEXP = TEXP*TWO 320 CONTINUE B( MAX( 1, J-KD+1 ) ) = ( REAL( KD+2 ) / $ REAL( KD+3 ) )*TSCAL 330 CONTINUE ELSE DO 350 J = 1, N, KD TEXP = ONE LENJ = MIN( KD+1, N-J+1 ) DO 340 I = J, MIN( N, J+KD-1 ), 2 AB( LENJ-( I-J ), J ) = -TSCAL / REAL( KD+2 ) AB( 1, J ) = ONE B( J ) = TEXP*( ONE-ULP ) IF( I.LT.MIN( N, J+KD-1 ) ) THEN AB( LENJ-( I-J+1 ), I+1 ) = -( TSCAL / $ REAL( KD+2 ) ) / REAL( KD+3 ) AB( 1, I+1 ) = ONE B( I+1 ) = TEXP*REAL( ( KD+1 )*( KD+1 )+KD ) END IF TEXP = TEXP*TWO 340 CONTINUE B( MIN( N, J+KD-1 ) ) = ( REAL( KD+2 ) / $ REAL( KD+3 ) )*TSCAL 350 CONTINUE END IF ELSE DO 360 J = 1, N AB( 1, J ) = ONE B( J ) = REAL( J ) 360 CONTINUE END IF * ELSE IF( IMAT.EQ.17 ) THEN * * Type 17: Generate a unit triangular matrix with elements * between -1 and 1, and make the right hand side large so that it * requires scaling. * IF( UPPER ) THEN DO 370 J = 1, N LENJ = MIN( J-1, KD ) CALL SLARNV( 2, ISEED, LENJ, AB( KD+1-LENJ, J ) ) AB( KD+1, J ) = REAL( J ) 370 CONTINUE ELSE DO 380 J = 1, N LENJ = MIN( N-J, KD ) IF( LENJ.GT.0 ) $ CALL SLARNV( 2, ISEED, LENJ, AB( 2, J ) ) AB( 1, J ) = REAL( J ) 380 CONTINUE END IF * * Set the right hand side so that the largest value is BIGNUM. * CALL SLARNV( 2, ISEED, N, B ) IY = ISAMAX( N, B, 1 ) BNORM = ABS( B( IY ) ) BSCAL = BIGNUM / MAX( ONE, BNORM ) CALL SSCAL( N, BSCAL, B, 1 ) * ELSE IF( IMAT.EQ.18 ) THEN * * Type 18: Generate a triangular matrix with elements between * BIGNUM/KD and BIGNUM so that at least one of the column * norms will exceed BIGNUM. * TLEFT = BIGNUM / MAX( ONE, REAL( KD ) ) TSCAL = BIGNUM*( REAL( KD ) / REAL( KD+1 ) ) IF( UPPER ) THEN DO 400 J = 1, N LENJ = MIN( J, KD+1 ) CALL SLARNV( 2, ISEED, LENJ, AB( KD+2-LENJ, J ) ) DO 390 I = KD + 2 - LENJ, KD + 1 AB( I, J ) = SIGN( TLEFT, AB( I, J ) ) + $ TSCAL*AB( I, J ) 390 CONTINUE 400 CONTINUE ELSE DO 420 J = 1, N LENJ = MIN( N-J+1, KD+1 ) CALL SLARNV( 2, ISEED, LENJ, AB( 1, J ) ) DO 410 I = 1, LENJ AB( I, J ) = SIGN( TLEFT, AB( I, J ) ) + $ TSCAL*AB( I, J ) 410 CONTINUE 420 CONTINUE END IF CALL SLARNV( 2, ISEED, N, B ) CALL SSCAL( N, TWO, B, 1 ) END IF * * Flip the matrix if the transpose will be used. * IF( .NOT.LSAME( TRANS, 'N' ) ) THEN IF( UPPER ) THEN DO 430 J = 1, N / 2 LENJ = MIN( N-2*J+1, KD+1 ) CALL SSWAP( LENJ, AB( KD+1, J ), LDAB-1, $ AB( KD+2-LENJ, N-J+1 ), -1 ) 430 CONTINUE ELSE DO 440 J = 1, N / 2 LENJ = MIN( N-2*J+1, KD+1 ) CALL SSWAP( LENJ, AB( 1, J ), 1, AB( LENJ, N-J+2-LENJ ), $ -LDAB+1 ) 440 CONTINUE END IF END IF * RETURN * * End of SLATTB * END
gpl-2.0
omni-compiler/omni-compiler
tests/XMP/NOT-IMPLEMENTED/59/reduction_async21.f90
2
3339
! testp101.f ! loop»Ø¼¨Ê¸¤Èreflect»Ø¼¨Ê¸¤Î¥Æ¥¹¥È program main include 'xmp_lib.h' integer,parameter:: N=1000 !$xmp nodes p(4,*) !$xmp template t1(N,N) !$xmp template t2(N,N) !$xmp template t3(N,N) !$xmp distribute t1(block,block) onto p !$xmp distribute t2(block,block) onto p !$xmp distribute t3(block,block) onto p integer a1(N,N), a2(N,N) real*8 b1(N,N), b2(N,N) real*4 c1(N,N), c2(N,N) !$xmp align a1(i,j) with t1(i,j) !$xmp align a2(i,j) with t1(i,j) !$xmp align b1(i,j) with t2(i,j) !$xmp align b2(i,j) with t2(i,j) !$xmp align c1(i,j) with t3(i,j) !$xmp align c2(i,j) with t3(i,j) !$xmp shadow a2(1,1) !$xmp shadow b2(2,2) !$xmp shadow c2(3,3) character(len=3) result !$xmp loop (i,j) on t1(i,j) do j=1, N do i=1, N a1(i,j) = 0 a2(i,j) = (j-1)*N+i enddo enddo !$xmp loop (i,j) on t2(i,j) do j=1, N do i=1, N b1(i,j) = 0.0 b2(i,j) = dble((j-1)*N+i) enddo enddo !$xmp loop (i,j) on t3(i,j) do j=1, N do i=1, N c1(i,j) = 0.0 c2(i,j) = real((j-1)*N+i) enddo enddo result = 'OK ' !$xmp loop (i,j) on t1(i,j) do j=2, N-1 do i=2, N-1 !$xmp reflect (a2) async(1) if(a1(i,j) .ne. 0) result = 'NG1' !$xmp wait_async(1) do jj=j-1, j+1 do ii=i-1, i+1 a1(i,j) = a1(i,j)+a2(ii,jj) enddo enddo a1(i,j) = a1(i,j)/9 enddo enddo !$xmp loop (i,j) on t2(i,j) do j=3, N-2 do i=3, N-2 !$xmp reflect (b2) async(1) if(b1(i,j) .ne. 0) result = 'NG2' !$xmp wait_async(1) do jj=j-2, j+2 do ii=i-2, i+2 b1(i,j) = b1(i,j)+b2(ii,jj) enddo enddo b1(i,j) = b1(i,j)/25.0 enddo enddo !$xmp loop (i,j) on t3(i,j) do j=4, N-3 do i=4, N-3 !$xmp reflect (c2) async(1) if(c1(i,j) .ne. 0) result = 'NG3' !$xmp wait_async(1) do jj=j-3, j+3 do ii=i-3, i+3 c1(i,j) = c1(i,j)+c2(ii,jj) enddo enddo c1(i,j) = c1(i,j)/49.0 enddo enddo !$xmp loop (i,j) on t1(i,j) do j=1, N do i=1, N if(i.eq.1.or.i.eq.N.or.j.eq.1.or.j.eq.N) then if(a1(i,j) .ne. 0) result = 'NG4' else if(a1(i,j) .ne. (j-1)*N+i) result = 'NG5' endif enddo enddo !$xmp loop (i,j) on t2(i,j) do j=1, N do i=1, N if(i.le.2.or.i.ge.N-1.or.j.le.2.or.j.ge.N-1) then if(b1(i,j) .ne. 0.0) result = 'NG6' else if(abs(b1(i,j)-dble((j-1)*N+i)) .gt. 0.000001) $ result = 'NG7' endif enddo enddo !$xmp loop (i,j) on t3(i,j) do j=1, N do i=1, N if(i.le.3.or.i.ge.N-2.or.j.le.3.or.j.ge.N-2) then if(c1(i,j) .ne. 0.0) result = 'NG8' else if(abs(c1(i,j)-real((j-1)*N+i)) .gt. 1) then result = 'NG9' endif endif enddo enddo print *, xmp_node_num(), 'testp101.f ', result end
lgpl-3.0
omni-compiler/omni-compiler
tests/XMP/global-view/reduction/F/plus.f90
1
1729
program main include 'xmp_lib.h' integer,parameter:: N=1000 !$xmp nodes p(4) !$xmp template t(N) !$xmp distribute t(cyclic) onto p integer a(N), sa real*8 b(N), sb real*4 c(N), sc integer procs, w, result, w1(4) !$xmp align a(i) with t(i) !$xmp align b(i) with t(i) !$xmp align c(i) with t(i) sa = 0 sb = 0.0 sc = 0.0 !$xmp loop on t(i) do i=1, N a(i) = 1 b(i) = 0.5 c(i) = 0.01 end do !$xmp loop on t(i) do i=1, N sa = sa+a(i) enddo !$xmp reduction(+:sa) on p(1:2) !$xmp loop on t(i) do i=1, N sb = sb+b(i) enddo !$xmp reduction(+:sb) on p(2:3) !$xmp loop on t(i) do i=1, N sc = sc+c(i) enddo !$xmp reduction(+:sc) on p(3:4) procs = xmp_num_nodes() w1(:) = N/procs result = 0 if(xmp_node_num().eq.1) then if( sa .ne. (w1(1)+w1(2)) .or. abs(sb-(dble(w1(1))*0.5)) .gt. 0.000001 .or. abs(sc-(real(w1(1))*0.01)) .gt. 0.0001) then result = -1 endif else if(xmp_node_num().eq.2) then if( sa .ne. (w1(1)+w1(2)) .or. abs(sb-(dble(w1(2)+w1(3))*0.5)) .gt. 0.000001 .or. abs(sc-(real(w1(2))*0.01)) .gt. 0.0001) then result = -1 endif else if(xmp_node_num().eq.3)then if( sa .ne. (w1(3)) .or. abs(sb-(dble(w1(2)+w1(3))*0.5)) .gt. 0.000001 .or. abs(sc-(real(w1(3)+w1(4))*0.01)) .gt. 0.0001) then result = -1 endif else if(xmp_node_num().eq.4)then if( sa .ne. (w1(4)) .or. abs(sb-(dble(w1(4))*0.5)) .gt. 0.000001 .or. abs(sc-(real(w1(3)+w1(4))*0.01)) .gt. 0.0001) then result = -1 endif endif !$xmp reduction(+:result) !$xmp task on p(1) if( result .eq. 0 ) then write(*,*) "PASS" else write(*,*) "ERROR" call exit(1) endif !$xmp end task end program main
lgpl-3.0
wilmarcardonac/hypermcmc
lapack-3.5.0/SRC/dgelqf.f
55
7572
*> \brief \b DGELQF * * =========== DOCUMENTATION =========== * * Online html documentation available at * http://www.netlib.org/lapack/explore-html/ * *> \htmlonly *> Download DGELQF + dependencies *> <a href="http://www.netlib.org/cgi-bin/netlibfiles.tgz?format=tgz&filename=/lapack/lapack_routine/dgelqf.f"> *> [TGZ]</a> *> <a href="http://www.netlib.org/cgi-bin/netlibfiles.zip?format=zip&filename=/lapack/lapack_routine/dgelqf.f"> *> [ZIP]</a> *> <a href="http://www.netlib.org/cgi-bin/netlibfiles.txt?format=txt&filename=/lapack/lapack_routine/dgelqf.f"> *> [TXT]</a> *> \endhtmlonly * * Definition: * =========== * * SUBROUTINE DGELQF( M, N, A, LDA, TAU, WORK, LWORK, INFO ) * * .. Scalar Arguments .. * INTEGER INFO, LDA, LWORK, M, N * .. * .. Array Arguments .. * DOUBLE PRECISION A( LDA, * ), TAU( * ), WORK( * ) * .. * * *> \par Purpose: * ============= *> *> \verbatim *> *> DGELQF computes an LQ factorization of a real M-by-N matrix A: *> A = L * Q. *> \endverbatim * * Arguments: * ========== * *> \param[in] M *> \verbatim *> M is INTEGER *> The number of rows of the matrix A. M >= 0. *> \endverbatim *> *> \param[in] N *> \verbatim *> N is INTEGER *> The number of columns of the matrix A. N >= 0. *> \endverbatim *> *> \param[in,out] A *> \verbatim *> A is DOUBLE PRECISION array, dimension (LDA,N) *> On entry, the M-by-N matrix A. *> On exit, the elements on and below the diagonal of the array *> contain the m-by-min(m,n) lower trapezoidal matrix L (L is *> lower triangular if m <= n); the elements above the diagonal, *> with the array TAU, represent the orthogonal matrix Q as a *> product of elementary reflectors (see Further Details). *> \endverbatim *> *> \param[in] LDA *> \verbatim *> LDA is INTEGER *> The leading dimension of the array A. LDA >= max(1,M). *> \endverbatim *> *> \param[out] TAU *> \verbatim *> TAU is DOUBLE PRECISION array, dimension (min(M,N)) *> The scalar factors of the elementary reflectors (see Further *> Details). *> \endverbatim *> *> \param[out] WORK *> \verbatim *> WORK is DOUBLE PRECISION array, dimension (MAX(1,LWORK)) *> On exit, if INFO = 0, WORK(1) returns the optimal LWORK. *> \endverbatim *> *> \param[in] LWORK *> \verbatim *> LWORK is INTEGER *> The dimension of the array WORK. LWORK >= max(1,M). *> For optimum performance LWORK >= M*NB, where NB is the *> optimal blocksize. *> *> If LWORK = -1, then a workspace query is assumed; the routine *> only calculates the optimal size of the WORK array, returns *> this value as the first entry of the WORK array, and no error *> message related to LWORK is issued by XERBLA. *> \endverbatim *> *> \param[out] INFO *> \verbatim *> INFO is INTEGER *> = 0: successful exit *> < 0: if INFO = -i, the i-th argument had an illegal value *> \endverbatim * * Authors: * ======== * *> \author Univ. of Tennessee *> \author Univ. of California Berkeley *> \author Univ. of Colorado Denver *> \author NAG Ltd. * *> \date November 2011 * *> \ingroup doubleGEcomputational * *> \par Further Details: * ===================== *> *> \verbatim *> *> The matrix Q is represented as a product of elementary reflectors *> *> Q = H(k) . . . H(2) H(1), where k = min(m,n). *> *> Each H(i) has the form *> *> H(i) = I - tau * v * v**T *> *> where tau is a real scalar, and v is a real vector with *> v(1:i-1) = 0 and v(i) = 1; v(i+1:n) is stored on exit in A(i,i+1:n), *> and tau in TAU(i). *> \endverbatim *> * ===================================================================== SUBROUTINE DGELQF( M, N, A, LDA, TAU, WORK, LWORK, INFO ) * * -- LAPACK computational routine (version 3.4.0) -- * -- LAPACK is a software package provided by Univ. of Tennessee, -- * -- Univ. of California Berkeley, Univ. of Colorado Denver and NAG Ltd..-- * November 2011 * * .. Scalar Arguments .. INTEGER INFO, LDA, LWORK, M, N * .. * .. Array Arguments .. DOUBLE PRECISION A( LDA, * ), TAU( * ), WORK( * ) * .. * * ===================================================================== * * .. Local Scalars .. LOGICAL LQUERY INTEGER I, IB, IINFO, IWS, K, LDWORK, LWKOPT, NB, $ NBMIN, NX * .. * .. External Subroutines .. EXTERNAL DGELQ2, DLARFB, DLARFT, XERBLA * .. * .. Intrinsic Functions .. INTRINSIC MAX, MIN * .. * .. External Functions .. INTEGER ILAENV EXTERNAL ILAENV * .. * .. Executable Statements .. * * Test the input arguments * INFO = 0 NB = ILAENV( 1, 'DGELQF', ' ', M, N, -1, -1 ) LWKOPT = M*NB WORK( 1 ) = LWKOPT LQUERY = ( LWORK.EQ.-1 ) IF( M.LT.0 ) THEN INFO = -1 ELSE IF( N.LT.0 ) THEN INFO = -2 ELSE IF( LDA.LT.MAX( 1, M ) ) THEN INFO = -4 ELSE IF( LWORK.LT.MAX( 1, M ) .AND. .NOT.LQUERY ) THEN INFO = -7 END IF IF( INFO.NE.0 ) THEN CALL XERBLA( 'DGELQF', -INFO ) RETURN ELSE IF( LQUERY ) THEN RETURN END IF * * Quick return if possible * K = MIN( M, N ) IF( K.EQ.0 ) THEN WORK( 1 ) = 1 RETURN END IF * NBMIN = 2 NX = 0 IWS = M IF( NB.GT.1 .AND. NB.LT.K ) THEN * * Determine when to cross over from blocked to unblocked code. * NX = MAX( 0, ILAENV( 3, 'DGELQF', ' ', M, N, -1, -1 ) ) IF( NX.LT.K ) THEN * * Determine if workspace is large enough for blocked code. * LDWORK = M IWS = LDWORK*NB IF( LWORK.LT.IWS ) THEN * * Not enough workspace to use optimal NB: reduce NB and * determine the minimum value of NB. * NB = LWORK / LDWORK NBMIN = MAX( 2, ILAENV( 2, 'DGELQF', ' ', M, N, -1, $ -1 ) ) END IF END IF END IF * IF( NB.GE.NBMIN .AND. NB.LT.K .AND. NX.LT.K ) THEN * * Use blocked code initially * DO 10 I = 1, K - NX, NB IB = MIN( K-I+1, NB ) * * Compute the LQ factorization of the current block * A(i:i+ib-1,i:n) * CALL DGELQ2( IB, N-I+1, A( I, I ), LDA, TAU( I ), WORK, $ IINFO ) IF( I+IB.LE.M ) THEN * * Form the triangular factor of the block reflector * H = H(i) H(i+1) . . . H(i+ib-1) * CALL DLARFT( 'Forward', 'Rowwise', N-I+1, IB, A( I, I ), $ LDA, TAU( I ), WORK, LDWORK ) * * Apply H to A(i+ib:m,i:n) from the right * CALL DLARFB( 'Right', 'No transpose', 'Forward', $ 'Rowwise', M-I-IB+1, N-I+1, IB, A( I, I ), $ LDA, WORK, LDWORK, A( I+IB, I ), LDA, $ WORK( IB+1 ), LDWORK ) END IF 10 CONTINUE ELSE I = 1 END IF * * Use unblocked code to factor the last or only block. * IF( I.LE.K ) $ CALL DGELQ2( M-I+1, N-I+1, A( I, I ), LDA, TAU( I ), WORK, $ IINFO ) * WORK( 1 ) = IWS RETURN * * End of DGELQF * END
gpl-2.0
linzhaoming/origin
vendor/gonum.org/v1/gonum/lapack/internal/testdata/dlasqtest/testdlasq4.f90
59
11159
program testdlasq4 implicit none ! Dlasq4 tests integer :: i0, n0, pp, ttype, iter, nDiv, n, n0in real(kind=8), dimension(401) :: z real(kind=8) :: dmin, desig, qmax, dmin1, dmin2, dn, dn1, dn2, g, tau, sigma logical :: ieee z(1:401) = (/2.9266499599402414D+02, & 2.9276699640004830D+02, & 2.9210200041216615D+02, & 2.9171973344922628D+02, & 2.9254120660184350D+02, & 2.9246923723528141D+02, & 2.8739845025761718D+02, & 2.8713781898215319D+02, & 2.9216230331620721D+02, & 2.9216609319427272D+02, & 2.9037912623973870D+02, & 2.9019341222762625D+02, & 2.9184732870824223D+02, & 2.9211597271231784D+02, & 2.9133173969911888D+02, & 2.9116703928303986D+02, & 2.9158395177813247D+02, & 2.9142053084921997D+02, & 2.8936184155474774D+02, & 2.9014388604362898D+02, & 2.9216722380092682D+02, & 2.9216917065163557D+02, & 2.9033857172870131D+02, & 2.9017428768626024D+02, & 2.9187084534700494D+02, & 2.9185392666684271D+02, & 2.8851014988393416D+02, & 2.8849290783118727D+02, & 2.9182506564169046D+02, & 2.9184679532940385D+02, & 2.9022222656964715D+02, & 2.9051820223150668D+02, & 2.9219746119018231D+02, & 2.9219997046052623D+02, & 2.9076912988009974D+02, & 2.9110108536012547D+02, & 2.9226281758828725D+02, & 2.9246883105892533D+02, & 2.9221612201279271D+02, & 2.9059157967819368D+02, & 2.9112833071623868D+02, & 2.9210680427275844D+02, & 2.9199887004058536D+02, & 2.9151030826460186D+02, & 2.9154564759046622D+02, & 2.9212462005167004D+02, & 2.9212108612522559D+02, & 2.9225720737270348D+02, & 2.9226471402909704D+02, & 2.9186949422820902D+02, & 2.9179442772569342D+02, & 2.9025839700680774D+02, & 2.9028281327393216D+02, & 2.9168280284451140D+02, & 2.9168036127921908D+02, & 2.9115346030764749D+02, & 2.9115401102000044D+02, & 2.9212282665919003D+02, & 2.9212277159409672D+02, & 2.9212554020600300D+02, & 2.9212559651286460D+02, & 2.9050907549403615D+02, & 2.9050344542208029D+02, & 2.9211004769628386D+02, & 2.9211127836880860D+02, & 2.9159257985266015D+02, & 2.9158027318883302D+02, & 2.9042716308833894D+02, & 2.9043622253245718D+02, & 2.9134221002346220D+02, & 2.9134130414047053D+02, & 2.9193179671375327D+02, & 2.9193426987096007D+02, & 2.9145366956406895D+02, & 2.9145119646828226D+02, & 2.9144876630819033D+02, & 2.9145122608379586D+02, & 2.9058395601500280D+02, & 2.9055935887314877D+02, & 2.9123982459393329D+02, & 2.9125037059550806D+02, & 2.9111624624209884D+02, & 2.9110570030194424D+02, & 2.9250004994137356D+02, & 2.9254994096967755D+02, & 2.9166071282413282D+02, & 2.9116180260251298D+02, & 2.8862845048087325D+02, & 2.8925662460652461D+02, & 2.9012609983518610D+02, & 2.9010672249354360D+02, & 2.9142999275190090D+02, & 2.9150806548221971D+02, & 2.9078477842534176D+02, & 2.8840517363552317D+02, & 2.8946267131307206D+02, & 2.9189614533792309D+02, & 2.9232617409967031D+02, & 2.9223702224333306D+02, & 2.9149978725880743D+02, & 2.9168777367421643D+02, & 2.9213296087125275D+02, & 2.9211416223585388D+02, & 2.9151431726536367D+02, & 2.9159900781717892D+02, & 2.9215362494632291D+02, & 2.9214515589728342D+02, & 2.9229900293632022D+02, & 2.9231644811476662D+02, & 2.9119079594655176D+02, & 2.9016344223508082D+02, & 2.9040052826233938D+02, & 2.9146756071890462D+02, & 2.9216592215429023D+02, & 2.9212317137116514D+02, & 2.9220217331561315D+02, & 2.9227234439098311D+02, & 2.9210931773273273D+02, & 2.9139146663504778D+02, & 2.9047426145779627D+02, & 2.9113243832972501D+02, & 2.9163901100086372D+02, & 2.9155399887833846D+02, & 2.9145039523229758D+02, & 2.9151950918932886D+02, & 2.9116352441156198D+02, & 2.9094410515950784D+02, & 2.9056083843332891D+02, & 2.9097140423254604D+02, & 2.9185385310744653D+02, & 2.9181279658894493D+02, & 2.9031697123096876D+02, & 2.9033298229128292D+02, & 2.9212507489852788D+02, & 2.9212491479406674D+02, & 2.9123248207180859D+02, & 2.9123278004625678D+02, & 2.9210890357464513D+02, & 2.9210887378334229D+02, & 2.9240010366769212D+02, & 2.9240021314868147D+02, & 2.9212046105624000D+02, & 2.9212035158139264D+02, & 2.9215242607939217D+02, & 2.9215256473001551D+02, & 2.9086373488934720D+02, & 2.9084987044121846D+02, & 2.9162085042968522D+02, & 2.9163097873649599D+02, & 2.9113228736441005D+02, & 2.9112215911901944D+02, & 2.9210393504686402D+02, & 2.9211255232953414D+02, & 2.9191445519642213D+02, & 2.9182828243114074D+02, & 2.9127013482394887D+02, & 2.9129823908392501D+02, & 2.9220880435635905D+02, & 2.9220599393650343D+02, & 2.9144676491963560D+02, & 2.9145286023012017D+02, & 2.9148058174349006D+02, & 2.9147448649442555D+02, & 2.9186619188590822D+02, & 2.9187731897876392D+02, & 2.9151148084374620D+02, & 2.9150035381231066D+02, & 2.9224292392669071D+02, & 2.9224832614828313D+02, & 2.9140236136264468D+02, & 2.9134833920814032D+02, & 2.9241531971951883D+02, & 2.9247972954055604D+02, & 2.9164613863843044D+02, & 2.8920404894780614D+02, & 2.8913485112658549D+02, & 2.9142701775363003D+02, & 2.9213449277295280D+02, & 2.9191925854858397D+02, & 2.9217029610406047D+02, & 2.9224915292105180D+02, & 2.9220325626287905D+02, & 2.9212439945202976D+02, & 2.9057154227612733D+02, & 2.9093384291672965D+02, & 2.9183595231931184D+02, & 2.9179972231667176D+02, & 2.9133916987034183D+02, & 2.9135453536038978D+02, & 2.9047085843212886D+02, & 2.9031720414585078D+02, & 2.9113106705127024D+02, & 2.9119455617800747D+02, & 2.9230127009862616D+02, & 2.9229492119209442D+02, & 2.9098170102485551D+02, & 2.9110028345622749D+02, & 2.9215236246918653D+02, & 2.9215215113995436D+02, & 2.9124650182241129D+02, & 2.9124684419934567D+02, & 2.9216244260160767D+02, & 2.9216240837005626D+02, & 2.9314769094184447D+02, & 2.9314772207133655D+02, & 2.9212215646682506D+02, & 2.9212184517804621D+02, & 2.9224739389310008D+02, & 2.9224802593241526D+02, & 2.8978611958992855D+02, & 2.8915408641678846D+02, & 2.9118533307571403D+02, & 2.9194553410039072D+02, & 2.9244688594134544D+02, & 2.9237086584501975D+02, & 2.9189894464487475D+02, & 2.9210832103555418D+02, & 2.9227685116407457D+02, & 2.9225842459914986D+02, & 2.9224821267514392D+02, & 2.9226591109467802D+02, & 2.9158625025645608D+02, & 2.9140926612253548D+02, & 2.9125298964526195D+02, & 2.9136239316241648D+02, & 2.9182040805585694D+02, & 2.9171100460012258D+02, & 2.9126693393315793D+02, & 2.9130800749967943D+02, & 2.9084722625682167D+02, & 2.9043649120580767D+02, & 2.9153791610078673D+02, & 2.9210440912405335D+02, & 2.9188686486416555D+02, & 2.9138068978583891D+02, & 2.9158124399039616D+02, & 2.9213540811751852D+02, & 2.9211624446790427D+02, & 2.9138960755567365D+02, & 2.9060415959100914D+02, & 2.9118025885063923D+02, & 2.9132902926505932D+02, & 2.9120918643494110D+02, & 2.9222955158764825D+02, & 2.9236106160611405D+02, & 2.9219941546106151D+02, & 2.9167905448737707D+02, & 2.8956733560159137D+02, & 2.9016660738228080D+02, & 2.9069372888915495D+02, & 2.9058385568123452D+02, & 2.9219861470697771D+02, & 2.9223599112669444D+02, & 2.9150234673408067D+02, & 2.9112858259833354D+02, & 2.9011809831967531D+02, & 2.9046138673473865D+02, & 2.9176526297220903D+02, & 2.9173093419212285D+02, & 2.9150067445343569D+02, & 2.9152418894132262D+02, & 2.9197021328944544D+02, & 2.9194669886297868D+02, & 2.9168012546172463D+02, & 2.9169701864791432D+02, & 2.9061916960844030D+02, & 2.9045023836074438D+02, & 2.9212529304266053D+02, & 2.9217230349727680D+02, & 2.9156357220873417D+02, & 2.9093467723991887D+02, & 2.9015918793416472D+02, & 2.9095983823965622D+02, & 2.9124303667219704D+02, & 2.9116297170306802D+02, & 2.9162557939634507D+02, & 2.9193291492830070D+02, & 2.9138731414547760D+02, & 2.9079978674942083D+02, & 2.9159254111122891D+02, & 2.9228695093326087D+02, & 2.9225423965335352D+02, & 2.9126542837357596D+02, & 2.9173807466948557D+02, & 2.9270696227984581D+02, & 2.9274075480094893D+02, & 2.9210759999419366D+02, & 2.9091701924155882D+02, & 2.9163130710260498D+02, & 2.9157158980248664D+02, & 2.9031984685457667D+02, & 2.8939239820067894D+02, & 2.9070124438246870D+02, & 2.9196350995833507D+02, & 2.9189730956351508D+02, & 2.9047434516138509D+02, & 2.9050934070611282D+02, & 2.9179387236503283D+02, & 2.9179037287198020D+02, & 2.9197909575321057D+02, & 2.9198343084479546D+02, & 2.9146450345905629D+02, & 2.9146016842889151D+02, & 2.9233889755268928D+02, & 2.9234209014701219D+02, & 2.9032302536354865D+02, & 2.8837665454569191D+02, & 2.8923259893670223D+02, & 2.9119948081590582D+02, & 2.9158422265927129D+02, & 2.9138706789415261D+02, & 2.9131767302238063D+02, & 2.9147948119882238D+02, & 2.9186937598758146D+02, & 2.9170756787255982D+02, & 2.9181460198203825D+02, & 2.9210008868832023D+02, & 2.9132088639794199D+02, & 2.9113460155819826D+02, & 2.9159448593680958D+02, & 2.9214172380575934D+02, & 2.9182660907964311D+02, & 2.8938570202792107D+02, & 2.8829979954353007D+02, & 2.9064250900128923D+02, & 2.9110347860364448D+02, & 2.9039527564479215D+02, & 2.9152783923893156D+02, & 2.9213818222324863D+02, & 2.9211881276563861D+02, & 2.9133414472425187D+02, & 2.9125375097531855D+02, & 2.9190226937530139D+02, & 2.9164903795105636D+02, & 2.8851961249369930D+02, & 2.8835729910731652D+02, & 2.9144629542849515D+02, & 2.9171485796658368D+02, & 2.9126891989861593D+02, & 2.9051052150188838D+02, & 2.9113570969073521D+02, & 2.9141652614094619D+02, & 2.9133186866181995D+02, & 2.8912484642922516D+02, & 2.8915669391948876D+02, & 2.9117142770169869D+02, & 2.9117110928821620D+02, & 2.9183490795481288D+02, & 2.9183646161652371D+02, & 2.9254379194824975D+02, & 2.9254363658822064D+02, & 2.9192127768678108D+02, & 2.9192154096878102D+02, & 2.9151073810022524D+02, & 2.9151047487964541D+02, & 2.9013993357169915D+02, & 2.9014000572685774D+02, & 2.9145714571416084D+02, & 2.9145713856006512D+02, & 2.9196091751473017D+02, & 2.9196093255283131D+02, & 2.9195731369267685D+02, & 2.9195729871599588D+02, & 2.9149460806187619D+02, & 2.9149461579988633D+02, & 2.9034687539457741D+02, & 2.9034679862867739D+02, & 2.9010765498373922D+02, & 2.9010767881379803D+02, & 2.8967492890608241D+02, & 2.8967469674750663D+02, & 2.9215189060671338D+02, & 2.9215194287124120D+02, & 2.8956132995364590D+02, & 2.8950907156783751D+02, & 2.9210783379750950D+02, & 2.9211890340058585D+02, & 2.9139896954309916D+02, & 2.9128827357375536D+02, & 2.9190012628763964D+02, & 2.9212457714005234D+02, & 2.9221336158434212D+02, & 2.9217879707919576D+02, & 2.9127472708852724D+02, & 2.9132783649002283D+02, & 2.9227509889951233D+02, & 2.9226978796550475D+02, & 2.9142078378447616D+02, & 2.9142906715955786D+02, & 2.9017517054475991D+02, & 2.8992337408144391D+02, & 2.8477362931531121D+02, & 2.8514676291150971D+02, & 2.8393423954726200D+02, & 2.8313625395453965D+02, & 2.8449999402409759D+02, & 2.8534282615303522D+02, & 2.8523140662657408D+02, & 2.8739845025761718D+02, & 2.8713781898215319D+02, & 0.0000000000000000D+00/) i0 = 1 n0 = 100 pp = 1 n0in = 100 dmin = 7.9798559272231942D+282 dmin1 = 7.9798559272231942D+282 dmin2 = 2.3215857579138407D+285 dn = 2.3140662657409930D+284 dn1 = 7.9798559272231942D+282 dn2 = 8.2833136615500372D+288 g = 2.5000000000000000D-01 tau = 6.1420124051338430D+283 ttype = -4 ieee = .True. print *, "Starting Dlasq4" call Dlasq4(i0, n0, z, pp, n0in, dmin, dmin1, dmin2, dn, dn1, dn2, tau, ttype, g) print *, "Done calling dlasq4" print *, "tau = ", tau print *, tau, ttype, g end
apache-2.0
wilmarcardonac/hypermcmc
lapack-3.5.0/SRC/cgeqlf.f
25
8099
*> \brief \b CGEQLF * * =========== DOCUMENTATION =========== * * Online html documentation available at * http://www.netlib.org/lapack/explore-html/ * *> \htmlonly *> Download CGEQLF + dependencies *> <a href="http://www.netlib.org/cgi-bin/netlibfiles.tgz?format=tgz&filename=/lapack/lapack_routine/cgeqlf.f"> *> [TGZ]</a> *> <a href="http://www.netlib.org/cgi-bin/netlibfiles.zip?format=zip&filename=/lapack/lapack_routine/cgeqlf.f"> *> [ZIP]</a> *> <a href="http://www.netlib.org/cgi-bin/netlibfiles.txt?format=txt&filename=/lapack/lapack_routine/cgeqlf.f"> *> [TXT]</a> *> \endhtmlonly * * Definition: * =========== * * SUBROUTINE CGEQLF( M, N, A, LDA, TAU, WORK, LWORK, INFO ) * * .. Scalar Arguments .. * INTEGER INFO, LDA, LWORK, M, N * .. * .. Array Arguments .. * COMPLEX A( LDA, * ), TAU( * ), WORK( * ) * .. * * *> \par Purpose: * ============= *> *> \verbatim *> *> CGEQLF computes a QL factorization of a complex M-by-N matrix A: *> A = Q * L. *> \endverbatim * * Arguments: * ========== * *> \param[in] M *> \verbatim *> M is INTEGER *> The number of rows of the matrix A. M >= 0. *> \endverbatim *> *> \param[in] N *> \verbatim *> N is INTEGER *> The number of columns of the matrix A. N >= 0. *> \endverbatim *> *> \param[in,out] A *> \verbatim *> A is COMPLEX array, dimension (LDA,N) *> On entry, the M-by-N matrix A. *> On exit, *> if m >= n, the lower triangle of the subarray *> A(m-n+1:m,1:n) contains the N-by-N lower triangular matrix L; *> if m <= n, the elements on and below the (n-m)-th *> superdiagonal contain the M-by-N lower trapezoidal matrix L; *> the remaining elements, with the array TAU, represent the *> unitary matrix Q as a product of elementary reflectors *> (see Further Details). *> \endverbatim *> *> \param[in] LDA *> \verbatim *> LDA is INTEGER *> The leading dimension of the array A. LDA >= max(1,M). *> \endverbatim *> *> \param[out] TAU *> \verbatim *> TAU is COMPLEX array, dimension (min(M,N)) *> The scalar factors of the elementary reflectors (see Further *> Details). *> \endverbatim *> *> \param[out] WORK *> \verbatim *> WORK is COMPLEX array, dimension (MAX(1,LWORK)) *> On exit, if INFO = 0, WORK(1) returns the optimal LWORK. *> \endverbatim *> *> \param[in] LWORK *> \verbatim *> LWORK is INTEGER *> The dimension of the array WORK. LWORK >= max(1,N). *> For optimum performance LWORK >= N*NB, where NB is *> the optimal blocksize. *> *> If LWORK = -1, then a workspace query is assumed; the routine *> only calculates the optimal size of the WORK array, returns *> this value as the first entry of the WORK array, and no error *> message related to LWORK is issued by XERBLA. *> \endverbatim *> *> \param[out] INFO *> \verbatim *> INFO is INTEGER *> = 0: successful exit *> < 0: if INFO = -i, the i-th argument had an illegal value *> \endverbatim * * Authors: * ======== * *> \author Univ. of Tennessee *> \author Univ. of California Berkeley *> \author Univ. of Colorado Denver *> \author NAG Ltd. * *> \date November 2011 * *> \ingroup complexGEcomputational * *> \par Further Details: * ===================== *> *> \verbatim *> *> The matrix Q is represented as a product of elementary reflectors *> *> Q = H(k) . . . H(2) H(1), where k = min(m,n). *> *> Each H(i) has the form *> *> H(i) = I - tau * v * v**H *> *> where tau is a complex scalar, and v is a complex vector with *> v(m-k+i+1:m) = 0 and v(m-k+i) = 1; v(1:m-k+i-1) is stored on exit in *> A(1:m-k+i-1,n-k+i), and tau in TAU(i). *> \endverbatim *> * ===================================================================== SUBROUTINE CGEQLF( M, N, A, LDA, TAU, WORK, LWORK, INFO ) * * -- LAPACK computational routine (version 3.4.0) -- * -- LAPACK is a software package provided by Univ. of Tennessee, -- * -- Univ. of California Berkeley, Univ. of Colorado Denver and NAG Ltd..-- * November 2011 * * .. Scalar Arguments .. INTEGER INFO, LDA, LWORK, M, N * .. * .. Array Arguments .. COMPLEX A( LDA, * ), TAU( * ), WORK( * ) * .. * * ===================================================================== * * .. Local Scalars .. LOGICAL LQUERY INTEGER I, IB, IINFO, IWS, K, KI, KK, LDWORK, LWKOPT, $ MU, NB, NBMIN, NU, NX * .. * .. External Subroutines .. EXTERNAL CGEQL2, CLARFB, CLARFT, XERBLA * .. * .. Intrinsic Functions .. INTRINSIC MAX, MIN * .. * .. External Functions .. INTEGER ILAENV EXTERNAL ILAENV * .. * .. Executable Statements .. * * Test the input arguments * INFO = 0 LQUERY = ( LWORK.EQ.-1 ) IF( M.LT.0 ) THEN INFO = -1 ELSE IF( N.LT.0 ) THEN INFO = -2 ELSE IF( LDA.LT.MAX( 1, M ) ) THEN INFO = -4 END IF * IF( INFO.EQ.0 ) THEN K = MIN( M, N ) IF( K.EQ.0 ) THEN LWKOPT = 1 ELSE NB = ILAENV( 1, 'CGEQLF', ' ', M, N, -1, -1 ) LWKOPT = N*NB END IF WORK( 1 ) = LWKOPT * IF( LWORK.LT.MAX( 1, N ) .AND. .NOT.LQUERY ) THEN INFO = -7 END IF END IF * IF( INFO.NE.0 ) THEN CALL XERBLA( 'CGEQLF', -INFO ) RETURN ELSE IF( LQUERY ) THEN RETURN END IF * * Quick return if possible * IF( K.EQ.0 ) THEN RETURN END IF * NBMIN = 2 NX = 1 IWS = N IF( NB.GT.1 .AND. NB.LT.K ) THEN * * Determine when to cross over from blocked to unblocked code. * NX = MAX( 0, ILAENV( 3, 'CGEQLF', ' ', M, N, -1, -1 ) ) IF( NX.LT.K ) THEN * * Determine if workspace is large enough for blocked code. * LDWORK = N IWS = LDWORK*NB IF( LWORK.LT.IWS ) THEN * * Not enough workspace to use optimal NB: reduce NB and * determine the minimum value of NB. * NB = LWORK / LDWORK NBMIN = MAX( 2, ILAENV( 2, 'CGEQLF', ' ', M, N, -1, $ -1 ) ) END IF END IF END IF * IF( NB.GE.NBMIN .AND. NB.LT.K .AND. NX.LT.K ) THEN * * Use blocked code initially. * The last kk columns are handled by the block method. * KI = ( ( K-NX-1 ) / NB )*NB KK = MIN( K, KI+NB ) * DO 10 I = K - KK + KI + 1, K - KK + 1, -NB IB = MIN( K-I+1, NB ) * * Compute the QL factorization of the current block * A(1:m-k+i+ib-1,n-k+i:n-k+i+ib-1) * CALL CGEQL2( M-K+I+IB-1, IB, A( 1, N-K+I ), LDA, TAU( I ), $ WORK, IINFO ) IF( N-K+I.GT.1 ) THEN * * Form the triangular factor of the block reflector * H = H(i+ib-1) . . . H(i+1) H(i) * CALL CLARFT( 'Backward', 'Columnwise', M-K+I+IB-1, IB, $ A( 1, N-K+I ), LDA, TAU( I ), WORK, LDWORK ) * * Apply H**H to A(1:m-k+i+ib-1,1:n-k+i-1) from the left * CALL CLARFB( 'Left', 'Conjugate transpose', 'Backward', $ 'Columnwise', M-K+I+IB-1, N-K+I-1, IB, $ A( 1, N-K+I ), LDA, WORK, LDWORK, A, LDA, $ WORK( IB+1 ), LDWORK ) END IF 10 CONTINUE MU = M - K + I + NB - 1 NU = N - K + I + NB - 1 ELSE MU = M NU = N END IF * * Use unblocked code to factor the last or only block * IF( MU.GT.0 .AND. NU.GT.0 ) $ CALL CGEQL2( MU, NU, A, LDA, TAU, WORK, IINFO ) * WORK( 1 ) = IWS RETURN * * End of CGEQLF * END
gpl-2.0
e-q/scipy
scipy/sparse/linalg/eigen/arpack/ARPACK/SRC/cngets.f
141
5563
c\BeginDoc c c\Name: cngets c c\Description: c Given the eigenvalues of the upper Hessenberg matrix H, c computes the NP shifts AMU that are zeros of the polynomial of c degree NP which filters out components of the unwanted eigenvectors c corresponding to the AMU's based on some given criteria. c c NOTE: call this even in the case of user specified shifts in order c to sort the eigenvalues, and error bounds of H for later use. c c\Usage: c call cngets c ( ISHIFT, WHICH, KEV, NP, RITZ, BOUNDS ) c c\Arguments c ISHIFT Integer. (INPUT) c Method for selecting the implicit shifts at each iteration. c ISHIFT = 0: user specified shifts c ISHIFT = 1: exact shift with respect to the matrix H. c c WHICH Character*2. (INPUT) c Shift selection criteria. c 'LM' -> want the KEV eigenvalues of largest magnitude. c 'SM' -> want the KEV eigenvalues of smallest magnitude. c 'LR' -> want the KEV eigenvalues of largest REAL part. c 'SR' -> want the KEV eigenvalues of smallest REAL part. c 'LI' -> want the KEV eigenvalues of largest imaginary part. c 'SI' -> want the KEV eigenvalues of smallest imaginary part. c c KEV Integer. (INPUT) c The number of desired eigenvalues. c c NP Integer. (INPUT) c The number of shifts to compute. c c RITZ Complex array of length KEV+NP. (INPUT/OUTPUT) c On INPUT, RITZ contains the the eigenvalues of H. c On OUTPUT, RITZ are sorted so that the unwanted c eigenvalues are in the first NP locations and the wanted c portion is in the last KEV locations. When exact shifts are c selected, the unwanted part corresponds to the shifts to c be applied. Also, if ISHIFT .eq. 1, the unwanted eigenvalues c are further sorted so that the ones with largest Ritz values c are first. c c BOUNDS Complex array of length KEV+NP. (INPUT/OUTPUT) c Error bounds corresponding to the ordering in RITZ. c c c c\EndDoc c c----------------------------------------------------------------------- c c\BeginLib c c\Local variables: c xxxxxx Complex c c\Routines called: c csortc ARPACK sorting routine. c ivout ARPACK utility routine that prints integers. c arscnd ARPACK utility routine for timing. c cvout ARPACK utility routine that prints vectors. c c\Author c Danny Sorensen Phuong Vu c Richard Lehoucq CRPC / Rice University c Dept. of Computational & Houston, Texas c Applied Mathematics c Rice University c Houston, Texas c c\SCCS Information: @(#) c FILE: ngets.F SID: 2.2 DATE OF SID: 4/20/96 RELEASE: 2 c c\Remarks c 1. This routine does not keep complex conjugate pairs of c eigenvalues together. c c\EndLib c c----------------------------------------------------------------------- c subroutine cngets ( ishift, which, kev, np, ritz, bounds) c c %----------------------------------------------------% c | Include files for debugging and timing information | c %----------------------------------------------------% c include 'debug.h' include 'stat.h' c c %------------------% c | Scalar Arguments | c %------------------% c character*2 which integer ishift, kev, np c c %-----------------% c | Array Arguments | c %-----------------% c Complex & bounds(kev+np), ritz(kev+np) c c %------------% c | Parameters | c %------------% c Complex & one, zero parameter (one = (1.0E+0, 0.0E+0), zero = (0.0E+0, 0.0E+0)) c c %---------------% c | Local Scalars | c %---------------% c integer msglvl c c %----------------------% c | External Subroutines | c %----------------------% c external cvout, csortc, arscnd c c %-----------------------% c | Executable Statements | c %-----------------------% c c %-------------------------------% c | Initialize timing statistics | c | & message level for debugging | c %-------------------------------% c call arscnd (t0) msglvl = mcgets c call csortc (which, .true., kev+np, ritz, bounds) c if ( ishift .eq. 1 ) then c c %-------------------------------------------------------% c | Sort the unwanted Ritz values used as shifts so that | c | the ones with largest Ritz estimates are first | c | This will tend to minimize the effects of the | c | forward instability of the iteration when the shifts | c | are applied in subroutine cnapps. | c | Be careful and use 'SM' since we want to sort BOUNDS! | c %-------------------------------------------------------% c call csortc ( 'SM', .true., np, bounds, ritz ) c end if c call arscnd (t1) tcgets = tcgets + (t1 - t0) c if (msglvl .gt. 0) then call ivout (logfil, 1, kev, ndigit, '_ngets: KEV is') call ivout (logfil, 1, np, ndigit, '_ngets: NP is') call cvout (logfil, kev+np, ritz, ndigit, & '_ngets: Eigenvalues of current H matrix ') call cvout (logfil, kev+np, bounds, ndigit, & '_ngets: Ritz estimates of the current KEV+NP Ritz values') end if c return c c %---------------% c | End of cngets | c %---------------% c end
bsd-3-clause
omni-compiler/omni-compiler
samples/XMP/NPB-CG/Local-view/common/print_results.f
16
3698
subroutine print_results(name, class, n1, n2, n3, niter, > nprocs_compiled, nprocs_total, > t, mops, optype, verified, npbversion, > compiletime, cs1, cs2, cs3, cs4, cs5, cs6, cs7) implicit none character*2 name character*1 class integer n1, n2, n3, niter, nprocs_compiled, nprocs_total, j double precision t, mops character optype*24, size*15 logical verified character*(*) npbversion, compiletime, > cs1, cs2, cs3, cs4, cs5, cs6, cs7 write (*, 2) name 2 format(//, ' ', A2, ' Benchmark Completed.') write (*, 3) Class 3 format(' Class = ', 12x, a12) c If this is not a grid-based problem (EP, FT, CG), then c we only print n1, which contains some measure of the c problem size. In that case, n2 and n3 are both zero. c Otherwise, we print the grid size n1xn2xn3 if ((n2 .eq. 0) .and. (n3 .eq. 0)) then if (name(1:2) .eq. 'EP') then write(size, '(f15.0)' ) 2.d0**n1 j = 15 if (size(j:j) .eq. '.') j = j - 1 write (*,42) size(1:j) 42 format(' Size = ',9x, a15) else write (*,44) n1 44 format(' Size = ',12x, i12) endif else write (*, 4) n1,n2,n3 4 format(' Size = ',9x, i4,'x',i4,'x',i4) endif write (*, 5) niter 5 format(' Iterations = ', 12x, i12) write (*, 6) t 6 format(' Time in seconds = ',12x, f12.2) write (*,7) nprocs_total 7 format(' Total processes = ', 12x, i12) write (*,8) nprocs_compiled 8 format(' Compiled procs = ', 12x, i12) write (*,9) mops 9 format(' Mop/s total = ',12x, f12.2) write (*,10) mops/float( nprocs_total ) 10 format(' Mop/s/process = ', 12x, f12.2) write(*, 11) optype 11 format(' Operation type = ', a24) if (verified) then write(*,12) ' SUCCESSFUL' else write(*,12) 'UNSUCCESSFUL' endif 12 format(' Verification = ', 12x, a) write(*,13) npbversion 13 format(' Version = ', 12x, a12) write(*,14) compiletime 14 format(' Compile date = ', 12x, a12) write (*,121) cs1 121 format(/, ' Compile options:', /, > ' MPIF77 = ', A) write (*,122) cs2 122 format(' FLINK = ', A) write (*,123) cs3 123 format(' FMPI_LIB = ', A) write (*,124) cs4 124 format(' FMPI_INC = ', A) write (*,125) cs5 125 format(' FFLAGS = ', A) write (*,126) cs6 126 format(' FLINKFLAGS = ', A) write(*, 127) cs7 127 format(' RAND = ', A) write (*,130) 130 format(//' Please send feedbacks and/or' > ' the results of this run to:'// > ' NPB Development Team '/ > ' Internet: npb@nas.nasa.gov'//) c 130 format(//' Please send the results of this run to:'// c > ' NPB Development Team '/ c > ' Internet: npb@nas.nasa.gov'/ c > ' '/ c > ' If email is not available, send this to:'// c > ' MS T27A-1'/ c > ' NASA Ames Research Center'/ c > ' Moffett Field, CA 94035-1000'// c > ' Fax: 650-604-3957'//) return end
lgpl-3.0
QEF/q-e
PHonon/PH/phcom.f90
1
18048
! ! Copyright (C) 2001-2018 Quantum ESPRESSO group ! This file is distributed under the terms of the ! GNU General Public License. See the file `License' ! in the root directory of the present distribution, ! or http://www.gnu.org/copyleft/gpl.txt . ! !---------------------------------------------------------------------------- ! MODULE modes ! !! Common variables for the phonon program needed to describe the modes !! and the small group of q. ! USE kinds, ONLY : DP ! SAVE ! INTEGER :: nirr !! number of irreducible representations contained in the dynamical matrix INTEGER :: nmodes !! number of modes INTEGER, ALLOCATABLE, TARGET :: npert(:) !(3 * nat ) !! the number of perturbations per IR INTEGER :: npertx !! max number of perturbations per IR COMPLEX (DP), ALLOCATABLE :: u(:,:) !(3 * nat, 3 * nat) !! the transformation modes patterns COMPLEX (DP), ALLOCATABLE :: t(:,:,:,:) !(npertx, npertx, 48,3 * nat), !! the mode for deltarho COMPLEX (DP), ALLOCATABLE :: tmq(:,:,:) !(npertx, npertx, 3 * nat) !! the symmetry in the base of the pattern ! the symmetry q<->-q in the base of the pa ! CHARACTER(15), ALLOCATABLE :: name_rap_mode(:) !! symmetry type of each mode INTEGER, ALLOCATABLE :: num_rap_mode(:) !! number of the representation for each mode ! END MODULE modes ! MODULE cryst_ph ! !! This module contains the variables that describe properties of the !! crystal that are needed by the phonon program and are not in pw data !! probably these variables should be in the common of pw. !! These variables are sets immediately after reading the pw variables. ! USE kinds, ONLY : DP ! SAVE ! LOGICAL :: magnetic_sym !! TRUE in the non-collinear magnetic case ! END MODULE cryst_ph ! MODULE dynmat ! !! The dynamical matrix ! USE kinds, ONLY : DP ! SAVE ! COMPLEX(DP), ALLOCATABLE :: dyn00(:,:) ! (3 * nat, 3 * nat) !! the initial dynamical matrix COMPLEX(DP), ALLOCATABLE :: dyn(:,:) ! (3 * nat, 3 * nat) !! the dynamical matrix COMPLEX(DP), ALLOCATABLE :: dyn_rec(:,:) ! (3 * nat, 3 * nat) !! the contribution of each representation to the dynamical matrix REAL (DP), ALLOCATABLE :: w2(:) ! (3 * nat) !! omega^2 ! ! DFPT+U COMPLEX(DP), ALLOCATABLE :: dyn_hub_bare(:,:) ! (3*nat,*3nat) !! the bare part of the Hubbard dynamical matrix COMPLEX(DP), ALLOCATABLE :: dyn_hub_scf(:,:) ! (3*nat,*3nat) !! the scf part of the Hubbard dynamical matrix ! END MODULE dynmat ! ! MODULE efield_mod ! !! The variables for the electric field perturbation. ! USE kinds, ONLY : DP ! SAVE ! REAL (DP) :: epsilon (3, 3) !! the dielectric constant REAL (DP), ALLOCATABLE :: zstareu(:,:,:) !(3, 3, nat), !! the effective charges Z(E,Us) (E=scf,Us=bare) REAL (DP), ALLOCATABLE :: zstarue(:,:,:) !(3, nat, 3) !! the effective charges Z(Us,E) (Us=scf,E=bare) COMPLEX (DP), ALLOCATABLE :: & zstareu0(:,:), &! 3, 3 * nat), zstarue0(:,:), &! 3 * nat, 3) zstarue0_rec(:,:) ! 3 * nat, 3) ! the effective charges ! END MODULE efield_mod ! ! MODULE nlcc_ph ! !! The variables needed for non-linear core correction. ! USE kinds, ONLY : DP ! SAVE ! COMPLEX (DP), ALLOCATABLE, TARGET :: drc(:,:) ! (ngm, ntyp) !! contain the rhoc (without structure fac) for all atomic types. ! END MODULE nlcc_ph ! ! MODULE phus ! !! These are additional variables needed for the linear response !! program with the US pseudopotentials. ! USE kinds, ONLY : DP USE becmod, ONLY : bec_type ! SAVE ! REAL (DP), ALLOCATABLE :: alphasum(:,:,:,:) ! (nhm*(nhm+1)/2,3,nat,nspin) !! used to compute modes. It contains \(\sum_i \langle \psi_i| d/du !! (|\beta_n><beta_m|) | \psi_i\rangle + (m-n)\) ! dipole moment of each Q. ! These variables contains the five integrals defined in PRB 64, 35118 (2001) COMPLEX (DP), ALLOCATABLE :: int1(:,:,:,:,:) ! nhm, nhm, 3, nat, nspin),& !! int1 -> \int V_eff d/du (Q) d^3r COMPLEX (DP), ALLOCATABLE :: int2(:,:,:,:,:) ! nhm, nhm, 3,nat, nat),& !! int2 -> \int d/du (V_loc) Q d^3r COMPLEX (DP), ALLOCATABLE :: int4(:,:,:,:,:) ! nhm*(nhm+1)/2, 3, 3, nat, nspin),& !! int4 -> \int V_eff d^2/dudu (Q) d^3r COMPLEX (DP), ALLOCATABLE :: int5(:,:,:,:,:) ! nhm*(nhm+1)/2, 3, 3, nat, nat),& !! int5 -> \int d/du (V_loc) d/du (Q) d^3r COMPLEX (DP), ALLOCATABLE :: int1_nc(:,:,:,:,:) ! nhm, nhm, 3, nat, nspin),& !! int1 - noncollinear COMPLEX (DP), ALLOCATABLE :: int2_so(:,:,:,:,:,:) ! nhm, nhm, 3, nat,nat,nspin),& !! int2 - spin-orbit COMPLEX (DP), ALLOCATABLE :: int4_nc(:,:,:,:,:,:) ! nhm, nhm, 3, 3, nat, nspin),& !! int4 - noncollinear COMPLEX (DP), ALLOCATABLE :: int5_so(:,:,:,:,:,:,:) ! nhm*(nhm+1)/2, 3, 3, nat, nat, nspin),& !! int5 - spin-orbit ! ! int3 -> \int d\du (V_Hxc) Q d^3r .... generalized to Delta V_Hxc and move to lr_us in LR_Modules ! COMPLEX (DP), ALLOCATABLE :: becsum_nc(:,:,:,:) ! nhm*(nhm+1)/2,nat,npol,npol) !! it contains \(\sum_i \langle\psi_i | \beta_n\rangle\langle\beta_m| \psi_i \rangle + (m-n)\) COMPLEX (DP), ALLOCATABLE :: becsumort(:,:,:,:) ! nhm*(nhm+1)/2,nat,nspin,3*nat) !! it contains \(\text{alphasum}+\sum_i \langle\psi_i | \beta_n\rangle\langle\beta_m| \delta \psi_i \rangle\) COMPLEX (DP), ALLOCATABLE :: alphasum_nc(:,:,:,:,:) ! nhm*(nhm+1)/2,3,nat,npol,npol) ! ! type(bec_type), ALLOCATABLE, TARGET :: alphap(:,:) ! nkbtot, nbnd, 3, nksq) !! contains \( \langle d\du (\beta_n) | \psi_i \rangle\) ! END MODULE phus ! ! MODULE partial ! !! The variables needed for partial computation of dynamical matrix. ! USE kinds, ONLY : DP ! SAVE ! INTEGER, ALLOCATABLE :: atomo(:) !! (nat) : list of the atoms that moves INTEGER :: nat_todo !! number of atoms to compute INTEGER :: nat_todo_input !! nat_todo given in input LOGICAL, ALLOCATABLE :: comp_irr(:) !(3*nat) !! TRUE if this irr.rep. has to be computed LOGICAL, ALLOCATABLE :: done_irr(:) ! (3*nat) !! TRUE if this irr.rep. has been done LOGICAL :: all_comp !! if TRUE all representation have been computed INTERFACE SUBROUTINE set_local_atomo(nat, nat_todo_, atomo_, nsym, irt, nat_l, atomo_l) IMPLICIT NONE INTEGER,INTENT(IN) :: nat, nat_todo_, nsym, atomo_(nat_todo_), irt(48,nat) !! :nat: total number of atoms !! :nat_todo: number of atoms effectively displaced !! :nsym: number of symmetries in the system !! :atomo: list of atoms to be displaced before symmetrization !! :irt: atoms corresponding atom for each sym operation and atom INTEGER,INTENT(OUT) :: nat_l !! actual number of atoms to be displaced considering symmetries INTEGER,ALLOCATABLE,INTENT(OUT) :: atomo_l(:) !! list with the indeces of all the atoms to be displaced END SUBROUTINE set_local_atomo END INTERFACE END MODULE partial ! MODULE gamma_gamma ! INTEGER, ALLOCATABLE :: has_equivalent(:) !! 0 if the atom has to be calculated INTEGER, ALLOCATABLE :: with_symmetry(:) !! calculated by symmetry INTEGER, ALLOCATABLE :: n_equiv_atoms(:) !! number of equivalent atoms INTEGER, ALLOCATABLE :: equiv_atoms(:,:) !! which atoms are equivalent INTEGER :: n_diff_sites !! Number of different sites INTEGER :: nasr !! atom calculated with asr LOGICAL :: asr !! if TRUE apply the asr ! END MODULE gamma_gamma ! MODULE control_ph ! !! The variables controlling the phonon run. ! USE kinds, ONLY : DP USE parameters, ONLY: npk ! SAVE ! INTEGER, PARAMETER :: maxter = 150 !! maximum number of iterations INTEGER :: niter_ph !! maximum number of iterations (read from input) INTEGER :: nmix_ph !! mixing type INTEGER :: start_irr !! initial representation INTEGER :: last_irr !! last representation of this run INTEGER :: current_iq !! current q point INTEGER :: start_q !! initial q in the list INTEGER :: last_q !! last_q in the list ! REAL(DP) :: tr2_ph !! threshold for phonon calculation REAL(DP) :: alpha_mix(maxter) !! the mixing parameter CHARACTER(LEN=10) :: where_rec='no_recover' !! where the ph run recovered CHARACTER(LEN=12) :: electron_phonon CHARACTER(LEN=256) :: flmixdpot, tmp_dir_ph, tmp_dir_phq INTEGER :: rec_code=-1000 !! code for recover INTEGER :: rec_code_read=-1000 !! code for recover. Not changed during the run LOGICAL :: lgamma_gamma !! if TRUE this is a q=0 computation with k=0 only LOGICAL :: convt !! if TRUE the phonon has converged LOGICAL :: epsil !! if TRUE computes dielec. const and eff. charges LOGICAL :: done_epsil=.FALSE. !! TRUE when diel. constant is available LOGICAL :: trans !! if TRUE computes phonons LOGICAL :: zue !! if TRUE computes eff. charges as induced polarization LOGICAL :: done_zue=.FALSE. !! TRUE when the eff. charges are available LOGICAL :: zeu !! if TRUE computes eff. charges as induced forces LOGICAL :: done_zeu=.FALSE. !! TRUE when the eff. charges are available LOGICAL :: done_start_zstar=.FALSE. ! LOGICAL :: only_wfc=.FALSE. !! if TRUE computes only bands LOGICAL :: only_init=.FALSE. !! if TRUE computes only initial stuff LOGICAL :: with_ext_images=.FALSE. !! if TRUE use an external driver to decide what each image does. LOGICAL :: always_run=.FALSE. !! if TRUE the code do not stop after doing partial representations !! always_run=.TRUE., only for testing purposes LOGICAL :: recover !! if TRUE the run restarts LOGICAL :: low_directory_check=.FALSE. !! if TRUE search on the phsave directory only the representations !! requested in input. LOGICAL :: ext_restart !! if TRUE there is a restart file LOGICAL :: ext_recover !! if TRUE there is a recover file LOGICAL :: lnoloc !! if TRUE calculates the dielectric constant neglecting local field effects LOGICAL :: search_sym=.TRUE. !! if TRUE search the mode symmetry LOGICAL :: search_sym_save=.TRUE. !! save search symmetry LOGICAL :: lnscf !! if TRUE the run makes first a nscf calculation LOGICAL :: ldisp !! if TRUE the run calculates full phonon dispersion LOGICAL :: reduce_io !! if TRUE reduces needed I/O LOGICAL :: done_bands !! if TRUE the bands have been calculated LOGICAL :: bands_computed=.FALSE. !! if TRUE the bands were computed in this run LOGICAL :: nogg !! if TRUE gamma_gamma tricks are disabled LOGICAL :: u_from_file=.FALSE. !! if TRUE the u are on file LOGICAL :: recover_read=.FALSE. !! if TRUE the recover data have been read LOGICAL :: ldiag=.FALSE. !! if TRUE force the diagonalization LOGICAL :: lqdir=.FALSE. !! if TRUE each q writes in its directory LOGICAL :: qplot=.FALSE. !! if TRUE the q are read from input LOGICAL :: xmldyn=.FALSE. !! if TRUE the dynamical matrix is in xml form LOGICAL :: all_done !! if TRUE all representations have been done ! LOGICAL :: newgrid=.FALSE. !! if TRUE use new k-point grid nk1,nk2,nk3 INTEGER :: nk1,nk2,nk3, k1,k2,k3 !! new Monkhorst-Pack k-point grid ! END MODULE control_ph ! ! MODULE freq_ph ! !! The variables for computing frequency dependent dielectric constant. ! USE kinds, ONLY : DP ! SAVE ! LOGICAL :: fpol !! if TRUE dynamic dielectric constant is computed LOGICAL :: done_fpol !! if TRUE all dynamic dielectric constant is computed ! INTEGER :: nfs !! number of frequencies ! INTEGER :: current_iu !! the current frequency ! REAL (KIND=DP), ALLOCATABLE :: fiu(:) !! values of frequency ! REAL (KIND=DP), ALLOCATABLE :: polar(:,:,:) !! values of frequency LOGICAL, ALLOCATABLE :: comp_iu(:) !! values of frequency to calculate in this ru ! LOGICAL, ALLOCATABLE :: done_iu(:) !! values of frequency already calculated ! END MODULE freq_ph ! ! MODULE units_ph ! !! The units of the files and the record lengths. ! SAVE ! INTEGER :: iuvkb !! unit with vkb INTEGER :: iubar !! unit with the part DV_bare INTEGER :: lrbar !! length of the DV_bare INTEGER :: iuebar !! unit with the part DV_bare for the electric field INTEGER :: lrebar !! length of the DV_bare fro the electric field INTEGER :: iupsir !! unit with evc in real space INTEGER :: iudrhous, lrdrhous INTEGER :: iudyn !! the unit for the dynamical matrix INTEGER :: iupdyn !! the unit for the partial dynamical matrix INTEGER :: iunrec !! the unit with the recover data INTEGER :: iudvscf !! the unit where the delta Vscf is written INTEGER :: iudrho !! the unit where the delta rho is written INTEGER :: lrdrho !! the length of the deltarho files INTEGER :: iucom !! the unit of the bare commutator in US case INTEGER :: lrcom !! the length of the bare commutator in US case INTEGER :: iudvkb3, lrdvkb3 INTEGER :: iuint3paw !! the unit of the int3_paw coefficients INTEGER :: lint3paw !! the length of the int3_paw coefficients INTEGER :: iundnsscf !! the unit of dnsscf, for DFPT+U INTEGER :: iudvpsi !! unit of DV_SCF * psi INTEGER :: lrdvpsi !! length of DV_SCF * psi INTEGER :: iugauge !! Unit for reading and writing gauge information in ahc.f90 ! LOGICAL, ALLOCATABLE :: this_dvkb3_is_on_file(:), & this_pcxpsi_is_on_file(:,:) ! END MODULE units_ph ! ! MODULE output ! !! The name of the files. ! SAVE ! CHARACTER (LEN=256) :: fildyn !! output file for the dynamical matrix CHARACTER (LEN=256) :: fildvscf !! output file for deltavscf CHARACTER (LEN=256) :: fildrho !! output file for deltarho ! END MODULE output ! ! MODULE disp ! USE kinds, ONLY: DP ! SAVE ! INTEGER :: nq1, nq2, nq3 !! number of q-points in each direction INTEGER :: nqs !! number of q points to be calculated REAL(DP), ALLOCATABLE :: x_q(:,:) !! coordinates of the q points REAL(DP), ALLOCATABLE :: wq(:) !! for plot REAL(DP), ALLOCATABLE :: omega_disp(:,:) LOGICAL, ALLOCATABLE :: lgamma_iq(:) !! if TRUE this q is gamma. LOGICAL, ALLOCATABLE :: done_iq(:) !! if TRUE this q point has been already calculated LOGICAL, ALLOCATABLE :: comp_iq(:) !! if TRUE this q point has to be calculated ! END MODULE disp MODULE grid_irr_iq ! INTEGER, ALLOCATABLE :: npert_irr_iq(:,:) !! for each q and irr: the number of perturbations INTEGER, ALLOCATABLE :: irr_iq(:) !! number of irreducible representation per q point INTEGER, ALLOCATABLE :: nsymq_iq(:) !! dimension of the small group of q for each q ! LOGICAL, ALLOCATABLE :: comp_irr_iq(:,:) !! for each q and irr: if TRUE this representation has to be calculated LOGICAL, ALLOCATABLE :: done_irr_iq(:,:) !! for each q and irr: if TRUE this representation has been already !! calculated LOGICAL, ALLOCATABLE :: done_elph_iq(:,:) !! for each q and irr: if TRUE the elph of this representation has !! been already calculated LOGICAL, ALLOCATABLE :: done_bands(:) !! nqs, if TRUE the bands of this q have been calculated ! END MODULE grid_irr_iq MODULE ldaU_ph ! USE kinds, ONLY : DP USE parameters, ONLY : ntypx ! SAVE ! ... atomic wfc's at k COMPLEX(DP), ALLOCATABLE, TARGET :: wfcatomk(:,:) !! atomic wfc at k COMPLEX(DP), ALLOCATABLE, TARGET :: dwfcatomk(:,:,:) !! derivative of atomic wfc at k COMPLEX(DP), ALLOCATABLE, TARGET :: sdwfcatomk(:,:) !! S * derivative of atomic wfc at k ! ! ... atomic wfc's at k+q COMPLEX(DP), POINTER :: wfcatomkpq(:,:) !! atomic wfc at k+q COMPLEX(DP), POINTER :: dwfcatomkpq(:,:,:) !! derivative of atomic wfc at k+q COMPLEX(DP), POINTER :: sdwfcatomkpq(:,:) !! S * derivative of atomic wfc at k+q ! COMPLEX(DP), ALLOCATABLE, TARGET :: dvkb(:,:,:) !! derivative of beta funtions at k COMPLEX(DP), POINTER :: vkbkpq(:,:) !! beta funtions at k+q COMPLEX(DP), POINTER :: dvkbkpq(:,:,:) !! derivative of beta funtions at k+q ! ! Various arrays for the response occupation matrix COMPLEX(DP), ALLOCATABLE :: dnsbare(:,:,:,:,:,:) !! bare derivative of ns COMPLEX(DP), ALLOCATABLE :: dnsbare_all_modes(:,:,:,:,:) !! bare derivative of ns for all modes COMPLEX(DP), ALLOCATABLE :: dnsscf_all_modes(:,:,:,:,:) !! SCF derivative of ns for all modes COMPLEX(DP), ALLOCATABLE :: dnsorth(:,:,:,:,:) !! valence component of dns COMPLEX(DP), ALLOCATABLE :: dnsorth_cart(:,:,:,:,:,:) !! same as above, but in cart. coordinates ! COMPLEX (DP), ALLOCATABLE :: proj1(:,:), & proj2(:,:), & projpb(:,:), & projpdb(:,:,:) ! Arrays to store scalar products between vectors ! projpb = <psi|beta> ! projpdb = <psi|dbeta> ! ! LOGICAL :: read_dns_bare !! if TRUE read the first bare derivative of ns from file CHARACTER(LEN=4) :: d2ns_type !! type of approximation to compute the second bare derivative !! of atomic occupation matrix ns ! END MODULE ldaU_ph MODULE nc_mag_aux USE kinds, ONLY : DP SAVE COMPLEX (DP), ALLOCATABLE :: & deeq_nc_save(:,:,:,:,:), & int1_nc_save(:,:,:,:,:,:), & int3_save(:, :, :, :, :, :) END MODULE nc_mag_aux !MODULE qpoint_aux ! USE kinds, ONLY : DP ! USE becmod, ONLY : bec_type ! SAVE ! INTEGER, ALLOCATABLE :: ikmks(:) ! index of -k for magnetic calculations ! INTEGER, ALLOCATABLE :: ikmkmqs(:) ! index of -k-q for magnetic calculations ! TYPE(bec_type), ALLOCATABLE :: becpt(:), alphapt(:,:) !END MODULE qpoint_aux MODULE phcom USE dynmat USE eqv USE efield_mod USE nlcc_ph USE phus USE partial USE control_ph USE freq_ph USE units_ph USE output USE gamma_gamma USE disp USE grid_irr_iq USE ldaU_ph USE nc_mag_aux ! USE qpoint_aux END MODULE phcom
gpl-2.0
wilmarcardonac/hypermcmc
lapack-3.5.0/SRC/zspsv.f
29
6945
*> \brief <b> ZSPSV computes the solution to system of linear equations A * X = B for OTHER matrices</b> * * =========== DOCUMENTATION =========== * * Online html documentation available at * http://www.netlib.org/lapack/explore-html/ * *> \htmlonly *> Download ZSPSV + dependencies *> <a href="http://www.netlib.org/cgi-bin/netlibfiles.tgz?format=tgz&filename=/lapack/lapack_routine/zspsv.f"> *> [TGZ]</a> *> <a href="http://www.netlib.org/cgi-bin/netlibfiles.zip?format=zip&filename=/lapack/lapack_routine/zspsv.f"> *> [ZIP]</a> *> <a href="http://www.netlib.org/cgi-bin/netlibfiles.txt?format=txt&filename=/lapack/lapack_routine/zspsv.f"> *> [TXT]</a> *> \endhtmlonly * * Definition: * =========== * * SUBROUTINE ZSPSV( UPLO, N, NRHS, AP, IPIV, B, LDB, INFO ) * * .. Scalar Arguments .. * CHARACTER UPLO * INTEGER INFO, LDB, N, NRHS * .. * .. Array Arguments .. * INTEGER IPIV( * ) * COMPLEX*16 AP( * ), B( LDB, * ) * .. * * *> \par Purpose: * ============= *> *> \verbatim *> *> ZSPSV computes the solution to a complex system of linear equations *> A * X = B, *> where A is an N-by-N symmetric matrix stored in packed format and X *> and B are N-by-NRHS matrices. *> *> The diagonal pivoting method is used to factor A as *> A = U * D * U**T, if UPLO = 'U', or *> A = L * D * L**T, if UPLO = 'L', *> where U (or L) is a product of permutation and unit upper (lower) *> triangular matrices, D is symmetric and block diagonal with 1-by-1 *> and 2-by-2 diagonal blocks. The factored form of A is then used to *> solve the system of equations A * X = B. *> \endverbatim * * Arguments: * ========== * *> \param[in] UPLO *> \verbatim *> UPLO is CHARACTER*1 *> = 'U': Upper triangle of A is stored; *> = 'L': Lower triangle of A is stored. *> \endverbatim *> *> \param[in] N *> \verbatim *> N is INTEGER *> The number of linear equations, i.e., the order of the *> matrix A. N >= 0. *> \endverbatim *> *> \param[in] NRHS *> \verbatim *> NRHS is INTEGER *> The number of right hand sides, i.e., the number of columns *> of the matrix B. NRHS >= 0. *> \endverbatim *> *> \param[in,out] AP *> \verbatim *> AP is COMPLEX*16 array, dimension (N*(N+1)/2) *> On entry, the upper or lower triangle of the symmetric matrix *> A, packed columnwise in a linear array. The j-th column of A *> is stored in the array AP as follows: *> if UPLO = 'U', AP(i + (j-1)*j/2) = A(i,j) for 1<=i<=j; *> if UPLO = 'L', AP(i + (j-1)*(2n-j)/2) = A(i,j) for j<=i<=n. *> See below for further details. *> *> On exit, the block diagonal matrix D and the multipliers used *> to obtain the factor U or L from the factorization *> A = U*D*U**T or A = L*D*L**T as computed by ZSPTRF, stored as *> a packed triangular matrix in the same storage format as A. *> \endverbatim *> *> \param[out] IPIV *> \verbatim *> IPIV is INTEGER array, dimension (N) *> Details of the interchanges and the block structure of D, as *> determined by ZSPTRF. If IPIV(k) > 0, then rows and columns *> k and IPIV(k) were interchanged, and D(k,k) is a 1-by-1 *> diagonal block. If UPLO = 'U' and IPIV(k) = IPIV(k-1) < 0, *> then rows and columns k-1 and -IPIV(k) were interchanged and *> D(k-1:k,k-1:k) is a 2-by-2 diagonal block. If UPLO = 'L' and *> IPIV(k) = IPIV(k+1) < 0, then rows and columns k+1 and *> -IPIV(k) were interchanged and D(k:k+1,k:k+1) is a 2-by-2 *> diagonal block. *> \endverbatim *> *> \param[in,out] B *> \verbatim *> B is COMPLEX*16 array, dimension (LDB,NRHS) *> On entry, the N-by-NRHS right hand side matrix B. *> On exit, if INFO = 0, the N-by-NRHS solution matrix X. *> \endverbatim *> *> \param[in] LDB *> \verbatim *> LDB is INTEGER *> The leading dimension of the array B. LDB >= max(1,N). *> \endverbatim *> *> \param[out] INFO *> \verbatim *> INFO is INTEGER *> = 0: successful exit *> < 0: if INFO = -i, the i-th argument had an illegal value *> > 0: if INFO = i, D(i,i) is exactly zero. The factorization *> has been completed, but the block diagonal matrix D is *> exactly singular, so the solution could not be *> computed. *> \endverbatim * * Authors: * ======== * *> \author Univ. of Tennessee *> \author Univ. of California Berkeley *> \author Univ. of Colorado Denver *> \author NAG Ltd. * *> \date November 2011 * *> \ingroup complex16OTHERsolve * *> \par Further Details: * ===================== *> *> \verbatim *> *> The packed storage scheme is illustrated by the following example *> when N = 4, UPLO = 'U': *> *> Two-dimensional storage of the symmetric matrix A: *> *> a11 a12 a13 a14 *> a22 a23 a24 *> a33 a34 (aij = aji) *> a44 *> *> Packed storage of the upper triangle of A: *> *> AP = [ a11, a12, a22, a13, a23, a33, a14, a24, a34, a44 ] *> \endverbatim *> * ===================================================================== SUBROUTINE ZSPSV( UPLO, N, NRHS, AP, IPIV, B, LDB, INFO ) * * -- LAPACK driver routine (version 3.4.0) -- * -- LAPACK is a software package provided by Univ. of Tennessee, -- * -- Univ. of California Berkeley, Univ. of Colorado Denver and NAG Ltd..-- * November 2011 * * .. Scalar Arguments .. CHARACTER UPLO INTEGER INFO, LDB, N, NRHS * .. * .. Array Arguments .. INTEGER IPIV( * ) COMPLEX*16 AP( * ), B( LDB, * ) * .. * * ===================================================================== * * .. External Functions .. LOGICAL LSAME EXTERNAL LSAME * .. * .. External Subroutines .. EXTERNAL XERBLA, ZSPTRF, ZSPTRS * .. * .. Intrinsic Functions .. INTRINSIC MAX * .. * .. Executable Statements .. * * Test the input parameters. * INFO = 0 IF( .NOT.LSAME( UPLO, 'U' ) .AND. .NOT.LSAME( UPLO, 'L' ) ) THEN INFO = -1 ELSE IF( N.LT.0 ) THEN INFO = -2 ELSE IF( NRHS.LT.0 ) THEN INFO = -3 ELSE IF( LDB.LT.MAX( 1, N ) ) THEN INFO = -7 END IF IF( INFO.NE.0 ) THEN CALL XERBLA( 'ZSPSV ', -INFO ) RETURN END IF * * Compute the factorization A = U*D*U**T or A = L*D*L**T. * CALL ZSPTRF( UPLO, N, AP, IPIV, INFO ) IF( INFO.EQ.0 ) THEN * * Solve the system A*X = B, overwriting B with X. * CALL ZSPTRS( UPLO, N, NRHS, AP, IPIV, B, LDB, INFO ) * END IF RETURN * * End of ZSPSV * END
gpl-2.0
Punzo/wcslib
Fortran/wcsfix_data.f
1
1901
*======================================================================= * * WCSLIB 7.1 - an implementation of the FITS WCS standard. * Copyright (C) 1995-2020, Mark Calabretta * * This file is part of WCSLIB. * * WCSLIB is free software: you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License as published * by the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * WCSLIB is distributed in the hope that it will be useful, but WITHOUT * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public * License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with WCSLIB. If not, see http://www.gnu.org/licenses. * * Direct correspondence concerning WCSLIB to mark@calabretta.id.au * * Author: Mark Calabretta, Australia Telescope National Facility, CSIRO. * http://www.atnf.csiro.au/people/Mark.Calabretta * $Id: wcsfix_data.f,v 7.1 2019/12/31 13:25:19 mcalabre Exp $ *======================================================================= BLOCK DATA WCSFIX_BLOCK_DATA CHARACTER WCSFIX_ERRMSG(-1:10)*80 COMMON /WCSFIX_DATA/ WCSFIX_ERRMSG DATA WCSFIX_ERRMSG / : 'No change (not an error)', : 'Success', : 'Null wcsprm pointer passed', : 'Memory allocation failed', : 'Linear transformation matrix is singular', : 'Inconsistent or unrecognized coordinate axis types', : 'Invalid parameter value', : 'Invalid coordinate transformation parameters', : 'Ill-conditioned coordinate transformation parameters', : 'All of the corner pixel coordinates are invalid', : 'Could not determine reference pixel coordinate', : 'Could not determine reference pixel value'/ END
lgpl-3.0
wilmarcardonac/hypermcmc
lapack-3.5.0/SRC/dormr2.f
24
7355
*> \brief \b DORMR2 multiplies a general matrix by the orthogonal matrix from a RQ factorization determined by sgerqf (unblocked algorithm). * * =========== DOCUMENTATION =========== * * Online html documentation available at * http://www.netlib.org/lapack/explore-html/ * *> \htmlonly *> Download DORMR2 + dependencies *> <a href="http://www.netlib.org/cgi-bin/netlibfiles.tgz?format=tgz&filename=/lapack/lapack_routine/dormr2.f"> *> [TGZ]</a> *> <a href="http://www.netlib.org/cgi-bin/netlibfiles.zip?format=zip&filename=/lapack/lapack_routine/dormr2.f"> *> [ZIP]</a> *> <a href="http://www.netlib.org/cgi-bin/netlibfiles.txt?format=txt&filename=/lapack/lapack_routine/dormr2.f"> *> [TXT]</a> *> \endhtmlonly * * Definition: * =========== * * SUBROUTINE DORMR2( SIDE, TRANS, M, N, K, A, LDA, TAU, C, LDC, * WORK, INFO ) * * .. Scalar Arguments .. * CHARACTER SIDE, TRANS * INTEGER INFO, K, LDA, LDC, M, N * .. * .. Array Arguments .. * DOUBLE PRECISION A( LDA, * ), C( LDC, * ), TAU( * ), WORK( * ) * .. * * *> \par Purpose: * ============= *> *> \verbatim *> *> DORMR2 overwrites the general real m by n matrix C with *> *> Q * C if SIDE = 'L' and TRANS = 'N', or *> *> Q**T* C if SIDE = 'L' and TRANS = 'T', or *> *> C * Q if SIDE = 'R' and TRANS = 'N', or *> *> C * Q**T if SIDE = 'R' and TRANS = 'T', *> *> where Q is a real orthogonal matrix defined as the product of k *> elementary reflectors *> *> Q = H(1) H(2) . . . H(k) *> *> as returned by DGERQF. Q is of order m if SIDE = 'L' and of order n *> if SIDE = 'R'. *> \endverbatim * * Arguments: * ========== * *> \param[in] SIDE *> \verbatim *> SIDE is CHARACTER*1 *> = 'L': apply Q or Q**T from the Left *> = 'R': apply Q or Q**T from the Right *> \endverbatim *> *> \param[in] TRANS *> \verbatim *> TRANS is CHARACTER*1 *> = 'N': apply Q (No transpose) *> = 'T': apply Q' (Transpose) *> \endverbatim *> *> \param[in] M *> \verbatim *> M is INTEGER *> The number of rows of the matrix C. M >= 0. *> \endverbatim *> *> \param[in] N *> \verbatim *> N is INTEGER *> The number of columns of the matrix C. N >= 0. *> \endverbatim *> *> \param[in] K *> \verbatim *> K is INTEGER *> The number of elementary reflectors whose product defines *> the matrix Q. *> If SIDE = 'L', M >= K >= 0; *> if SIDE = 'R', N >= K >= 0. *> \endverbatim *> *> \param[in] A *> \verbatim *> A is DOUBLE PRECISION array, dimension *> (LDA,M) if SIDE = 'L', *> (LDA,N) if SIDE = 'R' *> The i-th row must contain the vector which defines the *> elementary reflector H(i), for i = 1,2,...,k, as returned by *> DGERQF in the last k rows of its array argument A. *> A is modified by the routine but restored on exit. *> \endverbatim *> *> \param[in] LDA *> \verbatim *> LDA is INTEGER *> The leading dimension of the array A. LDA >= max(1,K). *> \endverbatim *> *> \param[in] TAU *> \verbatim *> TAU is DOUBLE PRECISION array, dimension (K) *> TAU(i) must contain the scalar factor of the elementary *> reflector H(i), as returned by DGERQF. *> \endverbatim *> *> \param[in,out] C *> \verbatim *> C is DOUBLE PRECISION array, dimension (LDC,N) *> On entry, the m by n matrix C. *> On exit, C is overwritten by Q*C or Q**T*C or C*Q**T or C*Q. *> \endverbatim *> *> \param[in] LDC *> \verbatim *> LDC is INTEGER *> The leading dimension of the array C. LDC >= max(1,M). *> \endverbatim *> *> \param[out] WORK *> \verbatim *> WORK is DOUBLE PRECISION array, dimension *> (N) if SIDE = 'L', *> (M) if SIDE = 'R' *> \endverbatim *> *> \param[out] INFO *> \verbatim *> INFO is INTEGER *> = 0: successful exit *> < 0: if INFO = -i, the i-th argument had an illegal value *> \endverbatim * * Authors: * ======== * *> \author Univ. of Tennessee *> \author Univ. of California Berkeley *> \author Univ. of Colorado Denver *> \author NAG Ltd. * *> \date September 2012 * *> \ingroup doubleOTHERcomputational * * ===================================================================== SUBROUTINE DORMR2( SIDE, TRANS, M, N, K, A, LDA, TAU, C, LDC, $ WORK, INFO ) * * -- LAPACK computational routine (version 3.4.2) -- * -- LAPACK is a software package provided by Univ. of Tennessee, -- * -- Univ. of California Berkeley, Univ. of Colorado Denver and NAG Ltd..-- * September 2012 * * .. Scalar Arguments .. CHARACTER SIDE, TRANS INTEGER INFO, K, LDA, LDC, M, N * .. * .. Array Arguments .. DOUBLE PRECISION A( LDA, * ), C( LDC, * ), TAU( * ), WORK( * ) * .. * * ===================================================================== * * .. Parameters .. DOUBLE PRECISION ONE PARAMETER ( ONE = 1.0D+0 ) * .. * .. Local Scalars .. LOGICAL LEFT, NOTRAN INTEGER I, I1, I2, I3, MI, NI, NQ DOUBLE PRECISION AII * .. * .. External Functions .. LOGICAL LSAME EXTERNAL LSAME * .. * .. External Subroutines .. EXTERNAL DLARF, XERBLA * .. * .. Intrinsic Functions .. INTRINSIC MAX * .. * .. Executable Statements .. * * Test the input arguments * INFO = 0 LEFT = LSAME( SIDE, 'L' ) NOTRAN = LSAME( TRANS, 'N' ) * * NQ is the order of Q * IF( LEFT ) THEN NQ = M ELSE NQ = N END IF IF( .NOT.LEFT .AND. .NOT.LSAME( SIDE, 'R' ) ) THEN INFO = -1 ELSE IF( .NOT.NOTRAN .AND. .NOT.LSAME( TRANS, 'T' ) ) THEN INFO = -2 ELSE IF( M.LT.0 ) THEN INFO = -3 ELSE IF( N.LT.0 ) THEN INFO = -4 ELSE IF( K.LT.0 .OR. K.GT.NQ ) THEN INFO = -5 ELSE IF( LDA.LT.MAX( 1, K ) ) THEN INFO = -7 ELSE IF( LDC.LT.MAX( 1, M ) ) THEN INFO = -10 END IF IF( INFO.NE.0 ) THEN CALL XERBLA( 'DORMR2', -INFO ) RETURN END IF * * Quick return if possible * IF( M.EQ.0 .OR. N.EQ.0 .OR. K.EQ.0 ) $ RETURN * IF( ( LEFT .AND. .NOT.NOTRAN ) .OR. ( .NOT.LEFT .AND. NOTRAN ) ) $ THEN I1 = 1 I2 = K I3 = 1 ELSE I1 = K I2 = 1 I3 = -1 END IF * IF( LEFT ) THEN NI = N ELSE MI = M END IF * DO 10 I = I1, I2, I3 IF( LEFT ) THEN * * H(i) is applied to C(1:m-k+i,1:n) * MI = M - K + I ELSE * * H(i) is applied to C(1:m,1:n-k+i) * NI = N - K + I END IF * * Apply H(i) * AII = A( I, NQ-K+I ) A( I, NQ-K+I ) = ONE CALL DLARF( SIDE, MI, NI, A( I, 1 ), LDA, TAU( I ), C, LDC, $ WORK ) A( I, NQ-K+I ) = AII 10 CONTINUE RETURN * * End of DORMR2 * END
gpl-2.0
wilmarcardonac/hypermcmc
lapack-3.5.0/SRC/dgehrd.f
21
10784
*> \brief \b DGEHRD * * =========== DOCUMENTATION =========== * * Online html documentation available at * http://www.netlib.org/lapack/explore-html/ * *> \htmlonly *> Download DGEHRD + dependencies *> <a href="http://www.netlib.org/cgi-bin/netlibfiles.tgz?format=tgz&filename=/lapack/lapack_routine/dgehrd.f"> *> [TGZ]</a> *> <a href="http://www.netlib.org/cgi-bin/netlibfiles.zip?format=zip&filename=/lapack/lapack_routine/dgehrd.f"> *> [ZIP]</a> *> <a href="http://www.netlib.org/cgi-bin/netlibfiles.txt?format=txt&filename=/lapack/lapack_routine/dgehrd.f"> *> [TXT]</a> *> \endhtmlonly * * Definition: * =========== * * SUBROUTINE DGEHRD( N, ILO, IHI, A, LDA, TAU, WORK, LWORK, INFO ) * * .. Scalar Arguments .. * INTEGER IHI, ILO, INFO, LDA, LWORK, N * .. * .. Array Arguments .. * DOUBLE PRECISION A( LDA, * ), TAU( * ), WORK( * ) * .. * * *> \par Purpose: * ============= *> *> \verbatim *> *> DGEHRD reduces a real general matrix A to upper Hessenberg form H by *> an orthogonal similarity transformation: Q**T * A * Q = H . *> \endverbatim * * Arguments: * ========== * *> \param[in] N *> \verbatim *> N is INTEGER *> The order of the matrix A. N >= 0. *> \endverbatim *> *> \param[in] ILO *> \verbatim *> ILO is INTEGER *> \endverbatim *> *> \param[in] IHI *> \verbatim *> IHI is INTEGER *> *> It is assumed that A is already upper triangular in rows *> and columns 1:ILO-1 and IHI+1:N. ILO and IHI are normally *> set by a previous call to DGEBAL; otherwise they should be *> set to 1 and N respectively. See Further Details. *> 1 <= ILO <= IHI <= N, if N > 0; ILO=1 and IHI=0, if N=0. *> \endverbatim *> *> \param[in,out] A *> \verbatim *> A is DOUBLE PRECISION array, dimension (LDA,N) *> On entry, the N-by-N general matrix to be reduced. *> On exit, the upper triangle and the first subdiagonal of A *> are overwritten with the upper Hessenberg matrix H, and the *> elements below the first subdiagonal, with the array TAU, *> represent the orthogonal matrix Q as a product of elementary *> reflectors. See Further Details. *> \endverbatim *> *> \param[in] LDA *> \verbatim *> LDA is INTEGER *> The leading dimension of the array A. LDA >= max(1,N). *> \endverbatim *> *> \param[out] TAU *> \verbatim *> TAU is DOUBLE PRECISION array, dimension (N-1) *> The scalar factors of the elementary reflectors (see Further *> Details). Elements 1:ILO-1 and IHI:N-1 of TAU are set to *> zero. *> \endverbatim *> *> \param[out] WORK *> \verbatim *> WORK is DOUBLE PRECISION array, dimension (LWORK) *> On exit, if INFO = 0, WORK(1) returns the optimal LWORK. *> \endverbatim *> *> \param[in] LWORK *> \verbatim *> LWORK is INTEGER *> The length of the array WORK. LWORK >= max(1,N). *> For optimum performance LWORK >= N*NB, where NB is the *> optimal blocksize. *> *> If LWORK = -1, then a workspace query is assumed; the routine *> only calculates the optimal size of the WORK array, returns *> this value as the first entry of the WORK array, and no error *> message related to LWORK is issued by XERBLA. *> \endverbatim *> *> \param[out] INFO *> \verbatim *> INFO is INTEGER *> = 0: successful exit *> < 0: if INFO = -i, the i-th argument had an illegal value. *> \endverbatim * * Authors: * ======== * *> \author Univ. of Tennessee *> \author Univ. of California Berkeley *> \author Univ. of Colorado Denver *> \author NAG Ltd. * *> \date November 2011 * *> \ingroup doubleGEcomputational * *> \par Further Details: * ===================== *> *> \verbatim *> *> The matrix Q is represented as a product of (ihi-ilo) elementary *> reflectors *> *> Q = H(ilo) H(ilo+1) . . . H(ihi-1). *> *> Each H(i) has the form *> *> H(i) = I - tau * v * v**T *> *> where tau is a real scalar, and v is a real vector with *> v(1:i) = 0, v(i+1) = 1 and v(ihi+1:n) = 0; v(i+2:ihi) is stored on *> exit in A(i+2:ihi,i), and tau in TAU(i). *> *> The contents of A are illustrated by the following example, with *> n = 7, ilo = 2 and ihi = 6: *> *> on entry, on exit, *> *> ( a a a a a a a ) ( a a h h h h a ) *> ( a a a a a a ) ( a h h h h a ) *> ( a a a a a a ) ( h h h h h h ) *> ( a a a a a a ) ( v2 h h h h h ) *> ( a a a a a a ) ( v2 v3 h h h h ) *> ( a a a a a a ) ( v2 v3 v4 h h h ) *> ( a ) ( a ) *> *> where a denotes an element of the original matrix A, h denotes a *> modified element of the upper Hessenberg matrix H, and vi denotes an *> element of the vector defining H(i). *> *> This file is a slight modification of LAPACK-3.0's DGEHRD *> subroutine incorporating improvements proposed by Quintana-Orti and *> Van de Geijn (2006). (See DLAHR2.) *> \endverbatim *> * ===================================================================== SUBROUTINE DGEHRD( N, ILO, IHI, A, LDA, TAU, WORK, LWORK, INFO ) * * -- LAPACK computational routine (version 3.4.0) -- * -- LAPACK is a software package provided by Univ. of Tennessee, -- * -- Univ. of California Berkeley, Univ. of Colorado Denver and NAG Ltd..-- * November 2011 * * .. Scalar Arguments .. INTEGER IHI, ILO, INFO, LDA, LWORK, N * .. * .. Array Arguments .. DOUBLE PRECISION A( LDA, * ), TAU( * ), WORK( * ) * .. * * ===================================================================== * * .. Parameters .. INTEGER NBMAX, LDT PARAMETER ( NBMAX = 64, LDT = NBMAX+1 ) DOUBLE PRECISION ZERO, ONE PARAMETER ( ZERO = 0.0D+0, $ ONE = 1.0D+0 ) * .. * .. Local Scalars .. LOGICAL LQUERY INTEGER I, IB, IINFO, IWS, J, LDWORK, LWKOPT, NB, $ NBMIN, NH, NX DOUBLE PRECISION EI * .. * .. Local Arrays .. DOUBLE PRECISION T( LDT, NBMAX ) * .. * .. External Subroutines .. EXTERNAL DAXPY, DGEHD2, DGEMM, DLAHR2, DLARFB, DTRMM, $ XERBLA * .. * .. Intrinsic Functions .. INTRINSIC MAX, MIN * .. * .. External Functions .. INTEGER ILAENV EXTERNAL ILAENV * .. * .. Executable Statements .. * * Test the input parameters * INFO = 0 NB = MIN( NBMAX, ILAENV( 1, 'DGEHRD', ' ', N, ILO, IHI, -1 ) ) LWKOPT = N*NB WORK( 1 ) = LWKOPT LQUERY = ( LWORK.EQ.-1 ) IF( N.LT.0 ) THEN INFO = -1 ELSE IF( ILO.LT.1 .OR. ILO.GT.MAX( 1, N ) ) THEN INFO = -2 ELSE IF( IHI.LT.MIN( ILO, N ) .OR. IHI.GT.N ) THEN INFO = -3 ELSE IF( LDA.LT.MAX( 1, N ) ) THEN INFO = -5 ELSE IF( LWORK.LT.MAX( 1, N ) .AND. .NOT.LQUERY ) THEN INFO = -8 END IF IF( INFO.NE.0 ) THEN CALL XERBLA( 'DGEHRD', -INFO ) RETURN ELSE IF( LQUERY ) THEN RETURN END IF * * Set elements 1:ILO-1 and IHI:N-1 of TAU to zero * DO 10 I = 1, ILO - 1 TAU( I ) = ZERO 10 CONTINUE DO 20 I = MAX( 1, IHI ), N - 1 TAU( I ) = ZERO 20 CONTINUE * * Quick return if possible * NH = IHI - ILO + 1 IF( NH.LE.1 ) THEN WORK( 1 ) = 1 RETURN END IF * * Determine the block size * NB = MIN( NBMAX, ILAENV( 1, 'DGEHRD', ' ', N, ILO, IHI, -1 ) ) NBMIN = 2 IWS = 1 IF( NB.GT.1 .AND. NB.LT.NH ) THEN * * Determine when to cross over from blocked to unblocked code * (last block is always handled by unblocked code) * NX = MAX( NB, ILAENV( 3, 'DGEHRD', ' ', N, ILO, IHI, -1 ) ) IF( NX.LT.NH ) THEN * * Determine if workspace is large enough for blocked code * IWS = N*NB IF( LWORK.LT.IWS ) THEN * * Not enough workspace to use optimal NB: determine the * minimum value of NB, and reduce NB or force use of * unblocked code * NBMIN = MAX( 2, ILAENV( 2, 'DGEHRD', ' ', N, ILO, IHI, $ -1 ) ) IF( LWORK.GE.N*NBMIN ) THEN NB = LWORK / N ELSE NB = 1 END IF END IF END IF END IF LDWORK = N * IF( NB.LT.NBMIN .OR. NB.GE.NH ) THEN * * Use unblocked code below * I = ILO * ELSE * * Use blocked code * DO 40 I = ILO, IHI - 1 - NX, NB IB = MIN( NB, IHI-I ) * * Reduce columns i:i+ib-1 to Hessenberg form, returning the * matrices V and T of the block reflector H = I - V*T*V**T * which performs the reduction, and also the matrix Y = A*V*T * CALL DLAHR2( IHI, I, IB, A( 1, I ), LDA, TAU( I ), T, LDT, $ WORK, LDWORK ) * * Apply the block reflector H to A(1:ihi,i+ib:ihi) from the * right, computing A := A - Y * V**T. V(i+ib,ib-1) must be set * to 1 * EI = A( I+IB, I+IB-1 ) A( I+IB, I+IB-1 ) = ONE CALL DGEMM( 'No transpose', 'Transpose', $ IHI, IHI-I-IB+1, $ IB, -ONE, WORK, LDWORK, A( I+IB, I ), LDA, ONE, $ A( 1, I+IB ), LDA ) A( I+IB, I+IB-1 ) = EI * * Apply the block reflector H to A(1:i,i+1:i+ib-1) from the * right * CALL DTRMM( 'Right', 'Lower', 'Transpose', $ 'Unit', I, IB-1, $ ONE, A( I+1, I ), LDA, WORK, LDWORK ) DO 30 J = 0, IB-2 CALL DAXPY( I, -ONE, WORK( LDWORK*J+1 ), 1, $ A( 1, I+J+1 ), 1 ) 30 CONTINUE * * Apply the block reflector H to A(i+1:ihi,i+ib:n) from the * left * CALL DLARFB( 'Left', 'Transpose', 'Forward', $ 'Columnwise', $ IHI-I, N-I-IB+1, IB, A( I+1, I ), LDA, T, LDT, $ A( I+1, I+IB ), LDA, WORK, LDWORK ) 40 CONTINUE END IF * * Use unblocked code to reduce the rest of the matrix * CALL DGEHD2( N, I, IHI, A, LDA, TAU, WORK, IINFO ) WORK( 1 ) = IWS * RETURN * * End of DGEHRD * END
gpl-2.0
markusappel/McCode
support/common/pgplot/examples/pgdemo7.f
6
7968
PROGRAM PGDEM7 C C Demonstration program for 3D surface plotting routine FREDDY. C INTEGER PGBEG REAL A(51,51), R, SIZE INTEGER I, J C IF (PGBEG(0, '?', 1, 1) .NE. 1) THEN STOP END IF C C Calculate a sample data array. C DO 20 I=1,51 DO 10 J=1,51 R = (I-26)**2 + (J-26)**2 R = 0.5*SQRT(R) IF (R.GT.0.0) THEN A(I,J) = SIN(R)/R ELSE A(I,J) = 1.0 END IF 10 CONTINUE 20 CONTINUE C C FREDDY assumes the window is square of size SIZE. C SIZE = 1.0 CALL PGENV(0., SIZE, 0., SIZE, 1, -2) CALL FREDDY(A,51,51, SIZE, 25.0) CALL PGEND END C----------------------------------------------------------------------- SUBROUTINE FREDDY(ARRAY,KX,NY,SIZE,ANGLE) INTEGER KX, NY REAL ARRAY(KX,NY), SIZE, ANGLE C C Draws isometric plot of array C REAL FMAX,FMIN,DELTAX,DELTAY,DELTAV,SINE,PEAK,X,DX,HEIGHT INTEGER I,J,KI,KJ,NX,MX,MY,STEP,LEFT,RIGHT,IT,MN,INCX LOGICAL VISBLE COMMON /FREDCM/ DELTAX,X,STEP,LEFT,RIGHT,IT,NX,VISBLE C MN = KX*NY NX = KX C Check array size: IF(NX.LT.2 .OR. NY.LT.2) RETURN FMAX = ARRAY(1,1) FMIN = FMAX DO 20 J=1,NY DO 10 I=1,NX FMIN = AMIN1(ARRAY(I,J),FMIN) FMAX = AMAX1(ARRAY(I,J),FMAX) 10 CONTINUE 20 CONTINUE DELTAX = SIZE/(NX+NY) SINE = SIN(ANGLE/58.) DELTAY = DELTAX*SINE HEIGHT = SIZE*(1.-ABS(SINE)) DELTAV = HEIGHT FMAX = FMAX-FMIN IF(FMAX.LT.0.0001) FMAX = DELTAV DELTAV = DELTAV/FMAX MX = NX+1 MY = NY+1 STEP = MX C C Start PGPLOT buffering. C CALL PGBBUF C C Work our way down the Y axis, then up the X axis, C calculating the Y plotter coordinates for each C column of the plot, doing the hidden-line suppression C at the same time. C DO 50 J=1,NY KJ = MY-J KI = 1 C ( KI,KJ are coordinates of bottom of column) ARRAY(KI,KJ) = DELTAY*(KI+KJ) + DELTAV*(ARRAY(KI,KJ)-FMIN) 30 PEAK = ARRAY(KI,KJ) 40 KI = KI+1 KJ = KJ+1 IF(KI.GT.NX .OR. KJ.GT.NY) GOTO 50 ARRAY(KI,KJ) = DELTAY*(KI+KJ) + DELTAV*(ARRAY(KI,KJ)-FMIN) IF(ARRAY(KI,KJ).GT.PEAK) GOTO 30 IF(ARRAY(KI,KJ).LE.PEAK) ARRAY(KI,KJ) = -ABS(ARRAY(KI,KJ)) GOTO 40 50 CONTINUE C C Now to work our way up the X axis C DO 80 I=2,NX KI = I KJ = 1 ARRAY(KI,KJ) = DELTAY*(KI+KJ)+DELTAV*(ARRAY(KI,KJ)-FMIN) 60 PEAK = ARRAY(KI,KJ) 70 KI = KI+1 KJ = KJ+1 IF(KI.GT.NX .OR. KJ.GT.NY) GOTO 80 ARRAY(KI,KJ) = DELTAY*(KI+KJ)+DELTAV*(ARRAY(KI,KJ)-FMIN) IF(ARRAY(KI,KJ).GT.PEAK) GOTO 60 IF(ARRAY(KI,KJ).LE.PEAK) ARRAY(KI,KJ) = -ABS(ARRAY(KI,KJ)) GOTO 70 80 CONTINUE C C Draw a line along the bottom of the vertical faces C CALL PGMOVE(DELTAX*(NX+NY-2), DELTAY*(MX)) CALL PGDRAW(DELTAX*(NY-1), DELTAY*2) CALL PGDRAW(0.0, DELTAY*MY) C C Array is now ready for plotting. If a point is C positive, then it is to be plotted at that Y C coordinate; if it is negative, then it is C invisible, but at minus that Y coordinate (the point C where the line heading towards it disappears has to C be determined by finding the intersection of it and C the cresting line). C C Plot rows: C DO 110 J=1,NY,2 KJ = MY-J DX = DELTAX*(J-2) X = DX+DELTAX CALL PGMOVE(X,DELTAY*(KJ+1)) CALL PGDRAW(X,ARRAY(1,KJ)) VISBLE = .TRUE. DO 90 I=2,NX RIGHT = I+NX*(KJ-1) LEFT = RIGHT-1 IT = RIGHT X = DX+DELTAX*I CALL FREDGO(ARRAY,MN) 90 CONTINUE C C Now at far end of row so come back C KJ = KJ-1 IF(KJ.LE.0) GOTO 170 VISBLE = ARRAY(NX,KJ).GE.0.0 DX = DELTAX*(NX+J) IF(VISBLE) CALL PGMOVE(DX-DELTAX,ARRAY(NX,KJ)) DELTAX = -DELTAX DO 100 I=2,NX KI = MX-I LEFT = KI+NX*(KJ-1) RIGHT = LEFT+1 IT = LEFT X = DX+DELTAX*I CALL FREDGO(ARRAY,MN) 100 CONTINUE C X = DX+DELTAX*NX IF(.NOT.VISBLE) CALL PGMOVE(X,ARRAY(1,KJ)) CALL PGDRAW(X,DELTAY*(KJ+1)) C (set DELTAX positive for return trip) DELTAX = -DELTAX 110 CONTINUE C C Now do the columns: C as we fell out of the last DO-loop we do the C columns in ascending-X order C INCX = 1 KI = 1 C (set DELTAX -ve since scanning R to L) 120 DX = DELTAX*(KI+NY-1) DELTAX = -DELTAX X = DX+DELTAX CALL PGMOVE(X,ARRAY(1,1)) 130 VISBLE = .TRUE. DO 140 J=2,NY LEFT = KI+NX*(J-1) RIGHT = LEFT-NX IT = LEFT X = DX+DELTAX*J CALL FREDGO(ARRAY,MN) 140 CONTINUE C C At far end, increment X and check still inside array C KI = KI+INCX IF(KI.LE.0 .OR. KI.GT.NX) GOTO 180 VISBLE = ARRAY(KI,NY).GE.0.0 DELTAX = -DELTAX DX = DELTAX*(KI-2) X = DX+DELTAX IF(VISBLE) CALL PGMOVE(X,ARRAY(KI,NY)) DO 150 J=2,NY KJ = MY-J RIGHT = KI+NX*(KJ-1) LEFT = RIGHT+NX IT = RIGHT X = DX+DELTAX*J CALL FREDGO(ARRAY,MN) 150 CONTINUE C X = DX+DELTAX*NY IF(.NOT.VISBLE) CALL PGMOVE(X,ARRAY(KI,1)) IF(KI.EQ.1) GOTO 180 CALL PGDRAW(X,DELTAY*(KI+1)) KI = KI+INCX IF(KI.GT.NX) GOTO 180 IF(KI.EQ.1) GOTO 120 160 DELTAX = -DELTAX DX = DELTAX*(1-KI-NY) X = DX+DELTAX CALL PGMOVE(X,DELTAY*(KI+1)) CALL PGDRAW(X,ARRAY(KI,1)) GOTO 130 C C Do columns backwards because ended rows at far end of X C 170 KI = NX INCX = -1 DX = DELTAX*(KI+NY) GOTO 160 C C 180 CALL PGEBUF END C----------------------------------------------------------------------- SUBROUTINE FREDGO(ARRAY,MN) INTEGER MN REAL ARRAY(MN) C INTEGER STEP,LEFT,RIGHT,IT,NX LOGICAL VISBLE REAL AL,AR,BL,EM,XX,X,Y,DELTAX COMMON /FREDCM/ DELTAX,X,STEP,LEFT,RIGHT,IT,NX,VISBLE C C Test visibility C IF(ARRAY(IT).LT.0.0) GOTO 80 C C This point is visible - was last? C IF(VISBLE) GOTO 50 C C No: calculate point where this line vanishes C 10 IF(LEFT.LE.NX .OR. MOD(LEFT-1,NX).EQ.0 .OR. 1 RIGHT.LE.NX .OR. MOD(RIGHT-1,NX).EQ.0) GOTO 100 AL = ABS(ARRAY(LEFT)) AR = ABS(ARRAY(RIGHT)) IF(ARRAY(LEFT).LT.0.0) GOTO 70 C Right-hand point is crested 20 RIGHT = RIGHT-STEP IF(ARRAY(RIGHT).LT.0.0) GOTO 20 C Left-hand end of cresting line is either C RIGHT+NX or RIGHT-1 LEFT = RIGHT+NX IF(ARRAY(LEFT).LT.0.0) LEFT = RIGHT-1 C C RIGHT and LEFT index into the endpoints of the C cresting line 30 BL = ABS(ARRAY(LEFT)) EM = ABS(ARRAY(RIGHT))-BL XX = EM-AR+AL IF(ABS(XX).LT.0.0001) GOTO 60 XX = (AL-BL)/XX 40 Y = EM*XX+BL IF(DELTAX.GT.0.0) XX = 1.0-XX XX = X-XX*DELTAX IF(VISBLE) GOTO 90 C Drawing a line from an invisible point C to a visible one CALL PGMOVE(XX,Y) VISBLE = .TRUE. 50 CALL PGDRAW(X,ARRAY(IT)) RETURN C 60 XX = 0.5 GOTO 40 C C Left-hand point crested C 70 LEFT = LEFT-STEP IF(ARRAY(LEFT).LT.0.0) GOTO 70 C C Right-hand end of cresting line is either LEFT+1 or LEFT-NX C RIGHT = LEFT+1 IF(ARRAY(RIGHT).LT.0.0) RIGHT = LEFT-NX GOTO 30 C C This point is invisible; if last one was too, then forget it; C else draw a line towards it C 80 IF(.NOT.VISBLE) RETURN GOTO 10 C 90 CALL PGDRAW(XX,Y) 100 VISBLE = .FALSE. RETURN END
gpl-2.0
wilmarcardonac/hypermcmc
lapack-3.5.0/BLAS/SRC/caxpy.f
26
2274
*> \brief \b CAXPY * * =========== DOCUMENTATION =========== * * Online html documentation available at * http://www.netlib.org/lapack/explore-html/ * * Definition: * =========== * * SUBROUTINE CAXPY(N,CA,CX,INCX,CY,INCY) * * .. Scalar Arguments .. * COMPLEX CA * INTEGER INCX,INCY,N * .. * .. Array Arguments .. * COMPLEX CX(*),CY(*) * .. * * *> \par Purpose: * ============= *> *> \verbatim *> *> CAXPY constant times a vector plus a vector. *> \endverbatim * * Authors: * ======== * *> \author Univ. of Tennessee *> \author Univ. of California Berkeley *> \author Univ. of Colorado Denver *> \author NAG Ltd. * *> \date November 2011 * *> \ingroup complex_blas_level1 * *> \par Further Details: * ===================== *> *> \verbatim *> *> jack dongarra, linpack, 3/11/78. *> modified 12/3/93, array(1) declarations changed to array(*) *> \endverbatim *> * ===================================================================== SUBROUTINE CAXPY(N,CA,CX,INCX,CY,INCY) * * -- Reference BLAS level1 routine (version 3.4.0) -- * -- Reference BLAS is a software package provided by Univ. of Tennessee, -- * -- Univ. of California Berkeley, Univ. of Colorado Denver and NAG Ltd..-- * November 2011 * * .. Scalar Arguments .. COMPLEX CA INTEGER INCX,INCY,N * .. * .. Array Arguments .. COMPLEX CX(*),CY(*) * .. * * ===================================================================== * * .. Local Scalars .. INTEGER I,IX,IY * .. * .. External Functions .. REAL SCABS1 EXTERNAL SCABS1 * .. IF (N.LE.0) RETURN IF (SCABS1(CA).EQ.0.0E+0) RETURN IF (INCX.EQ.1 .AND. INCY.EQ.1) THEN * * code for both increments equal to 1 * DO I = 1,N CY(I) = CY(I) + CA*CX(I) END DO ELSE * * code for unequal increments or equal increments * not equal to 1 * IX = 1 IY = 1 IF (INCX.LT.0) IX = (-N+1)*INCX + 1 IF (INCY.LT.0) IY = (-N+1)*INCY + 1 DO I = 1,N CY(IY) = CY(IY) + CA*CX(IX) IX = IX + INCX IY = IY + INCY END DO END IF * RETURN END
gpl-2.0
JohnGBaker/gleam
cmplx_roots_sg.f90
1
56751
! Copyright 2012 Jan Skowron & Andrew Gould ! ! Licensed under the Apache License, Version 2.0 (the "License"); ! you may not use this file except in compliance with the License. ! You may obtain a copy of the License at ! ! http://www.apache.org/licenses/LICENSE-2.0 ! ! Unless required by applicable law or agreed to in writing, software ! distributed under the License is distributed on an "AS IS" BASIS, ! WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. ! See the License for the specific language governing permissions and ! limitations under the License. ! !-------------------------------------------------------------------! ! ! The authors also release this file under the GNU Lesser General ! Public License version 2 or any later version, as well as under ! a "customary scientific license", which implies ! that if this code was important in the scientific process or ! for the results of your scientific work, we ask for the ! appropriate citation of the Paper (Skowron & Gould 2012). ! !-------------------------------------------------------------------! ! ! No Subroutine ! ! 1 cmplx_roots_gen - general polynomial solver, works for random degree, not as fast or robust as cmplx_roots_5 ! 2 cmplx_roots_5 - complex roots finding algorithm taylored for 5th order polynomial (with failsafes for polishing) ! 3 sort_5_points_by_separation - sorting of an array of 5 points, 1st most isolated, 4th and 5th - closest ! 4 sort_5_points_by_separation_i - sorting same as above, returns array of indicies rather than sorted array ! 5 find_2_closest_from_5 - finds closest pair of 5 points ! 6 cmplx_laguerre - Laguerre's method with simplified Adams' stopping criterion ! 7 cmplx_newton_spec - Newton's method with stopping criterion calculated every 10 steps ! 8 cmplx_laguerre2newton - three regime method: Laguerre's, Second-order General method and Newton's ! 9 solve_quadratic_eq - quadratic equation solver ! 10 solve_cubic_eq - cubic equation solver based on Lagrange's method ! 11 divide_poly_1 - division of the polynomial by (x-p) ! ! fortran 90 code ! ! Paper: Skowron & Gould 2012 ! "General Complex Polynomial Root Solver and Its Further Optimization for Binary Microlenses" ! ! for a full text see: ! http://www.astrouw.edu.pl/~jskowron/cmplx_roots_sg/ ! or http://arxiv.org/find/astro-ph ! or http://www.adsabs.harvard.edu/abstract_service.html ! see also file NOTICE and LICENSE ! !-------------------------------------------------------------------! ! _1_ CMPLX_ROOTS_GEN ! !-------------------------------------------------------------------! subroutine cmplx_roots_gen(roots, poly, degree, polish_roots_after, use_roots_as_starting_points) ! This subroutine finds roots of a complex polynomial. ! It is general, however less fast or robust than cmplx_roots_5 ! which contains failsafe checks in the polishing stage, but is ! designed only for 5th order polynomials. ! It uses a new dynamic root finding algorithm (see the Paper). ! ! It can use Laguerre's method (subroutine cmplx_laguerre) ! or Laguerre->SG->Newton method (subroutine ! cmplx_laguerre2newton - this is default choice) to find ! roots. It divides polynomial one by one by found roots. At the ! end it finds last root from Viete's formula for quadratic ! equation. Finally, it polishes all found roots using a full ! polynomial and Newton's or Laguerre's method (default is ! Laguerre's - subroutine cmplx_laguerre). ! You can change default choices by commenting out and uncommenting ! certain lines in the code below. ! ! Note: ! - we solve for the last root with Viete's formula rather ! than doing full Laguerre step (which is time consuming ! and unnecessary) ! - we do not introduce any preference to real roots ! - in Laguerre implementation we omit unneccesarry calculation of ! absolute values of denominator ! - we do not sort roots. If you need to sort ! roots - we have provided sorting subroutine called: ! sort_5_points_by_separation, which sorts points from most ! isolated to most close. Algorithm in this routine can be ! easily used for number of points different than 5. ! implicit none ! roots - array which will hold all roots that had been found. ! If the flag 'use_roots_as_starting_points' is set to ! .true., then instead of point (0,0) we use value from ! this array as starting point for cmplx_laguerre ! poly - is an array of polynomial cooefs, length = degree+1, ! poly(1) is a constant term: ! 1 2 3 ! poly(1) x^0 + poly(2) x^1 + poly(3) x^2 + ... ! degree - degree of the polynomial and size of 'roots' array ! polish_roots_after - after all roots have been found by dividing ! original polynomial by each root found, ! you can opt in to polish all roots using full ! polynomial ! use_roots_as_starting_points - usually we start Laguerre's ! method from point (0,0), but you can decide to use the ! values of 'roots' array as starting point for each new ! root that is searched for. This is useful if you have ! very rough idea where some of the roots can be. ! integer, parameter :: RK = 8 integer, intent(in) :: degree complex(kind=RK), dimension(degree+1), intent(in) :: poly ! coeffs of the polynomial complex(kind=RK), dimension(degree), intent(inout) :: roots logical, intent(in) :: polish_roots_after, use_roots_as_starting_points complex(kind=RK), dimension(degree+1) :: poly2 complex(kind=RK), parameter :: zero = cmplx(0d0,0d0,RK) integer :: i, n, iter logical :: success complex(kind=RK) :: coef, prev poly2=poly ! initialize starting points if(.not.use_roots_as_starting_points) roots=zero ! skip small degree polynomials from doing Laguerre's method if(degree<=1)then if(degree==1) roots(1)=-poly(2)/poly(1) return endif do n=degree, 3, -1 ! find root with Laguerre's method !call cmplx_laguerre(poly2, n, roots(n), iter, success) ! or ! find root with (Laguerre's method -> SG method -> Newton's method) call cmplx_laguerre2newton(poly2, n, roots(n), iter, success, 2) if(.not.success) then roots(n)=zero call cmplx_laguerre(poly2, n, roots(n), iter, success) endif ! divide the polynomial by this root coef=poly2(n+1) do i=n,1,-1 prev=poly2(i) poly2(i)=coef coef=prev+roots(n)*coef enddo ! variable coef now holds a remainder - should be close to 0 enddo ! find all but last root with Laguerre's method !call cmplx_laguerre(poly2, 2, roots(2), iter, success) ! or call cmplx_laguerre2newton(poly2, 2, roots(2), iter, success, 2) if(.not.success) then call solve_quadratic_eq(roots(2),roots(1),poly2) else ! calculate last root from Viete's formula roots(1)=-(roots(2)+poly2(2)/poly2(3)) endif if(polish_roots_after)then do n=1, degree ! polish roots one-by-one with a full polynomial call cmplx_laguerre(poly, degree, roots(n), iter, success) !call cmplx_newton_spec(poly, degree, roots(n), iter, success) enddo endif return end !-------------------------------------------------------------------! ! _2_ CMPLX_ROOTS_5 ! !-------------------------------------------------------------------! subroutine cmplx_roots_5(roots, first_3_roots_order_changed, poly, polish_only) implicit none ! Subroutine finds or polishes roots of a complex polynomial ! (degree=5) ! This routine is especially tailored for solving binary lens ! equation in form of 5th order polynomial. ! ! Use of this routine, in comparission to 'cmplx_roots_gen' can yield ! consideribly faster code, because it makes polishing of the roots ! (that come in as a guess from previous solutions) secure by ! implementing additional checks on the result of polishing. ! If those checks are not satisfied then routine reverts to the ! robust algorithm. These checks are designed to work for 5th order ! polynomial originated from binary lens equation. ! ! Usage: ! ! polish_only == false - I do not know the roots, routine should ! find them from scratch. At the end it ! sorts roots from the most distant to closest. ! Two last roots are the closest (in no particular ! order). ! polish_only = true - I do know the roots pretty well, for example ! I have changed the coefficiens of the polynomial ! only a bit, so the two closest roots are ! most likely still the closest ones. ! If the output flag 'first_3_roots_order_changed' ! is returned as 'false', then first 3 returned roots ! are in the same order as initialy given to the ! routine. The last two roots are the closest ones, ! but in no specific order (!). ! If 'first_3_roots_order_changed' is 'true' then ! it means that all roots had been resorted. ! Two last roots are the closest ones. First is most ! isolated one. ! ! ! If you do not know the position of the roots just use flag ! polish_only=.false. In this case routine will find the roots by ! itself. ! Returns all five roots in the 'roots' array. ! ! poly - is an array of polynomial cooefs, length = degree+1 ! poly(1) x^0 + poly(2) x^1 + poly(3) x^2 + poly(4) x^3 + ... ! roots - roots of the polynomial ('out' and optionally 'in') ! ! ! Jan Skowron 2011 ! integer, parameter :: degree=5 integer, parameter :: RK=8 ! kind for real and complex variables complex(kind=RK), dimension(degree), intent(inout) :: roots logical, intent(out) :: first_3_roots_order_changed complex(kind=RK), dimension(degree+1), intent(in) :: poly logical, intent(in) :: polish_only !------------------------------------------------------------------ ! complex(kind=RK) :: remainder, roots_robust(degree) real(kind=RK) :: d2min integer :: iter, loops, go_to_robust, m, root4, root5, i, i2 complex(kind=RK), dimension(degree+1) :: poly2 !integer, dimension(degree) :: sorted_ind complex(kind=RK), parameter :: zero=cmplx(0d0,0d0,RK) logical :: succ !--------------------------------------- go_to_robust=0 if(.not.polish_only) then ! initialize roots roots=zero go_to_robust=1 endif first_3_roots_order_changed=.false. do loops=1,3 ! ROBUST ! (we do not know the roots) if(go_to_robust>0) then if(go_to_robust>2)then ! something is wrong roots=roots_robust ! return not-polished roots, because polishing creates errors return endif poly2=poly ! copy coeffs do m=degree,4,-1 ! find the roots one-by-one (until 3 are left to be found) call cmplx_laguerre2newton(poly2, m, roots(m), iter, succ, 2) if(.not.succ)then roots(m)=zero call cmplx_laguerre(poly2, m, roots(m), iter, succ) endif ! divide polynomial by this root call divide_poly_1(poly2, remainder, roots(m), poly2, m) enddo ! find last 3 roots with cubic euqation solver (Lagrange's method) call solve_cubic_eq(roots(1),roots(2),roots(3),poly2) ! all roots found ! sort roots - first will be most isolated, last two will be the closest call sort_5_points_by_separation(roots) ! copy roots in case something will go wrong during polishing roots_robust=roots ! set flag, that roots have been resorted first_3_roots_order_changed=.true. endif ! go_to_robust>0 ! POLISH ! (we know the roots approximately, and we guess that last two are closest) !--------------------- poly2=poly ! copy coeffs do m=1,degree-2 !do m=1,degree ! POWN - polish only with Newton (option) ! polish roots with full polynomial call cmplx_newton_spec(poly2, degree, roots(m), iter, succ) if(.not.succ)then ! go back to robust go_to_robust=go_to_robust+1 roots=zero exit endif enddo ! m=1,degree-2 if(succ) then ! comment out division and quadratic if you (POWN) polish with Newton only do m=1,degree-2 call divide_poly_1(poly2, remainder, roots(m), poly2, degree-m+1) enddo ! last two roots are found with quadratic equation solver ! (this is faster and more robust, although little less accurate) call solve_quadratic_eq(roots(degree-1), & roots(degree ),poly2) ! all roots found and polished ! TEST ORDER ! test closest roots if they are the same pair as given to polish call find_2_closest_from_5(root4,root5, d2min, roots) ! check if the closest roots are not too close, this could happen ! when using polishing with Newton only, when two roots erroneously ! colapsed to the same root. This check is not needed for polishing ! 3 roots by Newton and using quadratic for the remaining two. ! If the real roots are so close indeed (very low probability), this will just ! take more time and the unpolished result be returned at the end ! but algorithm will work, and will return accurate enough result !if(d2min<1d-18) then ! POWN - polish only with Newton ! go_to_robust=go_to_robust+1 ! POWN - polish only with Newton !else ! POWN - polish only with Newton if((root4<degree-1).or.(root5<degree-1)) then ! after polishing some of the 3 far roots become one of the 2 closest ones ! go back to robust if(go_to_robust>0)then ! if came from robust ! copy two most isolated roots as starting points for new robust do i=1,degree-3 roots(degree-i+1)=roots_robust(i) enddo else ! came from users initial guess ! copy some 2 roots (except the closest ones) i2=degree do i=1,degree if((i/=root4).and.(i/=root5))then roots(i2)=roots(i) i2=i2-1 endif if(i2<=3) exit ! do not copy those that will be done by cubic in robust enddo endif go_to_robust=go_to_robust+1 else ! root4 and root5 comes from the initial closest pair ! most common case return endif !endif ! POWN - polish only with Newton endif ! !--------------------- enddo ! loops return end !-------------------------------------------------------------------! ! _3_ SORT_5_POINTS_BY_SEPARATION ! !-------------------------------------------------------------------! subroutine sort_5_points_by_separation(points) ! Sort array of five points ! Most isolated point will become the first point in the array ! The closest points will be the last two points in the array ! ! Algorithm works well for all dimensions. We put n=5 as ! a hardcoded value just for optimization purposes. implicit none integer, parameter :: RK=8 integer, parameter :: n=5 ! works for different n as well, but is faster for n as constant (optimization) complex(kind=RK), dimension(n), intent(inout) :: points integer, dimension(n) :: sorted_points complex(kind=RK), dimension(n) :: savepoints integer :: i call sort_5_points_by_separation_i(sorted_points, points) savepoints=points do i=1,n points(i)=savepoints(sorted_points(i)) enddo return end !-------------------------------------------------------------------! ! _4_ SORT_5_POINTS_BY_SEPARATION_I ! !-------------------------------------------------------------------! subroutine sort_5_points_by_separation_i(sorted_points, points) ! Return index array that sorts array of five points ! Index of the most isolated point will appear on the firts place ! of the output array. ! The indices of the closest 2 points will be at the last two ! places in the 'sorted_points' array ! ! Algorithm works well for all dimensions. We put n=5 as ! a hardcoded value just for optimization purposes. implicit none integer, parameter :: RK=8 integer, parameter :: n=5 ! works for different n as well, but is faster for n as constant (optimization) integer, dimension(n), intent(out) :: sorted_points complex(kind=RK), dimension(n), intent(in) :: points real(kind=RK) :: dmin, d1, d2, d real(kind=RK), dimension(n,n) :: distances2 integer :: ki, kj, ind2, put real(kind=RK), dimension(n) :: neigh1st, neigh2nd complex(kind=RK) :: p distances2=1d100 dmin=1d100 do kj=1, n do ki=1, kj-1 p=points(ki)-points(kj) d=conjg(p)*p distances2(ki,kj)=d distances2(kj,ki)=d enddo enddo ! find neighbours neigh1st=1d100 neigh2nd=1d100 do kj=1, n do ki=1, n d=distances2(kj,ki) if(d<neigh2nd(kj))then if(d<neigh1st(kj))then neigh2nd(kj)=neigh1st(kj) neigh1st(kj)=d else neigh2nd(kj)=d endif endif enddo enddo ! initialize sorted_points do ki=1,n sorted_points(ki)=ki enddo ! sort the rest 1..n-2 do kj=2,n d1=neigh1st(kj) d2=neigh2nd(kj) put=1 do ki=kj-1,1,-1 ind2=sorted_points(ki) d=neigh1st(ind2) if(d>=d1) then if(d==d1)then if(neigh2nd(ind2)>d2)then put=ki+1 exit endif else put=ki+1 exit endif endif sorted_points(ki+1)=sorted_points(ki) enddo sorted_points(put)=kj enddo return end !-------------------------------------------------------------------! ! _5_ FIND_2_CLOSEST_FROM_5 ! !-------------------------------------------------------------------! subroutine find_2_closest_from_5(i1,i2, d2min, points) ! Returns indices of the two closest points out of array of 5 implicit none integer, parameter :: RK=8 integer, parameter :: n=5 ! will work for other n too, but it is faster with n as constant integer, intent(out) :: i1, i2 !real(kind=RK), dimension(n,n) :: distances2 complex(kind=RK), dimension(n), intent(in) :: points real(kind=RK), intent(out) :: d2min ! square of minimal distance real(kind=RK) :: d2min1, d2 integer :: i,j complex(kind=RK) :: p d2min1=1d100 do j=1,n !distances2(j,j)=0d0 do i=1,j-1 p=points(i)-points(j) d2=conjg(p)*p !distances2(i,j)=d2 !distances2(j,i)=d2 if(d2<=d2min1)then i1=i i2=j d2min1=d2 endif enddo enddo d2min=d2min1 end !-------------------------------------------------------------------! ! _6_ CMPLX_LAGUERRE ! !-------------------------------------------------------------------! recursive subroutine cmplx_laguerre(poly, degree, root, iter, success) implicit none ! Subroutine finds one root of a complex polynomial using ! Laguerre's method. In every loop it calculates simplified ! Adams' stopping criterion for the value of the polynomial. ! ! Uses 'root' value as a starting point (!!!!!) ! Remember to initialize 'root' to some initial guess or to ! point (0,0) if you have no prior knowledge. ! ! poly - is an array of polynomial cooefs ! length = degree+1, poly(1) is constant ! 1 2 3 ! poly(1) x^0 + poly(2) x^1 + poly(3) x^2 + ... ! degree - a degree of the polynomial ! root - input: guess for the value of a root ! output: a root of the polynomial ! iter - number of iterations performed (the number of polynomial ! evaluations and stopping criterion evaluation) ! success - is false if routine reaches maximum number of iterations ! ! For a summary of the method go to: ! http://en.wikipedia.org/wiki/Laguerre's_method ! integer, parameter :: RK=8 ! kind for real and complex variables integer, parameter :: MAX_ITERS=200 ! Laguerre is used as a failsafe ! constants needed to break cycles in the scheme integer, parameter :: FRAC_JUMP_EVERY=10 integer, parameter :: FRAC_JUMP_LEN=10 real(kind=RK), dimension(FRAC_JUMP_LEN), parameter :: FRAC_JUMPS=(/0.64109297d0, & 0.91577881d0, 0.25921289d0, 0.50487203d0, & 0.08177045d0, 0.13653241d0, 0.306162d0 , & 0.37794326d0, 0.04618805d0, 0.75132137d0/) ! some random numbers real(kind=RK), parameter :: pi = 3.141592653589793d0 real(kind=RK) :: faq ! jump length real(kind=RK), parameter :: FRAC_ERR = 2.0d-15 ! fractional error for kind=8 (see. Adams 1967 Eqs 9 and 10) integer, intent(in) :: degree complex(kind=RK), dimension(degree+1), intent(in) :: poly integer, intent(out) :: iter complex(kind=RK), intent(inout) :: root logical, intent(out) :: success complex(kind=RK) :: p ! value of polynomial complex(kind=RK) :: dp ! value of 1st derivative complex(kind=RK) :: d2p_half ! value of 2nd derivative integer :: i, k logical :: good_to_go !complex(kind=RK) :: G, H, G2 complex(kind=RK) :: denom, denom_sqrt, dx, newroot real(kind=RK) :: ek, absroot, abs2p complex(kind=RK) :: fac_netwon, fac_extra, F_half, c_one_nth real(kind=RK) :: one_nth, n_1_nth, two_n_div_n_1 complex(kind=RK), parameter :: c_one=cmplx(1d0,0d0,RK) complex(kind=RK), parameter :: zero=cmplx(0d0,0d0,RK) real(kind=RK) :: stopping_crit2 !--------------------------------------- iter=0 success=.true. ! next if-endif block is an EXTREME failsafe, not usually needed, and thus turned off in this version. if(.false.)then ! change false-->true if you would like to use caution about having first coefficient == 0 if(degree<0) then write(*,*) 'Error: cmplx_laguerre: degree<0' return endif if(poly(degree+1)==zero) then if(degree==0) return call cmplx_laguerre(poly, degree-1, root, iter, success) return endif if(degree<=1)then if(degree==0) then ! we know from previous check than poly(1) not equal zero success=.false. write(*,*) 'Warning: cmplx_laguerre: degree=0 and poly(1)/=0, no roots' return else root=-poly(1)/poly(2) return endif endif endif ! end EXTREME failsafe good_to_go=.false. one_nth=1d0/degree n_1_nth=(degree-1d0)*one_nth two_n_div_n_1=2d0/n_1_nth c_one_nth=cmplx(one_nth,0d0,RK) do i=1,MAX_ITERS ! prepare stoping criterion ek=abs(poly(degree+1)) absroot=abs(root) ! calculate value of polynomial and its first two derivatives p =poly(degree+1) dp =zero d2p_half=zero do k=degree,1,-1 ! Horner Scheme, see for eg. Numerical Recipes Sec. 5.3 how to evaluate polynomials and derivatives d2p_half=dp + d2p_half*root dp =p + dp*root p =poly(k)+p*root ! b_k ! Adams, Duane A., 1967, "A stopping criterion for polynomial root finding", ! Communications of the ACM, Volume 10 Issue 10, Oct. 1967, p. 655 ! ftp://reports.stanford.edu/pub/cstr/reports/cs/tr/67/55/CS-TR-67-55.pdf ! Eq 8. ek=absroot*ek+abs(p) enddo iter=iter+1 abs2p=conjg(p)*p if(abs2p==0d0) return stopping_crit2=(FRAC_ERR*ek)**2 if(abs2p<stopping_crit2) then ! (simplified a little Eq. 10 of Adams 1967) ! do additional iteration if we are less than 10x from stopping criterion if(abs2p<0.01d0*stopping_crit2) then return ! return immediately, because we are at very good place else good_to_go=.true. ! do one iteration more endif else good_to_go=.false. ! reset if we are outside the zone of the root endif faq=1d0 fac_netwon=p/dp fac_extra=d2p_half/dp F_half=fac_netwon*fac_extra denom_sqrt=sqrt(c_one-two_n_div_n_1*F_half) !G=dp/p ! gradient of ln(p) !G2=G*G !H=G2-2d0*d2p_half/p ! second derivative of ln(p) !denom_sqrt=sqrt( (degree-1)*(degree*H-G2) ) ! NEXT LINE PROBABLY CAN BE COMMENTED OUT if(real(denom_sqrt)>=0d0)then ! real part of a square root is positive for probably all compilers. You can ! test this on your compiler and if so, you can omit this check denom=c_one_nth+n_1_nth*denom_sqrt else denom=c_one_nth-n_1_nth*denom_sqrt endif if(denom==zero)then !test if demoninators are > 0.0 not to divide by zero dx=(absroot+1d0)*exp(cmplx(0d0,FRAC_JUMPS(mod(i,FRAC_JUMP_LEN)+1)*2*pi,RK)) ! make some random jump else dx=fac_netwon/denom !dx=degree/denom endif newroot=root-dx if(newroot==root) return ! nothing changes -> return if(good_to_go)then ! this was jump already after stopping criterion was met root=newroot return endif if(mod(i,FRAC_JUMP_EVERY)==0) then ! decide whether to do a jump of modified length (to break cycles) faq=FRAC_JUMPS(mod(i/FRAC_JUMP_EVERY-1,FRAC_JUMP_LEN)+1) newroot=root-faq*dx ! do jump of some semi-random length (0<faq<1) endif root=newroot enddo success=.false. ! too many iterations here end !-------------------------------------------------------------------! ! _7_ CMPLX_NEWTON_SPEC ! !-------------------------------------------------------------------! recursive subroutine cmplx_newton_spec(poly, degree, root, iter, success) implicit none ! Subroutine finds one root of a complex polynomial using ! Newton's method. It calculates simplified Adams' stopping ! criterion for the value of the polynomial once per 10 iterations (!), ! after initial iteration. This is done to speed up calculations ! when polishing roots that are known preety well, and stopping ! criterion does significantly change in their neighborhood. ! ! Uses 'root' value as a starting point (!!!!!) ! Remember to initialize 'root' to some initial guess. ! Do not initilize 'root' to point (0,0) if the polynomial ! coefficients are strictly real, because it will make going ! to imaginary roots impossible. ! ! poly - is an array of polynomial cooefs ! length = degree+1, poly(1) is constant ! 1 2 3 ! poly(1) x^0 + poly(2) x^1 + poly(3) x^2 + ... ! degree - a degree of the polynomial ! root - input: guess for the value of a root ! output: a root of the polynomial ! iter - number of iterations performed (the number of polynomial ! evaluations) ! success - is false if routine reaches maximum number of iterations ! ! For a summary of the method go to: ! http://en.wikipedia.org/wiki/Newton's_method ! integer, parameter :: RK=8 ! kind for real and complex variables integer, parameter :: MAX_ITERS=50 ! constants needed to break cycles in the scheme integer, parameter :: FRAC_JUMP_EVERY=10 integer, parameter :: FRAC_JUMP_LEN=10 real(kind=RK), dimension(FRAC_JUMP_LEN), parameter :: FRAC_JUMPS=(/0.64109297d0, & 0.91577881d0, 0.25921289d0, 0.50487203d0, & 0.08177045d0, 0.13653241d0, 0.306162d0 , & 0.37794326d0, 0.04618805d0, 0.75132137d0/) ! some random numbers real(kind=8), parameter :: pi = 3.141592653589793d0 real(kind=RK) :: faq ! jump length real(kind=RK), parameter :: FRAC_ERR = 2.0d-15 ! fractional error for kind=8 (see. Adams 1967 Eqs 9 and 10) integer, intent(in) :: degree complex(kind=RK), dimension(degree+1), intent(in) :: poly integer, intent(out) :: iter complex(kind=RK), intent(inout) :: root logical, intent(out) :: success complex(kind=RK) :: p ! value of polynomial complex(kind=RK) :: dp ! value of 1st derivative integer :: i, k logical :: good_to_go complex(kind=RK) :: dx, newroot real(kind=RK) :: ek, absroot, abs2p complex(kind=RK), parameter :: zero=cmplx(0d0,0d0,RK) real(kind=RK) :: stopping_crit2 !--------------------------------------- iter=0 success=.true. ! next if-endif block is an EXTREME failsafe, not usually needed, and thus turned off in this version. if(.false.)then ! change false-->true if you would like to use caution about having first coefficient == 0 if(degree<0) then write(*,*) 'Error: cmplx_newton_spec: degree<0' return endif if(poly(degree+1)==zero) then if(degree==0) return call cmplx_newton_spec(poly, degree-1, root, iter, success) return endif if(degree<=1)then if(degree==0) then ! we know from previous check than poly(1) not equal zero success=.false. write(*,*) 'Warning: cmplx_newton_spec: degree=0 and poly(1)/=0, no roots' return else root=-poly(1)/poly(2) return endif endif endif ! end EXTREME failsafe good_to_go=.false. do i=1,MAX_ITERS faq=1d0 ! prepare stoping criterion ! calculate value of polynomial and its first two derivatives p =poly(degree+1) dp =zero if(mod(i,10)==1) then ! calculate stopping criterion every tenth iteration ek=abs(poly(degree+1)) absroot=abs(root) do k=degree,1,-1 ! Horner Scheme, see for eg. Numerical Recipes Sec. 5.3 how to evaluate polynomials and derivatives dp =p + dp*root p =poly(k)+p*root ! b_k ! Adams, Duane A., 1967, "A stopping criterion for polynomial root finding", ! Communications of the ACM, Volume 10 Issue 10, Oct. 1967, p. 655 ! ftp://reports.stanford.edu/pub/cstr/reports/cs/tr/67/55/CS-TR-67-55.pdf ! Eq 8. ek=absroot*ek+abs(p) enddo stopping_crit2=(FRAC_ERR*ek)**2 else ! calculate just the value and derivative do k=degree,1,-1 ! Horner Scheme, see for eg. Numerical Recipes Sec. 5.3 how to evaluate polynomials and derivatives dp =p + dp*root p =poly(k)+p*root ! b_k enddo endif iter=iter+1 abs2p=conjg(p)*p if(abs2p==0d0) return if(abs2p<stopping_crit2) then ! (simplified a little Eq. 10 of Adams 1967) if(dp==zero) return ! if we have problem with zero, but we are close to the root, just accept ! do additional iteration if we are less than 10x from stopping criterion if(abs2p<0.01d0*stopping_crit2) then return ! return immediately, because we are at very good place else good_to_go=.true. ! do one iteration more endif else good_to_go=.false. ! reset if we are outside the zone of the root endif if(dp==zero)then ! problem with zero dx=(abs(root)+1d0)*exp(cmplx(0d0,FRAC_JUMPS(mod(i,FRAC_JUMP_LEN)+1)*2*pi,RK)) ! make some random jump else dx=p/dp ! Newton method, see http://en.wikipedia.org/wiki/Newton's_method endif newroot=root-dx if(newroot==root) return ! nothing changes -> return if(good_to_go)then ! this was jump already after stopping criterion was met root=newroot return endif if(mod(i,FRAC_JUMP_EVERY)==0) then ! decide whether to do a jump of modified length (to break cycles) faq=FRAC_JUMPS(mod(i/FRAC_JUMP_EVERY-1,FRAC_JUMP_LEN)+1) newroot=root-faq*dx ! do jump of some semi-random length (0<faq<1) endif root=newroot enddo success=.false. return ! too many iterations here end !-------------------------------------------------------------------! ! _8_ CMPLX_LAGUERRE2NEWTON ! !-------------------------------------------------------------------! recursive subroutine cmplx_laguerre2newton(poly, degree, root, iter, success, starting_mode) implicit none ! Subroutine finds one root of a complex polynomial using ! Laguerre's method, Second-order General method and Newton's ! method - depending on the value of function F, which is a ! combination of second derivative, first derivative and ! value of polynomial [F=-(p"*p)/(p'p')]. ! ! Subroutine has 3 modes of operation. It starts with mode=2 ! which is the Laguerre's method, and continues until F ! becames F<0.50, at which point, it switches to mode=1, ! i.e., SG method (see paper). While in the first two ! modes, routine calculates stopping criterion once per every ! iteration. Switch to the last mode, Newton's method, (mode=0) ! happens when becomes F<0.05. In this mode, routine calculates ! stopping criterion only once, at the beginning, under an ! assumption that we are already very close to the root. ! If there are more than 10 iterations in Newton's mode, ! it means that in fact we were far from the root, and ! routine goes back to Laguerre's method (mode=2). ! ! Uses 'root' value as a starting point (!!!!!) ! Remember to initialize 'root' to some initial guess or to ! point (0,0) if you have no prior knowledge. ! ! poly - is an array of polynomial cooefs ! length = degree+1, poly(1) is constant ! 1 2 3 ! poly(1) x^0 + poly(2) x^1 + poly(3) x^2 + ... ! degree - a degree of the polynomial ! root - input: guess for the value of a root ! output: a root of the polynomial ! iter - number of iterations performed (the number of polynomial ! evaluations and stopping criterion evaluation) ! success - is false if routine reaches maximum number of iterations ! starting_mode - this should be by default = 2. However if you ! choose to start with SG method put 1 instead. ! Zero will cause the routine to ! start with Newton for first 10 iterations, and ! then go back to mode 2. ! ! ! For a summary of the method see the paper: Skowron & Gould (2012) ! integer, parameter :: RK=8 ! kind for real and complex variables integer, parameter :: MAX_ITERS=50 ! constants needed to break cycles in the scheme integer, parameter :: FRAC_JUMP_EVERY=10 integer, parameter :: FRAC_JUMP_LEN=10 real(kind=RK), dimension(FRAC_JUMP_LEN), parameter :: FRAC_JUMPS=(/0.64109297d0, & 0.91577881d0, 0.25921289d0, 0.50487203d0, & 0.08177045d0, 0.13653241d0, 0.306162d0 , & 0.37794326d0, 0.04618805d0, 0.75132137d0/) ! some random numbers real(kind=RK), parameter :: pi = 3.141592653589793d0 real(kind=RK) :: faq ! jump length real(kind=RK), parameter :: FRAC_ERR = 2.0d-15 ! fractional error for kind=8 (see. Adams 1967 Eqs 9 and 10) integer, intent(in) :: degree complex(kind=RK), dimension(degree+1), intent(in) :: poly integer, intent(out) :: iter complex(kind=RK), intent(inout) :: root integer, intent(in) :: starting_mode logical, intent(out) :: success complex(kind=RK) :: p ! value of polynomial complex(kind=RK) :: dp ! value of 1st derivative complex(kind=RK) :: d2p_half ! value of 2nd derivative integer :: i, j, k logical :: good_to_go !complex(kind=RK) :: G, H, G2 complex(kind=RK) :: denom, denom_sqrt, dx, newroot real(kind=RK) :: ek, absroot, abs2p, abs2_F_half complex(kind=RK) :: fac_netwon, fac_extra, F_half, c_one_nth real(kind=RK) :: one_nth, n_1_nth, two_n_div_n_1 integer :: mode complex(kind=RK), parameter :: c_one=cmplx(1d0,0d0,RK) complex(kind=RK), parameter :: zero=cmplx(0d0,0d0,RK) real(kind=RK) :: stopping_crit2 iter=0 success=.true. ! next if-endif block is an EXTREME failsafe, not usually needed, and thus turned off in this version. if(.false.)then ! change false-->true if you would like to use caution about having first coefficient == 0 if(degree<0) then write(*,*) 'Error: cmplx_laguerre2newton: degree<0' return endif if(poly(degree+1)==zero) then if(degree==0) return call cmplx_laguerre2newton(poly, degree-1, root, iter, success, starting_mode) return endif if(degree<=1)then if(degree==0) then ! we know from previous check than poly(1) not equal zero success=.false. write(*,*) 'Warning: cmplx_laguerre2newton: degree=0 and poly(1)/=0, no roots' return else root=-poly(1)/poly(2) return endif endif endif ! end EXTREME failsafe j=1 good_to_go=.false. mode=starting_mode ! mode=2 full laguerre, mode=1 SG, mode=0 newton do ! infinite loop, just to be able to come back from newton, if more than 10 iteration there !------------------------------------------------------------- mode 2 if(mode>=2) then ! LAGUERRE'S METHOD one_nth=1d0/degree n_1_nth=(degree-1d0)*one_nth two_n_div_n_1=2d0/n_1_nth c_one_nth=cmplx(one_nth,0d0,RK) do i=1,MAX_ITERS ! faq=1d0 ! prepare stoping criterion ek=abs(poly(degree+1)) absroot=abs(root) ! calculate value of polynomial and its first two derivatives p =poly(degree+1) dp =zero d2p_half=zero do k=degree,1,-1 ! Horner Scheme, see for eg. Numerical Recipes Sec. 5.3 how to evaluate polynomials and derivatives d2p_half=dp + d2p_half*root dp =p + dp*root p =poly(k)+p*root ! b_k ! Adams, Duane A., 1967, "A stopping criterion for polynomial root finding", ! Communications of the ACM, Volume 10 Issue 10, Oct. 1967, p. 655 ! ftp://reports.stanford.edu/pub/cstr/reports/cs/tr/67/55/CS-TR-67-55.pdf ! Eq 8. ek=absroot*ek+abs(p) enddo abs2p=conjg(p)*p !abs(p) iter=iter+1 if(abs2p==0d0) return stopping_crit2=(FRAC_ERR*ek)**2 if(abs2p<stopping_crit2) then ! (simplified a little Eq. 10 of Adams 1967) ! do additional iteration if we are less than 10x from stopping criterion if(abs2p<0.01d0*stopping_crit2) then ! ten times better than stopping criterion return ! return immediately, because we are at very good place else good_to_go=.true. ! do one iteration more endif else good_to_go=.false. ! reset if we are outside the zone of the root endif fac_netwon=p/dp fac_extra=d2p_half/dp F_half=fac_netwon*fac_extra abs2_F_half=conjg(F_half)*F_half if(abs2_F_half<=0.0625d0)then ! F<0.50, F/2<0.25 ! go to SG method if(abs2_F_half<=0.000625d0)then ! F<0.05, F/2<0.025 mode=0 ! go to Newton's else mode=1 ! go to SG endif endif denom_sqrt=sqrt(c_one-two_n_div_n_1*F_half) ! NEXT LINE PROBABLY CAN BE COMMENTED OUT if(real(denom_sqrt)>=0d0)then ! real part of a square root is positive for probably all compilers. You can ! test this on your compiler and if so, you can omit this check denom=c_one_nth+n_1_nth*denom_sqrt else denom=c_one_nth-n_1_nth*denom_sqrt endif if(denom==zero)then !test if demoninators are > 0.0 not to divide by zero dx=(abs(root)+1d0)*exp(cmplx(0d0,FRAC_JUMPS(mod(i,FRAC_JUMP_LEN)+1)*2*pi,RK)) ! make some random jump else dx=fac_netwon/denom endif newroot=root-dx if(newroot==root) return ! nothing changes -> return if(good_to_go)then ! this was jump already after stopping criterion was met root=newroot return endif if(mode/=2) then root=newroot j=i+1 ! remember iteration index exit ! go to Newton's or SG endif if(mod(i,FRAC_JUMP_EVERY)==0) then ! decide whether to do a jump of modified length (to break cycles) faq=FRAC_JUMPS(mod(i/FRAC_JUMP_EVERY-1,FRAC_JUMP_LEN)+1) newroot=root-faq*dx ! do jump of some semi-random length (0<faq<1) endif root=newroot enddo ! do mode 2 if(i>=MAX_ITERS) then success=.false. return endif endif ! if mode 2 !------------------------------------------------------------- mode 1 if(mode==1) then ! SECOND-ORDER GENERAL METHOD (SG) do i=j,MAX_ITERS ! faq=1d0 ! calculate value of polynomial and its first two derivatives p =poly(degree+1) dp =zero d2p_half=zero if(mod(i-j,10)==0)then ! prepare stoping criterion ek=abs(poly(degree+1)) absroot=abs(root) do k=degree,1,-1 ! Horner Scheme, see for eg. Numerical Recipes Sec. 5.3 how to evaluate polynomials and derivatives d2p_half=dp + d2p_half*root dp =p + dp*root p =poly(k)+p*root ! b_k ! Adams, Duane A., 1967, "A stopping criterion for polynomial root finding", ! Communications of the ACM, Volume 10 Issue 10, Oct. 1967, p. 655 ! ftp://reports.stanford.edu/pub/cstr/reports/cs/tr/67/55/CS-TR-67-55.pdf ! Eq 8. ek=absroot*ek+abs(p) enddo stopping_crit2=(FRAC_ERR*ek)**2 else do k=degree,1,-1 ! Horner Scheme, see for eg. Numerical Recipes Sec. 5.3 how to evaluate polynomials and derivatives d2p_half=dp + d2p_half*root dp =p + dp*root p =poly(k)+p*root ! b_k enddo endif abs2p=conjg(p)*p !abs(p)**2 iter=iter+1 if(abs2p==0d0) return if(abs2p<stopping_crit2) then ! (simplified a little Eq. 10 of Adams 1967) if(dp==zero) return ! do additional iteration if we are less than 10x from stopping criterion if(abs2p<0.01d0*stopping_crit2) then ! ten times better than stopping criterion return ! return immediately, because we are at very good place else good_to_go=.true. ! do one iteration more endif else good_to_go=.false. ! reset if we are outside the zone of the root endif if(dp==zero)then !test if demoninators are > 0.0 not to divide by zero dx=(abs(root)+1d0)*exp(cmplx(0d0,FRAC_JUMPS(mod(i,FRAC_JUMP_LEN)+1)*2*pi,RK)) ! make some random jump else fac_netwon=p/dp fac_extra=d2p_half/dp F_half=fac_netwon*fac_extra abs2_F_half=conjg(F_half)*F_half if(abs2_F_half<=0.000625d0)then ! F<0.05, F/2<0.025 mode=0 ! set Newton's, go there after jump endif dx=fac_netwon*(c_one+F_half) ! SG endif newroot=root-dx if(newroot==root) return ! nothing changes -> return if(good_to_go)then ! this was jump already after stopping criterion was met root=newroot return endif if(mode/=1) then root=newroot j=i+1 ! remember iteration number exit ! go to Newton's endif if(mod(i,FRAC_JUMP_EVERY)==0) then ! decide whether to do a jump of modified length (to break cycles) faq=FRAC_JUMPS(mod(i/FRAC_JUMP_EVERY-1,FRAC_JUMP_LEN)+1) newroot=root-faq*dx ! do jump of some semi-random length (0<faq<1) endif root=newroot enddo ! do mode 1 if(i>=MAX_ITERS) then success=.false. return endif endif ! if mode 1 !------------------------------------------------------------- mode 0 if(mode==0) then ! NEWTON'S METHOD do i=j,j+10 ! do only 10 iterations the most, then go back to full Laguerre's faq=1d0 ! calculate value of polynomial and its first two derivatives p =poly(degree+1) dp =zero if(i==j)then ! calculate stopping crit only once at the begining ! prepare stoping criterion ek=abs(poly(degree+1)) absroot=abs(root) do k=degree,1,-1 ! Horner Scheme, see for eg. Numerical Recipes Sec. 5.3 how to evaluate polynomials and derivatives dp =p + dp*root p =poly(k)+p*root ! b_k ! Adams, Duane A., 1967, "A stopping criterion for polynomial root finding", ! Communications of the ACM, Volume 10 Issue 10, Oct. 1967, p. 655 ! ftp://reports.stanford.edu/pub/cstr/reports/cs/tr/67/55/CS-TR-67-55.pdf ! Eq 8. ek=absroot*ek+abs(p) enddo stopping_crit2=(FRAC_ERR*ek)**2 else ! do k=degree,1,-1 ! Horner Scheme, see for eg. Numerical Recipes Sec. 5.3 how to evaluate polynomials and derivatives dp =p + dp*root p =poly(k)+p*root ! b_k enddo endif abs2p=conjg(p)*p !abs(p)**2 iter=iter+1 if(abs2p==0d0) return if(abs2p<stopping_crit2) then ! (simplified a little Eq. 10 of Adams 1967) if(dp==zero) return ! do additional iteration if we are less than 10x from stopping criterion if(abs2p<0.01d0*stopping_crit2) then ! ten times better than stopping criterion return ! return immediately, because we are at very good place else good_to_go=.true. ! do one iteration more endif else good_to_go=.false. ! reset if we are outside the zone of the root endif if(dp==zero)then ! test if demoninators are > 0.0 not to divide by zero dx=(abs(root)+1d0)*exp(cmplx(0d0,FRAC_JUMPS(mod(i,FRAC_JUMP_LEN)+1)*2*pi,RK)) ! make some random jump else dx=p/dp endif newroot=root-dx if(newroot==root) return ! nothing changes -> return if(good_to_go)then root=newroot return endif ! this loop is done only 10 times. So skip this check !if(mod(i,FRAC_JUMP_EVERY)==0) then ! decide whether to do a jump of modified length (to break cycles) ! faq=FRAC_JUMPS(mod(i/FRAC_JUMP_EVERY-1,FRAC_JUMP_LEN)+1) ! newroot=root-faq*dx ! do jump of some semi-random length (0<faq<1) !endif root=newroot enddo ! do mode 0 10 times if(iter>=MAX_ITERS) then ! too many iterations here success=.false. return endif mode=2 ! go back to Laguerre's. This happens when we were unable to converge in 10 iterations with Newton's endif ! if mode 0 enddo ! end of infinite loop !------------------------------------------------------------- success=.false. end !-------------------------------------------------------------------! ! _9_ SOLVE_QUADRATIC_EQ ! !-------------------------------------------------------------------! subroutine solve_quadratic_eq(x0,x1,poly) ! Quadratic equation solver for complex polynomial (degree=2) implicit none complex(kind=8), intent(out) :: x0, x1 complex(kind=8), dimension(*), intent(in) :: poly ! coeffs of the polynomial ! poly - is an array of polynomial cooefs, length = degree+1, poly(1) is constant ! 1 2 3 ! poly(1) x^0 + poly(2) x^1 + poly(3) x^2 complex(kind=8) :: a, b, c, b2, delta complex(kind=8) :: val, x integer :: i a=poly(3) b=poly(2) c=poly(1) ! quadratic equation: a z^2 + b z + c = 0 b2=b*b delta=sqrt(b2-4d0*(a*c)) if( real(conjg(b)*delta)>=0d0 )then ! scallar product to decide the sign yielding bigger magnitude x0=-0.5d0*(b+delta) else x0=-0.5d0*(b-delta) endif if(x0==cmplx(0d0,0d0,8))then x1=cmplx(0d0,0d0,8) else ! Viete's formula x1=c/x0 x0=x0/a endif if(.false.)then ! print the results x=x0 val=poly(3) do i=2,1,-1 val=val*x+poly(i) enddo write(*,'(2f19.15,a3,2f19.15)') x,' ->',val x=x1 val=poly(3) do i=2,1,-1 val=val*x+poly(i) enddo write(*,'(2f19.15,a3,2f19.15)') x,' ->',val endif end !-------------------------------------------------------------------! ! _10_ SOLVE_CUBIC_EQ ! !-------------------------------------------------------------------! subroutine solve_cubic_eq(x0,x1,x2,poly) ! Cubic equation solver for complex polynomial (degree=3) ! http://en.wikipedia.org/wiki/Cubic_function Lagrange's method implicit none complex(kind=8), intent(out) :: x0, x1, x2 complex(kind=8), dimension(*), intent(in) :: poly ! coeffs of the polynomial ! poly - is an array of polynomial cooefs, length = degree+1, poly(1) is constant ! 1 2 3 4 ! poly(1) x^0 + poly(2) x^1 + poly(3) x^2 + poly(4) x^3 complex(kind=8), parameter :: zeta =cmplx(-0.5d0, 0.8660254037844386d0, 8) ! sqrt3(1) complex(kind=8), parameter :: zeta2=cmplx(-0.5d0,-0.8660254037844386d0, 8) ! sqrt3(1)**2 real(kind=8), parameter :: third=0.3333333333333333d0 ! 1/3 complex(kind=8) :: s0, s1, s2 complex(kind=8) :: E1 ! x0+x1+x2 complex(kind=8) :: E2 ! x0x1+x1x2+x2x0 complex(kind=8) :: E3 ! x0x1x2 complex(kind=8) :: A, B, a_1, E12 complex(kind=8) :: delta, A2 complex(kind=8) :: val, x integer :: i a_1=poly(4)**(-1) E1=-poly(3)*a_1 E2=poly(2)*a_1 E3=-poly(1)*a_1 s0=E1 E12=E1*E1 A=2d0*E1*E12-9d0*E1*E2+27d0*E3 ! = s1^3 + s2^3 B=E12-3d0*E2 ! = s1 s2 ! quadratic equation: z^2-Az+B^3=0 where roots are equal to s1^3 and s2^3 A2=A*A delta=sqrt(A2-4d0*(B*B*B)) if( real(conjg(A)*delta)>=0d0 )then ! scallar product to decide the sign yielding bigger magnitude s1=(0.5d0*(A+delta))**third else s1=(0.5d0*(A-delta))**third endif if(s1==cmplx(0d0,0d0,8))then s2=cmplx(0d0,0d0,8) else s2=B/s1 endif x0=third*(s0+s1+s2) x1=third*(s0+s1*zeta2+s2*zeta ) x2=third*(s0+s1*zeta +s2*zeta2) if(.false.)then ! print the results x=x0 val=poly(4) do i=3,1,-1 val=val*x+poly(i) enddo write(*,'(2f19.15,a3,2f19.15)') x,' ->',val x=x1 val=poly(4) do i=3,1,-1 val=val*x+poly(i) enddo write(*,'(2f19.15,a3,2f19.15)') x,' ->',val x=x2 val=poly(4) do i=3,1,-1 val=val*x+poly(i) enddo write(*,'(2f19.15,a3,2f19.15)') x,' ->',val endif end !-------------------------------------------------------------------! ! _11_ DIVIDE_POLY_1 ! !-------------------------------------------------------------------! subroutine divide_poly_1(polyout, remainder, p, polyin, degree) ! Subroutine will divide polynomial 'polyin' by (x-p) ! results will be returned in polynomial 'polyout' of degree-1 ! The remainder of the division will be returned in 'remainder' ! ! You can provide same array as 'polyin' and 'polyout' - this ! routine will work fine, though it will not set to zero the ! unused, highest coefficient in the output array. You just have ! remember the proper degree of a polynomial. implicit none integer, intent(in) :: degree complex(kind=8), dimension(degree), intent(out) :: polyout complex(kind=8), intent(out) :: remainder complex(kind=8), intent(in) :: p complex(kind=8), dimension(degree+1), intent(in) :: polyin ! coeffs of the polynomial ! poly - is an array of polynomial cooefs, length = degree+1, poly(1) is constant ! 1 2 3 ! poly(1) x^0 + poly(2) x^1 + poly(3) x^2 + ... integer :: i complex(kind=8) :: coef, prev coef=polyin(degree+1) polyout=polyin(1:degree) do i=degree,1,-1 prev=polyout(i) polyout(i)=coef coef=prev+p*coef enddo remainder=coef return end !-------------------------------------------------------------------! ! _12_ EVAL_POLY ! !-------------------------------------------------------------------! complex(kind=8) function eval_poly(x, poly, degree, errk) ! Evaluation of the complex polynomial 'poly' of a given degree ! at the point 'x'. This routine calculates also the simplified ! Adams' (1967) stopping criterion. ('errk' should be multiplied ! by 2d-15 for double precisioni,real*8, arithmetic) implicit none complex(kind=8), intent(in) :: x integer, intent(in) :: degree real(kind=8), intent(out) :: errk ! complex(kind=8), dimension(degree+1), intent(in) :: poly ! coeffs of the polynomial ! poly - is an array of polynomial cooefs, length = degree+1, poly(1) is constant ! 1 2 3 ! poly(1) x^0 + poly(2) x^1 + poly(3) x^2 + ... integer :: i complex(kind=8) :: val real(kind=8) :: absx ! prepare stoping criterion errk=abs(poly(degree+1)) val=poly(degree+1) absx=abs(x) do i=degree,1,-1 ! Horner Scheme, see for eg. Numerical Recipes Sec. 5.3 how to evaluate polynomials and derivatives val=val*x+poly(i) ! Adams, Duane A., 1967, "A stopping criterion for polynomial root finding", ! Communications of the ACM, Volume 10 Issue 10, Oct. 1967, p. 655 ! ftp://reports.stanford.edu/pub/cstr/reports/cs/tr/67/55/CS-TR-67-55.pdf ! Eq 8. errk=errk*absx+abs(val) enddo eval_poly=val ! if(abs(val)<2d-15*errk) return ! (simplified a little Eq. 10 of Adams 1967) return end !-------------------------------------------------------------------! ! _13_ MULTIPLY_POLY_1 ! !-------------------------------------------------------------------! subroutine multiply_poly_1(polyout, p, polyin, degree) ! Subroutine will multiply polynomial 'polyin' by (x-p) ! results will be returned in polynomial 'polyout' of degree+1 ! ! You can provide same array as 'polyin' and 'polyout' - this ! routine will work fine. implicit none integer, intent(in) :: degree ! OLD degree, new will be +1 complex(kind=8), dimension(degree+2), intent(out) :: polyout complex(kind=8), intent(in) :: p complex(kind=8), dimension(degree+1), intent(in) :: polyin ! coeffs of the polynomial ! poly - is an array of polynomial cooefs, length = degree+1, poly(1) is constant ! 1 2 3 ! poly(1) x^0 + poly(2) x^1 + poly(3) x^2 + ... integer :: i polyout(1:degree+1)=polyin(1:degree+1) ! copy polyout(degree+2)=polyout(degree+1) do i=degree+1,2,-1 polyout(i)=polyout(i-1)-polyout(i)*p enddo polyout(1)=-polyout(1)*p return end !-------------------------------------------------------------------! ! _14_ CREATE_POLY_FROM_ROOTS ! !-------------------------------------------------------------------! subroutine create_poly_from_roots(poly, degree, a, roots) ! Routine will build polynomial from a set of points given in ! the array 'roots'. These points will be zeros of the resulting ! polynomial. ! ! poly - is an array of polynomial cooefs, length = degree+1, poly(1) is constant ! 1 2 3 ! poly(1) x^0 + poly(2) x^1 + poly(3) x^2 + ... ! degree - is and integer denoting size of the 'roots' array ! a - gives the leading coefficient of the resutling polynomial ! roots - input array of points, size=degree ! ! This subroutine works, but it is not optimal - it will work ! up to a polynomial of degree~50, if you would like to have ! more robust routine, up to a degree ~ 2000, you should ! split your factors into a binary tree, and then multiply ! leafs level by level from down up with subroutine like: ! multiply_poly for arbitraty polynomial multiplications ! not multiply_poly_1. ! implicit none integer, intent(in) :: degree complex(kind=8), dimension(degree+1), intent(out) :: poly complex(kind=8), intent(in) :: a complex(kind=8), dimension(degree), intent(in) :: roots ! integer :: i ! poly=cmplx(0d0,0d0,8) poly(1)=a ! leading coeff of the polynomial do i=1,degree call multiply_poly_1(poly, roots(i), poly, i-1) enddo end !-------------------------------------------------------------------!
apache-2.0
wilmarcardonac/hypermcmc
lapack-3.5.0/TESTING/LIN/ddrvgbx.f
32
40550
*> \brief \b DDRVGBX * * =========== DOCUMENTATION =========== * * Online html documentation available at * http://www.netlib.org/lapack/explore-html/ * * Definition: * =========== * * SUBROUTINE DDRVGB( DOTYPE, NN, NVAL, NRHS, THRESH, TSTERR, A, LA, * AFB, LAFB, ASAV, B, BSAV, X, XACT, S, WORK, * RWORK, IWORK, NOUT ) * * .. Scalar Arguments .. * LOGICAL TSTERR * INTEGER LA, LAFB, NN, NOUT, NRHS * DOUBLE PRECISION THRESH * .. * .. Array Arguments .. * LOGICAL DOTYPE( * ) * INTEGER IWORK( * ), NVAL( * ) * DOUBLE PRECISION A( * ), AFB( * ), ASAV( * ), B( * ), BSAV( * ), * $ RWORK( * ), S( * ), WORK( * ), X( * ), * $ XACT( * ) * .. * * *> \par Purpose: * ============= *> *> \verbatim *> *> DDRVGB tests the driver routines DGBSV, -SVX, and -SVXX. *> *> Note that this file is used only when the XBLAS are available, *> otherwise ddrvgb.f defines this subroutine. *> \endverbatim * * Arguments: * ========== * *> \param[in] DOTYPE *> \verbatim *> DOTYPE is LOGICAL array, dimension (NTYPES) *> The matrix types to be used for testing. Matrices of type j *> (for 1 <= j <= NTYPES) are used for testing if DOTYPE(j) = *> .TRUE.; if DOTYPE(j) = .FALSE., then type j is not used. *> \endverbatim *> *> \param[in] NN *> \verbatim *> NN is INTEGER *> The number of values of N contained in the vector NVAL. *> \endverbatim *> *> \param[in] NVAL *> \verbatim *> NVAL is INTEGER array, dimension (NN) *> The values of the matrix column dimension N. *> \endverbatim *> *> \param[in] NRHS *> \verbatim *> NRHS is INTEGER *> The number of right hand side vectors to be generated for *> each linear system. *> \endverbatim *> *> \param[in] THRESH *> \verbatim *> THRESH is DOUBLE PRECISION *> The threshold value for the test ratios. A result is *> included in the output file if RESULT >= THRESH. To have *> every test ratio printed, use THRESH = 0. *> \endverbatim *> *> \param[in] TSTERR *> \verbatim *> TSTERR is LOGICAL *> Flag that indicates whether error exits are to be tested. *> \endverbatim *> *> \param[out] A *> \verbatim *> A is DOUBLE PRECISION array, dimension (LA) *> \endverbatim *> *> \param[in] LA *> \verbatim *> LA is INTEGER *> The length of the array A. LA >= (2*NMAX-1)*NMAX *> where NMAX is the largest entry in NVAL. *> \endverbatim *> *> \param[out] AFB *> \verbatim *> AFB is DOUBLE PRECISION array, dimension (LAFB) *> \endverbatim *> *> \param[in] LAFB *> \verbatim *> LAFB is INTEGER *> The length of the array AFB. LAFB >= (3*NMAX-2)*NMAX *> where NMAX is the largest entry in NVAL. *> \endverbatim *> *> \param[out] ASAV *> \verbatim *> ASAV is DOUBLE PRECISION array, dimension (LA) *> \endverbatim *> *> \param[out] B *> \verbatim *> B is DOUBLE PRECISION array, dimension (NMAX*NRHS) *> \endverbatim *> *> \param[out] BSAV *> \verbatim *> BSAV is DOUBLE PRECISION array, dimension (NMAX*NRHS) *> \endverbatim *> *> \param[out] X *> \verbatim *> X is DOUBLE PRECISION array, dimension (NMAX*NRHS) *> \endverbatim *> *> \param[out] XACT *> \verbatim *> XACT is DOUBLE PRECISION array, dimension (NMAX*NRHS) *> \endverbatim *> *> \param[out] S *> \verbatim *> S is DOUBLE PRECISION array, dimension (2*NMAX) *> \endverbatim *> *> \param[out] WORK *> \verbatim *> WORK is DOUBLE PRECISION array, dimension *> (NMAX*max(3,NRHS,NMAX)) *> \endverbatim *> *> \param[out] RWORK *> \verbatim *> RWORK is DOUBLE PRECISION array, dimension *> (max(NMAX,2*NRHS)) *> \endverbatim *> *> \param[out] IWORK *> \verbatim *> IWORK is INTEGER array, dimension (2*NMAX) *> \endverbatim *> *> \param[in] NOUT *> \verbatim *> NOUT is INTEGER *> The unit number for output. *> \endverbatim * * Authors: * ======== * *> \author Univ. of Tennessee *> \author Univ. of California Berkeley *> \author Univ. of Colorado Denver *> \author NAG Ltd. * *> \date November 2011 * *> \ingroup double_lin * * ===================================================================== SUBROUTINE DDRVGB( DOTYPE, NN, NVAL, NRHS, THRESH, TSTERR, A, LA, $ AFB, LAFB, ASAV, B, BSAV, X, XACT, S, WORK, $ RWORK, IWORK, NOUT ) * * -- LAPACK test routine (version 3.4.0) -- * -- LAPACK is a software package provided by Univ. of Tennessee, -- * -- Univ. of California Berkeley, Univ. of Colorado Denver and NAG Ltd..-- * November 2011 * * .. Scalar Arguments .. LOGICAL TSTERR INTEGER LA, LAFB, NN, NOUT, NRHS DOUBLE PRECISION THRESH * .. * .. Array Arguments .. LOGICAL DOTYPE( * ) INTEGER IWORK( * ), NVAL( * ) DOUBLE PRECISION A( * ), AFB( * ), ASAV( * ), B( * ), BSAV( * ), $ RWORK( * ), S( * ), WORK( * ), X( * ), $ XACT( * ) * .. * * ===================================================================== * * .. Parameters .. DOUBLE PRECISION ONE, ZERO PARAMETER ( ONE = 1.0D+0, ZERO = 0.0D+0 ) INTEGER NTYPES PARAMETER ( NTYPES = 8 ) INTEGER NTESTS PARAMETER ( NTESTS = 7 ) INTEGER NTRAN PARAMETER ( NTRAN = 3 ) * .. * .. Local Scalars .. LOGICAL EQUIL, NOFACT, PREFAC, TRFCON, ZEROT CHARACTER DIST, EQUED, FACT, TRANS, TYPE, XTYPE CHARACTER*3 PATH INTEGER I, I1, I2, IEQUED, IFACT, IKL, IKU, IMAT, IN, $ INFO, IOFF, ITRAN, IZERO, J, K, K1, KL, KU, $ LDA, LDAFB, LDB, MODE, N, NB, NBMIN, NERRS, $ NFACT, NFAIL, NIMAT, NKL, NKU, NRUN, NT, $ N_ERR_BNDS DOUBLE PRECISION AINVNM, AMAX, ANORM, ANORMI, ANORMO, ANRMPV, $ CNDNUM, COLCND, RCOND, RCONDC, RCONDI, RCONDO, $ ROLDC, ROLDI, ROLDO, ROWCND, RPVGRW, $ RPVGRW_SVXX * .. * .. Local Arrays .. CHARACTER EQUEDS( 4 ), FACTS( 3 ), TRANSS( NTRAN ) INTEGER ISEED( 4 ), ISEEDY( 4 ) DOUBLE PRECISION RESULT( NTESTS ), BERR( NRHS ), $ ERRBNDS_N( NRHS, 3 ), ERRBNDS_C( NRHS, 3 ) * .. * .. External Functions .. LOGICAL LSAME DOUBLE PRECISION DGET06, DLAMCH, DLANGB, DLANGE, DLANTB, $ DLA_GBRPVGRW EXTERNAL LSAME, DGET06, DLAMCH, DLANGB, DLANGE, DLANTB, $ DLA_GBRPVGRW * .. * .. External Subroutines .. EXTERNAL ALADHD, ALAERH, ALASVM, DERRVX, DGBEQU, DGBSV, $ DGBSVX, DGBT01, DGBT02, DGBT05, DGBTRF, DGBTRS, $ DGET04, DLACPY, DLAQGB, DLARHS, DLASET, DLATB4, $ DLATMS, XLAENV, DGBSVXX, DGBEQUB * .. * .. Intrinsic Functions .. INTRINSIC ABS, MAX, MIN * .. * .. Scalars in Common .. LOGICAL LERR, OK CHARACTER*32 SRNAMT INTEGER INFOT, NUNIT * .. * .. Common blocks .. COMMON / INFOC / INFOT, NUNIT, OK, LERR COMMON / SRNAMC / SRNAMT * .. * .. Data statements .. DATA ISEEDY / 1988, 1989, 1990, 1991 / DATA TRANSS / 'N', 'T', 'C' / DATA FACTS / 'F', 'N', 'E' / DATA EQUEDS / 'N', 'R', 'C', 'B' / * .. * .. Executable Statements .. * * Initialize constants and the random number seed. * PATH( 1: 1 ) = 'Double precision' PATH( 2: 3 ) = 'GB' NRUN = 0 NFAIL = 0 NERRS = 0 DO 10 I = 1, 4 ISEED( I ) = ISEEDY( I ) 10 CONTINUE * * Test the error exits * IF( TSTERR ) $ CALL DERRVX( PATH, NOUT ) INFOT = 0 * * Set the block size and minimum block size for testing. * NB = 1 NBMIN = 2 CALL XLAENV( 1, NB ) CALL XLAENV( 2, NBMIN ) * * Do for each value of N in NVAL * DO 150 IN = 1, NN N = NVAL( IN ) LDB = MAX( N, 1 ) XTYPE = 'N' * * Set limits on the number of loop iterations. * NKL = MAX( 1, MIN( N, 4 ) ) IF( N.EQ.0 ) $ NKL = 1 NKU = NKL NIMAT = NTYPES IF( N.LE.0 ) $ NIMAT = 1 * DO 140 IKL = 1, NKL * * Do for KL = 0, N-1, (3N-1)/4, and (N+1)/4. This order makes * it easier to skip redundant values for small values of N. * IF( IKL.EQ.1 ) THEN KL = 0 ELSE IF( IKL.EQ.2 ) THEN KL = MAX( N-1, 0 ) ELSE IF( IKL.EQ.3 ) THEN KL = ( 3*N-1 ) / 4 ELSE IF( IKL.EQ.4 ) THEN KL = ( N+1 ) / 4 END IF DO 130 IKU = 1, NKU * * Do for KU = 0, N-1, (3N-1)/4, and (N+1)/4. This order * makes it easier to skip redundant values for small * values of N. * IF( IKU.EQ.1 ) THEN KU = 0 ELSE IF( IKU.EQ.2 ) THEN KU = MAX( N-1, 0 ) ELSE IF( IKU.EQ.3 ) THEN KU = ( 3*N-1 ) / 4 ELSE IF( IKU.EQ.4 ) THEN KU = ( N+1 ) / 4 END IF * * Check that A and AFB are big enough to generate this * matrix. * LDA = KL + KU + 1 LDAFB = 2*KL + KU + 1 IF( LDA*N.GT.LA .OR. LDAFB*N.GT.LAFB ) THEN IF( NFAIL.EQ.0 .AND. NERRS.EQ.0 ) $ CALL ALADHD( NOUT, PATH ) IF( LDA*N.GT.LA ) THEN WRITE( NOUT, FMT = 9999 )LA, N, KL, KU, $ N*( KL+KU+1 ) NERRS = NERRS + 1 END IF IF( LDAFB*N.GT.LAFB ) THEN WRITE( NOUT, FMT = 9998 )LAFB, N, KL, KU, $ N*( 2*KL+KU+1 ) NERRS = NERRS + 1 END IF GO TO 130 END IF * DO 120 IMAT = 1, NIMAT * * Do the tests only if DOTYPE( IMAT ) is true. * IF( .NOT.DOTYPE( IMAT ) ) $ GO TO 120 * * Skip types 2, 3, or 4 if the matrix is too small. * ZEROT = IMAT.GE.2 .AND. IMAT.LE.4 IF( ZEROT .AND. N.LT.IMAT-1 ) $ GO TO 120 * * Set up parameters with DLATB4 and generate a * test matrix with DLATMS. * CALL DLATB4( PATH, IMAT, N, N, TYPE, KL, KU, ANORM, $ MODE, CNDNUM, DIST ) RCONDC = ONE / CNDNUM * SRNAMT = 'DLATMS' CALL DLATMS( N, N, DIST, ISEED, TYPE, RWORK, MODE, $ CNDNUM, ANORM, KL, KU, 'Z', A, LDA, WORK, $ INFO ) * * Check the error code from DLATMS. * IF( INFO.NE.0 ) THEN CALL ALAERH( PATH, 'DLATMS', INFO, 0, ' ', N, N, $ KL, KU, -1, IMAT, NFAIL, NERRS, NOUT ) GO TO 120 END IF * * For types 2, 3, and 4, zero one or more columns of * the matrix to test that INFO is returned correctly. * IZERO = 0 IF( ZEROT ) THEN IF( IMAT.EQ.2 ) THEN IZERO = 1 ELSE IF( IMAT.EQ.3 ) THEN IZERO = N ELSE IZERO = N / 2 + 1 END IF IOFF = ( IZERO-1 )*LDA IF( IMAT.LT.4 ) THEN I1 = MAX( 1, KU+2-IZERO ) I2 = MIN( KL+KU+1, KU+1+( N-IZERO ) ) DO 20 I = I1, I2 A( IOFF+I ) = ZERO 20 CONTINUE ELSE DO 40 J = IZERO, N DO 30 I = MAX( 1, KU+2-J ), $ MIN( KL+KU+1, KU+1+( N-J ) ) A( IOFF+I ) = ZERO 30 CONTINUE IOFF = IOFF + LDA 40 CONTINUE END IF END IF * * Save a copy of the matrix A in ASAV. * CALL DLACPY( 'Full', KL+KU+1, N, A, LDA, ASAV, LDA ) * DO 110 IEQUED = 1, 4 EQUED = EQUEDS( IEQUED ) IF( IEQUED.EQ.1 ) THEN NFACT = 3 ELSE NFACT = 1 END IF * DO 100 IFACT = 1, NFACT FACT = FACTS( IFACT ) PREFAC = LSAME( FACT, 'F' ) NOFACT = LSAME( FACT, 'N' ) EQUIL = LSAME( FACT, 'E' ) * IF( ZEROT ) THEN IF( PREFAC ) $ GO TO 100 RCONDO = ZERO RCONDI = ZERO * ELSE IF( .NOT.NOFACT ) THEN * * Compute the condition number for comparison * with the value returned by DGESVX (FACT = * 'N' reuses the condition number from the * previous iteration with FACT = 'F'). * CALL DLACPY( 'Full', KL+KU+1, N, ASAV, LDA, $ AFB( KL+1 ), LDAFB ) IF( EQUIL .OR. IEQUED.GT.1 ) THEN * * Compute row and column scale factors to * equilibrate the matrix A. * CALL DGBEQU( N, N, KL, KU, AFB( KL+1 ), $ LDAFB, S, S( N+1 ), ROWCND, $ COLCND, AMAX, INFO ) IF( INFO.EQ.0 .AND. N.GT.0 ) THEN IF( LSAME( EQUED, 'R' ) ) THEN ROWCND = ZERO COLCND = ONE ELSE IF( LSAME( EQUED, 'C' ) ) THEN ROWCND = ONE COLCND = ZERO ELSE IF( LSAME( EQUED, 'B' ) ) THEN ROWCND = ZERO COLCND = ZERO END IF * * Equilibrate the matrix. * CALL DLAQGB( N, N, KL, KU, AFB( KL+1 ), $ LDAFB, S, S( N+1 ), $ ROWCND, COLCND, AMAX, $ EQUED ) END IF END IF * * Save the condition number of the * non-equilibrated system for use in DGET04. * IF( EQUIL ) THEN ROLDO = RCONDO ROLDI = RCONDI END IF * * Compute the 1-norm and infinity-norm of A. * ANORMO = DLANGB( '1', N, KL, KU, AFB( KL+1 ), $ LDAFB, RWORK ) ANORMI = DLANGB( 'I', N, KL, KU, AFB( KL+1 ), $ LDAFB, RWORK ) * * Factor the matrix A. * CALL DGBTRF( N, N, KL, KU, AFB, LDAFB, IWORK, $ INFO ) * * Form the inverse of A. * CALL DLASET( 'Full', N, N, ZERO, ONE, WORK, $ LDB ) SRNAMT = 'DGBTRS' CALL DGBTRS( 'No transpose', N, KL, KU, N, $ AFB, LDAFB, IWORK, WORK, LDB, $ INFO ) * * Compute the 1-norm condition number of A. * AINVNM = DLANGE( '1', N, N, WORK, LDB, $ RWORK ) IF( ANORMO.LE.ZERO .OR. AINVNM.LE.ZERO ) THEN RCONDO = ONE ELSE RCONDO = ( ONE / ANORMO ) / AINVNM END IF * * Compute the infinity-norm condition number * of A. * AINVNM = DLANGE( 'I', N, N, WORK, LDB, $ RWORK ) IF( ANORMI.LE.ZERO .OR. AINVNM.LE.ZERO ) THEN RCONDI = ONE ELSE RCONDI = ( ONE / ANORMI ) / AINVNM END IF END IF * DO 90 ITRAN = 1, NTRAN * * Do for each value of TRANS. * TRANS = TRANSS( ITRAN ) IF( ITRAN.EQ.1 ) THEN RCONDC = RCONDO ELSE RCONDC = RCONDI END IF * * Restore the matrix A. * CALL DLACPY( 'Full', KL+KU+1, N, ASAV, LDA, $ A, LDA ) * * Form an exact solution and set the right hand * side. * SRNAMT = 'DLARHS' CALL DLARHS( PATH, XTYPE, 'Full', TRANS, N, $ N, KL, KU, NRHS, A, LDA, XACT, $ LDB, B, LDB, ISEED, INFO ) XTYPE = 'C' CALL DLACPY( 'Full', N, NRHS, B, LDB, BSAV, $ LDB ) * IF( NOFACT .AND. ITRAN.EQ.1 ) THEN * * --- Test DGBSV --- * * Compute the LU factorization of the matrix * and solve the system. * CALL DLACPY( 'Full', KL+KU+1, N, A, LDA, $ AFB( KL+1 ), LDAFB ) CALL DLACPY( 'Full', N, NRHS, B, LDB, X, $ LDB ) * SRNAMT = 'DGBSV ' CALL DGBSV( N, KL, KU, NRHS, AFB, LDAFB, $ IWORK, X, LDB, INFO ) * * Check error code from DGBSV . * IF( INFO.NE.IZERO ) $ CALL ALAERH( PATH, 'DGBSV ', INFO, $ IZERO, ' ', N, N, KL, KU, $ NRHS, IMAT, NFAIL, NERRS, $ NOUT ) * * Reconstruct matrix from factors and * compute residual. * CALL DGBT01( N, N, KL, KU, A, LDA, AFB, $ LDAFB, IWORK, WORK, $ RESULT( 1 ) ) NT = 1 IF( IZERO.EQ.0 ) THEN * * Compute residual of the computed * solution. * CALL DLACPY( 'Full', N, NRHS, B, LDB, $ WORK, LDB ) CALL DGBT02( 'No transpose', N, N, KL, $ KU, NRHS, A, LDA, X, LDB, $ WORK, LDB, RESULT( 2 ) ) * * Check solution from generated exact * solution. * CALL DGET04( N, NRHS, X, LDB, XACT, $ LDB, RCONDC, RESULT( 3 ) ) NT = 3 END IF * * Print information about the tests that did * not pass the threshold. * DO 50 K = 1, NT IF( RESULT( K ).GE.THRESH ) THEN IF( NFAIL.EQ.0 .AND. NERRS.EQ.0 ) $ CALL ALADHD( NOUT, PATH ) WRITE( NOUT, FMT = 9997 )'DGBSV ', $ N, KL, KU, IMAT, K, RESULT( K ) NFAIL = NFAIL + 1 END IF 50 CONTINUE NRUN = NRUN + NT END IF * * --- Test DGBSVX --- * IF( .NOT.PREFAC ) $ CALL DLASET( 'Full', 2*KL+KU+1, N, ZERO, $ ZERO, AFB, LDAFB ) CALL DLASET( 'Full', N, NRHS, ZERO, ZERO, X, $ LDB ) IF( IEQUED.GT.1 .AND. N.GT.0 ) THEN * * Equilibrate the matrix if FACT = 'F' and * EQUED = 'R', 'C', or 'B'. * CALL DLAQGB( N, N, KL, KU, A, LDA, S, $ S( N+1 ), ROWCND, COLCND, $ AMAX, EQUED ) END IF * * Solve the system and compute the condition * number and error bounds using DGBSVX. * SRNAMT = 'DGBSVX' CALL DGBSVX( FACT, TRANS, N, KL, KU, NRHS, A, $ LDA, AFB, LDAFB, IWORK, EQUED, $ S, S( N+1 ), B, LDB, X, LDB, $ RCOND, RWORK, RWORK( NRHS+1 ), $ WORK, IWORK( N+1 ), INFO ) * * Check the error code from DGBSVX. * IF( INFO.NE.IZERO ) $ CALL ALAERH( PATH, 'DGBSVX', INFO, IZERO, $ FACT // TRANS, N, N, KL, KU, $ NRHS, IMAT, NFAIL, NERRS, $ NOUT ) * * Compare WORK(1) from DGBSVX with the computed * reciprocal pivot growth factor RPVGRW * IF( INFO.NE.0 ) THEN ANRMPV = ZERO DO 70 J = 1, INFO DO 60 I = MAX( KU+2-J, 1 ), $ MIN( N+KU+1-J, KL+KU+1 ) ANRMPV = MAX( ANRMPV, $ ABS( A( I+( J-1 )*LDA ) ) ) 60 CONTINUE 70 CONTINUE RPVGRW = DLANTB( 'M', 'U', 'N', INFO, $ MIN( INFO-1, KL+KU ), $ AFB( MAX( 1, KL+KU+2-INFO ) ), $ LDAFB, WORK ) IF( RPVGRW.EQ.ZERO ) THEN RPVGRW = ONE ELSE RPVGRW = ANRMPV / RPVGRW END IF ELSE RPVGRW = DLANTB( 'M', 'U', 'N', N, KL+KU, $ AFB, LDAFB, WORK ) IF( RPVGRW.EQ.ZERO ) THEN RPVGRW = ONE ELSE RPVGRW = DLANGB( 'M', N, KL, KU, A, $ LDA, WORK ) / RPVGRW END IF END IF RESULT( 7 ) = ABS( RPVGRW-WORK( 1 ) ) / $ MAX( WORK( 1 ), RPVGRW ) / $ DLAMCH( 'E' ) * IF( .NOT.PREFAC ) THEN * * Reconstruct matrix from factors and * compute residual. * CALL DGBT01( N, N, KL, KU, A, LDA, AFB, $ LDAFB, IWORK, WORK, $ RESULT( 1 ) ) K1 = 1 ELSE K1 = 2 END IF * IF( INFO.EQ.0 ) THEN TRFCON = .FALSE. * * Compute residual of the computed solution. * CALL DLACPY( 'Full', N, NRHS, BSAV, LDB, $ WORK, LDB ) CALL DGBT02( TRANS, N, N, KL, KU, NRHS, $ ASAV, LDA, X, LDB, WORK, LDB, $ RESULT( 2 ) ) * * Check solution from generated exact * solution. * IF( NOFACT .OR. ( PREFAC .AND. $ LSAME( EQUED, 'N' ) ) ) THEN CALL DGET04( N, NRHS, X, LDB, XACT, $ LDB, RCONDC, RESULT( 3 ) ) ELSE IF( ITRAN.EQ.1 ) THEN ROLDC = ROLDO ELSE ROLDC = ROLDI END IF CALL DGET04( N, NRHS, X, LDB, XACT, $ LDB, ROLDC, RESULT( 3 ) ) END IF * * Check the error bounds from iterative * refinement. * CALL DGBT05( TRANS, N, KL, KU, NRHS, ASAV, $ LDA, B, LDB, X, LDB, XACT, $ LDB, RWORK, RWORK( NRHS+1 ), $ RESULT( 4 ) ) ELSE TRFCON = .TRUE. END IF * * Compare RCOND from DGBSVX with the computed * value in RCONDC. * RESULT( 6 ) = DGET06( RCOND, RCONDC ) * * Print information about the tests that did * not pass the threshold. * IF( .NOT.TRFCON ) THEN DO 80 K = K1, NTESTS IF( RESULT( K ).GE.THRESH ) THEN IF( NFAIL.EQ.0 .AND. NERRS.EQ.0 ) $ CALL ALADHD( NOUT, PATH ) IF( PREFAC ) THEN WRITE( NOUT, FMT = 9995 ) $ 'DGBSVX', FACT, TRANS, N, KL, $ KU, EQUED, IMAT, K, $ RESULT( K ) ELSE WRITE( NOUT, FMT = 9996 ) $ 'DGBSVX', FACT, TRANS, N, KL, $ KU, IMAT, K, RESULT( K ) END IF NFAIL = NFAIL + 1 END IF 80 CONTINUE NRUN = NRUN + 7 - K1 ELSE IF( RESULT( 1 ).GE.THRESH .AND. .NOT. $ PREFAC ) THEN IF( NFAIL.EQ.0 .AND. NERRS.EQ.0 ) $ CALL ALADHD( NOUT, PATH ) IF( PREFAC ) THEN WRITE( NOUT, FMT = 9995 )'DGBSVX', $ FACT, TRANS, N, KL, KU, EQUED, $ IMAT, 1, RESULT( 1 ) ELSE WRITE( NOUT, FMT = 9996 )'DGBSVX', $ FACT, TRANS, N, KL, KU, IMAT, 1, $ RESULT( 1 ) END IF NFAIL = NFAIL + 1 NRUN = NRUN + 1 END IF IF( RESULT( 6 ).GE.THRESH ) THEN IF( NFAIL.EQ.0 .AND. NERRS.EQ.0 ) $ CALL ALADHD( NOUT, PATH ) IF( PREFAC ) THEN WRITE( NOUT, FMT = 9995 )'DGBSVX', $ FACT, TRANS, N, KL, KU, EQUED, $ IMAT, 6, RESULT( 6 ) ELSE WRITE( NOUT, FMT = 9996 )'DGBSVX', $ FACT, TRANS, N, KL, KU, IMAT, 6, $ RESULT( 6 ) END IF NFAIL = NFAIL + 1 NRUN = NRUN + 1 END IF IF( RESULT( 7 ).GE.THRESH ) THEN IF( NFAIL.EQ.0 .AND. NERRS.EQ.0 ) $ CALL ALADHD( NOUT, PATH ) IF( PREFAC ) THEN WRITE( NOUT, FMT = 9995 )'DGBSVX', $ FACT, TRANS, N, KL, KU, EQUED, $ IMAT, 7, RESULT( 7 ) ELSE WRITE( NOUT, FMT = 9996 )'DGBSVX', $ FACT, TRANS, N, KL, KU, IMAT, 7, $ RESULT( 7 ) END IF NFAIL = NFAIL + 1 NRUN = NRUN + 1 END IF * END IF * * --- Test DGBSVXX --- * * Restore the matrices A and B. * CALL DLACPY( 'Full', KL+KU+1, N, ASAV, LDA, A, $ LDA ) CALL DLACPY( 'Full', N, NRHS, BSAV, LDB, B, LDB ) IF( .NOT.PREFAC ) $ CALL DLASET( 'Full', 2*KL+KU+1, N, ZERO, ZERO, $ AFB, LDAFB ) CALL DLASET( 'Full', N, NRHS, ZERO, ZERO, X, LDB ) IF( IEQUED.GT.1 .AND. N.GT.0 ) THEN * * Equilibrate the matrix if FACT = 'F' and * EQUED = 'R', 'C', or 'B'. * CALL DLAQGB( N, N, KL, KU, A, LDA, S, S( N+1 ), $ ROWCND, COLCND, AMAX, EQUED ) END IF * * Solve the system and compute the condition number * and error bounds using DGBSVXX. * SRNAMT = 'DGBSVXX' N_ERR_BNDS = 3 CALL DGBSVXX( FACT, TRANS, N, KL, KU, NRHS, A, LDA, $ AFB, LDAFB, IWORK, EQUED, S, S( N+1 ), B, LDB, $ X, LDB, RCOND, RPVGRW_SVXX, BERR, N_ERR_BNDS, $ ERRBNDS_N, ERRBNDS_C, 0, ZERO, WORK, $ IWORK( N+1 ), INFO ) * * Check the error code from DGBSVXX. * IF( INFO.EQ.N+1 ) GOTO 90 IF( INFO.NE.IZERO ) THEN CALL ALAERH( PATH, 'DGBSVXX', INFO, IZERO, $ FACT // TRANS, N, N, -1, -1, NRHS, $ IMAT, NFAIL, NERRS, NOUT ) GOTO 90 END IF * * Compare rpvgrw_svxx from DGBSVXX with the computed * reciprocal pivot growth factor RPVGRW * IF ( INFO .GT. 0 .AND. INFO .LT. N+1 ) THEN RPVGRW = DLA_GBRPVGRW(N, KL, KU, INFO, A, LDA, $ AFB, LDAFB) ELSE RPVGRW = DLA_GBRPVGRW(N, KL, KU, N, A, LDA, $ AFB, LDAFB) ENDIF RESULT( 7 ) = ABS( RPVGRW-rpvgrw_svxx ) / $ MAX( rpvgrw_svxx, RPVGRW ) / $ DLAMCH( 'E' ) * IF( .NOT.PREFAC ) THEN * * Reconstruct matrix from factors and compute * residual. * CALL DGBT01( N, N, KL, KU, A, LDA, AFB, LDAFB, $ IWORK, WORK, RESULT( 1 ) ) K1 = 1 ELSE K1 = 2 END IF * IF( INFO.EQ.0 ) THEN TRFCON = .FALSE. * * Compute residual of the computed solution. * CALL DLACPY( 'Full', N, NRHS, BSAV, LDB, WORK, $ LDB ) CALL DGBT02( TRANS, N, N, KL, KU, NRHS, ASAV, $ LDA, X, LDB, WORK, LDB, $ RESULT( 2 ) ) * * Check solution from generated exact solution. * IF( NOFACT .OR. ( PREFAC .AND. LSAME( EQUED, $ 'N' ) ) ) THEN CALL DGET04( N, NRHS, X, LDB, XACT, LDB, $ RCONDC, RESULT( 3 ) ) ELSE IF( ITRAN.EQ.1 ) THEN ROLDC = ROLDO ELSE ROLDC = ROLDI END IF CALL DGET04( N, NRHS, X, LDB, XACT, LDB, $ ROLDC, RESULT( 3 ) ) END IF ELSE TRFCON = .TRUE. END IF * * Compare RCOND from DGBSVXX with the computed value * in RCONDC. * RESULT( 6 ) = DGET06( RCOND, RCONDC ) * * Print information about the tests that did not pass * the threshold. * IF( .NOT.TRFCON ) THEN DO 45 K = K1, NTESTS IF( RESULT( K ).GE.THRESH ) THEN IF( NFAIL.EQ.0 .AND. NERRS.EQ.0 ) $ CALL ALADHD( NOUT, PATH ) IF( PREFAC ) THEN WRITE( NOUT, FMT = 9995 )'DGBSVXX', $ FACT, TRANS, N, KL, KU, EQUED, $ IMAT, K, RESULT( K ) ELSE WRITE( NOUT, FMT = 9996 )'DGBSVXX', $ FACT, TRANS, N, KL, KU, IMAT, K, $ RESULT( K ) END IF NFAIL = NFAIL + 1 END IF 45 CONTINUE NRUN = NRUN + 7 - K1 ELSE IF( RESULT( 1 ).GE.THRESH .AND. .NOT.PREFAC ) $ THEN IF( NFAIL.EQ.0 .AND. NERRS.EQ.0 ) $ CALL ALADHD( NOUT, PATH ) IF( PREFAC ) THEN WRITE( NOUT, FMT = 9995 )'DGBSVXX', FACT, $ TRANS, N, KL, KU, EQUED, IMAT, 1, $ RESULT( 1 ) ELSE WRITE( NOUT, FMT = 9996 )'DGBSVXX', FACT, $ TRANS, N, KL, KU, IMAT, 1, $ RESULT( 1 ) END IF NFAIL = NFAIL + 1 NRUN = NRUN + 1 END IF IF( RESULT( 6 ).GE.THRESH ) THEN IF( NFAIL.EQ.0 .AND. NERRS.EQ.0 ) $ CALL ALADHD( NOUT, PATH ) IF( PREFAC ) THEN WRITE( NOUT, FMT = 9995 )'DGBSVXX', FACT, $ TRANS, N, KL, KU, EQUED, IMAT, 6, $ RESULT( 6 ) ELSE WRITE( NOUT, FMT = 9996 )'DGBSVXX', FACT, $ TRANS, N, KL, KU, IMAT, 6, $ RESULT( 6 ) END IF NFAIL = NFAIL + 1 NRUN = NRUN + 1 END IF IF( RESULT( 7 ).GE.THRESH ) THEN IF( NFAIL.EQ.0 .AND. NERRS.EQ.0 ) $ CALL ALADHD( NOUT, PATH ) IF( PREFAC ) THEN WRITE( NOUT, FMT = 9995 )'DGBSVXX', FACT, $ TRANS, N, KL, KU, EQUED, IMAT, 7, $ RESULT( 7 ) ELSE WRITE( NOUT, FMT = 9996 )'DGBSVXX', FACT, $ TRANS, N, KL, KU, IMAT, 7, $ RESULT( 7 ) END IF NFAIL = NFAIL + 1 NRUN = NRUN + 1 END IF * END IF 90 CONTINUE 100 CONTINUE 110 CONTINUE 120 CONTINUE 130 CONTINUE 140 CONTINUE 150 CONTINUE * * Print a summary of the results. * CALL ALASVM( PATH, NOUT, NFAIL, NRUN, NERRS ) * Test Error Bounds from DGBSVXX CALL DEBCHVXX(THRESH, PATH) 9999 FORMAT( ' *** In DDRVGB, LA=', I5, ' is too small for N=', I5, $ ', KU=', I5, ', KL=', I5, / ' ==> Increase LA to at least ', $ I5 ) 9998 FORMAT( ' *** In DDRVGB, LAFB=', I5, ' is too small for N=', I5, $ ', KU=', I5, ', KL=', I5, / $ ' ==> Increase LAFB to at least ', I5 ) 9997 FORMAT( 1X, A, ', N=', I5, ', KL=', I5, ', KU=', I5, ', type ', $ I1, ', test(', I1, ')=', G12.5 ) 9996 FORMAT( 1X, A, '( ''', A1, ''',''', A1, ''',', I5, ',', I5, ',', $ I5, ',...), type ', I1, ', test(', I1, ')=', G12.5 ) 9995 FORMAT( 1X, A, '( ''', A1, ''',''', A1, ''',', I5, ',', I5, ',', $ I5, ',...), EQUED=''', A1, ''', type ', I1, ', test(', I1, $ ')=', G12.5 ) * RETURN * * End of DDRVGB * END
gpl-2.0
QEF/q-e
PHonon/PH/addusdynmat.f90
2
7563
! ! Copyright (C) 2001 PWSCF group ! This file is distributed under the terms of the ! GNU General Public License. See the file `License' ! in the root directory of the present distribution, ! or http://www.gnu.org/copyleft/gpl.txt . ! !----------------------------------------------------------------------- subroutine addusdynmat (dynwrk) !----------------------------------------------------------------------- !! This routine computes the additional terms which are contained in !! \(\langle\psi\|V''\|\psi\rangle\) part of the dynamical matrix and !! which are due to the change of the self consistent D term in the !! pseudopotential. !! There are four additional terms which we compute here. ! USE kinds, only : DP USE ions_base, ONLY : nat, ityp USE noncollin_module, ONLY : noncolin, npol USE uspp, ONLY: okvan, becsum USE uspp_param, only: upf, nh USE lsda_mod, ONLY : nspin USE noncollin_module, ONLY : nspin_lsda, lspinorb USE phus, ONLY : int1, int1_nc, int2, int2_so, int4, int4_nc, & int5, int5_so, alphasum, alphasum_nc, becsum_nc USE modes, ONLY : nmodes implicit none complex(DP) :: dynwrk (3 * nat, 3 * nat) !! inp/out: the dynamical matrix integer :: ipol, jpol, np, na, nb, nu_i, nu_j, ih, jh, ijh, dim, & is, is1, is2, ijs ! counter on polarizations ! counter on pseudopotentials ! counter on atoms ! counter on modes ! counter on solid beta functions ! composed dimension of the beta ! counter on spin complex(DP) :: term (3, 3), dyn1 (3 * nat, 3 * nat) ! auxiliary space ! auxiliary dynamical matrix if (.not.okvan) return call start_clock ('addusdynmat') IF (noncolin) CALL set_int12_nc(1) dyn1 (:,:) = (0.d0, 0.d0) ! ! We compute the four terms required ! do na = 1, nat np = ityp (na) if (upf(np)%tvanp ) then dim = (nh (np) * (nh (np) + 1) ) / 2 do ipol = 1, 3 nu_i = 3 * (na - 1) + ipol do jpol = 1, 3 nu_j = 3 * (na - 1) + jpol IF (noncolin) THEN ijh=1 DO ih=1,nh(np) DO jh=ih,nh(np) ijs=0 DO is1=1,npol DO is2=1,npol ijs=ijs+1 dynwrk(nu_i, nu_j)=dynwrk(nu_i, nu_j) + & int4_nc(ih,jh,ipol,jpol,na,ijs) * & becsum_nc(ijh,na,is1,is2) IF (ih.NE.jh) THEN dynwrk(nu_i, nu_j)=dynwrk(nu_i, nu_j) + & int4_nc(jh,ih,ipol,jpol,na,ijs) * & CONJG(becsum_nc(ijh,na,is2,is1)) END IF END DO END DO ijh=ijh+1 END DO END DO ELSE do is = 1, nspin do ijh = 1, dim dynwrk(nu_i, nu_j)=dynwrk(nu_i, nu_j)+ & int4(ijh,ipol,jpol,na,is) * becsum(ijh,na,is) enddo enddo END IF enddo enddo ! ! The second term requires an exchange of the components. ! term (:,:) = (0.d0, 0.d0) do ipol = 1, 3 do jpol = 1, 3 ijh = 0 do ih = 1, nh (np) do jh = ih, nh (np) ijh = ijh + 1 IF (noncolin) THEN ijs=0 do is1 = 1, npol do is2 = 1, npol ijs=ijs+1 term(ipol,jpol) = term(ipol,jpol) + & int1_nc(ih,jh,ipol,na,ijs)* & alphasum_nc(ijh,jpol,na,is1,is2) IF (ih.ne.jh) THEN term(ipol,jpol) = term(ipol,jpol) + & int1_nc(jh,ih,ipol,na,ijs)* & CONJG(alphasum_nc(ijh,jpol,na,is2,is1)) ENDIF enddo enddo ELSE do is = 1, nspin term(ipol,jpol) = term(ipol,jpol) + & CONJG(int1(ih,jh,ipol,na,is))*alphasum(ijh,jpol,na,is) enddo END IF enddo enddo enddo enddo ! ! And then we add the appropriate terms to the dynamical matrix ! do ipol = 1, 3 nu_i = 3 * (na - 1) + ipol do jpol = 1, 3 nu_j = 3 * (na - 1) + jpol dynwrk (nu_i, nu_j) = dynwrk (nu_i, nu_j) + & term (ipol, jpol) + term (jpol, ipol) enddo enddo ! ! the other two terms do not contain a delta ss' ! do nb = 1, nat do ipol = 1, 3 nu_i = 3 * (nb - 1) + ipol do jpol = 1, 3 nu_j = 3 * (na - 1) + jpol ijh = 0 do ih = 1, nh (np) do jh = ih, nh (np) ijh = ijh + 1 IF (lspinorb) THEN ijs=0 do is1 = 1, npol do is2 = 1, npol ijs=ijs+1 dyn1(nu_i,nu_j)=dyn1(nu_i,nu_j) + & int2_so(ih,jh,ipol,nb,na,ijs) * & alphasum_nc(ijh,jpol,na,is1,is2) + & int5_so(ih,jh,ipol,jpol,nb,na,ijs) * & becsum_nc(ijh,na,is1,is2) IF (ih.ne.jh) THEN dyn1(nu_i,nu_j)=dyn1(nu_i,nu_j) + & int2_so(jh,ih,ipol,nb,na,ijs) * & CONJG(alphasum_nc(ijh,jpol,na,is2,is1))+& int5_so(jh,ih,ipol,jpol,nb,na,ijs) * & CONJG(becsum_nc(ijh,na,is2,is1)) END IF enddo enddo ELSE do is = 1, nspin_lsda dyn1(nu_i,nu_j)=dyn1(nu_i,nu_j) + & CONJG(int2(ih,jh,ipol,nb,na)) * & alphasum(ijh,jpol,na,is) + & int5(ijh,ipol,jpol,nb,na) * & becsum(ijh,na,is) enddo END IF enddo enddo enddo enddo enddo endif enddo do nu_i = 1, nmodes do nu_j = 1, nmodes dynwrk (nu_i, nu_j) = dynwrk (nu_i, nu_j) + & dyn1 (nu_i, nu_j) + CONJG(dyn1 (nu_j, nu_i) ) enddo enddo deallocate (int4) deallocate (int5) IF (noncolin) THEN call set_int12_nc(0) deallocate(int4_nc) if (lspinorb) deallocate(int5_so) END IF call stop_clock ('addusdynmat') return end subroutine addusdynmat
gpl-2.0
omni-compiler/omni-compiler
tests/XMP/global-view/intrinsic/F/intrinsic_pack_unpack.f90
1
1915
program main !$xmp nodes p(2,2) !$xmp template tp(10,10) !$xmp distribute tp(block,block) onto p !$xmp nodes q(4) !$xmp template tq(100) !$xmp distribute tq(block) onto q integer(8):: a(10,10),adash(10,10) logical:: mask(10,10) integer(8):: v(100),vdash(100) !$xmp align a(i,j) with tp(i,j) !$xmp align mask(i,j) with tp(i,j) !$xmp align v(i) with tq(i) integer:: i,j,answer=0 do i=1,10 do j=1,10 vdash((i-1)*10+j)=(j-1)*10+(i-1)*2 enddo enddo do i=51,100 vdash(i)=0 end do do i=1,10 do j=1,10 adash(i,j)=0 enddo enddo do i=1,10 do j=1,10 if(mod(j-1,2).eq.0)then adash(i,j)=(i-1)*10+j-1 end if end do end do !$xmp loop on tp(i,j) do i=1,10 do j=1,10 a(i,j)=(i-1)*10+(j-1) end do end do !$xmp loop on tq(i) do i=1,100 v(i)=0 end do !$xmp loop on tp(i,j) do i=1,10 do j=1,10 if(mod(j-1,2).eq.0) then mask(i,j)=.true. else mask(i,j)=.false. endif end do end do call xmp_pack(xmp_desc_of(v),xmp_desc_of(a),xmp_desc_of(mask)) !$xmp loop on tq(i) do i=1,100 if(v(i).ne.vdash(i)) then answer = -1 endif end do !$xmp reduction(+:answer) !$xmp task on p(1,1) if ( answer /= 0 ) then write(*,*) "ERROR" call exit(1) endif write(*,*) "PASS" !$xmp end task !$xmp loop on tp(i,j) do j=1,10 do i=1,10 a(i,j)=0 end do end do call xmp_unpack(xmp_desc_of(a),xmp_desc_of(v),xmp_desc_of(mask)) !$xmp loop on tp(i,j) do i=1,10 do j=1,10 if(a(i,j).ne.adash(i,j)) then answer = -1 endif end do end do !$xmp reduction(+:answer) !$xmp task on p(1,1) if ( answer /= 0 ) then write(*,*) "ERROR" call exit(1) endif write(*,*) "PASS" !$xmp end task end program main
lgpl-3.0
QEF/q-e
PHonon/PH/psyme2.f90
2
1500
! ! Copyright (C) 2001-2008 Quantum ESPRESSO group ! This file is distributed under the terms of the ! GNU General Public License. See the file `License' ! in the root directory of the present distribution, ! or http://www.gnu.org/copyleft/gpl.txt . ! ! !----------------------------------------------------------------------- subroutine psyme2 (dvtosym) !----------------------------------------------------------------------- !! p-symmetrize the second derivative of charge density. ! use kinds, only : DP USE mp_bands, ONLY: me_bgrp USE fft_base, ONLY: dfftp USE scatter_mod, ONLY: cgather_sym implicit none ! complex(DP) :: dvtosym (dfftp%nnr, 6) !! the potential to symmetrize ! ! ... local variable ! #if defined(__MPI) integer :: i, iper, ir3, ioff, ioff_tg, nxyp complex(DP), allocatable :: ddvtosym (:,:) ! the potential to symmetrize allocate (ddvtosym (dfftp%nr1x*dfftp%nr2x*dfftp%nr3x, 6)) do iper = 1, 6 call cgather_sym (dfftp, dvtosym (:, iper), ddvtosym (:, iper) ) enddo call syme2 (ddvtosym) nxyp = dfftp%nr1x * dfftp%my_nr2p DO iper = 1, 6 DO ir3 = 1, dfftp%my_nr3p ioff = dfftp%nr1x * dfftp%my_nr2p * (ir3-1) ioff_tg = dfftp%nr1x * dfftp%nr2x * (dfftp%my_i0r3p+ir3-1) + dfftp%nr1x * dfftp%my_i0r2p CALL zcopy (nxyp, ddvtosym (ioff_tg+1, iper), 1, dvtosym (ioff+1, iper), 1) END DO ENDDO deallocate (ddvtosym) #else call syme2 (dvtosym) #endif return end subroutine psyme2
gpl-2.0
wilmarcardonac/hypermcmc
lapack-3.5.0/TESTING/MATGEN/clarnd.f
33
3907
*> \brief \b CLARND * * =========== DOCUMENTATION =========== * * Online html documentation available at * http://www.netlib.org/lapack/explore-html/ * * Definition: * =========== * * COMPLEX FUNCTION CLARND( IDIST, ISEED ) * * .. Scalar Arguments .. * INTEGER IDIST * .. * .. Array Arguments .. * INTEGER ISEED( 4 ) * .. * * *> \par Purpose: * ============= *> *> \verbatim *> *> CLARND returns a random complex number from a uniform or normal *> distribution. *> \endverbatim * * Arguments: * ========== * *> \param[in] IDIST *> \verbatim *> IDIST is INTEGER *> Specifies the distribution of the random numbers: *> = 1: real and imaginary parts each uniform (0,1) *> = 2: real and imaginary parts each uniform (-1,1) *> = 3: real and imaginary parts each normal (0,1) *> = 4: uniformly distributed on the disc abs(z) <= 1 *> = 5: uniformly distributed on the circle abs(z) = 1 *> \endverbatim *> *> \param[in,out] ISEED *> \verbatim *> ISEED is INTEGER array, dimension (4) *> On entry, the seed of the random number generator; the array *> elements must be between 0 and 4095, and ISEED(4) must be *> odd. *> On exit, the seed is updated. *> \endverbatim * * Authors: * ======== * *> \author Univ. of Tennessee *> \author Univ. of California Berkeley *> \author Univ. of Colorado Denver *> \author NAG Ltd. * *> \date November 2011 * *> \ingroup complex_matgen * *> \par Further Details: * ===================== *> *> \verbatim *> *> This routine calls the auxiliary routine SLARAN to generate a random *> real number from a uniform (0,1) distribution. The Box-Muller method *> is used to transform numbers from a uniform to a normal distribution. *> \endverbatim *> * ===================================================================== COMPLEX FUNCTION CLARND( IDIST, ISEED ) * * -- LAPACK auxiliary routine (version 3.4.0) -- * -- LAPACK is a software package provided by Univ. of Tennessee, -- * -- Univ. of California Berkeley, Univ. of Colorado Denver and NAG Ltd..-- * November 2011 * * .. Scalar Arguments .. INTEGER IDIST * .. * .. Array Arguments .. INTEGER ISEED( 4 ) * .. * * ===================================================================== * * .. Parameters .. REAL ZERO, ONE, TWO PARAMETER ( ZERO = 0.0E+0, ONE = 1.0E+0, TWO = 2.0E+0 ) REAL TWOPI PARAMETER ( TWOPI = 6.2831853071795864769252867663E+0 ) * .. * .. Local Scalars .. REAL T1, T2 * .. * .. External Functions .. REAL SLARAN EXTERNAL SLARAN * .. * .. Intrinsic Functions .. INTRINSIC CMPLX, EXP, LOG, SQRT * .. * .. Executable Statements .. * * Generate a pair of real random numbers from a uniform (0,1) * distribution * T1 = SLARAN( ISEED ) T2 = SLARAN( ISEED ) * IF( IDIST.EQ.1 ) THEN * * real and imaginary parts each uniform (0,1) * CLARND = CMPLX( T1, T2 ) ELSE IF( IDIST.EQ.2 ) THEN * * real and imaginary parts each uniform (-1,1) * CLARND = CMPLX( TWO*T1-ONE, TWO*T2-ONE ) ELSE IF( IDIST.EQ.3 ) THEN * * real and imaginary parts each normal (0,1) * CLARND = SQRT( -TWO*LOG( T1 ) )*EXP( CMPLX( ZERO, TWOPI*T2 ) ) ELSE IF( IDIST.EQ.4 ) THEN * * uniform distribution on the unit disc abs(z) <= 1 * CLARND = SQRT( T1 )*EXP( CMPLX( ZERO, TWOPI*T2 ) ) ELSE IF( IDIST.EQ.5 ) THEN * * uniform distribution on the unit circle abs(z) = 1 * CLARND = EXP( CMPLX( ZERO, TWOPI*T2 ) ) END IF RETURN * * End of CLARND * END
gpl-2.0
wilmarcardonac/hypermcmc
lapack-3.5.0/TESTING/LIN/ddrvge.f
28
25364
*> \brief \b DDRVGE * * =========== DOCUMENTATION =========== * * Online html documentation available at * http://www.netlib.org/lapack/explore-html/ * * Definition: * =========== * * SUBROUTINE DDRVGE( DOTYPE, NN, NVAL, NRHS, THRESH, TSTERR, NMAX, * A, AFAC, ASAV, B, BSAV, X, XACT, S, WORK, * RWORK, IWORK, NOUT ) * * .. Scalar Arguments .. * LOGICAL TSTERR * INTEGER NMAX, NN, NOUT, NRHS * DOUBLE PRECISION THRESH * .. * .. Array Arguments .. * LOGICAL DOTYPE( * ) * INTEGER IWORK( * ), NVAL( * ) * DOUBLE PRECISION A( * ), AFAC( * ), ASAV( * ), B( * ), * $ BSAV( * ), RWORK( * ), S( * ), WORK( * ), * $ X( * ), XACT( * ) * .. * * *> \par Purpose: * ============= *> *> \verbatim *> *> DDRVGE tests the driver routines DGESV and -SVX. *> \endverbatim * * Arguments: * ========== * *> \param[in] DOTYPE *> \verbatim *> DOTYPE is LOGICAL array, dimension (NTYPES) *> The matrix types to be used for testing. Matrices of type j *> (for 1 <= j <= NTYPES) are used for testing if DOTYPE(j) = *> .TRUE.; if DOTYPE(j) = .FALSE., then type j is not used. *> \endverbatim *> *> \param[in] NN *> \verbatim *> NN is INTEGER *> The number of values of N contained in the vector NVAL. *> \endverbatim *> *> \param[in] NVAL *> \verbatim *> NVAL is INTEGER array, dimension (NN) *> The values of the matrix column dimension N. *> \endverbatim *> *> \param[in] NRHS *> \verbatim *> NRHS is INTEGER *> The number of right hand side vectors to be generated for *> each linear system. *> \endverbatim *> *> \param[in] THRESH *> \verbatim *> THRESH is DOUBLE PRECISION *> The threshold value for the test ratios. A result is *> included in the output file if RESULT >= THRESH. To have *> every test ratio printed, use THRESH = 0. *> \endverbatim *> *> \param[in] TSTERR *> \verbatim *> TSTERR is LOGICAL *> Flag that indicates whether error exits are to be tested. *> \endverbatim *> *> \param[in] NMAX *> \verbatim *> NMAX is INTEGER *> The maximum value permitted for N, used in dimensioning the *> work arrays. *> \endverbatim *> *> \param[out] A *> \verbatim *> A is DOUBLE PRECISION array, dimension (NMAX*NMAX) *> \endverbatim *> *> \param[out] AFAC *> \verbatim *> AFAC is DOUBLE PRECISION array, dimension (NMAX*NMAX) *> \endverbatim *> *> \param[out] ASAV *> \verbatim *> ASAV is DOUBLE PRECISION array, dimension (NMAX*NMAX) *> \endverbatim *> *> \param[out] B *> \verbatim *> B is DOUBLE PRECISION array, dimension (NMAX*NRHS) *> \endverbatim *> *> \param[out] BSAV *> \verbatim *> BSAV is DOUBLE PRECISION array, dimension (NMAX*NRHS) *> \endverbatim *> *> \param[out] X *> \verbatim *> X is DOUBLE PRECISION array, dimension (NMAX*NRHS) *> \endverbatim *> *> \param[out] XACT *> \verbatim *> XACT is DOUBLE PRECISION array, dimension (NMAX*NRHS) *> \endverbatim *> *> \param[out] S *> \verbatim *> S is DOUBLE PRECISION array, dimension (2*NMAX) *> \endverbatim *> *> \param[out] WORK *> \verbatim *> WORK is DOUBLE PRECISION array, dimension *> (NMAX*max(3,NRHS)) *> \endverbatim *> *> \param[out] RWORK *> \verbatim *> RWORK is DOUBLE PRECISION array, dimension (2*NRHS+NMAX) *> \endverbatim *> *> \param[out] IWORK *> \verbatim *> IWORK is INTEGER array, dimension (2*NMAX) *> \endverbatim *> *> \param[in] NOUT *> \verbatim *> NOUT is INTEGER *> The unit number for output. *> \endverbatim * * Authors: * ======== * *> \author Univ. of Tennessee *> \author Univ. of California Berkeley *> \author Univ. of Colorado Denver *> \author NAG Ltd. * *> \date November 2011 * *> \ingroup double_lin * * ===================================================================== SUBROUTINE DDRVGE( DOTYPE, NN, NVAL, NRHS, THRESH, TSTERR, NMAX, $ A, AFAC, ASAV, B, BSAV, X, XACT, S, WORK, $ RWORK, IWORK, NOUT ) * * -- LAPACK test routine (version 3.4.0) -- * -- LAPACK is a software package provided by Univ. of Tennessee, -- * -- Univ. of California Berkeley, Univ. of Colorado Denver and NAG Ltd..-- * November 2011 * * .. Scalar Arguments .. LOGICAL TSTERR INTEGER NMAX, NN, NOUT, NRHS DOUBLE PRECISION THRESH * .. * .. Array Arguments .. LOGICAL DOTYPE( * ) INTEGER IWORK( * ), NVAL( * ) DOUBLE PRECISION A( * ), AFAC( * ), ASAV( * ), B( * ), $ BSAV( * ), RWORK( * ), S( * ), WORK( * ), $ X( * ), XACT( * ) * .. * * ===================================================================== * * .. Parameters .. DOUBLE PRECISION ONE, ZERO PARAMETER ( ONE = 1.0D+0, ZERO = 0.0D+0 ) INTEGER NTYPES PARAMETER ( NTYPES = 11 ) INTEGER NTESTS PARAMETER ( NTESTS = 7 ) INTEGER NTRAN PARAMETER ( NTRAN = 3 ) * .. * .. Local Scalars .. LOGICAL EQUIL, NOFACT, PREFAC, TRFCON, ZEROT CHARACTER DIST, EQUED, FACT, TRANS, TYPE, XTYPE CHARACTER*3 PATH INTEGER I, IEQUED, IFACT, IMAT, IN, INFO, IOFF, ITRAN, $ IZERO, K, K1, KL, KU, LDA, LWORK, MODE, N, NB, $ NBMIN, NERRS, NFACT, NFAIL, NIMAT, NRUN, NT DOUBLE PRECISION AINVNM, AMAX, ANORM, ANORMI, ANORMO, CNDNUM, $ COLCND, RCOND, RCONDC, RCONDI, RCONDO, ROLDC, $ ROLDI, ROLDO, ROWCND, RPVGRW * .. * .. Local Arrays .. CHARACTER EQUEDS( 4 ), FACTS( 3 ), TRANSS( NTRAN ) INTEGER ISEED( 4 ), ISEEDY( 4 ) DOUBLE PRECISION RESULT( NTESTS ) * .. * .. External Functions .. LOGICAL LSAME DOUBLE PRECISION DGET06, DLAMCH, DLANGE, DLANTR EXTERNAL LSAME, DGET06, DLAMCH, DLANGE, DLANTR * .. * .. External Subroutines .. EXTERNAL ALADHD, ALAERH, ALASVM, DERRVX, DGEEQU, DGESV, $ DGESVX, DGET01, DGET02, DGET04, DGET07, DGETRF, $ DGETRI, DLACPY, DLAQGE, DLARHS, DLASET, DLATB4, $ DLATMS, XLAENV * .. * .. Intrinsic Functions .. INTRINSIC ABS, MAX * .. * .. Scalars in Common .. LOGICAL LERR, OK CHARACTER*32 SRNAMT INTEGER INFOT, NUNIT * .. * .. Common blocks .. COMMON / INFOC / INFOT, NUNIT, OK, LERR COMMON / SRNAMC / SRNAMT * .. * .. Data statements .. DATA ISEEDY / 1988, 1989, 1990, 1991 / DATA TRANSS / 'N', 'T', 'C' / DATA FACTS / 'F', 'N', 'E' / DATA EQUEDS / 'N', 'R', 'C', 'B' / * .. * .. Executable Statements .. * * Initialize constants and the random number seed. * PATH( 1: 1 ) = 'Double precision' PATH( 2: 3 ) = 'GE' NRUN = 0 NFAIL = 0 NERRS = 0 DO 10 I = 1, 4 ISEED( I ) = ISEEDY( I ) 10 CONTINUE * * Test the error exits * IF( TSTERR ) $ CALL DERRVX( PATH, NOUT ) INFOT = 0 * * Set the block size and minimum block size for testing. * NB = 1 NBMIN = 2 CALL XLAENV( 1, NB ) CALL XLAENV( 2, NBMIN ) * * Do for each value of N in NVAL * DO 90 IN = 1, NN N = NVAL( IN ) LDA = MAX( N, 1 ) XTYPE = 'N' NIMAT = NTYPES IF( N.LE.0 ) $ NIMAT = 1 * DO 80 IMAT = 1, NIMAT * * Do the tests only if DOTYPE( IMAT ) is true. * IF( .NOT.DOTYPE( IMAT ) ) $ GO TO 80 * * Skip types 5, 6, or 7 if the matrix size is too small. * ZEROT = IMAT.GE.5 .AND. IMAT.LE.7 IF( ZEROT .AND. N.LT.IMAT-4 ) $ GO TO 80 * * Set up parameters with DLATB4 and generate a test matrix * with DLATMS. * CALL DLATB4( PATH, IMAT, N, N, TYPE, KL, KU, ANORM, MODE, $ CNDNUM, DIST ) RCONDC = ONE / CNDNUM * SRNAMT = 'DLATMS' CALL DLATMS( N, N, DIST, ISEED, TYPE, RWORK, MODE, CNDNUM, $ ANORM, KL, KU, 'No packing', A, LDA, WORK, $ INFO ) * * Check error code from DLATMS. * IF( INFO.NE.0 ) THEN CALL ALAERH( PATH, 'DLATMS', INFO, 0, ' ', N, N, -1, -1, $ -1, IMAT, NFAIL, NERRS, NOUT ) GO TO 80 END IF * * For types 5-7, zero one or more columns of the matrix to * test that INFO is returned correctly. * IF( ZEROT ) THEN IF( IMAT.EQ.5 ) THEN IZERO = 1 ELSE IF( IMAT.EQ.6 ) THEN IZERO = N ELSE IZERO = N / 2 + 1 END IF IOFF = ( IZERO-1 )*LDA IF( IMAT.LT.7 ) THEN DO 20 I = 1, N A( IOFF+I ) = ZERO 20 CONTINUE ELSE CALL DLASET( 'Full', N, N-IZERO+1, ZERO, ZERO, $ A( IOFF+1 ), LDA ) END IF ELSE IZERO = 0 END IF * * Save a copy of the matrix A in ASAV. * CALL DLACPY( 'Full', N, N, A, LDA, ASAV, LDA ) * DO 70 IEQUED = 1, 4 EQUED = EQUEDS( IEQUED ) IF( IEQUED.EQ.1 ) THEN NFACT = 3 ELSE NFACT = 1 END IF * DO 60 IFACT = 1, NFACT FACT = FACTS( IFACT ) PREFAC = LSAME( FACT, 'F' ) NOFACT = LSAME( FACT, 'N' ) EQUIL = LSAME( FACT, 'E' ) * IF( ZEROT ) THEN IF( PREFAC ) $ GO TO 60 RCONDO = ZERO RCONDI = ZERO * ELSE IF( .NOT.NOFACT ) THEN * * Compute the condition number for comparison with * the value returned by DGESVX (FACT = 'N' reuses * the condition number from the previous iteration * with FACT = 'F'). * CALL DLACPY( 'Full', N, N, ASAV, LDA, AFAC, LDA ) IF( EQUIL .OR. IEQUED.GT.1 ) THEN * * Compute row and column scale factors to * equilibrate the matrix A. * CALL DGEEQU( N, N, AFAC, LDA, S, S( N+1 ), $ ROWCND, COLCND, AMAX, INFO ) IF( INFO.EQ.0 .AND. N.GT.0 ) THEN IF( LSAME( EQUED, 'R' ) ) THEN ROWCND = ZERO COLCND = ONE ELSE IF( LSAME( EQUED, 'C' ) ) THEN ROWCND = ONE COLCND = ZERO ELSE IF( LSAME( EQUED, 'B' ) ) THEN ROWCND = ZERO COLCND = ZERO END IF * * Equilibrate the matrix. * CALL DLAQGE( N, N, AFAC, LDA, S, S( N+1 ), $ ROWCND, COLCND, AMAX, EQUED ) END IF END IF * * Save the condition number of the non-equilibrated * system for use in DGET04. * IF( EQUIL ) THEN ROLDO = RCONDO ROLDI = RCONDI END IF * * Compute the 1-norm and infinity-norm of A. * ANORMO = DLANGE( '1', N, N, AFAC, LDA, RWORK ) ANORMI = DLANGE( 'I', N, N, AFAC, LDA, RWORK ) * * Factor the matrix A. * SRNAMT = 'DGETRF' CALL DGETRF( N, N, AFAC, LDA, IWORK, INFO ) * * Form the inverse of A. * CALL DLACPY( 'Full', N, N, AFAC, LDA, A, LDA ) LWORK = NMAX*MAX( 3, NRHS ) SRNAMT = 'DGETRI' CALL DGETRI( N, A, LDA, IWORK, WORK, LWORK, INFO ) * * Compute the 1-norm condition number of A. * AINVNM = DLANGE( '1', N, N, A, LDA, RWORK ) IF( ANORMO.LE.ZERO .OR. AINVNM.LE.ZERO ) THEN RCONDO = ONE ELSE RCONDO = ( ONE / ANORMO ) / AINVNM END IF * * Compute the infinity-norm condition number of A. * AINVNM = DLANGE( 'I', N, N, A, LDA, RWORK ) IF( ANORMI.LE.ZERO .OR. AINVNM.LE.ZERO ) THEN RCONDI = ONE ELSE RCONDI = ( ONE / ANORMI ) / AINVNM END IF END IF * DO 50 ITRAN = 1, NTRAN * * Do for each value of TRANS. * TRANS = TRANSS( ITRAN ) IF( ITRAN.EQ.1 ) THEN RCONDC = RCONDO ELSE RCONDC = RCONDI END IF * * Restore the matrix A. * CALL DLACPY( 'Full', N, N, ASAV, LDA, A, LDA ) * * Form an exact solution and set the right hand side. * SRNAMT = 'DLARHS' CALL DLARHS( PATH, XTYPE, 'Full', TRANS, N, N, KL, $ KU, NRHS, A, LDA, XACT, LDA, B, LDA, $ ISEED, INFO ) XTYPE = 'C' CALL DLACPY( 'Full', N, NRHS, B, LDA, BSAV, LDA ) * IF( NOFACT .AND. ITRAN.EQ.1 ) THEN * * --- Test DGESV --- * * Compute the LU factorization of the matrix and * solve the system. * CALL DLACPY( 'Full', N, N, A, LDA, AFAC, LDA ) CALL DLACPY( 'Full', N, NRHS, B, LDA, X, LDA ) * SRNAMT = 'DGESV ' CALL DGESV( N, NRHS, AFAC, LDA, IWORK, X, LDA, $ INFO ) * * Check error code from DGESV . * IF( INFO.NE.IZERO ) $ CALL ALAERH( PATH, 'DGESV ', INFO, IZERO, $ ' ', N, N, -1, -1, NRHS, IMAT, $ NFAIL, NERRS, NOUT ) * * Reconstruct matrix from factors and compute * residual. * CALL DGET01( N, N, A, LDA, AFAC, LDA, IWORK, $ RWORK, RESULT( 1 ) ) NT = 1 IF( IZERO.EQ.0 ) THEN * * Compute residual of the computed solution. * CALL DLACPY( 'Full', N, NRHS, B, LDA, WORK, $ LDA ) CALL DGET02( 'No transpose', N, N, NRHS, A, $ LDA, X, LDA, WORK, LDA, RWORK, $ RESULT( 2 ) ) * * Check solution from generated exact solution. * CALL DGET04( N, NRHS, X, LDA, XACT, LDA, $ RCONDC, RESULT( 3 ) ) NT = 3 END IF * * Print information about the tests that did not * pass the threshold. * DO 30 K = 1, NT IF( RESULT( K ).GE.THRESH ) THEN IF( NFAIL.EQ.0 .AND. NERRS.EQ.0 ) $ CALL ALADHD( NOUT, PATH ) WRITE( NOUT, FMT = 9999 )'DGESV ', N, $ IMAT, K, RESULT( K ) NFAIL = NFAIL + 1 END IF 30 CONTINUE NRUN = NRUN + NT END IF * * --- Test DGESVX --- * IF( .NOT.PREFAC ) $ CALL DLASET( 'Full', N, N, ZERO, ZERO, AFAC, $ LDA ) CALL DLASET( 'Full', N, NRHS, ZERO, ZERO, X, LDA ) IF( IEQUED.GT.1 .AND. N.GT.0 ) THEN * * Equilibrate the matrix if FACT = 'F' and * EQUED = 'R', 'C', or 'B'. * CALL DLAQGE( N, N, A, LDA, S, S( N+1 ), ROWCND, $ COLCND, AMAX, EQUED ) END IF * * Solve the system and compute the condition number * and error bounds using DGESVX. * SRNAMT = 'DGESVX' CALL DGESVX( FACT, TRANS, N, NRHS, A, LDA, AFAC, $ LDA, IWORK, EQUED, S, S( N+1 ), B, $ LDA, X, LDA, RCOND, RWORK, $ RWORK( NRHS+1 ), WORK, IWORK( N+1 ), $ INFO ) * * Check the error code from DGESVX. * IF( INFO.NE.IZERO ) $ CALL ALAERH( PATH, 'DGESVX', INFO, IZERO, $ FACT // TRANS, N, N, -1, -1, NRHS, $ IMAT, NFAIL, NERRS, NOUT ) * * Compare WORK(1) from DGESVX with the computed * reciprocal pivot growth factor RPVGRW * IF( INFO.NE.0 .AND. INFO.LE.N) THEN RPVGRW = DLANTR( 'M', 'U', 'N', INFO, INFO, $ AFAC, LDA, WORK ) IF( RPVGRW.EQ.ZERO ) THEN RPVGRW = ONE ELSE RPVGRW = DLANGE( 'M', N, INFO, A, LDA, $ WORK ) / RPVGRW END IF ELSE RPVGRW = DLANTR( 'M', 'U', 'N', N, N, AFAC, LDA, $ WORK ) IF( RPVGRW.EQ.ZERO ) THEN RPVGRW = ONE ELSE RPVGRW = DLANGE( 'M', N, N, A, LDA, WORK ) / $ RPVGRW END IF END IF RESULT( 7 ) = ABS( RPVGRW-WORK( 1 ) ) / $ MAX( WORK( 1 ), RPVGRW ) / $ DLAMCH( 'E' ) * IF( .NOT.PREFAC ) THEN * * Reconstruct matrix from factors and compute * residual. * CALL DGET01( N, N, A, LDA, AFAC, LDA, IWORK, $ RWORK( 2*NRHS+1 ), RESULT( 1 ) ) K1 = 1 ELSE K1 = 2 END IF * IF( INFO.EQ.0 ) THEN TRFCON = .FALSE. * * Compute residual of the computed solution. * CALL DLACPY( 'Full', N, NRHS, BSAV, LDA, WORK, $ LDA ) CALL DGET02( TRANS, N, N, NRHS, ASAV, LDA, X, $ LDA, WORK, LDA, RWORK( 2*NRHS+1 ), $ RESULT( 2 ) ) * * Check solution from generated exact solution. * IF( NOFACT .OR. ( PREFAC .AND. LSAME( EQUED, $ 'N' ) ) ) THEN CALL DGET04( N, NRHS, X, LDA, XACT, LDA, $ RCONDC, RESULT( 3 ) ) ELSE IF( ITRAN.EQ.1 ) THEN ROLDC = ROLDO ELSE ROLDC = ROLDI END IF CALL DGET04( N, NRHS, X, LDA, XACT, LDA, $ ROLDC, RESULT( 3 ) ) END IF * * Check the error bounds from iterative * refinement. * CALL DGET07( TRANS, N, NRHS, ASAV, LDA, B, LDA, $ X, LDA, XACT, LDA, RWORK, .TRUE., $ RWORK( NRHS+1 ), RESULT( 4 ) ) ELSE TRFCON = .TRUE. END IF * * Compare RCOND from DGESVX with the computed value * in RCONDC. * RESULT( 6 ) = DGET06( RCOND, RCONDC ) * * Print information about the tests that did not pass * the threshold. * IF( .NOT.TRFCON ) THEN DO 40 K = K1, NTESTS IF( RESULT( K ).GE.THRESH ) THEN IF( NFAIL.EQ.0 .AND. NERRS.EQ.0 ) $ CALL ALADHD( NOUT, PATH ) IF( PREFAC ) THEN WRITE( NOUT, FMT = 9997 )'DGESVX', $ FACT, TRANS, N, EQUED, IMAT, K, $ RESULT( K ) ELSE WRITE( NOUT, FMT = 9998 )'DGESVX', $ FACT, TRANS, N, IMAT, K, RESULT( K ) END IF NFAIL = NFAIL + 1 END IF 40 CONTINUE NRUN = NRUN + 7 - K1 ELSE IF( RESULT( 1 ).GE.THRESH .AND. .NOT.PREFAC ) $ THEN IF( NFAIL.EQ.0 .AND. NERRS.EQ.0 ) $ CALL ALADHD( NOUT, PATH ) IF( PREFAC ) THEN WRITE( NOUT, FMT = 9997 )'DGESVX', FACT, $ TRANS, N, EQUED, IMAT, 1, RESULT( 1 ) ELSE WRITE( NOUT, FMT = 9998 )'DGESVX', FACT, $ TRANS, N, IMAT, 1, RESULT( 1 ) END IF NFAIL = NFAIL + 1 NRUN = NRUN + 1 END IF IF( RESULT( 6 ).GE.THRESH ) THEN IF( NFAIL.EQ.0 .AND. NERRS.EQ.0 ) $ CALL ALADHD( NOUT, PATH ) IF( PREFAC ) THEN WRITE( NOUT, FMT = 9997 )'DGESVX', FACT, $ TRANS, N, EQUED, IMAT, 6, RESULT( 6 ) ELSE WRITE( NOUT, FMT = 9998 )'DGESVX', FACT, $ TRANS, N, IMAT, 6, RESULT( 6 ) END IF NFAIL = NFAIL + 1 NRUN = NRUN + 1 END IF IF( RESULT( 7 ).GE.THRESH ) THEN IF( NFAIL.EQ.0 .AND. NERRS.EQ.0 ) $ CALL ALADHD( NOUT, PATH ) IF( PREFAC ) THEN WRITE( NOUT, FMT = 9997 )'DGESVX', FACT, $ TRANS, N, EQUED, IMAT, 7, RESULT( 7 ) ELSE WRITE( NOUT, FMT = 9998 )'DGESVX', FACT, $ TRANS, N, IMAT, 7, RESULT( 7 ) END IF NFAIL = NFAIL + 1 NRUN = NRUN + 1 END IF * END IF * 50 CONTINUE 60 CONTINUE 70 CONTINUE 80 CONTINUE 90 CONTINUE * * Print a summary of the results. * CALL ALASVM( PATH, NOUT, NFAIL, NRUN, NERRS ) * 9999 FORMAT( 1X, A, ', N =', I5, ', type ', I2, ', test(', I2, ') =', $ G12.5 ) 9998 FORMAT( 1X, A, ', FACT=''', A1, ''', TRANS=''', A1, ''', N=', I5, $ ', type ', I2, ', test(', I1, ')=', G12.5 ) 9997 FORMAT( 1X, A, ', FACT=''', A1, ''', TRANS=''', A1, ''', N=', I5, $ ', EQUED=''', A1, ''', type ', I2, ', test(', I1, ')=', $ G12.5 ) RETURN * * End of DDRVGE * END
gpl-2.0
QEF/q-e
test-suite/not_epw_comp/phq_readin2.f90
2
36587
! ! Copyright (C) 2001-2020 Quantum ESPRESSO group ! This file is distributed under the terms of the ! GNU General Public License. See the file `License' ! in the root directory of the present distribution, ! or http://www.gnu.org/copyleft/gpl.txt . ! ! !---------------------------------------------------------------------------- SUBROUTINE phq_readin2() !---------------------------------------------------------------------------- !! This routine reads the control variables for the program \(\texttt{phononq}\). !! A second routine, \(\texttt{read_file}\), reads the variables saved to file !! by the self-consistent program. ! ! USE kinds, ONLY : DP USE ions_base, ONLY : nat, ntyp => nsp USE mp, ONLY : mp_bcast USE mp_world, ONLY : world_comm USE ions_base, ONLY : amass, atm USE check_stop, ONLY : max_seconds USE start_k, ONLY : reset_grid USE klist, ONLY : xk, nks, nkstot, lgauss, two_fermi_energies, ltetra USE control_flags, ONLY : gamma_only, tqr, restart, io_level, & ts_vdw, ldftd3, lxdm, isolve USE xc_lib, ONLY : xclib_dft_is USE uspp, ONLY : okvan USE fixed_occ, ONLY : tfixed_occ USE lsda_mod, ONLY : lsda, nspin USE fft_base, ONLY : dffts USE cellmd, ONLY : lmovecell USE run_info, ONLY : title USE control_ph, ONLY : maxter, alpha_mix, lgamma_gamma, epsil, & zue, zeu, xmldyn, newgrid, & trans, reduce_io, tr2_ph, niter_ph, & nmix_ph, ldisp, recover, lnoloc, start_irr, & last_irr, start_q, last_q, current_iq, tmp_dir_ph, & ext_recover, ext_restart, u_from_file, ldiag, & search_sym, lqdir, electron_phonon, tmp_dir_phq, & rec_code_read, qplot, only_init, only_wfc, & low_directory_check, nk1, nk2, nk3, k1, k2, k3 USE save_ph, ONLY : tmp_dir_save, save_ph_input_variables USE gamma_gamma, ONLY : asr USE partial, ONLY : atomo, nat_todo, nat_todo_input USE output, ONLY : fildyn, fildvscf, fildrho USE disp, ONLY : nq1, nq2, nq3, x_q, wq, nqs, lgamma_iq USE io_files, ONLY : tmp_dir, prefix, postfix, create_directory, & check_tempdir, xmlpun_schema USE noncollin_module, ONLY : domag, i_cons, noncolin, lspinorb USE control_flags, ONLY : iverbosity, modenum USE io_global, ONLY : meta_ionode, meta_ionode_id, ionode, ionode_id, & qestdin, stdout USE mp_images, ONLY : nimage, my_image_id, intra_image_comm, & me_image, nproc_image USE mp_pools, ONLY : npool USE paw_variables, ONLY : okpaw USE ramanm, ONLY : eth_rps, eth_ns, lraman, elop, dek USE freq_ph, ONLY : fpol, fiu, nfs USE cryst_ph, ONLY : magnetic_sym USE ph_restart, ONLY : ph_readfile USE el_phon, ONLY : elph,elph_mat,elph_simple,elph_epa,elph_nbnd_min, elph_nbnd_max, & el_ph_sigma, el_ph_nsigma, el_ph_ngauss,auxdvscf USE dfile_star, ONLY : drho_star, dvscf_star USE qpoint, ONLY : nksq, xq USE control_lr, ONLY : lgamma, lrpa ! YAMBO > USE YAMBO, ONLY : elph_yambo,dvscf_yambo ! YAMBO < USE elph_tetra_mod,ONLY : elph_tetra, lshift_q, in_alpha2f USE ktetra, ONLY : tetra_type USE ldaU, ONLY : lda_plus_u, Hubbard_projectors, lda_plus_u_kind USE ldaU_ph, ONLY : read_dns_bare, d2ns_type USE dvscf_interpolate, ONLY : ldvscf_interpolate, do_long_range, & do_charge_neutral, wpot_dir USE ahc, ONLY : elph_ahc, ahc_dir, ahc_nbnd, ahc_nbndskip, & skip_upperfan USE read_namelists_module, ONLY : check_namelist_read USE open_close_input_file, ONLY : open_input_file, close_input_file USE el_phon2, ONLY : kx, ky, kz, elph_epw ! IMPLICIT NONE ! CHARACTER(LEN=256), EXTERNAL :: trimcheck ! INTEGER :: ios, ipol, iter, na, it, ierr, ierr1 ! integer variable for I/O control ! counter on polarizations ! counter on iterations ! counter on atoms ! counter on types REAL(DP), ALLOCATABLE :: amass_input(:) ! save masses read from input here CHARACTER (LEN=256) :: outdir, filename CHARACTER (LEN=8) :: verbosity CHARACTER(LEN=80) :: card CHARACTER(LEN=6) :: int_to_char INTEGER :: i LOGICAL :: nogg LOGICAL :: q2d, q_in_band_form INTEGER, EXTERNAL :: atomic_number REAL(DP), EXTERNAL :: atom_weight LOGICAL, EXTERNAL :: imatches LOGICAL, EXTERNAL :: has_xml LOGICAL :: exst, parallelfs REAL(DP), ALLOCATABLE :: xqaux(:,:) INTEGER, ALLOCATABLE :: wqaux(:) INTEGER :: nqaux, iq CHARACTER(len=80) :: diagonalization='david' ! NAMELIST / INPUTPH / tr2_ph, amass, alpha_mix, niter_ph, nmix_ph, & nat_todo, verbosity, iverbosity, outdir, epsil, & trans, zue, zeu, max_seconds, reduce_io, & modenum, prefix, fildyn, fildvscf, fildrho, & ldisp, nq1, nq2, nq3, & eth_rps, eth_ns, lraman, elop, dek, recover, & fpol, asr, lrpa, lnoloc, start_irr, last_irr, & start_q, last_q, nogg, ldiag, search_sym, lqdir, & nk1, nk2, nk3, k1, k2, k3, & drho_star, dvscf_star, only_init, only_wfc, & elph_nbnd_min, elph_nbnd_max, el_ph_ngauss, & el_ph_nsigma, el_ph_sigma, electron_phonon, & q_in_band_form, q2d, qplot, low_directory_check, & lshift_q, read_dns_bare, d2ns_type, diagonalization, & ldvscf_interpolate, do_long_range, do_charge_neutral, & wpot_dir, ahc_dir, ahc_nbnd, ahc_nbndskip, & skip_upperfan, & kx, ky, kz ! tr2_ph : convergence threshold ! amass : atomic masses ! alpha_mix : the mixing parameter ! niter_ph : maximum number of iterations ! nmix_ph : number of previous iterations used in mixing ! nat_todo : number of atom to be displaced ! verbosity : verbosity control (iverbosity is obsolete) ! outdir : directory where input, output, temporary files reside ! epsil : if true calculate dielectric constant ! trans : if true calculate phonon ! electron-phonon : select the kind of electron-phonon calculation ! elph : if true calculate electron-phonon coefficients ! elph_mat : if true eph coefficients for wannier ! zue : if .true. calculate effective charges ( d force / dE ) ! zeu : if .true. calculate effective charges ( d P / du ) ! lraman : if true calculate raman tensor ! elop : if true calculate electro-optic tensor ! max_seconds : maximum cputime for this run ! reduce_io : reduce I/O to the strict minimum ! modenum : single mode calculation ! prefix : the prefix of files produced by pwscf ! fildyn : output file for the dynamical matrix ! fildvscf : output file containing deltavsc ! fildrho : output file containing deltarho ! fildrho_dir : directory where fildrho files will be stored (default: outdir or ESPRESSO_FILDRHO_DIR variable) ! eth_rps : threshold for calculation of Pc R |psi> (Raman) ! eth_ns : threshold for non-scf wavefunction calculation (Raman) ! dek : delta_xk used for wavefunctions derivation (Raman) ! recover : recover=.true. to restart from an interrupted run ! asr : in the gamma_gamma case apply acoustic sum rule ! start_q : in q list does the q points from start_q to last_q ! last_q : ! start_irr : does the irred. representation from start_irr to last_irr ! last_irr : ! nogg : if .true. lgamma_gamma tricks are not used ! ldiag : if .true. force diagonalization of the dyn mat ! lqdir : if .true. each q writes in its own directory ! search_sym : if .true. analyze symmetry if possible ! nk1,nk2,nk3, k1,k2,k3 : ! when specified in input, the phonon run uses a different ! k-point mesh from that used for the charge density. ! ! dvscf_star%open : if .true. write in dvscf_star%dir the dvscf_q ! 'for all q' in the star of q with suffix dvscf_star%ext. ! The dvscf_q' is written in the basis dvscf_star%basis; ! if dvscf_star%pat is .true. also save a pattern file. ! dvscf_star%dir, dvscf_star%ext, dvscf_star%basis : see dvscf_star%open ! drho_star%open : like dvscf_star%open but for drho_q ! drho_star%dir, drho_star%ext, drho_star%basis : see drho_star%open ! ! elph_nbnd_min, ! elph_nbnd_max: if (elph_mat=.true.) it dumps the eph matrix element from elph_nbnd_min ! to elph_nbnd_max ! el_ph_ngauss, ! el_ph_nsigma, ! el_ph_sigma : if (elph_mat=.true.) it defines the kind and the val-ue of the ! smearing to be used in the eph coupling calculation. ! qplot, : if true a list of q points is given in input ! q_in_band_form: if true the input list of q points defines paths ! q2d, : if .true. the q list define a mesh in a square. ! low_directory_check : if .true. only the requested representations ! are searched on file ! ! read_dns_bare : If .true. the code tries to read three files in DFPT+U calculations: ! dnsorth, dnsbare, d2nsbare ! d2ns_type : DFPT+U - the 2nd bare derivative of occupation matrices ns ! (d2ns_bare matrix). Experimental! This is why it is not documented in Doc. ! d2ns_type='full': matrix calculated with no approximation. ! d2ns_type='fmmp': assume a m <=> m' symmetry. ! d2ns_type='diag': if okvan=.true. the matrix is calculated retaining only ! for <\beta_J|\phi_I> products where for J==I. ! d2ns_type='dmmp': same as 'diag', but also assuming a m <=> m'. ! diagonalization : diagonalization method used in the nscf calc ! ldvscf_interpolate: if .true., use Fourier interpolation of phonon potential ! do_long_range: if .true., add the long-range part of the potential to dvscf ! do_charge_neutral: if .true., impose the neutrality condition on Born effective charges ! wpot_dir: folder where w_pot binary files are located ! ahc_dir: Directory where the output binary files for AHC e-ph coupling are written ! ahc_nbnd: Number of bands where the electron self-energy is to be computed. ! ahc_nbndskip: Number of bands to exclude when computing the self-energy. ! skip_upperfan: If .true., skip the calculation of upper Fan self-energy. ! ! Note: meta_ionode is a single processor that reads the input ! (ionode is also a single processor but per image) ! Data read from input is subsequently broadcast to all processors ! from ionode_id (using the default communicator world_comm) ! IF (meta_ionode) THEN ! ! ... Input from file (ios=0) or standard input (ios=-1) on unit "qestdin" ! ios = open_input_file ( ) ! ! ... Read the first line of the input file ! IF ( ios <= 0 ) READ( qestdin, '(A)', IOSTAT = ios ) title ! ENDIF ! CALL mp_bcast(ios, meta_ionode_id, world_comm ) CALL errore( 'phq_readin', 'reading input file ', ABS( ios ) ) CALL mp_bcast(title, meta_ionode_id, world_comm ) ! ! Rewind the input if the title is actually the beginning of inputph namelist ! IF( imatches("&inputph", title) ) THEN WRITE(stdout,'(6x,a)') "Title line not specified: using 'default'." title='default' IF (meta_ionode) REWIND(qestdin, iostat=ios) CALL mp_bcast(ios, meta_ionode_id, world_comm ) CALL errore('phq_readin', 'Title line missing from input.', abs(ios)) ENDIF ! ! ... set default values for variables in namelist ! tr2_ph = 1.D-12 eth_rps = 1.D-9 eth_ns = 1.D-12 amass(:) = 0.D0 alpha_mix(:) = 0.D0 alpha_mix(1) = 0.7D0 niter_ph = maxter nmix_ph = 4 nat_todo = 0 modenum = 0 iverbosity = 1234567 verbosity = 'default' trans = .TRUE. lrpa = .FALSE. lnoloc = .FALSE. epsil = .FALSE. zeu = .TRUE. zue = .FALSE. fpol = .FALSE. electron_phonon=' ' elph_nbnd_min = 1 elph_nbnd_max = 0 el_ph_sigma = 0.02 el_ph_nsigma = 10 el_ph_ngauss = 1 lraman = .FALSE. elop = .FALSE. max_seconds = 1.E+7_DP reduce_io = .FALSE. CALL get_environment_variable( 'ESPRESSO_TMPDIR', outdir ) IF ( TRIM( outdir ) == ' ' ) outdir = './' prefix = 'pwscf' fildyn = 'matdyn' fildrho = ' ' fildvscf = ' ' ldisp = .FALSE. nq1 = 0 nq2 = 0 nq3 = 0 dek = 1.0d-3 nogg = .FALSE. recover = .FALSE. asr = .FALSE. start_irr = 0 last_irr = -1000 start_q = 1 last_q =-1000 ldiag =.FALSE. lqdir =.FALSE. qplot =.FALSE. q_in_band_form=.FALSE. q2d = .FALSE. only_init = .FALSE. only_wfc = .FALSE. low_directory_check=.FALSE. search_sym =.TRUE. nk1 = 0 nk2 = 0 nk3 = 0 k1 = 0 k2 = 0 k3 = 0 ! kx = 0.D0 ky = 0.D0 kz = 0.D0 ! ! dvscf_interpolate ldvscf_interpolate = .FALSE. do_charge_neutral = .FALSE. do_long_range = .FALSE. wpot_dir = ' ' ! ! electron_phonon == 'ahc' ahc_dir = ' ' ahc_nbnd = 0 ahc_nbndskip = 0 skip_upperfan = .FALSE. elph_ahc = .FALSE. ! drho_star%open = .FALSE. drho_star%basis = 'modes' drho_star%pat = .TRUE. drho_star%ext = 'drho' CALL get_environment_variable( 'ESPRESSO_FILDRHO_DIR', drho_star%dir) IF ( TRIM( drho_star%dir ) == ' ' ) & drho_star%dir = TRIM(outdir)//"/Rotated_DRHO/" ! dvscf_star%open = .FALSE. dvscf_star%basis = 'modes' dvscf_star%pat = .FALSE. dvscf_star%ext = 'dvscf' CALL get_environment_variable( 'ESPRESSO_FILDVSCF_DIR', dvscf_star%dir) IF ( TRIM( dvscf_star%dir ) == ' ' ) & dvscf_star%dir = TRIM(outdir)//"/Rotated_DVSCF/" ! lshift_q = .false. read_dns_bare =.false. d2ns_type = 'full' ! ! ... reading the namelist inputph ! IF (meta_ionode) THEN READ( qestdin, INPUTPH, IOSTAT = ios ) ! ! ... iverbosity/verbosity hack ! IF ( iverbosity == 1234567 ) THEN SELECT CASE( trim( verbosity ) ) CASE( 'debug', 'high', 'medium' ) iverbosity = 1 CASE( 'low', 'default', 'minimal' ) iverbosity = 0 CASE DEFAULT iverbosity = 0 END SELECT ELSE ios = 1234567 END IF END IF CALL check_namelist_read(ios, qestdin, "inputph") 30 CONTINUE CALL mp_bcast(ios, meta_ionode_id, world_comm ) IF ( ios == 1234567 ) THEN CALL infomsg( 'phq_readin' , & 'iverbosity is obsolete, use "verbosity" instead' ) ELSE IF ( ABS(ios) /= 0 ) THEN CALL errore( 'phq_readin', 'reading inputph namelist', ABS( ios ) ) END IF ! diagonalization option SELECT CASE(TRIM(diagonalization)) CASE ('david','davidson') isolve = 0 CASE ('cg') isolve = 1 CASE DEFAULT CALL errore('phq_readin','diagonalization '//trim(diagonalization)//' not implemented',1) END SELECT ! ! ... broadcast all input variables ! tmp_dir = trimcheck (outdir) CALL bcast_ph_input ( ) CALL mp_bcast(nogg, meta_ionode_id, world_comm ) CALL mp_bcast(q2d, meta_ionode_id, world_comm ) CALL mp_bcast(q_in_band_form, meta_ionode_id, world_comm ) ! CALL mp_bcast(kx, meta_ionode_id, world_comm ) CALL mp_bcast(ky, meta_ionode_id, world_comm ) CALL mp_bcast(kz, meta_ionode_id, world_comm ) ! drho_star%dir=trimcheck(drho_star%dir) dvscf_star%dir=trimcheck(dvscf_star%dir) ! filename for the star must always be automatically generated: IF(drho_star%ext(1:5)/='auto:') drho_star%ext = 'auto:'//drho_star%ext IF(dvscf_star%ext(1:5)/='auto:') dvscf_star%ext = 'auto:'//dvscf_star%ext ! ! ... Check all namelist variables ! IF (tr2_ph <= 0.D0) CALL errore (' phq_readin', ' Wrong tr2_ph ', 1) IF (eth_rps<= 0.D0) CALL errore ( 'phq_readin', ' Wrong eth_rps', 1) IF (eth_ns <= 0.D0) CALL errore ( 'phq_readin', ' Wrong eth_ns ', 1) DO iter = 1, maxter IF (alpha_mix (iter) .LT.0.D0.OR.alpha_mix (iter) .GT.1.D0) CALL & errore ('phq_readin', ' Wrong alpha_mix ', iter) ENDDO IF (niter_ph.LT.1.OR.niter_ph.GT.maxter) CALL errore ('phq_readin', & ' Wrong niter_ph ', 1) IF (iverbosity.NE.0.AND.iverbosity.NE.1) CALL errore ('phq_readin', & &' Wrong iverbosity ', 1) IF (fildyn.EQ.' ') CALL errore ('phq_readin', ' Wrong fildyn ', 1) IF (max_seconds.LT.0.1D0) CALL errore ('phq_readin', ' Wrong max_seconds', 1) IF (only_init.AND.only_wfc) CALL errore('phq_readin', & 'only_init or only_wfc can be .true.', 1) IF (modenum < 0) CALL errore ('phq_readin', ' Wrong modenum ', 1) IF (dek <= 0.d0) CALL errore ( 'phq_readin', ' Wrong dek ', 1) ! ! elph_tetra = 0 elph_epw=.false. SELECT CASE( trim( electron_phonon ) ) CASE( 'simple' ) elph=.true. elph_mat=.false. elph_simple=.true. elph_epa=.false. CASE( 'epa' ) elph=.true. elph_mat=.false. elph_simple=.false. elph_epa=.true. CASE( 'Wannier' ) elph=.true. elph_mat=.true. elph_simple=.false. elph_epa=.false. auxdvscf=trim(fildvscf) CASE( 'interpolated' ) elph=.true. elph_mat=.false. elph_simple=.false. elph_epa=.false. ! YAMBO > CASE( 'yambo' ) elph=.true. elph_mat=.false. elph_simple=.false. elph_epa=.false. elph_yambo=.true. nogg=.true. auxdvscf=trim(fildvscf) CASE( 'dvscf' ) elph=.false. elph_mat=.false. elph_simple=.false. elph_epa=.false. elph_yambo=.false. dvscf_yambo=.true. nogg=.true. auxdvscf=trim(fildvscf) ! YAMBO < CASE( 'lambda_tetra' ) elph=.true. elph_mat=.false. elph_simple=.false. trans = .false. elph_tetra = 1 CASE( 'gamma_tetra' ) elph=.true. elph_mat=.false. elph_simple=.false. trans = .false. elph_tetra = 2 CASE( 'scdft_input' ) elph=.true. elph_mat=.false. elph_simple=.false. trans = .false. elph_tetra = 3 CASE( 'ahc' ) elph = .true. elph_ahc = .true. elph_mat = .false. elph_simple = .false. elph_epa = .false. trans = .false. nogg = .true. CASE( 'epw' ) elph=.true. elph_mat=.false. elph_simple=.false. elph_epa=.false. elph_epw=.true. CASE DEFAULT elph=.false. elph_mat=.false. elph_simple=.false. elph_epa=.false. END SELECT ! YAMBO > IF (.not.elph_yambo.and..not.dvscf_yambo) then ! YAMBO < IF (qplot.AND..NOT.ldisp) CALL errore('phq_readin','qplot requires ldisp=.true.',1) ! ENDIF IF (ldisp.AND.only_init.AND.(.NOT.lqdir)) & CALL errore('phq_readin', & 'only_init=.TRUE. requires lqdir=.TRUE. or data are lost',1) epsil = epsil .OR. lraman .OR. elop IF (modenum /= 0) search_sym=.FALSE. IF (elph_mat .OR. elph_ahc) THEN trans = .FALSE. ELSEIF (.NOT. elph) THEN trans = trans .OR. ldisp ENDIF ! ! Set default value for fildrho and fildvscf if they are required IF ( (lraman.OR.elop.OR.drho_star%open) .AND. fildrho == ' ') fildrho = 'drho' IF ( (elph_mat.OR.dvscf_star%open) .AND. fildvscf == ' ') fildvscf = 'dvscf' ! ! We can calculate dielectric, raman or elop tensors and no Born effective ! charges dF/dE, but we cannot calculate Born effective charges dF/dE ! without epsil. ! IF (zeu) zeu = epsil ! ! reads the q point (just if ldisp = .false.) ! IF (meta_ionode) THEN ios = 0 IF (qplot) THEN READ (qestdin, *, iostat = ios) nqaux ELSE IF (.NOT. ldisp) READ (qestdin, *, iostat = ios) (xq (ipol), ipol=1,3) ENDIF END IF CALL mp_bcast(ios, meta_ionode_id, world_comm ) CALL errore ('phq_readin', 'reading xq', ABS (ios) ) IF (qplot) THEN CALL mp_bcast(nqaux, meta_ionode_id, world_comm ) ALLOCATE(xqaux(3,nqaux)) ALLOCATE(wqaux(nqaux)) IF (meta_ionode) THEN DO iq=1, nqaux READ (qestdin, *, iostat = ios) (xqaux (ipol,iq), ipol=1,3), wqaux(iq) ENDDO ENDIF CALL mp_bcast(ios, meta_ionode_id, world_comm ) CALL errore ('phq_readin', 'reading xq', ABS (ios) ) CALL mp_bcast(xqaux, meta_ionode_id, world_comm ) CALL mp_bcast(wqaux, meta_ionode_id, world_comm ) ELSE CALL mp_bcast(xq, meta_ionode_id, world_comm ) ENDIF IF (.NOT.ldisp) THEN lgamma = xq (1) .EQ.0.D0.AND.xq (2) .EQ.0.D0.AND.xq (3) .EQ.0.D0 IF ( (epsil.OR.zue.or.lraman.or.elop) .AND..NOT.lgamma) & CALL errore ('phq_readin', 'gamma is needed for elec.field', 1) ENDIF IF (zue.AND..NOT.trans) CALL errore ('phq_readin', 'trans must be & &.t. for Zue calc.', 1) IF (trans.AND.(lrpa.OR.lnoloc)) CALL errore('phq_readin', & 'only dielectric constant with lrpa or lnoloc',1) IF (lrpa.or.lnoloc) THEN zeu=.FALSE. lraman=.FALSE. elop = .FALSE. ENDIF ! ! dvscf_interpolate ! IF (ldvscf_interpolate) THEN ! IF (wpot_dir == ' ') wpot_dir = TRIM(tmp_dir) // "w_pot/" wpot_dir = trimcheck(wpot_dir) ! IF (do_charge_neutral .AND. (.NOT. do_long_range)) THEN WRITE(stdout, '(5x,a)') 'charge neutrality for dvscf_interpolate is & & meaningful only if do_long_range is true.' WRITE(stdout, '(5x,a)') 'Set do_charge_neutral = .false.' do_charge_neutral = .FALSE. ENDIF ! ENDIF ! IF (trans .AND. ldvscf_interpolate) CALL errore ('phq_readin', & 'ldvscf_interpolate should be used only when trans = .false.', 1) IF (domag .AND. ldvscf_interpolate) CALL errore ('phq_readin', & 'ldvscf_interpolate and magnetism not implemented', 1) IF (okpaw .AND. ldvscf_interpolate) CALL errore ('phq_readin', & 'PAW and ldvscf_interpolate not tested.', 1) ! ! AHC e-ph coupling ! IF (elph_ahc) THEN ! IF (ahc_nbnd <= 0) CALL errore('phq_readin', & 'ahc_nbnd must be specified as a positive integer', 1) IF (ahc_nbndskip < 0) CALL errore('phq_readin', & 'ahc_nbndskip cannot be negative', 1) ! IF (ahc_dir == ' ') ahc_dir = TRIM(tmp_dir) // "ahc_dir/" ahc_dir = trimcheck(ahc_dir) ! ENDIF ! elph_ahc ! IF (elph_ahc .AND. trans) CALL errore ('phq_readin', & 'elph_ahc can be used only when trans = .false.', 1) ! ! reads the frequencies ( just if fpol = .true. ) ! IF ( fpol ) THEN IF ( .NOT. epsil) CALL errore ('phq_readin', & 'fpol=.TRUE. needs epsil=.TRUE.', 1 ) nfs=0 IF (meta_ionode) THEN READ (qestdin, *, iostat = ios) card IF ( TRIM(card)=='FREQUENCIES'.OR. & TRIM(card)=='frequencies'.OR. & TRIM(card)=='Frequencies') THEN READ (qestdin, *, iostat = ios) nfs ENDIF ENDIF CALL mp_bcast(ios, meta_ionode_id, world_comm ) CALL errore ('phq_readin', 'reading number of FREQUENCIES', ABS(ios) ) CALL mp_bcast(nfs, meta_ionode_id, world_comm ) if (nfs < 1) call errore('phq_readin','Too few frequencies',1) ALLOCATE(fiu(nfs)) IF (meta_ionode) THEN IF ( TRIM(card) == 'FREQUENCIES' .OR. & TRIM(card) == 'frequencies' .OR. & TRIM(card) == 'Frequencies' ) THEN DO i = 1, nfs READ (qestdin, *, iostat = ios) fiu(i) END DO END IF END IF CALL mp_bcast(ios, meta_ionode_id, world_comm ) CALL errore ('phq_readin', 'reading FREQUENCIES card', ABS(ios) ) CALL mp_bcast(fiu, meta_ionode_id, world_comm ) ELSE nfs=1 ALLOCATE(fiu(1)) fiu=0.0_DP END IF ! ! ! Here we finished the reading of the input file. ! Now allocate space for pwscf variables, read and check them. ! ! amass will be read again from file: ! save its content in auxiliary variables ! ALLOCATE ( amass_input( SIZE(amass) ) ) amass_input(:)= amass(:) ! tmp_dir_save=tmp_dir tmp_dir_ph= trimcheck( TRIM (tmp_dir) // '_ph' // int_to_char(my_image_id) ) CALL check_tempdir ( tmp_dir_ph, exst, parallelfs ) tmp_dir_phq=tmp_dir_ph ext_restart=.FALSE. ext_recover=.FALSE. rec_code_read=-1000 IF (recover) THEN ! ! With a recover run we read here the mesh of q points, the current iq, ! and the current frequency ! CALL ph_readfile('init', 0, 0, ierr) CALL ph_readfile('status_ph', 0, 0, ierr1) ! ! If some error occured here, we cannot recover the run ! IF (ierr /= 0 .OR. ierr1 /= 0 ) THEN write(stdout,'(5x,"Run is not recoverable starting from scratch")') recover=.FALSE. goto 1001 ENDIF ! ! We check if the bands and the information on the pw run are in the directory ! written by the phonon code for the current q point. If the file exists ! we read from there, otherwise use the information in tmp_dir. ! IF (lqdir) THEN tmp_dir_phq= trimcheck ( TRIM(tmp_dir_ph) // TRIM(prefix) // & & '.q_' // int_to_char(current_iq) ) CALL check_restart_recover(ext_recover, ext_restart) IF (.NOT.ext_recover.AND..NOT.ext_restart) tmp_dir_phq=tmp_dir_ph ENDIF ! filename=TRIM(tmp_dir_phq)//TRIM(prefix)//postfix//xmlpun_schema IF (ionode) inquire (file =TRIM(filename), exist = exst) ! CALL mp_bcast( exst, ionode_id, intra_image_comm ) ! ! If this file exist we use it to recover the pw.x informations ! IF (exst) tmp_dir=tmp_dir_phq u_from_file=.true. ENDIF 1001 CONTINUE IF (qplot.AND..NOT.recover) THEN IF (q2d) THEN nqs=wqaux(2)*wqaux(3) ALLOCATE(x_q(3,nqs)) ALLOCATE(wq(nqs)) CALL generate_k_in_plane(nqaux, xqaux, wqaux, x_q, wq, nqs) ELSEIF (q_in_band_form) THEN nqs=SUM(wqaux(1:nqaux-1))+1 DO i=1,nqaux-1 IF (wqaux(i)==0) nqs=nqs+1 ENDDO ALLOCATE(x_q(3,nqs)) ALLOCATE(wq(nqs)) CALL generate_k_along_lines(nqaux, xqaux, wqaux, x_q, wq, nqs) ELSE nqs=nqaux ALLOCATE(x_q(3,nqs)) ALLOCATE(wq(nqs)) wq(:)=wqaux(:) x_q(:,1:nqs)=xqaux(:,1:nqs) ENDIF DEALLOCATE(xqaux) DEALLOCATE(wqaux) ALLOCATE(lgamma_iq(nqs)) DO iq=1, nqs lgamma_iq(iq)= ( ABS(x_q(1,iq)) .LT. 1.0e-10_dp ) .AND. & ( ABS(x_q(2,iq)) .LT. 1.0e-10_dp ) .AND. & ( ABS(x_q(3,iq)) .LT. 1.0e-10_dp ) ENDDO WRITE(stdout, '(//5x,"Dynamical matrices for q-points given in input")') WRITE(stdout, '(5x,"(",i4,"q-points):")') nqs WRITE(stdout, '(5x," N xq(1) xq(2) xq(3) " )') DO iq = 1, nqs WRITE(stdout, '(5x,i3, 3f14.9)') iq, x_q(1,iq), x_q(2,iq), x_q(3,iq) END DO ENDIF ! IF (reduce_io) io_level=0 ! ! DFPT+U: the occupation matrix ns is read via read_file ! CALL read_file ( ) ! magnetic_sym=noncolin .AND. domag ! ! init_start_grid returns .true. if a new k-point grid is set from values ! read from input (this happens if nk1*nk2*nk3 > 0; otherwise reset_grid ! returns .false., leaves the current values, read in read_file, unchanged) ! newgrid = reset_grid (nk1, nk2, nk3, k1, k2, k3) if(newgrid.and.elph_mat)then WRITE(stdout, '(//5x,"WARNING: Wannier elph do not use explicit new grid: nk1 nk2 nk3 ignored")') newgrid=.false. end if ! tmp_dir=tmp_dir_save ! IF (modenum > 3*nat) CALL errore ('phq_readin', ' Wrong modenum ', 2) IF (gamma_only) CALL errore('phq_readin',& 'cannot start from pw.x data file using Gamma-point tricks',1) IF (lda_plus_u) THEN ! WRITE(stdout,'(/5x,a)') "Phonon calculation with DFPT+U; please cite" WRITE(stdout,'(5x,a)') "A. Floris et al., Phys. Rev. B 84, 161102(R) (2011)" WRITE(stdout,'(5x,a)') "A. Floris et al., Phys. Rev. B 101, 064305 (2020)" WRITE(stdout,'(5x,a)') "in publications or presentations arising from this work." ! IF (Hubbard_projectors.NE."atomic") CALL errore("phq_readin", & " The phonon code for this Hubbard projectors type is not implemented",1) IF (lda_plus_u_kind.NE.0) CALL errore("phq_readin", & " The phonon code for this lda_plus_u_kind is not implemented",1) IF (elph) CALL errore("phq_readin", & " Electron-phonon with Hubbard U is not supported",1) IF (lraman) CALL errore("phq_readin", & " The phonon code with Raman and Hubbard U is not implemented",1) ! ENDIF ! checks IF (elph_ahc .AND. domag) CALL errore ('phq_readin', & 'elph_ahc and magnetism not implemented', 1) IF (elph_ahc .AND. okpaw) CALL errore ('phq_readin', & 'elph_ahc and PAW not tested.', 1) IF (elph_ahc .AND. okvan) CALL errore ('phq_readin', & 'elph_ahc and PAW not tested.', 1) IF (elph_ahc .AND. lda_plus_u) CALL errore ('phq_readin', & 'elph_ahc and lda_plus_u not tested.', 1) IF (ts_vdw) CALL errore('phq_readin',& 'The phonon code with TS-VdW is not yet available',1) IF (ldftd3) CALL errore('phq_readin',& 'The phonon code with Grimme''s DFT-D3 is not yet available',1) IF ( xclib_dft_is('meta') ) CALL errore('phq_readin',& 'The phonon code with meta-GGA functionals is not yet available',1) IF ( xclib_dft_is('hybrid') ) CALL errore('phq_readin',& 'The phonon code with hybrid functionals is not yet available',1) IF (okpaw.and.(lraman.or.elop)) CALL errore('phq_readin',& 'The phonon code with paw and raman or elop is not yet available',1) IF (magnetic_sym) THEN WRITE(stdout,'(/5x,a)') "Phonon calculation in the non-collinear magnetic case;" WRITE(stdout,'(5x,a)') "please cite A. Urru and A. Dal Corso, Phys. Rev. B 100," WRITE(stdout,'(5x,a)') "045115 (2019) for the theoretical background." IF (okpaw) CALL errore('phq_readin',& 'The phonon code with paw and domag is not available yet',1) ENDIF IF (okvan.and.(lraman.or.elop)) CALL errore('phq_readin',& 'The phonon code with US-PP and raman or elop not yet available',1) IF (noncolin.and.(lraman.or.elop)) CALL errore('phq_readin', & 'lraman, elop, and noncolin not programmed',1) IF ( (noncolin.or.lspinorb) .and. elph ) CALL errore('phq_readin', & 'el-ph coefficient calculation disabled in noncolinear/spinorbit case',1) IF (lmovecell) CALL errore('phq_readin', & 'The phonon code is not working after vc-relax',1) if(elph_mat.and.fildvscf.eq.' ') call errore('phq_readin',& 'el-ph with wannier requires fildvscf',1) IF(elph_mat.and.npool.ne.1) call errore('phq_readin',& 'el-ph with wannier : pools not implemented',1) IF(elph.and.nimage>1) call errore('phq_readin',& 'el-ph with images not implemented',1) IF (elph.OR.fildvscf /= ' ') lqdir=.TRUE. IF(dvscf_star%open.and.nimage>1) CALL errore('phq_readin',& 'dvscf_star with image parallelization is not yet available',1) IF(drho_star%open.and.nimage>1) CALL errore('phq_readin',& 'drho_star with image parallelization is not yet available',1) IF (lda_plus_u .AND. read_dns_bare .AND. ldisp) lqdir=.TRUE. IF (.NOT.ldisp) lqdir=.FALSE. IF (i_cons /= 0) & CALL errore('phq_readin',& 'The phonon code with constrained magnetization is not yet available',1) IF (two_fermi_energies .AND. (ltetra .OR. lgauss)) & CALL errore('phq_readin',& 'The phonon code with two fermi energies is not available for metals',1) IF (tqr) CALL errore('phq_readin',& 'The phonon code with Q in real space not available',1) IF (start_irr < 0 ) CALL errore('phq_readin', 'wrong start_irr',1) ! IF (start_q <= 0 ) CALL errore('phq_readin', 'wrong start_q',1) ! ! the dynamical matrix is written in xml format if fildyn ends in ! .xml or in the noncollinear case. ! xmldyn=has_xml(fildyn) !IF (noncolin) xmldyn=.TRUE. ! ! If a band structure calculation needs to be done do not open a file ! for k point ! restart = recover ! ! set masses to values read from input, if available; ! leave values read from file otherwise ! DO it = 1, ntyp IF (amass_input(it) < 0.0_DP) amass_input(it)= & atom_weight(atomic_number(TRIM(atm(it)))) IF (amass_input(it) > 0.D0) amass(it) = amass_input(it) IF (amass(it) <= 0.D0) CALL errore ('phq_readin', 'Wrong masses', it) ENDDO DEALLOCATE (amass_input) lgamma_gamma=.FALSE. IF (.NOT.ldisp) THEN IF (nkstot==1.OR.(nkstot==2.AND.nspin==2)) THEN lgamma_gamma=(lgamma.AND.(ABS(xk(1,1))<1.D-12) & .AND.(ABS(xk(2,1))<1.D-12) & .AND.(ABS(xk(3,1))<1.D-12) ) ENDIF IF (nogg) lgamma_gamma=.FALSE. IF ((nat_todo /= 0) .and. lgamma_gamma) CALL errore( & 'phq_readin', 'gamma_gamma tricks with nat_todo & & not available. Use nogg=.true.', 1) IF (lda_plus_u .AND. lgamma_gamma) THEN WRITE(stdout,'(5x,a)') "DFPT+U does not support k=gamma and q=gamma tricks: disabling them..." lgamma_gamma=.FALSE. ENDIF ! IF (nimage > 1 .AND. lgamma_gamma) CALL errore( & 'phq_readin','gamma_gamma tricks with images not implemented',1) IF (lgamma) THEN nksq = nks ELSE nksq = nks / 2 ENDIF ENDIF IF (lgamma_gamma.AND.ldiag) CALL errore('phq_readin','incompatible flags',1) IF (lgamma_gamma.AND.elph ) CALL errore('phq_readin','lgamma_gamma and electron-phonon are incompatible',1) ! IF (tfixed_occ) & CALL errore('phq_readin','phonon with arbitrary occupations not tested',1) ! !YAMBO > IF (elph .AND. .NOT.(lgauss .OR. ltetra) & .AND. .NOT. (elph_yambo .OR. elph_ahc .OR. elph_epw).and..not.elph_mat) & CALL errore ('phq_readin', 'Electron-phonon only for metals', 1) !YAMBO < IF (elph .AND. fildvscf.EQ.' ' .AND. .NOT. ldvscf_interpolate) & CALL errore ('phq_readin', 'El-ph needs a DeltaVscf file', 1) ! There might be other variables in the input file which describe ! partial computation of the dynamical matrix. Read them here ! CALL allocate_part ( nat ) ! IF ( nat_todo < 0 .OR. nat_todo > nat ) & CALL errore ('phq_readin', 'nat_todo is wrong', 1) IF (nat_todo.NE.0) THEN IF (meta_ionode) READ (qestdin, *, iostat = ios) (atomo (na), na=1,nat_todo) CALL mp_bcast(ios, meta_ionode_id, world_comm ) CALL errore ('phq_readin', 'reading atoms', ABS (ios) ) CALL mp_bcast(atomo, meta_ionode_id, world_comm ) ENDIF nat_todo_input=nat_todo ! ! end of reading, close unit qestdin, remove temporary input file if existing ! FIXME: closing input file here breaks alpha2F.x that reads what follows !!! IF (meta_ionode) ios = close_input_file () IF (epsil.AND.(lgauss .OR. ltetra)) & CALL errore ('phq_readin', 'no elec. field with metals', 1) IF (modenum > 0) THEN IF ( ldisp ) & CALL errore('phq_readin','Dispersion calculation and & & single mode calculation not possibile !',1) nat_todo = 0 ENDIF ! ! Tetrahedron method for DFPT and El-Ph ! IF(ltetra .AND. tetra_type == 0) & & CALL errore ('phq_readin', 'DFPT with the Blochl correction is not implemented', 1) ! IF(.NOT. ltetra .AND. elph_tetra /= 0) & & CALL errore ('phq_readin', '"electron_phonon" and "occupation" are inconsistent.', 1) ! IF (modenum > 0 .OR. lraman ) lgamma_gamma=.FALSE. IF (.NOT.lgamma_gamma) asr=.FALSE. ! IF ((ldisp.AND..NOT.qplot) .AND. & (nq1 .LE. 0 .OR. nq2 .LE. 0 .OR. nq3 .LE. 0)) & CALL errore('phq_readin','nq1, nq2, and nq3 must be greater than 0',1) CALL save_ph_input_variables() ! RETURN ! END SUBROUTINE phq_readin2
gpl-2.0
wilmarcardonac/hypermcmc
lapack-3.5.0/SRC/slatps.f
24
24381
*> \brief \b SLATPS solves a triangular system of equations with the matrix held in packed storage. * * =========== DOCUMENTATION =========== * * Online html documentation available at * http://www.netlib.org/lapack/explore-html/ * *> \htmlonly *> Download SLATPS + dependencies *> <a href="http://www.netlib.org/cgi-bin/netlibfiles.tgz?format=tgz&filename=/lapack/lapack_routine/slatps.f"> *> [TGZ]</a> *> <a href="http://www.netlib.org/cgi-bin/netlibfiles.zip?format=zip&filename=/lapack/lapack_routine/slatps.f"> *> [ZIP]</a> *> <a href="http://www.netlib.org/cgi-bin/netlibfiles.txt?format=txt&filename=/lapack/lapack_routine/slatps.f"> *> [TXT]</a> *> \endhtmlonly * * Definition: * =========== * * SUBROUTINE SLATPS( UPLO, TRANS, DIAG, NORMIN, N, AP, X, SCALE, * CNORM, INFO ) * * .. Scalar Arguments .. * CHARACTER DIAG, NORMIN, TRANS, UPLO * INTEGER INFO, N * REAL SCALE * .. * .. Array Arguments .. * REAL AP( * ), CNORM( * ), X( * ) * .. * * *> \par Purpose: * ============= *> *> \verbatim *> *> SLATPS solves one of the triangular systems *> *> A *x = s*b or A**T*x = s*b *> *> with scaling to prevent overflow, where A is an upper or lower *> triangular matrix stored in packed form. Here A**T denotes the *> transpose of A, x and b are n-element vectors, and s is a scaling *> factor, usually less than or equal to 1, chosen so that the *> components of x will be less than the overflow threshold. If the *> unscaled problem will not cause overflow, the Level 2 BLAS routine *> STPSV is called. If the matrix A is singular (A(j,j) = 0 for some j), *> then s is set to 0 and a non-trivial solution to A*x = 0 is returned. *> \endverbatim * * Arguments: * ========== * *> \param[in] UPLO *> \verbatim *> UPLO is CHARACTER*1 *> Specifies whether the matrix A is upper or lower triangular. *> = 'U': Upper triangular *> = 'L': Lower triangular *> \endverbatim *> *> \param[in] TRANS *> \verbatim *> TRANS is CHARACTER*1 *> Specifies the operation applied to A. *> = 'N': Solve A * x = s*b (No transpose) *> = 'T': Solve A**T* x = s*b (Transpose) *> = 'C': Solve A**T* x = s*b (Conjugate transpose = Transpose) *> \endverbatim *> *> \param[in] DIAG *> \verbatim *> DIAG is CHARACTER*1 *> Specifies whether or not the matrix A is unit triangular. *> = 'N': Non-unit triangular *> = 'U': Unit triangular *> \endverbatim *> *> \param[in] NORMIN *> \verbatim *> NORMIN is CHARACTER*1 *> Specifies whether CNORM has been set or not. *> = 'Y': CNORM contains the column norms on entry *> = 'N': CNORM is not set on entry. On exit, the norms will *> be computed and stored in CNORM. *> \endverbatim *> *> \param[in] N *> \verbatim *> N is INTEGER *> The order of the matrix A. N >= 0. *> \endverbatim *> *> \param[in] AP *> \verbatim *> AP is REAL array, dimension (N*(N+1)/2) *> The upper or lower triangular matrix A, packed columnwise in *> a linear array. The j-th column of A is stored in the array *> AP as follows: *> if UPLO = 'U', AP(i + (j-1)*j/2) = A(i,j) for 1<=i<=j; *> if UPLO = 'L', AP(i + (j-1)*(2n-j)/2) = A(i,j) for j<=i<=n. *> \endverbatim *> *> \param[in,out] X *> \verbatim *> X is REAL array, dimension (N) *> On entry, the right hand side b of the triangular system. *> On exit, X is overwritten by the solution vector x. *> \endverbatim *> *> \param[out] SCALE *> \verbatim *> SCALE is REAL *> The scaling factor s for the triangular system *> A * x = s*b or A**T* x = s*b. *> If SCALE = 0, the matrix A is singular or badly scaled, and *> the vector x is an exact or approximate solution to A*x = 0. *> \endverbatim *> *> \param[in,out] CNORM *> \verbatim *> CNORM is REAL array, dimension (N) *> *> If NORMIN = 'Y', CNORM is an input argument and CNORM(j) *> contains the norm of the off-diagonal part of the j-th column *> of A. If TRANS = 'N', CNORM(j) must be greater than or equal *> to the infinity-norm, and if TRANS = 'T' or 'C', CNORM(j) *> must be greater than or equal to the 1-norm. *> *> If NORMIN = 'N', CNORM is an output argument and CNORM(j) *> returns the 1-norm of the offdiagonal part of the j-th column *> of A. *> \endverbatim *> *> \param[out] INFO *> \verbatim *> INFO is INTEGER *> = 0: successful exit *> < 0: if INFO = -k, the k-th argument had an illegal value *> \endverbatim * * Authors: * ======== * *> \author Univ. of Tennessee *> \author Univ. of California Berkeley *> \author Univ. of Colorado Denver *> \author NAG Ltd. * *> \date September 2012 * *> \ingroup realOTHERauxiliary * *> \par Further Details: * ===================== *> *> \verbatim *> *> A rough bound on x is computed; if that is less than overflow, STPSV *> is called, otherwise, specific code is used which checks for possible *> overflow or divide-by-zero at every operation. *> *> A columnwise scheme is used for solving A*x = b. The basic algorithm *> if A is lower triangular is *> *> x[1:n] := b[1:n] *> for j = 1, ..., n *> x(j) := x(j) / A(j,j) *> x[j+1:n] := x[j+1:n] - x(j) * A[j+1:n,j] *> end *> *> Define bounds on the components of x after j iterations of the loop: *> M(j) = bound on x[1:j] *> G(j) = bound on x[j+1:n] *> Initially, let M(0) = 0 and G(0) = max{x(i), i=1,...,n}. *> *> Then for iteration j+1 we have *> M(j+1) <= G(j) / | A(j+1,j+1) | *> G(j+1) <= G(j) + M(j+1) * | A[j+2:n,j+1] | *> <= G(j) ( 1 + CNORM(j+1) / | A(j+1,j+1) | ) *> *> where CNORM(j+1) is greater than or equal to the infinity-norm of *> column j+1 of A, not counting the diagonal. Hence *> *> G(j) <= G(0) product ( 1 + CNORM(i) / | A(i,i) | ) *> 1<=i<=j *> and *> *> |x(j)| <= ( G(0) / |A(j,j)| ) product ( 1 + CNORM(i) / |A(i,i)| ) *> 1<=i< j *> *> Since |x(j)| <= M(j), we use the Level 2 BLAS routine STPSV if the *> reciprocal of the largest M(j), j=1,..,n, is larger than *> max(underflow, 1/overflow). *> *> The bound on x(j) is also used to determine when a step in the *> columnwise method can be performed without fear of overflow. If *> the computed bound is greater than a large constant, x is scaled to *> prevent overflow, but if the bound overflows, x is set to 0, x(j) to *> 1, and scale to 0, and a non-trivial solution to A*x = 0 is found. *> *> Similarly, a row-wise scheme is used to solve A**T*x = b. The basic *> algorithm for A upper triangular is *> *> for j = 1, ..., n *> x(j) := ( b(j) - A[1:j-1,j]**T * x[1:j-1] ) / A(j,j) *> end *> *> We simultaneously compute two bounds *> G(j) = bound on ( b(i) - A[1:i-1,i]**T * x[1:i-1] ), 1<=i<=j *> M(j) = bound on x(i), 1<=i<=j *> *> The initial values are G(0) = 0, M(0) = max{b(i), i=1,..,n}, and we *> add the constraint G(j) >= G(j-1) and M(j) >= M(j-1) for j >= 1. *> Then the bound on x(j) is *> *> M(j) <= M(j-1) * ( 1 + CNORM(j) ) / | A(j,j) | *> *> <= M(0) * product ( ( 1 + CNORM(i) ) / |A(i,i)| ) *> 1<=i<=j *> *> and we can safely call STPSV if 1/M(n) and 1/G(n) are both greater *> than max(underflow, 1/overflow). *> \endverbatim *> * ===================================================================== SUBROUTINE SLATPS( UPLO, TRANS, DIAG, NORMIN, N, AP, X, SCALE, $ CNORM, INFO ) * * -- LAPACK auxiliary routine (version 3.4.2) -- * -- LAPACK is a software package provided by Univ. of Tennessee, -- * -- Univ. of California Berkeley, Univ. of Colorado Denver and NAG Ltd..-- * September 2012 * * .. Scalar Arguments .. CHARACTER DIAG, NORMIN, TRANS, UPLO INTEGER INFO, N REAL SCALE * .. * .. Array Arguments .. REAL AP( * ), CNORM( * ), X( * ) * .. * * ===================================================================== * * .. Parameters .. REAL ZERO, HALF, ONE PARAMETER ( ZERO = 0.0E+0, HALF = 0.5E+0, ONE = 1.0E+0 ) * .. * .. Local Scalars .. LOGICAL NOTRAN, NOUNIT, UPPER INTEGER I, IMAX, IP, J, JFIRST, JINC, JLAST, JLEN REAL BIGNUM, GROW, REC, SMLNUM, SUMJ, TJJ, TJJS, $ TMAX, TSCAL, USCAL, XBND, XJ, XMAX * .. * .. External Functions .. LOGICAL LSAME INTEGER ISAMAX REAL SASUM, SDOT, SLAMCH EXTERNAL LSAME, ISAMAX, SASUM, SDOT, SLAMCH * .. * .. External Subroutines .. EXTERNAL SAXPY, SSCAL, STPSV, XERBLA * .. * .. Intrinsic Functions .. INTRINSIC ABS, MAX, MIN * .. * .. Executable Statements .. * INFO = 0 UPPER = LSAME( UPLO, 'U' ) NOTRAN = LSAME( TRANS, 'N' ) NOUNIT = LSAME( DIAG, 'N' ) * * Test the input parameters. * IF( .NOT.UPPER .AND. .NOT.LSAME( UPLO, 'L' ) ) THEN INFO = -1 ELSE IF( .NOT.NOTRAN .AND. .NOT.LSAME( TRANS, 'T' ) .AND. .NOT. $ LSAME( TRANS, 'C' ) ) THEN INFO = -2 ELSE IF( .NOT.NOUNIT .AND. .NOT.LSAME( DIAG, 'U' ) ) THEN INFO = -3 ELSE IF( .NOT.LSAME( NORMIN, 'Y' ) .AND. .NOT. $ LSAME( NORMIN, 'N' ) ) THEN INFO = -4 ELSE IF( N.LT.0 ) THEN INFO = -5 END IF IF( INFO.NE.0 ) THEN CALL XERBLA( 'SLATPS', -INFO ) RETURN END IF * * Quick return if possible * IF( N.EQ.0 ) $ RETURN * * Determine machine dependent parameters to control overflow. * SMLNUM = SLAMCH( 'Safe minimum' ) / SLAMCH( 'Precision' ) BIGNUM = ONE / SMLNUM SCALE = ONE * IF( LSAME( NORMIN, 'N' ) ) THEN * * Compute the 1-norm of each column, not including the diagonal. * IF( UPPER ) THEN * * A is upper triangular. * IP = 1 DO 10 J = 1, N CNORM( J ) = SASUM( J-1, AP( IP ), 1 ) IP = IP + J 10 CONTINUE ELSE * * A is lower triangular. * IP = 1 DO 20 J = 1, N - 1 CNORM( J ) = SASUM( N-J, AP( IP+1 ), 1 ) IP = IP + N - J + 1 20 CONTINUE CNORM( N ) = ZERO END IF END IF * * Scale the column norms by TSCAL if the maximum element in CNORM is * greater than BIGNUM. * IMAX = ISAMAX( N, CNORM, 1 ) TMAX = CNORM( IMAX ) IF( TMAX.LE.BIGNUM ) THEN TSCAL = ONE ELSE TSCAL = ONE / ( SMLNUM*TMAX ) CALL SSCAL( N, TSCAL, CNORM, 1 ) END IF * * Compute a bound on the computed solution vector to see if the * Level 2 BLAS routine STPSV can be used. * J = ISAMAX( N, X, 1 ) XMAX = ABS( X( J ) ) XBND = XMAX IF( NOTRAN ) THEN * * Compute the growth in A * x = b. * IF( UPPER ) THEN JFIRST = N JLAST = 1 JINC = -1 ELSE JFIRST = 1 JLAST = N JINC = 1 END IF * IF( TSCAL.NE.ONE ) THEN GROW = ZERO GO TO 50 END IF * IF( NOUNIT ) THEN * * A is non-unit triangular. * * Compute GROW = 1/G(j) and XBND = 1/M(j). * Initially, G(0) = max{x(i), i=1,...,n}. * GROW = ONE / MAX( XBND, SMLNUM ) XBND = GROW IP = JFIRST*( JFIRST+1 ) / 2 JLEN = N DO 30 J = JFIRST, JLAST, JINC * * Exit the loop if the growth factor is too small. * IF( GROW.LE.SMLNUM ) $ GO TO 50 * * M(j) = G(j-1) / abs(A(j,j)) * TJJ = ABS( AP( IP ) ) XBND = MIN( XBND, MIN( ONE, TJJ )*GROW ) IF( TJJ+CNORM( J ).GE.SMLNUM ) THEN * * G(j) = G(j-1)*( 1 + CNORM(j) / abs(A(j,j)) ) * GROW = GROW*( TJJ / ( TJJ+CNORM( J ) ) ) ELSE * * G(j) could overflow, set GROW to 0. * GROW = ZERO END IF IP = IP + JINC*JLEN JLEN = JLEN - 1 30 CONTINUE GROW = XBND ELSE * * A is unit triangular. * * Compute GROW = 1/G(j), where G(0) = max{x(i), i=1,...,n}. * GROW = MIN( ONE, ONE / MAX( XBND, SMLNUM ) ) DO 40 J = JFIRST, JLAST, JINC * * Exit the loop if the growth factor is too small. * IF( GROW.LE.SMLNUM ) $ GO TO 50 * * G(j) = G(j-1)*( 1 + CNORM(j) ) * GROW = GROW*( ONE / ( ONE+CNORM( J ) ) ) 40 CONTINUE END IF 50 CONTINUE * ELSE * * Compute the growth in A**T * x = b. * IF( UPPER ) THEN JFIRST = 1 JLAST = N JINC = 1 ELSE JFIRST = N JLAST = 1 JINC = -1 END IF * IF( TSCAL.NE.ONE ) THEN GROW = ZERO GO TO 80 END IF * IF( NOUNIT ) THEN * * A is non-unit triangular. * * Compute GROW = 1/G(j) and XBND = 1/M(j). * Initially, M(0) = max{x(i), i=1,...,n}. * GROW = ONE / MAX( XBND, SMLNUM ) XBND = GROW IP = JFIRST*( JFIRST+1 ) / 2 JLEN = 1 DO 60 J = JFIRST, JLAST, JINC * * Exit the loop if the growth factor is too small. * IF( GROW.LE.SMLNUM ) $ GO TO 80 * * G(j) = max( G(j-1), M(j-1)*( 1 + CNORM(j) ) ) * XJ = ONE + CNORM( J ) GROW = MIN( GROW, XBND / XJ ) * * M(j) = M(j-1)*( 1 + CNORM(j) ) / abs(A(j,j)) * TJJ = ABS( AP( IP ) ) IF( XJ.GT.TJJ ) $ XBND = XBND*( TJJ / XJ ) JLEN = JLEN + 1 IP = IP + JINC*JLEN 60 CONTINUE GROW = MIN( GROW, XBND ) ELSE * * A is unit triangular. * * Compute GROW = 1/G(j), where G(0) = max{x(i), i=1,...,n}. * GROW = MIN( ONE, ONE / MAX( XBND, SMLNUM ) ) DO 70 J = JFIRST, JLAST, JINC * * Exit the loop if the growth factor is too small. * IF( GROW.LE.SMLNUM ) $ GO TO 80 * * G(j) = ( 1 + CNORM(j) )*G(j-1) * XJ = ONE + CNORM( J ) GROW = GROW / XJ 70 CONTINUE END IF 80 CONTINUE END IF * IF( ( GROW*TSCAL ).GT.SMLNUM ) THEN * * Use the Level 2 BLAS solve if the reciprocal of the bound on * elements of X is not too small. * CALL STPSV( UPLO, TRANS, DIAG, N, AP, X, 1 ) ELSE * * Use a Level 1 BLAS solve, scaling intermediate results. * IF( XMAX.GT.BIGNUM ) THEN * * Scale X so that its components are less than or equal to * BIGNUM in absolute value. * SCALE = BIGNUM / XMAX CALL SSCAL( N, SCALE, X, 1 ) XMAX = BIGNUM END IF * IF( NOTRAN ) THEN * * Solve A * x = b * IP = JFIRST*( JFIRST+1 ) / 2 DO 100 J = JFIRST, JLAST, JINC * * Compute x(j) = b(j) / A(j,j), scaling x if necessary. * XJ = ABS( X( J ) ) IF( NOUNIT ) THEN TJJS = AP( IP )*TSCAL ELSE TJJS = TSCAL IF( TSCAL.EQ.ONE ) $ GO TO 95 END IF TJJ = ABS( TJJS ) IF( TJJ.GT.SMLNUM ) THEN * * abs(A(j,j)) > SMLNUM: * IF( TJJ.LT.ONE ) THEN IF( XJ.GT.TJJ*BIGNUM ) THEN * * Scale x by 1/b(j). * REC = ONE / XJ CALL SSCAL( N, REC, X, 1 ) SCALE = SCALE*REC XMAX = XMAX*REC END IF END IF X( J ) = X( J ) / TJJS XJ = ABS( X( J ) ) ELSE IF( TJJ.GT.ZERO ) THEN * * 0 < abs(A(j,j)) <= SMLNUM: * IF( XJ.GT.TJJ*BIGNUM ) THEN * * Scale x by (1/abs(x(j)))*abs(A(j,j))*BIGNUM * to avoid overflow when dividing by A(j,j). * REC = ( TJJ*BIGNUM ) / XJ IF( CNORM( J ).GT.ONE ) THEN * * Scale by 1/CNORM(j) to avoid overflow when * multiplying x(j) times column j. * REC = REC / CNORM( J ) END IF CALL SSCAL( N, REC, X, 1 ) SCALE = SCALE*REC XMAX = XMAX*REC END IF X( J ) = X( J ) / TJJS XJ = ABS( X( J ) ) ELSE * * A(j,j) = 0: Set x(1:n) = 0, x(j) = 1, and * scale = 0, and compute a solution to A*x = 0. * DO 90 I = 1, N X( I ) = ZERO 90 CONTINUE X( J ) = ONE XJ = ONE SCALE = ZERO XMAX = ZERO END IF 95 CONTINUE * * Scale x if necessary to avoid overflow when adding a * multiple of column j of A. * IF( XJ.GT.ONE ) THEN REC = ONE / XJ IF( CNORM( J ).GT.( BIGNUM-XMAX )*REC ) THEN * * Scale x by 1/(2*abs(x(j))). * REC = REC*HALF CALL SSCAL( N, REC, X, 1 ) SCALE = SCALE*REC END IF ELSE IF( XJ*CNORM( J ).GT.( BIGNUM-XMAX ) ) THEN * * Scale x by 1/2. * CALL SSCAL( N, HALF, X, 1 ) SCALE = SCALE*HALF END IF * IF( UPPER ) THEN IF( J.GT.1 ) THEN * * Compute the update * x(1:j-1) := x(1:j-1) - x(j) * A(1:j-1,j) * CALL SAXPY( J-1, -X( J )*TSCAL, AP( IP-J+1 ), 1, X, $ 1 ) I = ISAMAX( J-1, X, 1 ) XMAX = ABS( X( I ) ) END IF IP = IP - J ELSE IF( J.LT.N ) THEN * * Compute the update * x(j+1:n) := x(j+1:n) - x(j) * A(j+1:n,j) * CALL SAXPY( N-J, -X( J )*TSCAL, AP( IP+1 ), 1, $ X( J+1 ), 1 ) I = J + ISAMAX( N-J, X( J+1 ), 1 ) XMAX = ABS( X( I ) ) END IF IP = IP + N - J + 1 END IF 100 CONTINUE * ELSE * * Solve A**T * x = b * IP = JFIRST*( JFIRST+1 ) / 2 JLEN = 1 DO 140 J = JFIRST, JLAST, JINC * * Compute x(j) = b(j) - sum A(k,j)*x(k). * k<>j * XJ = ABS( X( J ) ) USCAL = TSCAL REC = ONE / MAX( XMAX, ONE ) IF( CNORM( J ).GT.( BIGNUM-XJ )*REC ) THEN * * If x(j) could overflow, scale x by 1/(2*XMAX). * REC = REC*HALF IF( NOUNIT ) THEN TJJS = AP( IP )*TSCAL ELSE TJJS = TSCAL END IF TJJ = ABS( TJJS ) IF( TJJ.GT.ONE ) THEN * * Divide by A(j,j) when scaling x if A(j,j) > 1. * REC = MIN( ONE, REC*TJJ ) USCAL = USCAL / TJJS END IF IF( REC.LT.ONE ) THEN CALL SSCAL( N, REC, X, 1 ) SCALE = SCALE*REC XMAX = XMAX*REC END IF END IF * SUMJ = ZERO IF( USCAL.EQ.ONE ) THEN * * If the scaling needed for A in the dot product is 1, * call SDOT to perform the dot product. * IF( UPPER ) THEN SUMJ = SDOT( J-1, AP( IP-J+1 ), 1, X, 1 ) ELSE IF( J.LT.N ) THEN SUMJ = SDOT( N-J, AP( IP+1 ), 1, X( J+1 ), 1 ) END IF ELSE * * Otherwise, use in-line code for the dot product. * IF( UPPER ) THEN DO 110 I = 1, J - 1 SUMJ = SUMJ + ( AP( IP-J+I )*USCAL )*X( I ) 110 CONTINUE ELSE IF( J.LT.N ) THEN DO 120 I = 1, N - J SUMJ = SUMJ + ( AP( IP+I )*USCAL )*X( J+I ) 120 CONTINUE END IF END IF * IF( USCAL.EQ.TSCAL ) THEN * * Compute x(j) := ( x(j) - sumj ) / A(j,j) if 1/A(j,j) * was not used to scale the dotproduct. * X( J ) = X( J ) - SUMJ XJ = ABS( X( J ) ) IF( NOUNIT ) THEN * * Compute x(j) = x(j) / A(j,j), scaling if necessary. * TJJS = AP( IP )*TSCAL ELSE TJJS = TSCAL IF( TSCAL.EQ.ONE ) $ GO TO 135 END IF TJJ = ABS( TJJS ) IF( TJJ.GT.SMLNUM ) THEN * * abs(A(j,j)) > SMLNUM: * IF( TJJ.LT.ONE ) THEN IF( XJ.GT.TJJ*BIGNUM ) THEN * * Scale X by 1/abs(x(j)). * REC = ONE / XJ CALL SSCAL( N, REC, X, 1 ) SCALE = SCALE*REC XMAX = XMAX*REC END IF END IF X( J ) = X( J ) / TJJS ELSE IF( TJJ.GT.ZERO ) THEN * * 0 < abs(A(j,j)) <= SMLNUM: * IF( XJ.GT.TJJ*BIGNUM ) THEN * * Scale x by (1/abs(x(j)))*abs(A(j,j))*BIGNUM. * REC = ( TJJ*BIGNUM ) / XJ CALL SSCAL( N, REC, X, 1 ) SCALE = SCALE*REC XMAX = XMAX*REC END IF X( J ) = X( J ) / TJJS ELSE * * A(j,j) = 0: Set x(1:n) = 0, x(j) = 1, and * scale = 0, and compute a solution to A**T*x = 0. * DO 130 I = 1, N X( I ) = ZERO 130 CONTINUE X( J ) = ONE SCALE = ZERO XMAX = ZERO END IF 135 CONTINUE ELSE * * Compute x(j) := x(j) / A(j,j) - sumj if the dot * product has already been divided by 1/A(j,j). * X( J ) = X( J ) / TJJS - SUMJ END IF XMAX = MAX( XMAX, ABS( X( J ) ) ) JLEN = JLEN + 1 IP = IP + JINC*JLEN 140 CONTINUE END IF SCALE = SCALE / TSCAL END IF * * Scale the column norms by 1/TSCAL for return. * IF( TSCAL.NE.ONE ) THEN CALL SSCAL( N, ONE / TSCAL, CNORM, 1 ) END IF * RETURN * * End of SLATPS * END
gpl-2.0
QEF/q-e
PW/src/multable.f90
2
1579
! ! Copyright (C) 2001-2010 Quantum ESPRESSO group ! This file is distributed under the terms of the ! GNU General Public License. See the file `License' ! in the root directory of the present distribution, ! or http://www.gnu.org/copyleft/gpl.txt . ! ! !----------------------------------------------------------------------- SUBROUTINE multable( nsym, s, table ) !----------------------------------------------------------------------- !! Checks that {S} is a group and calculates multiplication table ! IMPLICIT NONE ! INTEGER, INTENT(IN) :: nsym !! the number of symmetry operations INTEGER, INTENT(IN) :: s(3,3,nsym) !! rotation matrix (in crystal axis, represented by integers) INTEGER, INTENT(OUT) :: table(48,48) ! multiplication table: S(n)*S(m) = S( table(n,m) ) ! ! ... local variables ! INTEGER :: isym, jsym, ksym, ss(3,3) LOGICAL :: found, smn ! ! DO isym = 1, nsym DO jsym = 1, nsym ! ss = MATMUL( s(:,:,jsym), s(:,:,isym) ) ! ! ... here we check that the input matrices really form a group ! and we set the multiplication table ! found = .FALSE. DO ksym = 1, nsym smn = ALL( s(:,:,ksym) == ss(:,:) ) IF (smn) THEN IF (found) CALL errore( 'multable', 'Not a group', 1 ) found = .TRUE. table (jsym,isym) = ksym ENDIF ENDDO IF ( .NOT. found) CALL errore( 'multable', ' Not a group', 2 ) ! ENDDO ENDDO ! ! RETURN ! END SUBROUTINE multable
gpl-2.0
omni-compiler/omni-compiler
tests/XMP/global-view/loop/F/292.f90
1
1629
program main !$xmp nodes p(2) !$xmp template t(10) !$xmp distribute t(block) onto p integer a(10), sa, ia !$xmp align a(i) with t(i) !$xmp task on p(1) a(1) = 2 a(2) = 1 a(3) = 4 a(4) = 6 a(5) = 3 !$xmp end task !$xmp task on p(2) a(6) = 2 a(7) = 6 a(8) = 3 a(9) = 3 a(10) = 1 !$xmp end task ! FIRST MAX sa = 0 !$xmp loop on t(i) reduction(firstmax:sa/ia/) do i=1, 10 if(sa .lt. a(i)) then ia = i sa = a(i) endif enddo !$xmp task on p(1) if(ia == 4 .and. sa == 6) then write(*,*) "PASS" else write(*,*) "ERROR" call exit(1) endif !$xmp end task ! LAST MAX sa = 0 !$xmp loop on t(i) reduction(lastmax:sa/ia/) do i=1, 10 if(sa .lt. a(i)) then ia = i sa = a(i) endif enddo !$xmp task on p(1) if(ia == 7 .and. sa == 6) then write(*,*) "PASS" else write(*,*) "ERROR" call exit(1) endif !$xmp end task ! FIRST MIN sa = 10 !$xmp loop on t(i) reduction(firstmin:sa/ia/) do i=1, 10 if(sa .gt. a(i)) then ia = i sa = a(i) endif enddo !$xmp task on p(1) if(ia == 2 .and. sa == 1) then write(*,*) "PASS" else write(*,*) "ERROR" call exit(1) endif !$xmp end task ! LAST MIN sa = 10 !$xmp loop on t(i) reduction(lastmin:sa/ia/) do i=1, 10 if(sa .gt. a(i)) then ia = i sa = a(i) endif enddo !$xmp task on p(1) if(ia == 10 .and. sa == 1) then write(*,*) "PASS" else write(*,*) "ERROR" call exit(1) endif !$xmp end task end program main
lgpl-3.0
QEF/q-e
PP/src/projwfc_box.f90
2
14764
! ! Copyright (C) 2001-2013 Quantum ESPRESSO group ! This file is distributed under the terms of the ! GNU General Public License. See the file `License' ! in the root directory of the present distribution, ! or http://www.gnu.org/copyleft/gpl.txt . ! ! real-space local DOS code courtesy of Guido Fratesi ! MODULE projections_ldos USE kinds, ONLY : DP REAL (DP), ALLOCATABLE :: proj (:,:,:) END MODULE projections_ldos ! !----------------------------------------------------------------------- SUBROUTINE projwave_boxes( filpdos, filproj, n_proj_boxes, irmin, irmax, plotboxes ) !----------------------------------------------------------------------- ! USE kinds, ONLY : DP USE io_global, ONLY : stdout, ionode USE run_info, ONLY: title USE atom USE ions_base, ONLY : zv, tau, nat, ntyp => nsp, ityp, atm USE basis, ONLY : natomwfc USE cell_base USE constants, ONLY: rytoev USE gvect USE gvecs, ONLY: dual USE gvecw, ONLY: ecutwfc USE klist, ONLY: xk, nks, nkstot, ngk, igk_k USE lsda_mod, ONLY: nspin, isk, current_spin, lsda USE wvfct, ONLY: npwx, nbnd, et, wg USE control_flags, ONLY: gamma_only USE uspp, ONLY: okvan USE noncollin_module, ONLY: noncolin, npol USE wavefunctions, ONLY: evc, psic, psic_nc USE io_files, ONLY : restart_dir USE scf, ONLY : rho USE projections_ldos, ONLY : proj USE fft_base, ONLY : dfftp USE scatter_mod, ONLY : scatter_grid USE fft_interfaces, ONLY : invfft USE mp_pools, ONLY : intra_pool_comm USE mp, ONLY : mp_sum USE pw_restart_new, ONLY : read_collected_wfc ! ! IMPLICIT NONE ! INTEGER, PARAMETER :: N_MAX_BOXES = 999 CHARACTER (len=256) :: filpdos CHARACTER (len=*) :: filproj INTEGER :: n_proj_boxes, irmin(3,*), irmax(3,*), nri(3) LOGICAL :: plotboxes ! INTEGER :: ik, ibnd, i, ir, ig, ipol, npw INTEGER :: ibox, ir1, ir2, ir3, c_tab, is, iunproj CHARACTER (len=33) :: filextension CHARACTER (len=256):: fileout COMPLEX(DP), ALLOCATABLE :: caux(:) REAL(DP), ALLOCATABLE :: thetabox(:), raux(:), thetathisproc(:,:), union(:), intersection(:) LOGICAL, ALLOCATABLE :: isInside(:,:) REAL(DP), EXTERNAL :: DDOT REAL(DP), ALLOCATABLE :: boxvolume(:), boxcharge(:) ! WRITE( stdout, '(/5x,"Calling projwave_boxes .... ")') IF ( gamma_only ) THEN WRITE( stdout, '(5x,"gamma-point specific algorithms are used")') ENDIF ! IF (noncolin) THEN WRITE( stdout, '(/5x,"Non spin-resolved DOS will be computed")') ENDIF ! IF (okvan) THEN CALL errore( 'projwave_boxes', 'Augmentation contributions are currently not included to the DOS in boxes',-1) ENDIF ! IF ( ( n_proj_boxes > N_MAX_BOXES ) .or. ( n_proj_boxes < 1 ) ) & CALL errore ('projwave_boxes', 'n_proj_boxes not correct', abs (n_proj_boxes) ) ! ! ... Define functions with values 1.0 ! ... on the specified boxes and 0.0 elsewhere. ! ALLOCATE( thetabox (dfftp%nr1x*dfftp%nr2x*dfftp%nr3x) ) ! ALLOCATE( thetathisproc(dfftp%nnr,1:n_proj_boxes) ) ! ALLOCATE ( isInside ( max(dfftp%nr1,dfftp%nr2,dfftp%nr3), 3 ) ) ! DO ibox = 1, n_proj_boxes ! ! A. Do the three directions independently: nri(1)=dfftp%nr1 nri(2)=dfftp%nr2 nri(3)=dfftp%nr3 DO i = 1, 3 ! boxes include the points in [irmin,irmax] if irmin<=irmax ! and the points in [1,irmax] and [irmin,nr] if irmin > irmax irmin(i,ibox)=mod(irmin(i,ibox),nri(i)) IF (irmin(i,ibox)<=0) irmin(i,ibox)=irmin(i,ibox)+nri(i) irmax(i,ibox)=mod(irmax(i,ibox),nri(i)) IF (irmax(i,ibox)<=0) irmax(i,ibox)=irmax(i,ibox)+nri(i) DO ir = 1, nri(i) IF (irmin(i,ibox)<=irmax(i,ibox)) THEN isInside(ir,i)=(ir>=irmin(i,ibox)).and.(ir<=irmax(i,ibox)) ELSE isInside(ir,i)=(ir>=irmin(i,ibox)).or. (ir<=irmax(i,ibox)) ENDIF ENDDO ENDDO ! ! B. Combine the conditions for the three directions to form a box ir=0 DO ir3 = 1, dfftp%nr3 DO ir2 = 1, dfftp%nr2 DO ir1 = 1, dfftp%nr1 ir=ir+1 IF ( isInside(ir1,1) .and. & isInside(ir2,2) .and. & isInside(ir3,3) ) THEN thetabox(ir)=1._DP ELSE thetabox(ir)=0._DP ENDIF ENDDO ENDDO ! ENDDO ! ! C. Output the functions thetabox in the XCrySDen format, ! so that the projection boxes can be visualised. IF ( ionode .and. plotboxes ) THEN filextension='.box#' ! 123456 c_tab = 6 IF (ibox < 10) THEN WRITE (filextension( c_tab : c_tab ),'(i1)') ibox c_tab = c_tab + 1 ELSEIF (ibox < 100) THEN WRITE (filextension( c_tab : c_tab+1 ),'(i2)') ibox c_tab = c_tab + 2 ELSEIF (ibox < 1000) THEN WRITE (filextension( c_tab : c_tab+2 ),'(i3)') ibox c_tab = c_tab + 3 ELSE CALL errore('projwave_boxes',& 'file extension not supporting so many boxes', n_proj_boxes) ENDIF ! fileout = trim(filpdos)//trim(filextension)//'.xsf' OPEN (4,file=fileout,form='formatted', status='unknown') CALL xsf_struct (alat, at, nat, tau, atm, ityp, 4) CALL xsf_fast_datagrid_3d(thetabox(1:dfftp%nr1x*dfftp%nr2x*dfftp%nr3x),& dfftp%nr1, dfftp%nr2, dfftp%nr3, & dfftp%nr1x, dfftp%nr2x, dfftp%nr3x, at, alat, 4) CLOSE (4) ! ENDIF ! #if defined(__MPI) CALL scatter_grid ( dfftp, thetabox(:), thetathisproc(:,ibox) ) #else thetathisproc(:,ibox) = thetabox(1:dfftp%nnr) #endif ! ENDDO ! DEALLOCATE ( isInside ) DEALLOCATE ( thetabox ) ! ! ! ... For each box output the volume and the electronic charge contained ! ALLOCATE ( boxvolume (1:n_proj_boxes) ) ALLOCATE ( boxcharge (1:n_proj_boxes) ) ALLOCATE ( raux (dfftp%nnr) ) ! ! A. Integrate the volume DO ibox = 1, n_proj_boxes boxvolume(ibox) = sum(thetathisproc(1:dfftp%nnr,ibox)) CALL mp_sum ( boxvolume(ibox) , intra_pool_comm ) ENDDO ! ! B1. Copy the total charge density to raux IF (noncolin) THEN CALL DCOPY (dfftp%nnr, rho%of_r, 1, raux, 1) ELSE CALL DCOPY (dfftp%nnr, rho%of_r (1, 1), 1, raux, 1) ENDIF ! ! B2. Integrate the charge ! the correct integral has dv = omega/(nr1*nr2*nr3) ! not omega/(nr1x*nr2x*nr3x) . PG 24 Oct 2010 DO ibox = 1, n_proj_boxes boxcharge(ibox) = DDOT(dfftp%nnr,raux(:),1,thetathisproc(:,ibox),1) & & * omega / (dfftp%nr1*dfftp%nr2*dfftp%nr3) CALL mp_sum ( boxcharge(ibox) , intra_pool_comm ) ENDDO ! ! C. Write the result IF (ionode) THEN WRITE (stdout,*) DO ibox = 1, n_proj_boxes WRITE (stdout, & '(5x,"Box #",i3," : vol ",f10.6," % = ",f14.6," (a.u.)^3; ",e13.6," elec")') & ibox, 100* boxvolume(ibox) /(dfftp%nr1*dfftp%nr2*dfftp%nr3), & omega* boxvolume(ibox)/(dfftp%nr1*dfftp%nr2*dfftp%nr3), boxcharge(ibox) ENDDO ENDIF ! DEALLOCATE ( boxvolume , boxcharge ) ! ! ... Here we sum for each k point the contribution ! ... of the wavefunctions to the charge in the specified box ! ALLOCATE( proj(1:n_proj_boxes,nbnd,nkstot) ) proj(:,:,:)=0._DP ! ALLOCATE( caux(dfftp%nnr) ) ! k_loop: DO ik = 1, nks ! IF ( lsda ) current_spin = isk(ik) npw = ngk(ik) CALL read_collected_wfc ( restart_dir(), ik, evc ) ! bnd_loop: DO ibnd = 1, nbnd ! IF (noncolin) THEN ! psic_nc = (0.d0,0.d0) DO ig = 1, npw psic_nc(dfftp%nl(igk_k(ig,ik)),1)=evc(ig ,ibnd) psic_nc(dfftp%nl(igk_k(ig,ik)),2)=evc(ig+npwx,ibnd) ENDDO raux=0._DP DO ipol=1,npol CALL invfft ('Rho', psic_nc(:,ipol), dfftp) raux(:) = raux(:)+dble( psic_nc(:,ipol) )**2 & + aimag( psic_nc(:,ipol) )**2 ENDDO ! ELSE ! caux(1:dfftp%nnr) = (0._DP,0._DP) DO ig = 1, npw caux (dfftp%nl (igk_k (ig,ik) ) ) = evc (ig, ibnd) ENDDO IF (gamma_only) THEN DO ig = 1, npw caux (dfftp%nlm(igk_k (ig,ik) ) ) = conjg(evc (ig, ibnd)) ENDDO ENDIF CALL invfft ('Rho', caux, dfftp) ! raux(:) = dble( caux(:) )**2 + aimag( caux(:) )**2 ! ENDIF ! ! The contribution of this wavefunction to the LDOS ! integrated in the volume is the projection of the ! squared wfc on a function =1 in the volume itself: ! DO ibox = 1, n_proj_boxes proj(ibox,ibnd,ik) = DDOT(dfftp%nnr,raux(:),1,thetathisproc(:,ibox),1) & & / (dfftp%nr1*dfftp%nr2*dfftp%nr3) ENDDO ! ENDDO bnd_loop ! CALL mp_sum ( proj(:,:,ik) , intra_pool_comm ) ! ENDDO k_loop ! DEALLOCATE ( caux ) DEALLOCATE ( raux ) DEALLOCATE ( thetathisproc ) ! ! vector proj is distributed across the pools ! collect data for all k-points to the first pool ! CALL poolrecover (proj, n_proj_boxes*nbnd, nkstot, nks) ! ! Output the projections IF ( ionode ) THEN IF (filproj/=' ') THEN iunproj=33 CALL write_io_header(filproj, iunproj, title, dfftp%nr1x, dfftp%nr2x, & dfftp%nr3x, dfftp%nr1, dfftp%nr2, dfftp%nr3, nat, ntyp, ibrav, & celldm, at, gcutm, dual, ecutwfc, nkstot,nbnd,natomwfc) DO ibox = 1, n_proj_boxes WRITE (iunproj,'(3i6)') ibox, n_proj_boxes WRITE (iunproj,'(i6,i6,f9.4,e13.6)') & ((ik,ibnd,et(ibnd,ik)*rytoev,proj(ibox,ibnd,ik),ibnd=1,nbnd),ik=1,nkstot) ENDDO CLOSE (iunproj) ENDIF ENDIF ! RETURN ! END SUBROUTINE projwave_boxes ! !----------------------------------------------------------------------- SUBROUTINE partialdos_boxes(Emin, Emax, DeltaE, kresolveddos, filpdos, n_proj_boxes) !----------------------------------------------------------------------- ! USE kinds, ONLY : DP USE io_global, ONLY : stdout USE klist, ONLY: wk, nkstot, degauss, ngauss, lgauss USE lsda_mod, ONLY: nspin, isk, current_spin USE wvfct, ONLY: et, nbnd USE constants, ONLY: rytoev USE projections_ldos, ONLY: proj ! IMPLICIT NONE CHARACTER (len=256) :: filpdos REAL(DP) :: Emin, Emax, DeltaE LOGICAL :: kresolveddos INTEGER :: n_proj_boxes ! CHARACTER (len=33) :: filextension CHARACTER (len=256):: fileout ! INTEGER :: ik, ibnd, ne, ie_mid, ie_delta, ie, is, nkseff, ikeff, ibox, nspin0 REAL(DP) :: etev, delta, Elw, Eup, wkeff REAL(DP), ALLOCATABLE :: dostot(:,:,:), dosbox(:,:,:,:), dosboxtot(:,:,:) REAL(DP), EXTERNAL :: w0gauss ! ! find band extrema ! Elw = et (1, 1) Eup = et (nbnd, 1) DO ik = 2, nkstot Elw = min (Elw, et (1, ik) ) Eup = max (Eup, et (nbnd, ik) ) ENDDO IF (degauss/=0.d0) THEN Eup = Eup + 3d0 * degauss Elw = Elw - 3d0 * degauss ENDIF Emin = max (Emin/rytoev, Elw) Emax = min (Emax/rytoev, Eup) DeltaE = DeltaE/rytoev ne = nint ( (Emax - Emin) / DeltaE+0.500001d0) ! IF (nspin==2) THEN nspin0 = 2 ELSE nspin0 = 1 ENDIF ! IF (kresolveddos) THEN IF ( nspin==2 ) THEN nkseff=nkstot/2 ELSE nkseff=nkstot ENDIF ELSE nkseff=1 ENDIF ! ALLOCATE (dosbox(0:ne,1:n_proj_boxes,nspin0,nkseff)) ALLOCATE (dostot(0:ne,nspin0,nkseff), dosboxtot(0:ne,nspin0,nkseff) ) dosbox(:,:,:,:) = 0.d0 dostot(:,:,:) = 0.d0 dosboxtot(:,:,:)= 0.d0 current_spin = 1 ie_delta = 5 * degauss / DeltaE + 1 ! DO ik = 1,nkstot ! IF (kresolveddos) THEN ! set equal weight to all k-points wkeff=1.D0 ! IF (( nspin==2 ).AND.( isk(ik)==2 )) THEN ikeff=ik-nkstot/2 ELSE ikeff=ik ENDIF ELSE ! use true weights wkeff=wk(ik) ! contributions from all k-points are summed in pdos(:,:,:,ikeff) ikeff=1 ENDIF ! IF ( nspin == 2 ) current_spin = isk ( ik ) DO ibnd = 1, nbnd etev = et(ibnd,ik) ie_mid = nint( (etev-Emin)/DeltaE ) DO ie = max(ie_mid-ie_delta, 0), min(ie_mid+ie_delta, ne) delta = w0gauss((Emin+DeltaE*ie-etev)/degauss,ngauss) & / degauss / rytoev ! DO ibox = 1, n_proj_boxes dosbox(ie,ibox,current_spin,ikeff) = & dosbox(ie,ibox,current_spin,ikeff) + & wkeff * delta * proj (ibox, ibnd, ik) ENDDO ! ! dostot(:,ns,ik) = total DOS (states/eV) for spin "ns" ! for k-point "ik" (or summed over all kp) ! dostot(ie,current_spin,ikeff) = dostot(ie,current_spin,ikeff) + & wkeff * delta ENDDO ENDDO ENDDO ! ! dosboxtot(:,ns,ik) = sum of all projected DOS ! DO ik=1,nkseff DO is=1,nspin0 DO ie=0,ne dosboxtot(ie,is,ik) = sum(dosbox(ie,1:n_proj_boxes,is,ik)) ENDDO ENDDO ENDDO ! fileout = trim(filpdos)//'.ldos_boxes' ! OPEN (4,file=fileout,form='formatted', & status='unknown') IF (kresolveddos) THEN WRITE (4,'("# ik ")', advance="NO") ELSE WRITE (4,'("#")', advance="NO") ENDIF IF (nspin0 == 2) THEN WRITE (4,'(" E (eV) tot_up(E) tot_dw(E) totldos_up totldos_dw ")', advance="NO") ELSE WRITE (4,'(" E (eV) tot(E) totldos ")', advance="NO") ENDIF DO ibox=1, n_proj_boxes IF (nspin0 == 2) THEN WRITE(4,'("#",i3," up(E) ")', advance="NO") ibox WRITE(4,'("#",i3," dw(E) ")', advance="NO") ibox ELSE WRITE(4,'("#",i3," (E) ")', advance="NO") ibox ENDIF ENDDO WRITE (4,*) DO ik=1,nkseff DO ie= 0, ne IF (kresolveddos) THEN WRITE (4,'(i5," ")', advance="NO") ik ENDIF etev = Emin + ie * DeltaE WRITE (4,'(f8.3,4(2e11.3),999(2e11.3))') etev*rytoev, & dostot(ie,1:nspin0,ik), dosboxtot(ie,1:nspin0,ik), & ( dosbox(ie,ibox,1:nspin0,ik), ibox = 1, n_proj_boxes ) ENDDO IF (kresolveddos) WRITE (4,*) ENDDO CLOSE (4) DEALLOCATE (dostot, dosboxtot) DEALLOCATE (dosbox) ! DEALLOCATE (proj) ! RETURN END SUBROUTINE partialdos_boxes
gpl-2.0
QEF/q-e
CPV/src/plugin_energy.f90
1
1087
! ! Copyright (C) 2015 Quantum ESPRESSO group ! This file is distributed under the terms of the ! GNU General Public License. See the file `License' ! in the root directory of the present distribution, ! or http://www.gnu.org/copyleft/gpl.txt . ! !---------------------------------------------------------------------------- SUBROUTINE plugin_energy(rhoin,plugin_etot) !---------------------------------------------------------------------------- !! This routine is used to calculate plugin energy related quantities !! that needs to be solved inside the scf cycle. ! USE io_global, ONLY : stdout, ionode USE kinds, ONLY : DP USE io_files, ONLY : tmp_dir ! USE fft_base, ONLY : dfftp USE electrons_base, ONLY : nspin ! USE plugin_flags ! ! ***Environ MODULES BEGIN*** ! ***Environ MODULES END*** ! IMPLICIT NONE ! real(DP), intent(in) :: rhoin(dfftp%nnr,nspin) real(DP), intent(inout) :: plugin_etot ! ! ***Environ VARIABLES BEGIN*** ! ***Environ VARIABLES END*** ! ! ***Environ CALLS BEGIN*** ! ***Environ CALLS END*** ! END SUBROUTINE plugin_energy
gpl-2.0
pts-eduardoacuna/pachy-learning
vendor/gonum.org/v1/gonum/mathext/internal/amos/amoslib/zrati.f
15
4019
SUBROUTINE ZRATI(ZR, ZI, FNU, N, CYR, CYI, TOL) C***BEGIN PROLOGUE ZRATI C***REFER TO ZBESI,ZBESK,ZBESH C C ZRATI COMPUTES RATIOS OF I BESSEL FUNCTIONS BY BACKWARD C RECURRENCE. THE STARTING INDEX IS DETERMINED BY FORWARD C RECURRENCE AS DESCRIBED IN J. RES. OF NAT. BUR. OF STANDARDS-B, C MATHEMATICAL SCIENCES, VOL 77B, P111-114, SEPTEMBER, 1973, C BESSEL FUNCTIONS I AND J OF COMPLEX ARGUMENT AND INTEGER ORDER, C BY D. J. SOOKNE. C C***ROUTINES CALLED ZABS,ZDIV C***END PROLOGUE ZRATI C COMPLEX Z,CY(1),CONE,CZERO,P1,P2,T1,RZ,PT,CDFNU DOUBLE PRECISION AK, AMAGZ, AP1, AP2, ARG, AZ, CDFNUI, CDFNUR, * CONEI, CONER, CYI, CYR, CZEROI, CZEROR, DFNU, FDNU, FLAM, FNU, * FNUP, PTI, PTR, P1I, P1R, P2I, P2R, RAK, RAP1, RHO, RT2, RZI, * RZR, TEST, TEST1, TOL, TTI, TTR, T1I, T1R, ZI, ZR, ZABS INTEGER I, ID, IDNU, INU, ITIME, K, KK, MAGZ, N DIMENSION CYR(N), CYI(N) DATA CZEROR,CZEROI,CONER,CONEI,RT2/ 1 0.0D0, 0.0D0, 1.0D0, 0.0D0, 1.41421356237309505D0 / AZ = ZABS(CMPLX(ZR,ZI,kind=KIND(1.0D0))) INU = INT(SNGL(FNU)) IDNU = INU + N - 1 MAGZ = INT(SNGL(AZ)) AMAGZ = DBLE(FLOAT(MAGZ+1)) FDNU = DBLE(FLOAT(IDNU)) FNUP = DMAX1(AMAGZ,FDNU) ID = IDNU - MAGZ - 1 ITIME = 1 K = 1 PTR = 1.0D0/AZ RZR = PTR*(ZR+ZR)*PTR RZI = -PTR*(ZI+ZI)*PTR T1R = RZR*FNUP T1I = RZI*FNUP P2R = -T1R P2I = -T1I P1R = CONER P1I = CONEI T1R = T1R + RZR T1I = T1I + RZI IF (ID.GT.0) ID = 0 AP2 = ZABS(CMPLX(P2R,P2I,kind=KIND(1.0D0))) AP1 = ZABS(CMPLX(P1R,P1I,kind=KIND(1.0D0))) C----------------------------------------------------------------------- C THE OVERFLOW TEST ON K(FNU+I-1,Z) BEFORE THE CALL TO CBKNU C GUARANTEES THAT P2 IS ON SCALE. SCALE TEST1 AND ALL SUBSEQUENT C P2 VALUES BY AP1 TO ENSURE THAT AN OVERFLOW DOES NOT OCCUR C PREMATURELY. C----------------------------------------------------------------------- ARG = (AP2+AP2)/(AP1*TOL) TEST1 = DSQRT(ARG) TEST = TEST1 RAP1 = 1.0D0/AP1 P1R = P1R*RAP1 P1I = P1I*RAP1 P2R = P2R*RAP1 P2I = P2I*RAP1 AP2 = AP2*RAP1 10 CONTINUE K = K + 1 AP1 = AP2 PTR = P2R PTI = P2I P2R = P1R - (T1R*PTR-T1I*PTI) P2I = P1I - (T1R*PTI+T1I*PTR) P1R = PTR P1I = PTI T1R = T1R + RZR T1I = T1I + RZI AP2 = ZABS(CMPLX(P2R,P2I,kind=KIND(1.0D0))) IF (AP1.LE.TEST) GO TO 10 IF (ITIME.EQ.2) GO TO 20 AK = ZABS(CMPLX(T1R,T1I,kind=KIND(1.0D0))*0.5D0) FLAM = AK + DSQRT(AK*AK-1.0D0) RHO = DMIN1(AP2/AP1,FLAM) TEST = TEST1*DSQRT(RHO/(RHO*RHO-1.0D0)) ITIME = 2 GO TO 10 20 CONTINUE KK = K + 1 - ID AK = DBLE(FLOAT(KK)) T1R = AK T1I = CZEROI DFNU = FNU + DBLE(FLOAT(N-1)) P1R = 1.0D0/AP2 P1I = CZEROI P2R = CZEROR P2I = CZEROI DO 30 I=1,KK PTR = P1R PTI = P1I RAP1 = DFNU + T1R TTR = RZR*RAP1 TTI = RZI*RAP1 P1R = (PTR*TTR-PTI*TTI) + P2R P1I = (PTR*TTI+PTI*TTR) + P2I P2R = PTR P2I = PTI T1R = T1R - CONER 30 CONTINUE IF (P1R.NE.CZEROR .OR. P1I.NE.CZEROI) GO TO 40 P1R = TOL P1I = TOL 40 CONTINUE CALL ZDIV(P2R, P2I, P1R, P1I, CYR(N), CYI(N)) IF (N.EQ.1) RETURN K = N - 1 AK = DBLE(FLOAT(K)) T1R = AK T1I = CZEROI CDFNUR = FNU*RZR CDFNUI = FNU*RZI DO 60 I=2,N PTR = CDFNUR + (T1R*RZR-T1I*RZI) + CYR(K+1) PTI = CDFNUI + (T1R*RZI+T1I*RZR) + CYI(K+1) AK = ZABS(CMPLX(PTR,PTI,kind=KIND(1.0D0))) IF (AK.NE.CZEROR) GO TO 50 PTR = TOL PTI = TOL AK = TOL*RT2 50 CONTINUE RAK = CONER/AK CYR(K) = RAK*PTR*RAK CYI(K) = -RAK*PTI*RAK T1R = T1R - CONER K = K - 1 60 CONTINUE RETURN END
gpl-3.0
QEF/q-e
PHonon/Gamma/macro.f90
2
1248
! ! Copyright (C) 2003 PWSCF group ! This file is distributed under the terms of the ! GNU General Public License. See the file `License' ! in the root directory of the present distribution, ! or http://www.gnu.org/copyleft/gpl.txt . ! ! !---------------------------------------------------------------------- SUBROUTINE macro !---------------------------------------------------------------------- ! USE klist, ONLY : nks USE cgcom, ONLY : iubar, dvpsi USE io_files, ONLY : seqopn ! IMPLICIT NONE INTEGER:: ik, ipol CHARACTER(len=7) :: filbar LOGICAL :: here ! DO ik=1,nks ! NB: this version works only for nks = 1 ! DO ipol=1,3 WRITE(filbar,'("filbar",i1)') ipol iubar=ipol CALL seqopn (iubar,filbar,'unformatted',here) !|| if (.not.here) then ! calculate x * psi (if not already done) dvpsi(:,:) = (0.d0, 0.d0) !|| else ! otherwise restart from x * psi that is present on from file !|| read(iubar) dvpsi !|| end if CALL dvpsi_e(ik,ipol) ! write x * psi REWIND(iubar) WRITE(iubar) dvpsi CLOSE(unit=iubar,status='keep') ENDDO ENDDO ! RETURN END SUBROUTINE macro
gpl-2.0
markusappel/McCode
support/common/pgplot/sys_win/w9driv.f
6
22069
C* W9DRIV -- PGPLOT device driver for Windows95 (or WindowsNT) C+ SUBROUTINE W9DRIV (IFUNC, RBUF, NBUF, CHR, LCHR, MODE) USE DFLIB IMPLICIT NONE INTEGER IFUNC, NBUF, LCHR, MODE REAL RBUF(*) CHARACTER CHR*(*) C C PGPLOT driver for IBM PC's and clones running DIGITAL Visual Fortran C (5.0 or higher). This driver will create a graphics window. C PGEND will return control to the default (text) window, but the graphics C window is not erased until <RETURN> is pressed. C C This routine must be compiled and linked with the Digital DFLIB graphics C library. Application must be compiled as a "QuickWin Graphics" project type, C compiler command line option /MW. C C 1989-Nov-03 - (MSDRIV) Started work [AFT] C 1989-Apr-06 - Improved version [AFT] C 1991-Mar-13 - Added cursor routine [JHT] C 12/1993 C. T. Dum: Version for MS Fortran Power Station C 1996-Apr-26 - W9DRIV (Windows95/PowerStation 4.0 version): C resolution modes; interrupt driven mouse (cursor band modes); C rectangle fill; pixel lines [Phil Seeger, PASeeger@aol.com] C 1996-Apr-30 - multiple devices; return color representation [PAS] C 1996-May-03 - each window has its own resolution and palette [PAS] C 1997-Dec-15 - change USE statement from Microsoft to Digital [PAS] C 1998-May-04 - had only 7 windows instead of 8 [PAS] C 1998-Jun-22 - moved window initialization to be after open [ACLarson] C----------------------------------------------------------------------- C C Supported device: IBM PC's and compatibles with Windows95/NT; C requires VGA or higher graphics adapter C C Device type code: /W95 (also /WV, /WS, /WX, or /WZ) C C Modes: 1, VGA, 640 x 480 C 2, SVGA, 800 x 600 C 3, XGA, 1024 x 768 C 4, ZGA, 1280 x 1024 C 0, from PGPLOT_VIDEO environment parameter, or SVGA C The Default mode is 800 x 640 pixels (SVGA). Other resolution C modes are accessed by entering SET PGPLOT_VIDEO=VGA (640x480), C XGA (1024x768), or ZGA (1280x1024) in the AUTOEXEC.BAT file, or C by using alternate device type designations. The maximum allowed C mode is determined by the graphics card and the Windows95 driver. C C Color capability: Color indices 0-15 are set to the default values C of PGPLOT, and indices 16-235 default to a gray scale. Palettes C of up to 235 colors are saved for each of 8 possible device C windows. (20 colors are reserved for the system.) C NOTE: There are some peculiar graphics adapters out there, and C even more peculiar drivers. The default colors have been C tweeked to appear unique in either the upper 6 or the lower C 6 bits of each byte. If you don't like what you see, you C may modify the DATA statement for RGB16. It may also be C necessary to change PARAMETER CNORM from 255 to 63. C C Default device name: None (the device name, if specified, is ignored). C C View surface dimensions: Depends on monitor, typical 7.5x10 inches C C Resolution: Depends on graphics card and Windows95 driver. C C Input capability: Mouse position, must be followed by a keyboard key. C C File format: None. C C Obtaining hardcopy: via Windows95, "File/Print" menu choice. C----------------------------------------------------------------------- C Notes: C Up to MAXDEV "devices" may be open at once. ACTIVE is the number C of the currently selected device (1 if no devices are open). C STATE(i) is 0 if device i is not open, 1 if it is open but with C no current picture, or 2 if it is open with a current picture. C----------------------------------------------------------------------- EXTERNAL GRW900, GRW901 INTEGER MAXDEV REAL*4 CNORM PARAMETER (MAXDEV=8, CNORM=255.) TYPE (xycoord) XY C CHARACTER CMSG*10, WINTITLE*80 INTEGER MX(0:4), MY(0:4), MXX(MAXDEV), MXY(MAXDEV), MXC(MAXDEV),& & I, ACTIVE,IUNIT(MAXDEV), STATE(0:MAXDEV), NPIC(MAXDEV) INTEGER*4 IRGB, RGB(0:235,MAXDEV), RGB16(0:15), RGB236(0:235) INTEGER*2 I2STAT, I2X0, I2Y0, I2X1, I2Y1, DASHLINE(5), ICOLOR, & & CBITS(MAXDEV), IX(1), IY(1), IC(1) INTEGER*4 I4STAT, I4X, I4Y, IXREF, IYREF, BAND, EVENT, IBUF LOGICAL FIRST, QFIRST(MAXDEV), LPOS SAVE FIRST, QFIRST, ACTIVE, STATE, XY, MXX, MXY, MXC, IUNIT, RGB, & & ICOLOR, NPIC, MX, MY, DASHLINE, CBITS, RGB16 DATA FIRST, QFIRST, ACTIVE, STATE(0:MAXDEV)/ & & .TRUE., MAXDEV*.TRUE., 1, -1, MAXDEV*0/ DATA MX, MY/ 0, 640, 800, 1024, 1280, & & 0, 480, 640, 768, 1024/ DATA DASHLINE/#FFFF, #FF80, #FC30, #CCCC, #FCCC/ C C Following data statement provides unique colors on all tested adapters DATA RGB16(0:15)/0, #FFFFFF, #0000FF, #00FF00, #FF0000, #FFFF00, & & #FF00FF, #00FFFF, #005FFF, #00FFAA, #AAFF00, #FF9300, #FF0093, & & #5F00FF, #555555, #AAAAAA/ C C--- C Initialize first 16 RGB values and gray scale for all windows IF (FIRST) THEN FIRST = .FALSE. DO ICOLOR=0,15 DO I=1,MAXDEV RGB(ICOLOR,I) = RGB16(ICOLOR) END DO END DO IRGB = #020202 DO ICOLOR=16,235 IRGB = IRGB + #010101 DO I=1,MAXDEV RGB(ICOLOR,I) = IRGB END DO END DO ICOLOR = 1 DO I=1,MAXDEV CBITS(I) = #0F END DO END IF C SELECT CASE (IFUNC) C CASE (1) C--- IFUNC = 1, Return device name.------------------------------------- SELECT CASE (MODE) CASE (1) CHR = 'WV (Windows95/NT, 640x480)' CASE (2) CHR = 'WS (Windows95/NT, 800x600)' CASE (3) CHR = 'WX (Windows95/NT, 1024x768)' CASE (4) CHR = 'WZ (Windows95/NT, 1280x1024)' CASE DEFAULT CHR = 'W9 (Windows95/NT, mode from environment)' END SELECT LCHR = LEN_TRIM(CHR) C CASE (2) C--- IFUNC = 2, Return physical min and max for plot device, and range C of color indices.--------------------------------------- IF (QFIRST(ACTIVE)) THEN MXX(ACTIVE) = MX(MODE) MXY(ACTIVE) = MY(MODE) MXC(ACTIVE) = 236 CALL GRW900(ACTIVE, MXX, MXY, MXC, QFIRST) END IF RBUF(1) = 0. RBUF(2) = MXX(ACTIVE) RBUF(3) = 0. RBUF(4) = MXY(ACTIVE) RBUF(5) = 0. RBUF(6) = MXC(ACTIVE) NBUF = 6 C CASE (3) C--- IFUNC = 3, Return device resolution. ------------------------------ C Divide the number of pixels on screen by a typical screen size in C inches. IF (QFIRST(ACTIVE)) THEN MXX(ACTIVE) = MX(MODE) MXY(ACTIVE) = MY(MODE) MXC(ACTIVE) = 236 CALL GRW900(ACTIVE, MXX, MXY, MXC, QFIRST) END IF RBUF(1) = FLOAT(MXX(ACTIVE)+1)/10. RBUF(2) = FLOAT(MXY(ACTIVE)+1)/7.5 RBUF(3) = 1.0 NBUF = 3 C CASE (4) C--- IFUNC = 4, Return misc device info. ------------------------------- C (This device is Interactive, Cursor, No dashed lines, No area fill, C No thick lines, Rectangle fill, Pixel primative, No ?, querY color C representation, No markers) CHR = 'ICNNNRPNYN' LCHR = 10 C CASE (5) C--- IFUNC = 5, Return default file name. ------------------------------ CHR = 'PGPlot Graphics' LCHR = LEN_TRIM(CHR) C CASE (6) C--- IFUNC = 6, Return default physical size of plot. ------------------ IF (QFIRST(ACTIVE)) THEN MXX(ACTIVE) = MX(MODE) MXY(ACTIVE) = MY(MODE) MXC(ACTIVE) = 236 CALL GRW900(ACTIVE, MXX, MXY, MXC, QFIRST) END IF RBUF(1) = 0. RBUF(2) = MXX(ACTIVE) RBUF(3) = 0. RBUF(4) = MXY(ACTIVE) NBUF = 4 C CASE (7) C--- IFUNC = 7, Return misc defaults. ---------------------------------- RBUF(1) = 1. NBUF = 1 C CASE (8) C--- IFUNC = 8, Select plot. ------------------------------------------- I = NINT(RBUF(2)) IF (I.GE.1 .AND. I.LE.MAXDEV .AND. STATE(I).GT.0) THEN IF (I .NE. ACTIVE) THEN ACTIVE = I I4STAT = SETACTIVEQQ(IUNIT(ACTIVE)) I4STAT = FOCUSQQ(IUNIT(ACTIVE)) DO I=0,235 RGB236(I) = RGB(I,ACTIVE) END DO I4STAT = REMAPALLPALETTE(RGB236) I2STAT = SETCOLOR(ICOLOR) END IF ELSE CALL GRWARN('invalid or unopened graphics window in W9DRIV') END IF C CASE (9) C--- IFUNC = 9, Open workstation. -------------------------------------- I = 0 DO WHILE (I.LE.MAXDEV .AND. STATE(I).NE.0) I = I + 1 END DO IF (I .GT. MAXDEV) THEN CALL GRWARN('maximum number of graphics windows exceeded') RBUF(1) = 0. RBUF(2) = 0. ELSE ACTIVE = I RBUF(1) = ACTIVE RBUF(2) = 1. C Initialize this window in requested mode, and open it MXX(ACTIVE) = MX(MODE) MXY(ACTIVE) = MY(MODE) MXC(ACTIVE) = 236 CALL GRGLUN(IUNIT(ACTIVE)) WRITE (WINTITLE, '(A,I2)') CHR(:LCHR)//', #', ACTIVE OPEN (IUNIT(ACTIVE), FILE='USER', TITLE=WINTITLE(:LCHR+5)) CALL GRW900(ACTIVE, MXX, MXY, MXC, QFIRST) DO I=0,235 RGB236(I) = RGB(I,ACTIVE) END DO I4STAT = REMAPALLPALETTE(RGB236) I2STAT = SETCOLOR(ICOLOR) STATE(ACTIVE) = 1 NPIC(ACTIVE) = 0 END IF NBUF = 2 C CASE (10) C--- IFUNC=10, Close workstation. -------------------------------------- IF (STATE(ACTIVE) .GT. 0) THEN print ('(A,I2)'), ' Type <RETURN> to close graphics '// & & 'window #',active read * CLOSE (IUNIT(ACTIVE)) STATE(ACTIVE) = 0 QFIRST(ACTIVE) = .TRUE. END IF C CASE (11) C--- IFUNC=11, Begin picture. ------------------------------------------ IF(NPIC(ACTIVE) .EQ. 0) THEN CALL CLEARSCREEN($GCLEARSCREEN) END IF STATE(ACTIVE) = 2 NPIC(ACTIVE) = NPIC(ACTIVE) + 1 I4STAT = SETACTIVEQQ(IUNIT(ACTIVE)) I4STAT = FOCUSQQ(IUNIT(ACTIVE)) C CASE (12) C--- IFUNC=12, Draw line. ---------------------------------------------- I2X0 = NINT(RBUF(1)) I2Y0 = MXY(ACTIVE) - NINT(RBUF(2)) CALL MOVETO(I2X0, I2Y0, XY) I2X1 = NINT(RBUF(3)) I2Y1 = MXY(ACTIVE) - NINT(RBUF(4)) I2STAT = LINETO(I2X1, I2Y1) C CASE (13) C--- IFUNC=13, Draw dot. ----------------------------------------------- I2X0 = NINT(RBUF(1)) I2Y0 = MXY(ACTIVE) - NINT(RBUF(2)) I4STAT = SETPIXEL(I2X0, I2Y0) C CASE (14) C--- IFUNC=14, End picture. -------------------------------------------- IF (STATE(ACTIVE) .GT. 0) STATE(ACTIVE) = 1 NPIC(ACTIVE) = 0 C CASE (15) C--- IFUNC=15, Select color index. ------------------------------------- ICOLOR = MIN(MXC(ACTIVE), MAX(0, NINT(RBUF(1)))) I2STAT = SETCOLOR(ICOLOR) C CASE (16) C--- IFUNC=16, Flush buffer. ------------------------------------------- C CASE (17) C--- IFUNC=17, Read cursor (mouse) AND keystroke ----------------------- I4X = NINT(RBUF(1)) I4Y = MXY(ACTIVE) - NINT(RBUF(2)) IF (NBUF .GE. 6) THEN C Support for multiple forms of cursor IXREF = NINT(RBUF(3)) IYREF = MXY(ACTIVE) - NINT(RBUF(4)) BAND = NINT(RBUF(5)) LPOS = RBUF(6) .GT. 0. ELSE C Simple crosshair cursor IXREF = I4X IYREF = I4Y BAND = 0 LPOS = .TRUE. END IF C C Set color index, for exclusive-ORing ICOLOR = SETCOLOR(CBITS(ACTIVE)) I4STAT = SETWRITEMODE($GXOR) C Initialize mouse routine by calling with fake arguments CALL GRW901(-BAND, MXX(ACTIVE), MXY(ACTIVE), IXREF, IYREF) C Initialize position of cursor by simulating mouse button click IF (LPOS) CALL GRW901(IUNIT(ACTIVE), MOUSE$MOVE, 0, I4X, I4Y) C Activate mouse callback routine EVENT = MOUSE$MOVE I4STAT = REGISTERMOUSEEVENT(IUNIT(ACTIVE), EVENT, GRW901) C Wait for a keystroke CHR(1:1) = GETCHARQQ() C C A key has been struck; turn off mouse, get position, restore color I4STAT = UNREGISTERMOUSEEVENT(IUNIT(ACTIVE), EVENT) CALL GRW901(0, 0, 0, I4X, I4Y) I4STAT = SETWRITEMODE($GPSET) I2STAT = SETCOLOR(ICOLOR) C Return results LCHR = 1 RBUF(1) = I4X RBUF(2) = MXY(ACTIVE) - I4Y NBUF = 2 C CASE (18) C--- IFUNC=18, Erase alpha screen. ------------------------------------- C CASE (19) C--- IFUNC=19, Set line style. ----------------------------------------- C Note: not likely to be called because IFUNC=4 returns "No dashed lines" I = MIN(5, MAX(0, NINT(RBUF(1)))) CALL SETLINESTYLE(DASHLINE(I)) C C--- IFUNC=20, Polygon fill. ------------------------------------------- C CASE (21) C--- IFUNC=21, Set color representation. ------------------------------- I = NINT(RBUF(1)) IF (I.GE.0 .AND. I.LE.MXC(ACTIVE)) THEN ICOLOR = I IRGB = NINT(RBUF(2)*CNORM) .OR. & & ISHFT(NINT(RBUF(3)*CNORM), 8) .OR. & & ISHFT(NINT(RBUF(4)*CNORM),16) RGB(I,ACTIVE) = IRGB CBITS(ACTIVE) = CBITS(ACTIVE) .OR. ICOLOR I4STAT = REMAPPALETTERGB(I, IRGB) END IF C C--- IFUNC=22, Set line width. ----------------------------------------- C C--- IFUNC=23, Escape. ------------------------------------------------- C CASE (24) C--- IFUNC=24, Rectangle fill. ----------------------------------------- I2X0 = NINT(RBUF(1)) I2Y0 = MXY(ACTIVE) - NINT(RBUF(2)) I2X1 = NINT(RBUF(3)) I2Y1 = MXY(ACTIVE) - NINT(RBUF(4)) I2STAT = RECTANGLE($GFILLINTERIOR, I2X0, I2Y0, I2X1, I2Y1) C C--- IFUNC=25, Set fill pattern. --------------------------------------- C CASE (26) C--- IFUNC=26, Line of pixels. ----------------------------------------- IY(1) = MXY(ACTIVE) - NINT(RBUF(2)) IF (IY(1).GE.0 .AND. IY(1).LE.MXY(ACTIVE)) THEN IX(1) = NINT(RBUF(1)) IBUF = 3 IF (IX(1) .LT. 0) THEN IBUF = 3 - IX(1) IX(1) = 0 END IF DO WHILE (IBUF.LE.NBUF .AND. I2X0.LE.MXX(ACTIVE)) IC(1) = MIN(MXC(ACTIVE), MAX(0, NINT(RBUF(IBUF)))) CALL SETPIXELS(1, IX, IY, IC) IBUF = IBUF + 1 IX(1) = IX(1) + 1 END DO END IF C C--- IFUNC=27, Scaling info -------------------------------------------- C C--- IFUNC=28, Draw marker --------------------------------------------- C CASE (29) C--- IFUNC=29, Query color representation.------------------------------ I = NINT(RBUF(1)) IRGB = RGB(I,ACTIVE) RBUF(2) = FLOAT(IAND(IRGB, #FF))/CNORM RBUF(3) = FLOAT(IAND(ISHFT(IRGB,-8), #FF))/CNORM RBUF(4) = FLOAT(IAND(ISHFT(IRGB,-16), #FF))/CNORM NBUF = 4 C CASE DEFAULT C--- Unimplemented Function WRITE (CMSG, '(I10)') IFUNC CALL GRWARN('Unimplemented function in Win95 device driver:'// & & CMSG) NBUF = -1 END SELECT RETURN END C********* SUBROUTINE GRW900(I, MXX, MXY, MXC, QFIRST) USE DFLIB C 1998-May-04 - change from MSFLIB to DFLIB C 1998-Jun-22 - don't set WC.title to 'PGPLOT' IMPLICIT NONE INTEGER I, MXX(*), MXY(*), MXC(*) LOGICAL QFIRST(*) C--- TYPE (WINDOWCONFIG) WC INTEGER TR$L LOGICAL STATUS CHARACTER TR$VID*128 C--- C Set default window configuration C Try to set to input values of MXX, MXY, default 800x600 IF (MXX(I).LE.1 .OR. MXY(I).LE.1) THEN MXX(I) = 800 MXY(I) = 600 MXC(I) = 256 CALL GRGENV('VIDEO', TR$VID, TR$L) IF (TR$L .GT. 0) THEN C There is a "PGPLOT_VIDEO" parameter in the Environment IF( TR$VID(1:1) .EQ. 'V') THEN C Set to VGA resolution MXX(I) = 640 MXY(I) = 480 ELSE IF (TR$VID(1:1) .EQ. 'X') THEN MXX(I) = 1024 MXY(I) = 768 ELSE IF (TR$VID(1:1) .EQ. 'Z') THEN MXX(I) = 1280 MXY(I) = 1024 END IF END IF END IF C WC.numxpixels = MXX(I) WC.numypixels = MXY(I) WC.numcolors = MXC(I) WC.numtextcols = -1 WC.numtextrows = -1 WC.fontsize = -1 STATUS = SETWINDOWCONFIG(WC) IF(.NOT.STATUS) STATUS = SETWINDOWCONFIG(WC) C MXX(I) = WC.numxpixels - 1 MXY(I) = WC.numypixels - 1 MXC(I) = WC.numcolors - 1 QFIRST(I) = .FALSE. RETURN END C********* RECURSIVE SUBROUTINE GRW901(IUNIT,EVENT,KEYSTATE,XMOUSE,YMOUSE) USE DFLIB IMPLICIT NONE INTEGER IUNIT, EVENT, KEYSTATE, XMOUSE, YMOUSE C C Callback routine for mouse events, specific to Windows95 C Note: cursor band modes implemented in software C C 1996-Apr-26 - P.A.Seeger C 1998-May-04 - change from MSFLIB to DFLIB C-- RECORD /xycoord/ XY INTEGER*2 BAND, LENGTH, IX0, IY0, IX1, IY1, IX2, IY2, IXR, IYR INTEGER*4 DUMMY LOGICAL INITIUS, FINIS DATA INITIUS /.TRUE./ SAVE INITIUS,BAND,LENGTH,IX0,IY0,IX1,IY1,IX2,IY2,IXR,IYR C C Disable mouse movement interrupts while in callback routine IF (IUNIT .GT. 0) DUMMY = UNREGISTERMOUSEEVENT(IUNIT, MOUSE$MOVE) C FINIS = IUNIT.EQ.0 .AND. EVENT.EQ.0 .AND. KEYSTATE.EQ.0 IF (IUNIT.LE.0 .AND. .NOT.FINIS) THEN INITIUS = .TRUE. C Get initialization parameters from callback calling sequence BAND = -IUNIT IXR = XMOUSE IYR = YMOUSE IX0 = IXR IY0 = IYR C Extract parameters for length of cursor lines IF (BAND .EQ. 0) THEN C Simple crosshair cursor LENGTH = MAX(EVENT, KEYSTATE)/80 + 3 ELSE LENGTH = 0 IX1 = 0 IX2 = 0 IY1 = 0 IY2 = 0 C Modes with full width horizontal line(s) IF (BAND.EQ.3 .OR. BAND.EQ.5 .OR. BAND.EQ.7) IX2 = EVENT C Modes with full height vertical line(s) IF (BAND.EQ.4 .OR. BAND.EQ.6 .OR. BAND.EQ.7) IY2 = KEYSTATE IF (BAND .EQ. 3) THEN C Draw fixed horizontal line at anchor CALL MOVETO(IX1, IYR, XY) DUMMY = LINETO(IX2, IYR ) ELSE IF (BAND .EQ. 4) THEN C Draw fixed vertical line at anchor CALL MOVETO(IXR, IY1, XY) DUMMY = LINETO(IXR, IY2 ) END IF END IF GO TO 700 END IF C IF (.NOT. INITIUS) THEN C This is NOT an initial call, so need to erase previous cursor C by rewriting it in complementary color mode IF (BAND .EQ. 1) THEN CALL MOVETO(IXR, IYR, XY) DUMMY = LINETO(IX0, IY0 ) ELSE IF (BAND .EQ. 2) THEN DUMMY = RECTANGLE($GBORDER, IXR, IYR, IX0, IY0) ELSE IF (IY2 .NE. IY1) THEN CALL MOVETO(IX0, IY1, XY) DUMMY = LINETO(IX0, IY2 ) END IF IF (IX2 .NE. IX1) THEN CALL MOVETO(IX1, IY0, XY) DUMMY = LINETO(IX2, IY0 ) END IF END IF END IF C IF (FINIS) THEN C Termination call, return latest mouse location XMOUSE = IX0 YMOUSE = IY0 IF (BAND .EQ. 3) THEN C Erase fixed horizontal line at anchor CALL MOVETO(IX1, IYR, XY) DUMMY = LINETO(IX2, IYR ) ELSE IF (BAND .EQ. 4) THEN C Erase fixed vertical line at anchor CALL MOVETO(IXR, IY1, XY) DUMMY = LINETO(IXR, IY2 ) END IF INITIUS = .TRUE. GO TO 700 END IF C C Save new cursor location IX0 = XMOUSE IY0 = YMOUSE IF (BAND .EQ. 0) THEN C Find ends of cursor line segments IX1 = IX0 - LENGTH IX2 = IX0 + LENGTH IY1 = IY0 - LENGTH IY2 = IY0 + LENGTH END IF C C Now draw line, box, or cursor in complementary color INITIUS = .FALSE. IF (BAND .EQ. 1) THEN C Line from anchor to cursor location CALL MOVETO(IXR, IYR, XY) DUMMY = LINETO(IX0, IY0 ) ELSE IF (BAND .EQ. 2) THEN C Box with vertices at anchor and cursor location DUMMY = RECTANGLE($GBORDER, IXR, IYR, IX0, IY0) ELSE IF (IY2 .NE. IY1) THEN C Draw a horizontal line (or segment) CALL MOVETO(IX0, IY1, XY) DUMMY = LINETO(IX0, IY2) END IF IF (IX2 .NE. IX1) THEN C Draw a vertical line (or segment) CALL MOVETO(IX1, IY0, XY) DUMMY = LINETO(IX2, IY0) END IF END IF C 700 CONTINUE IF (IUNIT.GT.0 .AND. .NOT.INITIUS) & & DUMMY = REGISTERMOUSEEVENT(IUNIT, MOUSE$MOVE, GRW901) RETURN END
gpl-2.0
e-q/scipy
scipy/interpolate/fitpack/fpbfout.f
148
5322
subroutine fpbfou(t,n,par,ress,resc) c subroutine fpbfou calculates the integrals c /t(n-3) c ress(j) = ! nj,4(x)*sin(par*x) dx and c t(4)/ c /t(n-3) c resc(j) = ! nj,4(x)*cos(par*x) dx , j=1,2,...n-4 c t(4)/ c where nj,4(x) denotes the cubic b-spline defined on the knots c t(j),t(j+1),...,t(j+4). c c calling sequence: c call fpbfou(t,n,par,ress,resc) c c input parameters: c t : real array,length n, containing the knots. c n : integer, containing the number of knots. c par : real, containing the value of the parameter par. c c output parameters: c ress : real array,length n, containing the integrals ress(j). c resc : real array,length n, containing the integrals resc(j). c c restrictions: c n >= 10, t(4) < t(5) < ... < t(n-4) < t(n-3). c .. c ..scalar arguments.. integer n real*8 par c ..array arguments.. real*8 t(n),ress(n),resc(n) c ..local scalars.. integer i,ic,ipj,is,j,jj,jp1,jp4,k,li,lj,ll,nmj,nm3,nm7 real*8 ak,beta,con1,con2,c1,c2,delta,eps,fac,f1,f2,f3,one,quart, * sign,six,s1,s2,term c ..local arrays.. real*8 co(5),si(5),hs(5),hc(5),rs(3),rc(3) c ..function references.. real*8 cos,sin,abs c .. c initialization. one = 0.1e+01 six = 0.6e+01 eps = 0.1e-07 quart = 0.25e0 con1 = 0.5e-01 con2 = 0.12e+03 nm3 = n-3 nm7 = n-7 if(par.ne.0.) term = six/par beta = par*t(4) co(1) = cos(beta) si(1) = sin(beta) c calculate the integrals ress(j) and resc(j), j=1,2,3 by setting up c a divided difference table. do 30 j=1,3 jp1 = j+1 jp4 = j+4 beta = par*t(jp4) co(jp1) = cos(beta) si(jp1) = sin(beta) call fpcsin(t(4),t(jp4),par,si(1),co(1),si(jp1),co(jp1), * rs(j),rc(j)) i = 5-j hs(i) = 0. hc(i) = 0. do 10 jj=1,j ipj = i+jj hs(ipj) = rs(jj) hc(ipj) = rc(jj) 10 continue do 20 jj=1,3 if(i.lt.jj) i = jj k = 5 li = jp4 do 20 ll=i,4 lj = li-jj fac = t(li)-t(lj) hs(k) = (hs(k)-hs(k-1))/fac hc(k) = (hc(k)-hc(k-1))/fac k = k-1 li = li-1 20 continue ress(j) = hs(5)-hs(4) resc(j) = hc(5)-hc(4) 30 continue if(nm7.lt.4) go to 160 c calculate the integrals ress(j) and resc(j),j=4,5,...,n-7. do 150 j=4,nm7 jp4 = j+4 beta = par*t(jp4) co(5) = cos(beta) si(5) = sin(beta) delta = t(jp4)-t(j) c the way of computing ress(j) and resc(j) depends on the value of c beta = par*(t(j+4)-t(j)). beta = delta*par if(abs(beta).le.one) go to 60 c if !beta! > 1 the integrals are calculated by setting up a divided c difference table. do 40 k=1,5 hs(k) = si(k) hc(k) = co(k) 40 continue do 50 jj=1,3 k = 5 li = jp4 do 50 ll=jj,4 lj = li-jj fac = par*(t(li)-t(lj)) hs(k) = (hs(k)-hs(k-1))/fac hc(k) = (hc(k)-hc(k-1))/fac k = k-1 li = li-1 50 continue s2 = (hs(5)-hs(4))*term c2 = (hc(5)-hc(4))*term go to 130 c if !beta! <= 1 the integrals are calculated by evaluating a series c expansion. 60 f3 = 0. do 70 i=1,4 ipj = i+j hs(i) = par*(t(ipj)-t(j)) hc(i) = hs(i) f3 = f3+hs(i) 70 continue f3 = f3*con1 c1 = quart s1 = f3 if(abs(f3).le.eps) go to 120 sign = one fac = con2 k = 5 is = 0 do 110 ic=1,20 k = k+1 ak = k fac = fac*ak f1 = 0. f3 = 0. do 80 i=1,4 f1 = f1+hc(i) f2 = f1*hs(i) hc(i) = f2 f3 = f3+f2 80 continue f3 = f3*six/fac if(is.eq.0) go to 90 is = 0 s1 = s1+f3*sign go to 100 90 sign = -sign is = 1 c1 = c1+f3*sign 100 if(abs(f3).le.eps) go to 120 110 continue 120 s2 = delta*(co(1)*s1+si(1)*c1) c2 = delta*(co(1)*c1-si(1)*s1) 130 ress(j) = s2 resc(j) = c2 do 140 i=1,4 co(i) = co(i+1) si(i) = si(i+1) 140 continue 150 continue c calculate the integrals ress(j) and resc(j),j=n-6,n-5,n-4 by setting c up a divided difference table. 160 do 190 j=1,3 nmj = nm3-j i = 5-j call fpcsin(t(nm3),t(nmj),par,si(4),co(4),si(i-1),co(i-1), * rs(j),rc(j)) hs(i) = 0. hc(i) = 0. do 170 jj=1,j ipj = i+jj hc(ipj) = rc(jj) hs(ipj) = rs(jj) 170 continue do 180 jj=1,3 if(i.lt.jj) i = jj k = 5 li = nmj do 180 ll=i,4 lj = li+jj fac = t(lj)-t(li) hs(k) = (hs(k-1)-hs(k))/fac hc(k) = (hc(k-1)-hc(k))/fac k = k-1 li = li+1 180 continue ress(nmj) = hs(4)-hs(5) resc(nmj) = hc(4)-hc(5) 190 continue return end
bsd-3-clause
wilmarcardonac/hypermcmc
lapack-3.5.0/TESTING/LIN/alaerh.f
24
38022
*> \brief \b ALAERH * * =========== DOCUMENTATION =========== * * Online html documentation available at * http://www.netlib.org/lapack/explore-html/ * * Definition: * =========== * * SUBROUTINE ALAERH( PATH, SUBNAM, INFO, INFOE, OPTS, M, N, KL, KU, * N5, IMAT, NFAIL, NERRS, NOUT ) * * .. Scalar Arguments .. * CHARACTER*3 PATH * CHARACTER*( * ) SUBNAM * CHARACTER*( * ) OPTS * INTEGER IMAT, INFO, INFOE, KL, KU, M, N, N5, NERRS, * $ NFAIL, NOUT * .. * * *> \par Purpose: * ============= *> *> \verbatim *> *> ALAERH is an error handler for the LAPACK routines. It prints the *> header if this is the first error message and prints the error code *> and form of recovery, if any. The character evaluations in this *> routine may make it slow, but it should not be called once the LAPACK *> routines are fully debugged. *> \endverbatim * * Arguments: * ========== * *> \param[in] PATH *> \verbatim *> PATH is CHARACTER*3 *> The LAPACK path name of subroutine SUBNAM. *> \endverbatim *> *> \param[in] SUBNAM *> \verbatim *> SUBNAM is CHARACTER*(*) *> The name of the subroutine that returned an error code. *> \endverbatim *> *> \param[in] INFO *> \verbatim *> INFO is INTEGER *> The error code returned from routine SUBNAM. *> \endverbatim *> *> \param[in] INFOE *> \verbatim *> INFOE is INTEGER *> The expected error code from routine SUBNAM, if SUBNAM were *> error-free. If INFOE = 0, an error message is printed, but *> if INFOE.NE.0, we assume only the return code INFO is wrong. *> \endverbatim *> *> \param[in] OPTS *> \verbatim *> OPTS is CHARACTER*(*) *> The character options to the subroutine SUBNAM, concatenated *> into a single character string. For example, UPLO = 'U', *> TRANS = 'T', and DIAG = 'N' for a triangular routine would *> be specified as OPTS = 'UTN'. *> \endverbatim *> *> \param[in] M *> \verbatim *> M is INTEGER *> The matrix row dimension. *> \endverbatim *> *> \param[in] N *> \verbatim *> N is INTEGER *> The matrix column dimension. Accessed only if PATH = xGE or *> xGB. *> \endverbatim *> *> \param[in] KL *> \verbatim *> KL is INTEGER *> The number of sub-diagonals of the matrix. Accessed only if *> PATH = xGB, xPB, or xTB. Also used for NRHS for PATH = xLS. *> \endverbatim *> *> \param[in] KU *> \verbatim *> KU is INTEGER *> The number of super-diagonals of the matrix. Accessed only *> if PATH = xGB. *> \endverbatim *> *> \param[in] N5 *> \verbatim *> N5 is INTEGER *> A fifth integer parameter, may be the blocksize NB or the *> number of right hand sides NRHS. *> \endverbatim *> *> \param[in] IMAT *> \verbatim *> IMAT is INTEGER *> The matrix type. *> \endverbatim *> *> \param[in] NFAIL *> \verbatim *> NFAIL is INTEGER *> The number of prior tests that did not pass the threshold; *> used to determine if the header should be printed. *> \endverbatim *> *> \param[in,out] NERRS *> \verbatim *> NERRS is INTEGER *> On entry, the number of errors already detected; used to *> determine if the header should be printed. *> On exit, NERRS is increased by 1. *> \endverbatim *> *> \param[in] NOUT *> \verbatim *> NOUT is INTEGER *> The unit number on which results are to be printed. *> \endverbatim * * Authors: * ======== * *> \author Univ. of Tennessee *> \author Univ. of California Berkeley *> \author Univ. of Colorado Denver *> \author NAG Ltd. * *> \date November 2013 * *> \ingroup aux_lin * * ===================================================================== SUBROUTINE ALAERH( PATH, SUBNAM, INFO, INFOE, OPTS, M, N, KL, KU, $ N5, IMAT, NFAIL, NERRS, NOUT ) * * -- LAPACK test routine (version 3.5.0) -- * -- LAPACK is a software package provided by Univ. of Tennessee, -- * -- Univ. of California Berkeley, Univ. of Colorado Denver and NAG Ltd..-- * November 2013 * * .. Scalar Arguments .. CHARACTER*3 PATH CHARACTER*( * ) SUBNAM CHARACTER*( * ) OPTS INTEGER IMAT, INFO, INFOE, KL, KU, M, N, N5, NERRS, $ NFAIL, NOUT * .. * * ===================================================================== * * .. Local Scalars .. CHARACTER UPLO CHARACTER*2 P2 CHARACTER*3 C3 * .. * .. External Functions .. LOGICAL LSAME, LSAMEN EXTERNAL LSAME, LSAMEN * .. * .. Intrinsic Functions .. INTRINSIC LEN_TRIM * .. * .. External Subroutines .. EXTERNAL ALADHD, ALAHD * .. * .. Executable Statements .. * IF( INFO.EQ.0 ) $ RETURN P2 = PATH( 2: 3 ) C3 = SUBNAM( 4: 6 ) * * Print the header if this is the first error message. * IF( NFAIL.EQ.0 .AND. NERRS.EQ.0 ) THEN IF( LSAMEN( 3, C3, 'SV ' ) .OR. LSAMEN( 3, C3, 'SVX' ) ) THEN CALL ALADHD( NOUT, PATH ) ELSE CALL ALAHD( NOUT, PATH ) END IF END IF NERRS = NERRS + 1 * * Print the message detailing the error and form of recovery, * if any. * IF( LSAMEN( 2, P2, 'GE' ) ) THEN * * xGE: General matrices * IF( LSAMEN( 3, C3, 'TRF' ) ) THEN IF( INFO.NE.INFOE .AND. INFOE.NE.0 ) THEN WRITE( NOUT, FMT = 9988 ) $ SUBNAM(1:LEN_TRIM( SUBNAM )), INFO, INFOE, M, N, N5, $ IMAT ELSE WRITE( NOUT, FMT = 9975 ) $ SUBNAM(1:LEN_TRIM( SUBNAM )), INFO, M, N, N5, IMAT END IF IF( INFO.NE.0 ) $ WRITE( NOUT, FMT = 9949 ) * ELSE IF( LSAMEN( 3, C3, 'SV ' ) ) THEN * IF( INFO.NE.INFOE .AND. INFOE.NE.0 ) THEN WRITE( NOUT, FMT = 9984 ) $ SUBNAM(1:LEN_TRIM( SUBNAM )), INFO, INFOE, N, N5, $ IMAT ELSE WRITE( NOUT, FMT = 9970 ) $ SUBNAM(1:LEN_TRIM( SUBNAM )), INFO, N, N5, IMAT END IF * ELSE IF( LSAMEN( 3, C3, 'SVX' ) ) THEN * IF( INFO.NE.INFOE .AND. INFOE.NE.0 ) THEN WRITE( NOUT, FMT = 9992 ) $ SUBNAM(1:LEN_TRIM( SUBNAM )), INFO, INFOE, $ OPTS( 1: 1 ), OPTS( 2: 2 ), N, N5, IMAT ELSE WRITE( NOUT, FMT = 9997 ) $ SUBNAM(1:LEN_TRIM( SUBNAM )), INFO, OPTS( 1: 1 ), $ OPTS( 2: 2 ), N, N5, IMAT END IF * ELSE IF( LSAMEN( 3, C3, 'TRI' ) ) THEN * WRITE( NOUT, FMT = 9971 ) $ SUBNAM(1:LEN_TRIM( SUBNAM )), INFO, N, N5, IMAT * ELSE IF( LSAMEN( 5, SUBNAM( 2: 6 ), 'LATMS' ) ) THEN * WRITE( NOUT, FMT = 9978 ) $ SUBNAM(1:LEN_TRIM( SUBNAM )), INFO, M, N, IMAT * ELSE IF( LSAMEN( 3, C3, 'CON' ) ) THEN * WRITE( NOUT, FMT = 9969 ) $ SUBNAM(1:LEN_TRIM( SUBNAM )), INFO, OPTS( 1: 1 ), M, $ IMAT * ELSE IF( LSAMEN( 3, C3, 'LS ' ) ) THEN * WRITE( NOUT, FMT = 9965 ) $ SUBNAM(1:LEN_TRIM( SUBNAM )), INFO, OPTS( 1: 1 ), M, N, $ KL, N5, IMAT * ELSE IF( LSAMEN( 3, C3, 'LSX' ) .OR. LSAMEN( 3, C3, 'LSS' ) ) $ THEN * WRITE( NOUT, FMT = 9974 ) $ SUBNAM(1:LEN_TRIM( SUBNAM )), INFO, M, N, KL, N5, IMAT * ELSE * WRITE( NOUT, FMT = 9963 ) $ SUBNAM(1:LEN_TRIM( SUBNAM )), INFO, OPTS( 1: 1 ), M, N5, $ IMAT END IF * ELSE IF( LSAMEN( 2, P2, 'GB' ) ) THEN * * xGB: General band matrices * IF( LSAMEN( 3, C3, 'TRF' ) ) THEN IF( INFO.NE.INFOE .AND. INFOE.NE.0 ) THEN WRITE( NOUT, FMT = 9989 ) $ SUBNAM(1:LEN_TRIM( SUBNAM )), INFO, INFOE, M, N, KL, $ KU, N5, IMAT ELSE WRITE( NOUT, FMT = 9976 ) $ SUBNAM(1:LEN_TRIM( SUBNAM )), INFO, M, N, KL, KU, N5, $ IMAT END IF IF( INFO.NE.0 ) $ WRITE( NOUT, FMT = 9949 ) * ELSE IF( LSAMEN( 3, C3, 'SV ' ) ) THEN * IF( INFO.NE.INFOE .AND. INFOE.NE.0 ) THEN WRITE( NOUT, FMT = 9986 ) $ SUBNAM(1:LEN_TRIM( SUBNAM )), INFO, INFOE, N, KL, KU, $ N5, IMAT ELSE WRITE( NOUT, FMT = 9972 ) $ SUBNAM(1:LEN_TRIM( SUBNAM )), INFO, N, KL, KU, N5, $ IMAT END IF * ELSE IF( LSAMEN( 3, C3, 'SVX' ) ) THEN * IF( INFO.NE.INFOE .AND. INFOE.NE.0 ) THEN WRITE( NOUT, FMT = 9993 ) $ SUBNAM(1:LEN_TRIM( SUBNAM )), INFO, INFOE, $ OPTS( 1: 1 ), OPTS( 2: 2 ), N, KL, KU, N5, IMAT ELSE WRITE( NOUT, FMT = 9998 ) $ SUBNAM(1:LEN_TRIM( SUBNAM )), INFO, OPTS( 1: 1 ), $ OPTS( 2: 2 ), N, KL, KU, N5, IMAT END IF * ELSE IF( LSAMEN( 5, SUBNAM( 2: 6 ), 'LATMS' ) ) THEN * WRITE( NOUT, FMT = 9977 ) $ SUBNAM(1:LEN_TRIM( SUBNAM )), INFO, M, N, KL, KU, IMAT * ELSE IF( LSAMEN( 3, C3, 'CON' ) ) THEN * WRITE( NOUT, FMT = 9968 ) $ SUBNAM(1:LEN_TRIM( SUBNAM )), INFO, OPTS( 1: 1 ), M, KL, $ KU, IMAT * ELSE * WRITE( NOUT, FMT = 9964 ) $ SUBNAM(1:LEN_TRIM( SUBNAM )), INFO, OPTS( 1: 1 ), M, KL, $ KU, N5, IMAT END IF * ELSE IF( LSAMEN( 2, P2, 'GT' ) ) THEN * * xGT: General tridiagonal matrices * IF( LSAMEN( 3, C3, 'TRF' ) ) THEN IF( INFO.NE.INFOE .AND. INFOE.NE.0 ) THEN WRITE( NOUT, FMT = 9987 ) $ SUBNAM(1:LEN_TRIM( SUBNAM )), INFO, INFOE, N, IMAT ELSE WRITE( NOUT, FMT = 9973 ) $ SUBNAM(1:LEN_TRIM( SUBNAM )), INFO, N, IMAT END IF IF( INFO.NE.0 ) $ WRITE( NOUT, FMT = 9949 ) * ELSE IF( LSAMEN( 3, C3, 'SV ' ) ) THEN * IF( INFO.NE.INFOE .AND. INFOE.NE.0 ) THEN WRITE( NOUT, FMT = 9984 ) $ SUBNAM(1:LEN_TRIM( SUBNAM )), INFO, INFOE, N, N5, $ IMAT ELSE WRITE( NOUT, FMT = 9970 ) $ SUBNAM(1:LEN_TRIM( SUBNAM )), INFO, N, N5, IMAT END IF * ELSE IF( LSAMEN( 3, C3, 'SVX' ) ) THEN * IF( INFO.NE.INFOE .AND. INFOE.NE.0 ) THEN WRITE( NOUT, FMT = 9992 ) $ SUBNAM(1:LEN_TRIM( SUBNAM )), INFO, INFOE, $ OPTS( 1: 1 ), OPTS( 2: 2 ), N, N5, IMAT ELSE WRITE( NOUT, FMT = 9997 ) $ SUBNAM(1:LEN_TRIM( SUBNAM )), INFO, OPTS( 1: 1 ), $ OPTS( 2: 2 ), N, N5, IMAT END IF * ELSE IF( LSAMEN( 3, C3, 'CON' ) ) THEN * WRITE( NOUT, FMT = 9969 ) $ SUBNAM(1:LEN_TRIM( SUBNAM )), INFO, OPTS( 1: 1 ), M, $ IMAT * ELSE * WRITE( NOUT, FMT = 9963 ) $ SUBNAM(1:LEN_TRIM( SUBNAM )), INFO, OPTS( 1: 1 ), M, N5, $ IMAT END IF * ELSE IF( LSAMEN( 2, P2, 'PO' ) ) THEN * * xPO: Symmetric or Hermitian positive definite matrices * UPLO = OPTS( 1: 1 ) IF( LSAMEN( 3, C3, 'TRF' ) ) THEN IF( INFO.NE.INFOE .AND. INFOE.NE.0 ) THEN WRITE( NOUT, FMT = 9980 ) $ SUBNAM(1:LEN_TRIM( SUBNAM )), INFO, INFOE, UPLO, M, $ N5, IMAT ELSE WRITE( NOUT, FMT = 9956 ) $ SUBNAM(1:LEN_TRIM( SUBNAM )), INFO, UPLO, M, N5, IMAT END IF IF( INFO.NE.0 ) $ WRITE( NOUT, FMT = 9949 ) * ELSE IF( LSAMEN( 3, C3, 'SV ' ) ) THEN * IF( INFO.NE.INFOE .AND. INFOE.NE.0 ) THEN WRITE( NOUT, FMT = 9979 ) $ SUBNAM(1:LEN_TRIM( SUBNAM )), INFO, INFOE, UPLO, N, $ N5, IMAT ELSE WRITE( NOUT, FMT = 9955 ) $ SUBNAM(1:LEN_TRIM( SUBNAM )), INFO, UPLO, N, N5, IMAT END IF * ELSE IF( LSAMEN( 3, C3, 'SVX' ) ) THEN * IF( INFO.NE.INFOE .AND. INFOE.NE.0 ) THEN WRITE( NOUT, FMT = 9990 ) $ SUBNAM(1:LEN_TRIM( SUBNAM )), INFO, INFOE, $ OPTS( 1: 1 ), OPTS( 2: 2 ), N, N5, IMAT ELSE WRITE( NOUT, FMT = 9995 ) $ SUBNAM(1:LEN_TRIM( SUBNAM )), INFO, OPTS( 1: 1 ), $ OPTS( 2: 2 ), N, N5, IMAT END IF * ELSE IF( LSAMEN( 3, C3, 'TRI' ) ) THEN * WRITE( NOUT, FMT = 9956 ) $ SUBNAM(1:LEN_TRIM( SUBNAM )), INFO, UPLO, M, N5, IMAT * ELSE IF( LSAMEN( 5, SUBNAM( 2: 6 ), 'LATMS' ) .OR. $ LSAMEN( 3, C3, 'CON' ) ) THEN * WRITE( NOUT, FMT = 9960 ) $ SUBNAM(1:LEN_TRIM( SUBNAM )), INFO, UPLO, M, IMAT * ELSE * WRITE( NOUT, FMT = 9955 ) $ SUBNAM(1:LEN_TRIM( SUBNAM )), INFO, UPLO, M, N5, IMAT END IF * ELSE IF( LSAMEN( 2, P2, 'PS' ) ) THEN * * xPS: Symmetric or Hermitian positive semi-definite matrices * UPLO = OPTS( 1: 1 ) IF( LSAMEN( 3, C3, 'TRF' ) ) THEN IF( INFO.NE.INFOE .AND. INFOE.NE.0 ) THEN WRITE( NOUT, FMT = 9980 )SUBNAM, INFO, INFOE, UPLO, M, $ N5, IMAT ELSE WRITE( NOUT, FMT = 9956 )SUBNAM, INFO, UPLO, M, N5, IMAT END IF IF( INFO.NE.0 ) $ WRITE( NOUT, FMT = 9949 ) * ELSE IF( LSAMEN( 3, C3, 'SV ' ) ) THEN * IF( INFO.NE.INFOE .AND. INFOE.NE.0 ) THEN WRITE( NOUT, FMT = 9979 )SUBNAM, INFO, INFOE, UPLO, N, $ N5, IMAT ELSE WRITE( NOUT, FMT = 9955 )SUBNAM, INFO, UPLO, N, N5, IMAT END IF * ELSE IF( LSAMEN( 3, C3, 'SVX' ) ) THEN * IF( INFO.NE.INFOE .AND. INFOE.NE.0 ) THEN WRITE( NOUT, FMT = 9990 )SUBNAM, INFO, INFOE, $ OPTS( 1: 1 ), OPTS( 2: 2 ), N, N5, IMAT ELSE WRITE( NOUT, FMT = 9995 )SUBNAM, INFO, OPTS( 1: 1 ), $ OPTS( 2: 2 ), N, N5, IMAT END IF * ELSE IF( LSAMEN( 3, C3, 'TRI' ) ) THEN * WRITE( NOUT, FMT = 9956 )SUBNAM, INFO, UPLO, M, N5, IMAT * ELSE IF( LSAMEN( 5, SUBNAM( 2: 6 ), 'LATMT' ) .OR. $ LSAMEN( 3, C3, 'CON' ) ) THEN * WRITE( NOUT, FMT = 9960 )SUBNAM, INFO, UPLO, M, IMAT * ELSE * WRITE( NOUT, FMT = 9955 )SUBNAM, INFO, UPLO, M, N5, IMAT END IF * ELSE IF( LSAMEN( 2, P2, 'SY' ) $ .OR. LSAMEN( 2, P2, 'SR' ) $ .OR. LSAMEN( 2, P2, 'HE' ) $ .OR. LSAMEN( 2, P2, 'HR' ) ) THEN * * xSY: symmetric indefinite matrices * with partial (Bunch-Kaufman) pivoting; * xSR: symmetric indefinite matrices * with rook (bounded Bunch-Kaufman) pivoting; * xHE: Hermitian indefinite matrices * with partial (Bunch-Kaufman) pivoting. * xHR: Hermitian indefinite matrices * with rook (bounded Bunch-Kaufman) pivoting; * UPLO = OPTS( 1: 1 ) IF( LSAMEN( 3, C3, 'TRF' ) ) THEN IF( INFO.NE.INFOE .AND. INFOE.NE.0 ) THEN WRITE( NOUT, FMT = 9980 ) $ SUBNAM(1:LEN_TRIM( SUBNAM )), INFO, INFOE, UPLO, M, $ N5, IMAT ELSE WRITE( NOUT, FMT = 9956 ) $ SUBNAM(1:LEN_TRIM( SUBNAM )), INFO, UPLO, M, N5, IMAT END IF IF( INFO.NE.0 ) $ WRITE( NOUT, FMT = 9949 ) * ELSE IF( LSAMEN( 2, C3, 'SV' ) ) THEN * IF( INFO.NE.INFOE .AND. INFOE.NE.0 ) THEN WRITE( NOUT, FMT = 9979 ) $ SUBNAM(1:LEN_TRIM( SUBNAM )), INFO, INFOE, UPLO, N, $ N5, IMAT ELSE WRITE( NOUT, FMT = 9955 ) $ SUBNAM(1:LEN_TRIM( SUBNAM )), INFO, UPLO, N, N5, IMAT END IF * ELSE IF( LSAMEN( 3, C3, 'SVX' ) ) THEN * IF( INFO.NE.INFOE .AND. INFOE.NE.0 ) THEN WRITE( NOUT, FMT = 9990 ) $ SUBNAM(1:LEN_TRIM( SUBNAM )), INFO, INFOE, $ OPTS( 1: 1 ), OPTS( 2: 2 ), N, N5, IMAT ELSE WRITE( NOUT, FMT = 9995 ) $ SUBNAM(1:LEN_TRIM( SUBNAM )), INFO, OPTS( 1: 1 ), $ OPTS( 2: 2 ), N, N5, IMAT END IF * ELSE IF( LSAMEN( 5, SUBNAM( 2: 6 ), 'LATMS' ) .OR. $ LSAMEN( 3, C3, 'TRI' ) .OR. LSAMEN( 3, C3, 'CON' ) ) $ THEN * WRITE( NOUT, FMT = 9960 ) $ SUBNAM(1:LEN_TRIM( SUBNAM )), INFO, UPLO, M, IMAT * ELSE * WRITE( NOUT, FMT = 9955 ) $ SUBNAM(1:LEN_TRIM( SUBNAM )), INFO, UPLO, M, N5, IMAT END IF * ELSE IF( LSAMEN( 2, P2, 'PP' ) .OR. LSAMEN( 2, P2, 'SP' ) .OR. $ LSAMEN( 2, P2, 'HP' ) ) THEN * * xPP, xHP, or xSP: Symmetric or Hermitian packed matrices * UPLO = OPTS( 1: 1 ) IF( LSAMEN( 3, C3, 'TRF' ) ) THEN IF( INFO.NE.INFOE .AND. INFOE.NE.0 ) THEN WRITE( NOUT, FMT = 9983 ) $ SUBNAM(1:LEN_TRIM( SUBNAM )), INFO, INFOE, UPLO, M, $ IMAT ELSE WRITE( NOUT, FMT = 9960 ) $ SUBNAM(1:LEN_TRIM( SUBNAM )), INFO, UPLO, M, IMAT END IF IF( INFO.NE.0 ) $ WRITE( NOUT, FMT = 9949 ) * ELSE IF( LSAMEN( 3, C3, 'SV ' ) ) THEN * IF( INFO.NE.INFOE .AND. INFOE.NE.0 ) THEN WRITE( NOUT, FMT = 9979 ) $ SUBNAM(1:LEN_TRIM( SUBNAM )), INFO, INFOE, UPLO, N, $ N5, IMAT ELSE WRITE( NOUT, FMT = 9955 ) $ SUBNAM(1:LEN_TRIM( SUBNAM )), INFO, UPLO, N, N5, IMAT END IF * ELSE IF( LSAMEN( 3, C3, 'SVX' ) ) THEN * IF( INFO.NE.INFOE .AND. INFOE.NE.0 ) THEN WRITE( NOUT, FMT = 9990 ) $ SUBNAM(1:LEN_TRIM( SUBNAM )), INFO, INFOE, $ OPTS( 1: 1 ), OPTS( 2: 2 ), N, N5, IMAT ELSE WRITE( NOUT, FMT = 9995 ) $ SUBNAM(1:LEN_TRIM( SUBNAM )), INFO, OPTS( 1: 1 ), $ OPTS( 2: 2 ), N, N5, IMAT END IF * ELSE IF( LSAMEN( 5, SUBNAM( 2: 6 ), 'LATMS' ) .OR. $ LSAMEN( 3, C3, 'TRI' ) .OR. LSAMEN( 3, C3, 'CON' ) ) $ THEN * WRITE( NOUT, FMT = 9960 ) $ SUBNAM(1:LEN_TRIM( SUBNAM )), INFO, UPLO, M, IMAT * ELSE * WRITE( NOUT, FMT = 9955 ) $ SUBNAM(1:LEN_TRIM( SUBNAM )), INFO, UPLO, M, N5, IMAT END IF * ELSE IF( LSAMEN( 2, P2, 'PB' ) ) THEN * * xPB: Symmetric (Hermitian) positive definite band matrix * UPLO = OPTS( 1: 1 ) IF( LSAMEN( 3, C3, 'TRF' ) ) THEN IF( INFO.NE.INFOE .AND. INFOE.NE.0 ) THEN WRITE( NOUT, FMT = 9982 ) $ SUBNAM(1:LEN_TRIM( SUBNAM )), INFO, INFOE, UPLO, M, $ KL, N5, IMAT ELSE WRITE( NOUT, FMT = 9958 ) $ SUBNAM(1:LEN_TRIM( SUBNAM )), INFO, UPLO, M, KL, N5, $ IMAT END IF IF( INFO.NE.0 ) $ WRITE( NOUT, FMT = 9949 ) * ELSE IF( LSAMEN( 3, C3, 'SV ' ) ) THEN * IF( INFO.NE.INFOE .AND. INFOE.NE.0 ) THEN WRITE( NOUT, FMT = 9981 ) $ SUBNAM(1:LEN_TRIM( SUBNAM )), INFO, INFOE, UPLO, N, $ KL, N5, IMAT ELSE WRITE( NOUT, FMT = 9957 ) $ SUBNAM(1:LEN_TRIM( SUBNAM )), INFO, UPLO, N, KL, N5, $ IMAT END IF * ELSE IF( LSAMEN( 3, C3, 'SVX' ) ) THEN * IF( INFO.NE.INFOE .AND. INFOE.NE.0 ) THEN WRITE( NOUT, FMT = 9991 ) $ SUBNAM(1:LEN_TRIM( SUBNAM )), INFO, INFOE, $ OPTS( 1: 1 ), OPTS( 2: 2 ), N, KL, N5, IMAT ELSE WRITE( NOUT, FMT = 9996 ) $ SUBNAM(1:LEN_TRIM( SUBNAM )), INFO, OPTS( 1: 1 ), $ OPTS( 2: 2 ), N, KL, N5, IMAT END IF * ELSE IF( LSAMEN( 5, SUBNAM( 2: 6 ), 'LATMS' ) .OR. $ LSAMEN( 3, C3, 'CON' ) ) THEN * WRITE( NOUT, FMT = 9959 ) $ SUBNAM(1:LEN_TRIM( SUBNAM )), INFO, UPLO, M, KL, IMAT * ELSE * WRITE( NOUT, FMT = 9957 ) $ SUBNAM(1:LEN_TRIM( SUBNAM )), INFO, UPLO, M, KL, N5, $ IMAT END IF * ELSE IF( LSAMEN( 2, P2, 'PT' ) ) THEN * * xPT: Positive definite tridiagonal matrices * IF( LSAMEN( 3, C3, 'TRF' ) ) THEN IF( INFO.NE.INFOE .AND. INFOE.NE.0 ) THEN WRITE( NOUT, FMT = 9987 ) $ SUBNAM(1:LEN_TRIM( SUBNAM )), INFO, INFOE, N, IMAT ELSE WRITE( NOUT, FMT = 9973 ) $ SUBNAM(1:LEN_TRIM( SUBNAM )), INFO, N, IMAT END IF IF( INFO.NE.0 ) $ WRITE( NOUT, FMT = 9949 ) * ELSE IF( LSAMEN( 3, C3, 'SV ' ) ) THEN * IF( INFO.NE.INFOE .AND. INFOE.NE.0 ) THEN WRITE( NOUT, FMT = 9984 ) $ SUBNAM(1:LEN_TRIM( SUBNAM )), INFO, INFOE, N, N5, $ IMAT ELSE WRITE( NOUT, FMT = 9970 ) $ SUBNAM(1:LEN_TRIM( SUBNAM )), INFO, N, N5, IMAT END IF * ELSE IF( LSAMEN( 3, C3, 'SVX' ) ) THEN * IF( INFO.NE.INFOE .AND. INFOE.NE.0 ) THEN WRITE( NOUT, FMT = 9994 ) $ SUBNAM(1:LEN_TRIM( SUBNAM )), INFO, INFOE, $ OPTS( 1: 1 ), N, N5, IMAT ELSE WRITE( NOUT, FMT = 9999 ) $ SUBNAM(1:LEN_TRIM( SUBNAM )), INFO, OPTS( 1: 1 ), N, $ N5, IMAT END IF * ELSE IF( LSAMEN( 3, C3, 'CON' ) ) THEN * IF( LSAME( SUBNAM( 1: 1 ), 'S' ) .OR. $ LSAME( SUBNAM( 1: 1 ), 'D' ) ) THEN WRITE( NOUT, FMT = 9973 ) $ SUBNAM(1:LEN_TRIM( SUBNAM )), INFO, M, IMAT ELSE WRITE( NOUT, FMT = 9969 ) $ SUBNAM(1:LEN_TRIM( SUBNAM )), INFO, OPTS( 1: 1 ), M, $ IMAT END IF * ELSE * WRITE( NOUT, FMT = 9963 ) $ SUBNAM(1:LEN_TRIM( SUBNAM )), INFO, OPTS( 1: 1 ), M, N5, $ IMAT END IF * ELSE IF( LSAMEN( 2, P2, 'TR' ) ) THEN * * xTR: Triangular matrix * IF( LSAMEN( 3, C3, 'TRI' ) ) THEN WRITE( NOUT, FMT = 9961 ) $ SUBNAM(1:LEN_TRIM( SUBNAM )), INFO, OPTS( 1: 1 ), $ OPTS( 2: 2 ), M, N5, IMAT ELSE IF( LSAMEN( 3, C3, 'CON' ) ) THEN WRITE( NOUT, FMT = 9967 ) $ SUBNAM(1:LEN_TRIM( SUBNAM )), INFO, OPTS( 1: 1 ), $ OPTS( 2: 2 ), OPTS( 3: 3 ), M, IMAT ELSE IF( LSAMEN( 5, SUBNAM( 2: 6 ), 'LATRS' ) ) THEN WRITE( NOUT, FMT = 9952 ) $ SUBNAM(1:LEN_TRIM( SUBNAM )), INFO, OPTS( 1: 1 ), $ OPTS( 2: 2 ), OPTS( 3: 3 ), OPTS( 4: 4 ), M, IMAT ELSE WRITE( NOUT, FMT = 9953 ) $ SUBNAM(1:LEN_TRIM( SUBNAM )), INFO, OPTS( 1: 1 ), $ OPTS( 2: 2 ), OPTS( 3: 3 ), M, N5, IMAT END IF * ELSE IF( LSAMEN( 2, P2, 'TP' ) ) THEN * * xTP: Triangular packed matrix * IF( LSAMEN( 3, C3, 'TRI' ) ) THEN WRITE( NOUT, FMT = 9962 ) $ SUBNAM(1:LEN_TRIM( SUBNAM )), INFO, OPTS( 1: 1 ), $ OPTS( 2: 2 ), M, IMAT ELSE IF( LSAMEN( 3, C3, 'CON' ) ) THEN WRITE( NOUT, FMT = 9967 ) $ SUBNAM(1:LEN_TRIM( SUBNAM )), INFO, OPTS( 1: 1 ), $ OPTS( 2: 2 ), OPTS( 3: 3 ), M, IMAT ELSE IF( LSAMEN( 5, SUBNAM( 2: 6 ), 'LATPS' ) ) THEN WRITE( NOUT, FMT = 9952 ) $ SUBNAM(1:LEN_TRIM( SUBNAM )), INFO, OPTS( 1: 1 ), $ OPTS( 2: 2 ), OPTS( 3: 3 ), OPTS( 4: 4 ), M, IMAT ELSE WRITE( NOUT, FMT = 9953 ) $ SUBNAM(1:LEN_TRIM( SUBNAM )), INFO, OPTS( 1: 1 ), $ OPTS( 2: 2 ), OPTS( 3: 3 ), M, N5, IMAT END IF * ELSE IF( LSAMEN( 2, P2, 'TB' ) ) THEN * * xTB: Triangular band matrix * IF( LSAMEN( 3, C3, 'CON' ) ) THEN WRITE( NOUT, FMT = 9966 ) $ SUBNAM(1:LEN_TRIM( SUBNAM )), INFO, OPTS( 1: 1 ), $ OPTS( 2: 2 ), OPTS( 3: 3 ), M, KL, IMAT ELSE IF( LSAMEN( 5, SUBNAM( 2: 6 ), 'LATBS' ) ) THEN WRITE( NOUT, FMT = 9951 ) $ SUBNAM(1:LEN_TRIM( SUBNAM )), INFO, OPTS( 1: 1 ), $ OPTS( 2: 2 ), OPTS( 3: 3 ), OPTS( 4: 4 ), M, KL, IMAT ELSE WRITE( NOUT, FMT = 9954 ) $ SUBNAM(1:LEN_TRIM( SUBNAM )), INFO, OPTS( 1: 1 ), $ OPTS( 2: 2 ), OPTS( 3: 3 ), M, KL, N5, IMAT END IF * ELSE IF( LSAMEN( 2, P2, 'QR' ) ) THEN * * xQR: QR factorization * IF( LSAMEN( 3, C3, 'QRS' ) ) THEN WRITE( NOUT, FMT = 9974 ) $ SUBNAM(1:LEN_TRIM( SUBNAM )), INFO, M, N, KL, N5, IMAT ELSE IF( LSAMEN( 5, SUBNAM( 2: 6 ), 'LATMS' ) ) THEN WRITE( NOUT, FMT = 9978 ) $ SUBNAM(1:LEN_TRIM( SUBNAM )), INFO, M, N, IMAT END IF * ELSE IF( LSAMEN( 2, P2, 'LQ' ) ) THEN * * xLQ: LQ factorization * IF( LSAMEN( 3, C3, 'LQS' ) ) THEN WRITE( NOUT, FMT = 9974 ) $ SUBNAM(1:LEN_TRIM( SUBNAM )), INFO, M, N, KL, N5, IMAT ELSE IF( LSAMEN( 5, SUBNAM( 2: 6 ), 'LATMS' ) ) THEN WRITE( NOUT, FMT = 9978 ) $ SUBNAM(1:LEN_TRIM( SUBNAM )), INFO, M, N, IMAT END IF * ELSE IF( LSAMEN( 2, P2, 'QL' ) ) THEN * * xQL: QL factorization * IF( LSAMEN( 3, C3, 'QLS' ) ) THEN WRITE( NOUT, FMT = 9974 ) $ SUBNAM(1:LEN_TRIM( SUBNAM )), INFO, M, N, KL, N5, IMAT ELSE IF( LSAMEN( 5, SUBNAM( 2: 6 ), 'LATMS' ) ) THEN WRITE( NOUT, FMT = 9978 ) $ SUBNAM(1:LEN_TRIM( SUBNAM )), INFO, M, N, IMAT END IF * ELSE IF( LSAMEN( 2, P2, 'RQ' ) ) THEN * * xRQ: RQ factorization * IF( LSAMEN( 3, C3, 'RQS' ) ) THEN WRITE( NOUT, FMT = 9974 ) $ SUBNAM(1:LEN_TRIM( SUBNAM )), INFO, M, N, KL, N5, IMAT ELSE IF( LSAMEN( 5, SUBNAM( 2: 6 ), 'LATMS' ) ) THEN WRITE( NOUT, FMT = 9978 ) $ SUBNAM(1:LEN_TRIM( SUBNAM )), INFO, M, N, IMAT END IF * ELSE IF( LSAMEN( 2, P2, 'LU' ) ) THEN * IF( INFO.NE.INFOE .AND. INFOE.NE.0 ) THEN WRITE( NOUT, FMT = 9988 ) $ SUBNAM(1:LEN_TRIM( SUBNAM )), INFO, INFOE, M, N, N5, $ IMAT ELSE WRITE( NOUT, FMT = 9975 ) $ SUBNAM(1:LEN_TRIM( SUBNAM )), INFO, M, N, N5, IMAT END IF * ELSE IF( LSAMEN( 2, P2, 'CH' ) ) THEN * IF( INFO.NE.INFOE .AND. INFOE.NE.0 ) THEN WRITE( NOUT, FMT = 9985 ) $ SUBNAM(1:LEN_TRIM( SUBNAM )), INFO, INFOE, M, N5, IMAT ELSE WRITE( NOUT, FMT = 9971 ) $ SUBNAM(1:LEN_TRIM( SUBNAM )), INFO, M, N5, IMAT END IF * ELSE * * Print a generic message if the path is unknown. * WRITE( NOUT, FMT = 9950 ) $ SUBNAM(1:LEN_TRIM( SUBNAM )), INFO END IF * * Description of error message (alphabetical, left to right) * * SUBNAM, INFO, FACT, N, NRHS, IMAT * 9999 FORMAT( ' *** Error code from ', A, '=', I5, ', FACT=''', A1, $ ''', N=', I5, ', NRHS=', I4, ', type ', I2 ) * * SUBNAM, INFO, FACT, TRANS, N, KL, KU, NRHS, IMAT * 9998 FORMAT( ' *** Error code from ', A, ' =', I5, / ' ==> FACT=''', $ A1, ''', TRANS=''', A1, ''', N=', I5, ', KL=', I5, ', KU=', $ I5, ', NRHS=', I4, ', type ', I1 ) * * SUBNAM, INFO, FACT, TRANS, N, NRHS, IMAT * 9997 FORMAT( ' *** Error code from ', A, ' =', I5, / ' ==> FACT=''', $ A1, ''', TRANS=''', A1, ''', N =', I5, ', NRHS =', I4, $ ', type ', I2 ) * * SUBNAM, INFO, FACT, UPLO, N, KD, NRHS, IMAT * 9996 FORMAT( ' *** Error code from ', A, ' =', I5, / ' ==> FACT=''', $ A1, ''', UPLO=''', A1, ''', N=', I5, ', KD=', I5, ', NRHS=', $ I4, ', type ', I2 ) * * SUBNAM, INFO, FACT, UPLO, N, NRHS, IMAT * 9995 FORMAT( ' *** Error code from ', A, ' =', I5, / ' ==> FACT=''', $ A1, ''', UPLO=''', A1, ''', N =', I5, ', NRHS =', I4, $ ', type ', I2 ) * * SUBNAM, INFO, INFOE, FACT, N, NRHS, IMAT * 9994 FORMAT( ' *** ', A, ' returned with INFO =', I5, ' instead of ', $ I2, / ' ==> FACT=''', A1, ''', N =', I5, ', NRHS =', I4, $ ', type ', I2 ) * * SUBNAM, INFO, INFOE, FACT, TRANS, N, KL, KU, NRHS, IMAT * 9993 FORMAT( ' *** ', A, ' returned with INFO =', I5, ' instead of ', $ I2, / ' ==> FACT=''', A1, ''', TRANS=''', A1, ''', N=', I5, $ ', KL=', I5, ', KU=', I5, ', NRHS=', I4, ', type ', I1 ) * * SUBNAM, INFO, INFOE, FACT, TRANS, N, NRHS, IMAT * 9992 FORMAT( ' *** ', A, ' returned with INFO =', I5, ' instead of ', $ I2, / ' ==> FACT=''', A1, ''', TRANS=''', A1, ''', N =', I5, $ ', NRHS =', I4, ', type ', I2 ) * * SUBNAM, INFO, INFOE, FACT, UPLO, N, KD, NRHS, IMAT * 9991 FORMAT( ' *** ', A, ' returned with INFO =', I5, ' instead of ', $ I2, / ' ==> FACT=''', A1, ''', UPLO=''', A1, ''', N=', I5, $ ', KD=', I5, ', NRHS=', I4, ', type ', I2 ) * * SUBNAM, INFO, INFOE, FACT, UPLO, N, NRHS, IMAT * 9990 FORMAT( ' *** ', A, ' returned with INFO =', I5, ' instead of ', $ I2, / ' ==> FACT=''', A1, ''', UPLO=''', A1, ''', N =', I5, $ ', NRHS =', I4, ', type ', I2 ) * * SUBNAM, INFO, INFOE, M, N, KL, KU, NB, IMAT * 9989 FORMAT( ' *** ', A, ' returned with INFO =', I5, ' instead of ', $ I2, / ' ==> M = ', I5, ', N =', I5, ', KL =', I5, ', KU =', $ I5, ', NB =', I4, ', type ', I2 ) * * SUBNAM, INFO, INFOE, M, N, NB, IMAT * 9988 FORMAT( ' *** ', A, ' returned with INFO =', I5, ' instead of ', $ I2, / ' ==> M =', I5, ', N =', I5, ', NB =', I4, ', type ', $ I2 ) * * SUBNAM, INFO, INFOE, N, IMAT * 9987 FORMAT( ' *** ', A, ' returned with INFO =', I5, ' instead of ', $ I2, ' for N=', I5, ', type ', I2 ) * * SUBNAM, INFO, INFOE, N, KL, KU, NRHS, IMAT * 9986 FORMAT( ' *** ', A, ' returned with INFO =', I5, ' instead of ', $ I2, / ' ==> N =', I5, ', KL =', I5, ', KU =', I5, $ ', NRHS =', I4, ', type ', I2 ) * * SUBNAM, INFO, INFOE, N, NB, IMAT * 9985 FORMAT( ' *** ', A, ' returned with INFO =', I5, ' instead of ', $ I2, / ' ==> N =', I5, ', NB =', I4, ', type ', I2 ) * * SUBNAM, INFO, INFOE, N, NRHS, IMAT * 9984 FORMAT( ' *** ', A, ' returned with INFO =', I5, ' instead of ', $ I2, / ' ==> N =', I5, ', NRHS =', I4, ', type ', I2 ) * * SUBNAM, INFO, INFOE, UPLO, N, IMAT * 9983 FORMAT( ' *** ', A, ' returned with INFO =', I5, ' instead of ', $ I2, / ' ==> UPLO = ''', A1, ''', N =', I5, ', type ', I2 ) * * SUBNAM, INFO, INFOE, UPLO, N, KD, NB, IMAT * 9982 FORMAT( ' *** ', A, ' returned with INFO =', I5, ' instead of ', $ I2, / ' ==> UPLO = ''', A1, ''', N =', I5, ', KD =', I5, $ ', NB =', I4, ', type ', I2 ) * * SUBNAM, INFO, INFOE, UPLO, N, KD, NRHS, IMAT * 9981 FORMAT( ' *** ', A, ' returned with INFO =', I5, ' instead of ', $ I2, / ' ==> UPLO=''', A1, ''', N =', I5, ', KD =', I5, $ ', NRHS =', I4, ', type ', I2 ) * * SUBNAM, INFO, INFOE, UPLO, N, NB, IMAT * 9980 FORMAT( ' *** ', A, ' returned with INFO =', I5, ' instead of ', $ I2, / ' ==> UPLO = ''', A1, ''', N =', I5, ', NB =', I4, $ ', type ', I2 ) * * SUBNAM, INFO, INFOE, UPLO, N, NRHS, IMAT * 9979 FORMAT( ' *** ', A, ' returned with INFO =', I5, ' instead of ', $ I2, / ' ==> UPLO = ''', A1, ''', N =', I5, ', NRHS =', I4, $ ', type ', I2 ) * * SUBNAM, INFO, M, N, IMAT * 9978 FORMAT( ' *** Error code from ', A, ' =', I5, ' for M =', I5, $ ', N =', I5, ', type ', I2 ) * * SUBNAM, INFO, M, N, KL, KU, IMAT * 9977 FORMAT( ' *** Error code from ', A, ' =', I5, / ' ==> M = ', I5, $ ', N =', I5, ', KL =', I5, ', KU =', I5, ', type ', I2 ) * * SUBNAM, INFO, M, N, KL, KU, NB, IMAT * 9976 FORMAT( ' *** Error code from ', A, ' =', I5, / ' ==> M = ', I5, $ ', N =', I5, ', KL =', I5, ', KU =', I5, ', NB =', I4, $ ', type ', I2 ) * * SUBNAM, INFO, M, N, NB, IMAT * 9975 FORMAT( ' *** Error code from ', A, '=', I5, ' for M=', I5, $ ', N=', I5, ', NB=', I4, ', type ', I2 ) * * SUBNAM, INFO, M, N, NRHS, NB, IMAT * 9974 FORMAT( ' *** Error code from ', A, '=', I5, / ' ==> M =', I5, $ ', N =', I5, ', NRHS =', I4, ', NB =', I4, ', type ', I2 ) * * SUBNAM, INFO, N, IMAT * 9973 FORMAT( ' *** Error code from ', A, ' =', I5, ' for N =', I5, $ ', type ', I2 ) * * SUBNAM, INFO, N, KL, KU, NRHS, IMAT * 9972 FORMAT( ' *** Error code from ', A, ' =', I5, / ' ==> N =', I5, $ ', KL =', I5, ', KU =', I5, ', NRHS =', I4, ', type ', I2 ) * * SUBNAM, INFO, N, NB, IMAT * 9971 FORMAT( ' *** Error code from ', A, '=', I5, ' for N=', I5, $ ', NB=', I4, ', type ', I2 ) * * SUBNAM, INFO, N, NRHS, IMAT * 9970 FORMAT( ' *** Error code from ', A, ' =', I5, ' for N =', I5, $ ', NRHS =', I4, ', type ', I2 ) * * SUBNAM, INFO, NORM, N, IMAT * 9969 FORMAT( ' *** Error code from ', A, ' =', I5, ' for NORM = ''', $ A1, ''', N =', I5, ', type ', I2 ) * * SUBNAM, INFO, NORM, N, KL, KU, IMAT * 9968 FORMAT( ' *** Error code from ', A, ' =', I5, / ' ==> NORM =''', $ A1, ''', N =', I5, ', KL =', I5, ', KU =', I5, ', type ', $ I2 ) * * SUBNAM, INFO, NORM, UPLO, DIAG, N, IMAT * 9967 FORMAT( ' *** Error code from ', A, ' =', I5, / ' ==> NORM=''', $ A1, ''', UPLO =''', A1, ''', DIAG=''', A1, ''', N =', I5, $ ', type ', I2 ) * * SUBNAM, INFO, NORM, UPLO, DIAG, N, KD, IMAT * 9966 FORMAT( ' *** Error code from ', A, ' =', I5, / ' ==> NORM=''', $ A1, ''', UPLO =''', A1, ''', DIAG=''', A1, ''', N=', I5, $ ', KD=', I5, ', type ', I2 ) * * SUBNAM, INFO, TRANS, M, N, NRHS, NB, IMAT * 9965 FORMAT( ' *** Error code from ', A, ' =', I5, $ / ' ==> TRANS = ''', A1, ''', M =', I5, ', N =', I5, $ ', NRHS =', I4, ', NB =', I4, ', type ', I2 ) * * SUBNAM, INFO, TRANS, N, KL, KU, NRHS, IMAT * 9964 FORMAT( ' *** Error code from ', A, '=', I5, / ' ==> TRANS=''', $ A1, ''', N =', I5, ', KL =', I5, ', KU =', I5, ', NRHS =', $ I4, ', type ', I2 ) * * SUBNAM, INFO, TRANS, N, NRHS, IMAT * 9963 FORMAT( ' *** Error code from ', A, ' =', I5, $ / ' ==> TRANS = ''', A1, ''', N =', I5, ', NRHS =', I4, $ ', type ', I2 ) * * SUBNAM, INFO, UPLO, DIAG, N, IMAT * 9962 FORMAT( ' *** Error code from ', A, ' =', I5, / ' ==> UPLO=''', $ A1, ''', DIAG =''', A1, ''', N =', I5, ', type ', I2 ) * * SUBNAM, INFO, UPLO, DIAG, N, NB, IMAT * 9961 FORMAT( ' *** Error code from ', A, ' =', I5, / ' ==> UPLO=''', $ A1, ''', DIAG =''', A1, ''', N =', I5, ', NB =', I4, $ ', type ', I2 ) * * SUBNAM, INFO, UPLO, N, IMAT * 9960 FORMAT( ' *** Error code from ', A, ' =', I5, ' for UPLO = ''', $ A1, ''', N =', I5, ', type ', I2 ) * * SUBNAM, INFO, UPLO, N, KD, IMAT * 9959 FORMAT( ' *** Error code from ', A, ' =', I5, / ' ==> UPLO = ''', $ A1, ''', N =', I5, ', KD =', I5, ', type ', I2 ) * * SUBNAM, INFO, UPLO, N, KD, NB, IMAT * 9958 FORMAT( ' *** Error code from ', A, ' =', I5, / ' ==> UPLO = ''', $ A1, ''', N =', I5, ', KD =', I5, ', NB =', I4, ', type ', $ I2 ) * * SUBNAM, INFO, UPLO, N, KD, NRHS, IMAT * 9957 FORMAT( ' *** Error code from ', A, '=', I5, / ' ==> UPLO = ''', $ A1, ''', N =', I5, ', KD =', I5, ', NRHS =', I4, ', type ', $ I2 ) * * SUBNAM, INFO, UPLO, N, NB, IMAT * 9956 FORMAT( ' *** Error code from ', A, ' =', I5, / ' ==> UPLO = ''', $ A1, ''', N =', I5, ', NB =', I4, ', type ', I2 ) * * SUBNAM, INFO, UPLO, N, NRHS, IMAT * 9955 FORMAT( ' *** Error code from ', A, ' =', I5, / ' ==> UPLO = ''', $ A1, ''', N =', I5, ', NRHS =', I4, ', type ', I2 ) * * SUBNAM, INFO, UPLO, TRANS, DIAG, N, KD, NRHS, IMAT * 9954 FORMAT( ' *** Error code from ', A, ' =', I5, / ' ==> UPLO=''', $ A1, ''', TRANS=''', A1, ''', DIAG=''', A1, ''', N=', I5, $ ', KD=', I5, ', NRHS=', I4, ', type ', I2 ) * * SUBNAM, INFO, UPLO, TRANS, DIAG, N, NRHS, IMAT * 9953 FORMAT( ' *** Error code from ', A, ' =', I5, / ' ==> UPLO=''', $ A1, ''', TRANS=''', A1, ''', DIAG=''', A1, ''', N =', I5, $ ', NRHS =', I4, ', type ', I2 ) * * SUBNAM, INFO, UPLO, TRANS, DIAG, NORMIN, N, IMAT * 9952 FORMAT( ' *** Error code from ', A, ' =', I5, / ' ==> UPLO=''', $ A1, ''', TRANS=''', A1, ''', DIAG=''', A1, ''', NORMIN=''', $ A1, ''', N =', I5, ', type ', I2 ) * * SUBNAM, INFO, UPLO, TRANS, DIAG, NORMIN, N, KD, IMAT * 9951 FORMAT( ' *** Error code from ', A, ' =', I5, / ' ==> UPLO=''', $ A1, ''', TRANS=''', A1, ''', DIAG=''', A1, ''', NORMIN=''', $ A1, ''', N=', I5, ', KD=', I5, ', type ', I2 ) * * Unknown type * 9950 FORMAT( ' *** Error code from ', A, ' =', I5 ) * * What we do next * 9949 FORMAT( ' ==> Doing only the condition estimate for this case' ) * RETURN * * End of ALAERH * END
gpl-2.0
QEF/q-e
PP/src/bands.f90
2
21019
! ! Copyright (C) 2001-2016 Quantum ESPRESSO group ! This file is distributed under the terms of the ! GNU General Public License. See the file `License' ! in the root directory of the present distribution, ! or http://www.gnu.org/copyleft/gpl.txt . ! ! !----------------------------------------------------------------------- PROGRAM do_bands !----------------------------------------------------------------------- ! ! See files INPUT_BANDS.* in Doc/ directory for usage ! ! USE io_files, ONLY : prefix, tmp_dir USE mp_global, ONLY : mp_startup USE mp_pools, ONLY : npool USE control_flags, ONLY : gamma_only USE environment, ONLY : environment_start, environment_end USE wvfct, ONLY : nbnd USE klist, ONLY : nkstot, two_fermi_energies USE noncollin_module, ONLY : noncolin, i_cons USE lsda_mod, ONLY : nspin USE io_global, ONLY : ionode, ionode_id, stdout USE mp, ONLY : mp_bcast USE mp_images, ONLY : intra_image_comm USE parameters,ONLY : npk ! IMPLICIT NONE ! CHARACTER(LEN=256), EXTERNAL :: trimcheck ! CHARACTER (len=256) :: filband, filp, outdir LOGICAL :: lsigma(4), lsym, lp, no_overlap, plot_2d INTEGER :: spin_component, firstk, lastk INTEGER :: ios ! NAMELIST / bands / outdir, prefix, filband, filp, spin_component, lsigma,& lsym, lp, filp, firstk, lastk, no_overlap, plot_2d ! ! initialise environment ! #if defined(__MPI) CALL mp_startup ( ) #endif CALL environment_start ( 'BANDS' ) ! ! set default values for variables in namelist ! prefix = 'pwscf' CALL get_environment_variable( 'ESPRESSO_TMPDIR', outdir ) IF ( trim( outdir ) == ' ' ) outdir = './' filband = 'bands.out' lsym=.true. no_overlap=.true. plot_2d=.false. lsigma=.false. lp=.false. filp='p_avg.dat' firstk=0 lastk=npk spin_component = 1 ! ios = 0 ! IF ( ionode ) THEN ! CALL input_from_file ( ) ! READ (5, bands, iostat = ios) ! lsigma(4)=.false. tmp_dir = trimcheck (outdir) ! ENDIF ! ! CALL mp_bcast( ios, ionode_id, intra_image_comm ) IF (ios /= 0) CALL errore ('bands', 'reading bands namelist', abs(ios) ) ! ! ... Broadcast variables ! CALL mp_bcast( tmp_dir, ionode_id, intra_image_comm ) CALL mp_bcast( prefix, ionode_id, intra_image_comm ) CALL mp_bcast( filband, ionode_id, intra_image_comm ) CALL mp_bcast( filp, ionode_id, intra_image_comm ) CALL mp_bcast( spin_component, ionode_id, intra_image_comm ) CALL mp_bcast( firstk, ionode_id, intra_image_comm ) CALL mp_bcast( lastk, ionode_id, intra_image_comm ) CALL mp_bcast( lp, ionode_id, intra_image_comm ) CALL mp_bcast( lsym, ionode_id, intra_image_comm ) CALL mp_bcast( lsigma, ionode_id, intra_image_comm ) CALL mp_bcast( no_overlap, ionode_id, intra_image_comm ) CALL mp_bcast( plot_2d, ionode_id, intra_image_comm ) IF (plot_2d) THEN lsym=.false. lp=.false. no_overlap=.true. ENDIF IF (lsym) no_overlap=.true. IF ( npool > 1 .and..not.(lsym.or.no_overlap)) CALL errore('bands', & 'pools not implemented',npool) IF ( spin_component < 1 .OR. spin_component > 2 ) & CALL errore('bands','incorrect spin_component',1) ! ! Now allocate space for pwscf variables, read and check them. ! CALL read_file() ! IF (gamma_only) CALL errore('bands','gamma_only case not implemented',1) IF (two_fermi_energies.or.i_cons /= 0) & CALL errore('bands',& 'The bands code with constrained magnetization has not been tested',1) IF ( ANY(lsigma) .AND. .NOT.noncolin ) & CALL errore ('punch_band', 'lsigma requires noncollinear run', 1 ) IF ( spin_component/=1 .and. nspin/=2 ) & CALL errore('punch_bands','incorrect spin_component',1) ! CALL openfil_pp() ! IF (plot_2d) THEN CALL punch_band_2d(filband,spin_component) ELSE CALL punch_band(filband,spin_component,lsigma,no_overlap) IF (lsym) CALL sym_band(filband,spin_component,firstk,lastk) IF (lp) CALL write_p_avg(filp,spin_component,firstk,lastk) END IF ! CALL environment_end ( 'BANDS' ) ! CALL stop_pp STOP END PROGRAM do_bands ! !----------------------------------------------------------------------- SUBROUTINE punch_band (filband, spin_component, lsigma, no_overlap) !----------------------------------------------------------------------- ! ! This routine writes the band energies on a file. The routine orders ! the eigenvalues using the overlap of the eigenvectors to give ! an estimate crossing and anticrossing of the bands. This simplified ! method works in many, but not in all the cases. ! ! USE kinds, ONLY : dp USE ions_base, ONLY : nat, ityp, ntyp => nsp USE cell_base, ONLY : at USE constants, ONLY : rytoev USE gvect, ONLY : g, ngm USE klist, ONLY : xk, nks, nkstot, ngk, igk_k USE io_files, ONLY : iunpun, nwordwfc, iunwfc USE wvfct, ONLY : nbnd, et, npwx USE uspp, ONLY : nkb, vkb USE uspp_param, ONLY : upf, nh, nhm USE noncollin_module, ONLY : noncolin, npol USE wavefunctions, ONLY : evc USE io_global, ONLY : ionode, ionode_id, stdout USE mp, ONLY : mp_bcast USE mp_images, ONLY : intra_image_comm USE becmod, ONLY : calbec, bec_type, allocate_bec_type, & deallocate_bec_type, becp USE uspp_init, ONLY : init_us_2 IMPLICIT NONE CHARACTER (len=*) :: filband INTEGER, INTENT(IN) :: spin_component LOGICAL, INTENT(IN) :: lsigma(4), no_overlap ! becp : <psi|beta> at current k-point INTEGER :: ibnd, jbnd, iter, i, ik, ig, ig1, ig2, ipol, npw, ngmax, jmax INTEGER :: nks1tot, nks2tot, nks1, nks2 INTEGER :: iunpun_sigma(4), ios(0:4), maxpos(2) CHARACTER(len=256) :: nomefile REAL(dp):: pscur, psmax, psr(nbnd,nbnd) LOGICAL :: mask(nbnd,nbnd) COMPLEX(dp), ALLOCATABLE :: psi(:,:), spsi(:,:), ps(:,:) INTEGER, ALLOCATABLE :: work(:), igg(:) INTEGER, ALLOCATABLE :: closest_band(:,:)! index for band ordering REAL(DP), ALLOCATABLE:: sigma_avg(:,:,:) ! expectation value of sigma REAL(DP), ALLOCATABLE:: et_(:,:) ! reordered eigenvalues in eV IF (filband == ' ') RETURN iunpun = 19 ios(:) = 0 ! IF ( ionode ) THEN ! OPEN (unit = iunpun, file = filband, status = 'unknown', form = & 'formatted', iostat = ios(0)) REWIND (iunpun) DO ipol=1,4 IF (lsigma(ipol)) THEN iunpun_sigma(ipol)=iunpun+ipol WRITE(nomefile,'(".",i1)') ipol OPEN (unit = iunpun_sigma(ipol), & file = trim(filband)//trim(nomefile), & status = 'unknown', form='formatted', iostat = ios(ipol)) REWIND (iunpun_sigma(ipol)) ENDIF ENDDO ! ENDIF ! CALL mp_bcast( ios, ionode_id, intra_image_comm ) IF ( ios(0) /= 0 ) & CALL errore ('punch_band', 'Opening filband file', abs(ios(0)) ) DO ipol=1,4 IF ( ios(ipol) /= 0 ) & CALL errore ('punch_band', 'Opening filband.N file ', ipol) ENDDO ! CALL find_nks1nks2(1,nkstot,nks1tot,nks1,nks2tot,nks2,spin_component) ! ! index of largest G in plane-wave basis set across k-points ! ALLOCATE ( closest_band(nbnd,nkstot) ) DO ik=1,nkstot ! ! default ordering: leave bands as they are ! DO ibnd=1,nbnd closest_band(ibnd,ik) = ibnd END DO END DO ! IF ( noncolin ) ALLOCATE ( sigma_avg(4,nbnd,nkstot) ) ALLOCATE ( psi(npwx*npol,nbnd), spsi(npwx*npol,nbnd), ps(nbnd,nbnd) ) CALL allocate_bec_type(nkb, nbnd, becp) ! DO ik = nks1, nks2 ! ! read eigenfunctions ! CALL davcio (evc, 2*nwordwfc, iunwfc, ik, - 1) ! ! calculate becp = <psi|beta>, needed to compute spsi = S|psi> ! npw = ngk(ik) CALL init_us_2 (npw, igk_k(1,ik), xk(1,ik), vkb) CALL calbec ( npw, vkb, evc, becp ) ! ! calculate average magnetization for noncolinear case ! IF (noncolin) & CALL compute_sigma_avg(sigma_avg(1,1,ik),becp%nc,ik,lsigma) ! IF ( ik > nks1 .AND. .NOT. no_overlap ) THEN ! ! compute correspondence between k+G_i indices at current and previous k ! ngmax = MAXVAL ( igk_k(:,ik-1:ik) ) ALLOCATE ( work(ngmax), igg(ngmax) ) work(:) = 0 DO ig1 = 1, ngk(ik-1) work( igk_k(ig1,ik-1)) = ig1 END DO igg(:) = 0 DO ig2 = 1, npw ig1 = work( igk_k(ig2,ik)) IF (ig1 > 0) igg(ig2) = ig1 END DO ! ! compute overlap <\psi_k|S\psi_{k-1}> (without the Bloch factor) ! psi(G) = \psi(k+G) (order of G-vectors same as for previous k) ! psi(:,:) = (0.0_dp,0.0_dp) DO ig2 = 1, npw IF ( igg(ig2) > 0 ) psi(igg(ig2),:) = evc(ig2,:) END DO IF ( noncolin) THEN DO ig2 = 1, npw IF ( igg(ig2) > 0 ) psi(npwx+igg(ig2),:) = evc(npwx+ig2,:) END DO END IF DEALLOCATE (igg, work) CALL calbec (ngk(ik-1), spsi, psi, ps ) ! ! ps(ibnd,jbnd) = <S\psi_{k-1,ibnd} | \psi_{k,jbnd}> ! ! assign bands on the basis of the relative overlap square modulus ! closest_band(:,ik) = -1 psr(:,:) = DBLE(ps*DCONJG(ps)) ! square modulus of overlap ! Set-up a mask that is .true. only for bands that are less than 0.5 eV apart DO ibnd = 1,nbnd DO jbnd = 1,nbnd mask(ibnd,jbnd) = ABS(et(jbnd,ik)-et(ibnd,ik-1))<0.5/rytoev ENDDO ENDDO ! DO iter=1,nbnd maxpos = MAXLOC(psr, MASK=mask) ! find the maximum of all overlaps ibnd = maxpos(1) jbnd = maxpos(2) !WRITE(*, '(3i3,f12.6)') iter, ibnd, jbnd, psr(ibnd,jbnd) IF(ibnd==0 .or. jbnd==0) CALL errore("overlap", "mask has killed me", 2) closest_band(jbnd,ik) = ibnd ! wfvc closer to jbnd at ik was iband at ik-1 IF(ABS(et(jbnd,ik)-et(ibnd,ik-1))>0.1/rytoev) THEN WRITE(*,'(7x, "Overlap warning: bands", i3, " and", i3, '& //'" are very far away! (ik, e1, e2)", i4, 2f12.6)') & jbnd, ibnd, ik, et(jbnd,ik)*rytoev,et(ibnd,ik-1)*rytoev ENDIF ! Set the entire line and entire row of overlap matrix to -1: ! The line, because I have found where bands jbnd,(ik-1) has gone ! The row, because I have found where band ibnd,ik comes from psr(:,jbnd) = -1._dp psr(ibnd,:) = -1._dp END DO ! IF(ANY(psr/=-1._dp)) CALL errore("overlap", "Something went wrong", 1) ENDIF ! IF ( ik < nks2 .AND. .NOT. no_overlap ) THEN ! ! compute S\psi_k to be used at next k-point ! CALL s_psi( npwx, npw, nbnd, evc, spsi ) ! END IF ! ENDDO ! IF (noncolin) CALL poolrecover(sigma_avg,4*nbnd,nkstot,nks) ! CALL deallocate_bec_type(becp) DEALLOCATE ( psi, spsi, ps ) ! IF ( ionode ) THEN ! ! Re-order eigenvalues according to overlap ! (ibnd=band index, jbnd=re-ordered index) ! ALLOCATE (et_(nbnd,nkstot)) DO ibnd=1,nbnd jbnd = ibnd DO ik=nks1tot,nks2tot et_(ibnd,ik) = et(jbnd,ik)* rytoev jbnd = closest_band(jbnd,ik) END DO END DO ! CALL punch_plottable_bands ( filband, nks1tot, nks2tot, nkstot, nbnd, & xk, et_ ) ! WRITE (iunpun, '(" &plot nbnd=",i4,", nks=",i6," /")') & nbnd, nks2tot-nks1tot+1 DO ipol=1,4 IF (lsigma(ipol)) WRITE(iunpun_sigma(ipol), & '(" &plot nbnd=",i4,", nks=",i6," /")') & nbnd, nks2tot-nks1tot+1 ENDDO DO ik=nks1tot,nks2tot WRITE (iunpun, '(10x,3f10.6)') xk(1,ik),xk(2,ik),xk(3,ik) WRITE (iunpun, '(10f9.3)') (et_(ibnd, ik), ibnd = 1, nbnd) DO ipol=1,4 IF (lsigma(ipol)) THEN WRITE (iunpun_sigma(ipol), '(10x,3f10.6)') & xk(1,ik),xk(2,ik),xk(3,ik) WRITE (iunpun_sigma(ipol), '(10f9.3)') & (sigma_avg(ipol, ibnd, ik), ibnd = 1, nbnd) ENDIF ENDDO ENDDO ! DEALLOCATE ( et_ ) ! ENDIF ! IF (noncolin) DEALLOCATE (sigma_avg) ! IF ( ionode ) THEN CLOSE (iunpun) WRITE ( stdout, & '(5x,"Bands written to file ",A)') TRIM(filband) DO ipol=1,4 IF (lsigma(ipol)) CLOSE(iunpun_sigma(ipol)) ENDDO ENDIF ! RETURN ! END SUBROUTINE punch_band SUBROUTINE punch_band_2d(filband,spin_component) ! ! This routine opens a file for each band and writes on output ! kx, ky, energy, ! kx, ky, energy ! .., .., .. ! where kx and ky are proportional to the length ! of the vectors k_1 and k_2 specified in the input of the 2d plot. ! ! The k points are supposed to be in the form ! xk(i,j) = xk_0 + dkx *(i-1) + dky * (j-1) 1<i<n1, 1<j<n2 ! ! kx(i,j) = (i-1) |dkx| ! ky(i,j) = (j-1) |dky| ! USE kinds, ONLY : DP USE constants, ONLY : eps8, rytoev USE lsda_mod, ONLY : nspin USE klist, ONLY : xk, nkstot, nks USE wvfct, ONLY : et, nbnd USE io_files, ONLY : iuntmp USE io_global, ONLY : ionode, ionode_id USE mp, ONLY : mp_bcast USE mp_images, ONLY : intra_image_comm IMPLICIT NONE CHARACTER(LEN=256),INTENT(IN) :: filband INTEGER, INTENT(IN) :: spin_component REAL(DP) :: xk0(3), xk1(3), xk2(3), dkx(3), dky(3), xkdum(3), mdkx, mdky INTEGER :: n1, n2 INTEGER :: ik, i, i1, i2, ibnd, ijk, start_k, last_k, nks_eff, j, ios CHARACTER(LEN=256) :: filename CHARACTER(LEN=6), EXTERNAL :: int_to_char REAL(DP), ALLOCATABLE :: xk_collect(:,:), et_collect(:,:) ALLOCATE(xk_collect(3,nkstot)) ALLOCATE(et_collect(nbnd,nkstot)) CALL poolcollect( 3, nks, xk, nkstot, xk_collect) CALL poolcollect( nbnd, nks, et, nkstot, et_collect) start_k=1 last_k=nkstot nks_eff=nkstot IF (nspin==2) THEN nks_eff=nkstot/2 IF (spin_component==1) THEN start_k=1 last_k=nks_eff ELSE start_k=nks_eff+1 last_k=nkstot ENDIF ENDIF ! ! Determine xk0 ! xk0(:)=xk_collect(:,start_k) ! ! Determine dkx ! dky(:)=xk_collect(:,start_k+1)-xk0(:) ! ! Determine n2 and dky ! loop_k: DO j=start_k+2, nkstot xkdum(:)=xk0(:)+(j-1)*dky(:) IF (ABS(xk_collect(1,j)-xkdum(1))>eps8.OR. & ABS(xk_collect(2,j)-xkdum(2))>eps8.OR. & ABS(xk_collect(3,j)-xkdum(3))>eps8) THEN n2=j-1 dkx(:)=xk_collect(:,j)-xk0(:) EXIT loop_k ENDIF ENDDO loop_k n1=nks_eff/n2 IF (n1*n2 /= nks_eff) CALL errore('punch_band_2d',& 'Problems with k points',1) mdkx = sqrt( dkx(1)**2 + dkx(2)**2 + dkx(3)**2 ) mdky = sqrt( dky(1)**2 + dky(2)**2 + dky(3)**2 ) ! ! write the output, a band per file ! DO ibnd=1,nbnd filename=TRIM(filband) // '.' // TRIM(int_to_char(ibnd)) IF (ionode) & open(unit=iuntmp,file=filename,status='unknown', err=100, iostat=ios) CALL mp_bcast(ios,ionode_id, intra_image_comm) 100 CALL errore('punch_band_2d','Problem opening outputfile',ios) ijk=0 DO i1=1,n1 DO i2=1,n2 ijk=ijk+1 IF (ionode) & WRITE(iuntmp,'(3f16.6)') mdkx*(i1-1), mdky*(i2-1), & et_collect(ibnd,ijk)*rytoev ENDDO ENDDO IF (ionode) CLOSE(unit=iuntmp,status='KEEP') ENDDO DEALLOCATE(xk_collect) DEALLOCATE(et_collect) RETURN END ! !---------------------------------------------------------------------------- SUBROUTINE punch_plottable_bands ( filband, nks1tot, nks2tot, nkstot, nbnd, & xk, et ) !--------------------------------------------------------------------------- ! USE kinds, ONLY : dp IMPLICIT NONE CHARACTER(LEN=*), INTENT(IN) :: filband INTEGER, INTENT(IN) :: nks1tot, nks2tot, nkstot, nbnd REAL(dp), INTENT(IN) :: xk(3,nkstot), et(nbnd,nkstot) ! INTEGER, PARAMETER :: max_lines = 100, stdout=6, iunpun0=18 INTEGER:: ios, i, n, nlines, npoints(max_lines), point(max_lines) LOGICAL :: high_symmetry(nkstot), opnd REAL(dp):: k1(3), k2(3), kx(nkstot), ps, dxmod, dxmod_save ! ! IF ( nks1tot < 1 .OR. nks2tot > nkstot .OR. nkstot < 1 .OR. nbnd < 1 ) THEN CALL infomsg('punch_plottable_bands','incorrect input data, exiting') RETURN END IF ios = 0 OPEN (unit = iunpun0, file = TRIM(filband)//'.gnu', status = 'unknown',& form = 'formatted', iostat = ios) IF ( ios /= 0 ) THEN WRITE ( stdout, & '(/,5x,"Error opening plottable file ",A)') TRIM(filband)//'.gnu' RETURN END IF ! ! Find high-symmetry points (poor man's algorithm) ! DO n=nks1tot,nks2tot IF (n==nks1tot .OR. n==nks2tot) THEN high_symmetry(n) = .true. ELSE k1(:) = xk(:,n) - xk(:,n-1) k2(:) = xk(:,n+1) - xk(:,n) IF ( k1(1)*k1(1) + k1(2)*k1(2) + k1(3)*k1(3) < 1.0d-8 .OR. & k2(1)*k2(1) + k2(2)*k2(2) + k2(3)*k2(3) < 1.0d-8 ) THEN CALL infomsg('punch_plottable_bands','two consecutive same k, exiting') RETURN END IF ps = ( k1(1)*k2(1) + k1(2)*k2(2) + k1(3)*k2(3) ) / & sqrt( k1(1)*k1(1) + k1(2)*k1(2) + k1(3)*k1(3) ) / & sqrt( k2(1)*k2(1) + k2(2)*k2(2) + k2(3)*k2(3) ) high_symmetry(n) = (ABS(ps-1.d0) >1.0d-4) ! ! The gamma point is a high symmetry point ! IF (xk(1,n)**2+xk(2,n)**2+xk(3,n)**2 < 1.0d-8) high_symmetry(n)=.true. ! ! save the typical length of dk ! IF (n==nks1tot+1) dxmod_save = sqrt( k1(1)**2 + k1(2)**2 + k1(3)**2) ENDIF ENDDO kx(nks1tot) = 0.0_dp DO n=nks1tot+1,nks2tot dxmod=sqrt ( (xk(1,n)-xk(1,n-1))**2 + & (xk(2,n)-xk(2,n-1))**2 + & (xk(3,n)-xk(3,n-1))**2 ) IF (dxmod > 5*dxmod_save) THEN ! ! A big jump in dxmod is a sign that the point xk(:,n) and xk(:,n-1) ! are quite distant and belong to two different lines. We put them on ! the same point in the graph ! kx(n)=kx(n-1) ELSEIF (dxmod > 1.d-4) THEN ! ! This is the usual case. The two points xk(:,n) and xk(:,n-1) are in ! the same path. ! kx(n) = kx(n-1) + dxmod dxmod_save = dxmod ELSE ! ! This is the case in which dxmod is almost zero. The two points ! coincide in the graph, but we do not save dxmod. ! kx(n) = kx(n-1) + dxmod ! ENDIF ENDDO ! ! Now we compute how many paths there are: nlines ! The first point of this path: point(iline) ! How many points are in each path: npoints(iline) ! DO n=nks1tot,nks2tot IF (high_symmetry(n)) THEN IF (n==nks1tot) THEN ! ! first point. Initialize the number of lines, and the number of point ! and say that this line start at the first point ! nlines=1 npoints(1)=1 point(1)=1 ELSEIF (n==nks2tot) THEN ! ! Last point. Here we save the last point of this line, but ! do not increase the number of lines ! npoints(nlines) = npoints(nlines)+1 point(nlines+1)=n ELSE ! ! Middle line. The current line has one more points, and there is ! a new line that has to be initialized. It has one point and its ! first point is the current k. ! npoints(nlines) = npoints(nlines)+1 nlines=nlines+1 IF (nlines>max_lines) THEN CALL infomsg('punch_plottable_bands','too many lines, exiting') RETURN END IF npoints(nlines) = 1 point(nlines)=n ENDIF ! WRITE( stdout,'(5x,"high-symmetry point: ",3f7.4,& &" x coordinate",f9.4)') (xk(i,n),i=1,3), kx(n) ELSE ! ! This k is not an high symmetry line so we just increase the number ! of points of this line. ! npoints(nlines) = npoints(nlines)+1 ENDIF ENDDO ! DO i=1,nbnd WRITE (iunpun0,'(2f10.4)') (kx(n), et(i,n),n=nks1tot,nks2tot) WRITE (iunpun0,*) ENDDO ! WRITE ( stdout, & '(/,5x,"Plottable bands (eV) written to file ",A)') TRIM(filband)//'.gnu' CLOSE(unit=iunpun0, STATUS='KEEP') RETURN ! END SUBROUTINE punch_plottable_bands
gpl-2.0
QEF/q-e
PHonon/PH/generate_dynamical_matrix_c.f90
2
3555
! ! Copyright (C) 2003-2010 Quantum ESPRESSO group ! This file is distributed under the terms of the ! GNU General Public License. See the file `License' ! in the root directory of the present distribution, ! or http://www.gnu.org/copyleft/gpl.txt . ! ! !----------------------------------------------------------------------- subroutine generate_dynamical_matrix & (nat, nsym, s, invs, irt, at, bg, n_diff_sites, equiv_atoms, & has_equivalent, dyn) !----------------------------------------------------------------------- !! Generate the complete dynamical matrix from independent modes only. !! Input: dyn = irreducible dyn.mat. !! Output: dyn = complete dyn.mat. ! USE kinds, only : DP implicit none integer :: nat, nsym, n_diff_sites, irt(48,nat), invs(48), & equiv_atoms(nat,nat), s(3,3,48), has_equivalent(nat) real(DP) :: at(3,3), bg(3,3) complex(DP) :: dyn(3*nat,3*nat) ! integer :: isym, na, nb, ni, nj, sni, snj, smu_i, smu_j, & i, j, k, l, mu_k, mu_l complex(DP), allocatable :: irreducible_dyn(:,:) complex(DP) :: work(3,3) logical :: no_equivalent_atoms integer, allocatable ::done(:,:) ! no_equivalent_atoms=.true. do na = 1,nat no_equivalent_atoms = no_equivalent_atoms .and. has_equivalent(na).eq.0 end do if (no_equivalent_atoms) return ! allocate ( irreducible_dyn( 3*nat, 3*nat)) call zcopy(3*nat*3*nat,dyn,1,irreducible_dyn,1) ! do na = 1,nat if (has_equivalent(na).eq.0 ) then do nb = 1,nat do i = 1,3 do j = 1,3 work(i,j) = irreducible_dyn(3*(na-1)+i,3*(nb-1)+j) end do end do ! ! transform to crystal axis ! call trntnsc(work,at,bg,-1) do i = 1,3 do j = 1,3 irreducible_dyn(3*(na-1)+i,3*(nb-1)+j) = work(i,j) end do end do end do end if end do ! allocate (done( 3*nat, 3*nat)) do smu_i = 1,3*nat do smu_j = 1,3*nat dyn(smu_i,smu_j) = (0.d0,0.d0) done(smu_i,smu_j)= 0 end do end do ! do isym = 1,nsym do na = 1,n_diff_sites ni = equiv_atoms(na,1) sni = irt(isym,ni) do i = 1,3 smu_i = 3*(sni-1)+i do nj = 1,nat snj = irt(isym,nj) do j = 1,3 smu_j = 3*(snj-1)+j if (done(smu_i,smu_j).eq.0) then do k = 1,3 mu_k = 3*(ni-1)+k do l = 1,3 mu_l = 3*(nj-1)+l dyn(smu_i,smu_j) = dyn(smu_i,smu_j) + & s(i,k,invs(isym)) * s(j,l,invs(isym)) * & irreducible_dyn(mu_k,mu_l) ! rotation matrices are S^-1 end do end do done(smu_i,smu_j)=1 end if end do end do end do end do end do ! deallocate(done) deallocate(irreducible_dyn) ! do na = 1,nat do nb = 1,nat do i = 1,3 do j = 1,3 work(i,j) = dyn(3*(na-1)+i,3*(nb-1)+j) end do end do ! back to cartesian axes call trntnsc(work,at,bg, 1) do i = 1,3 do j = 1,3 dyn(3*(na-1)+i,3*(nb-1)+j) = work(i,j) end do end do end do end do ! return end subroutine generate_dynamical_matrix
gpl-2.0
wilmarcardonac/hypermcmc
lapack-3.5.0/SRC/ctrttf.f
24
15895
*> \brief \b CTRTTF copies a triangular matrix from the standard full format (TR) to the rectangular full packed format (TF). * * =========== DOCUMENTATION =========== * * Online html documentation available at * http://www.netlib.org/lapack/explore-html/ * *> \htmlonly *> Download CTRTTF + dependencies *> <a href="http://www.netlib.org/cgi-bin/netlibfiles.tgz?format=tgz&filename=/lapack/lapack_routine/ctrttf.f"> *> [TGZ]</a> *> <a href="http://www.netlib.org/cgi-bin/netlibfiles.zip?format=zip&filename=/lapack/lapack_routine/ctrttf.f"> *> [ZIP]</a> *> <a href="http://www.netlib.org/cgi-bin/netlibfiles.txt?format=txt&filename=/lapack/lapack_routine/ctrttf.f"> *> [TXT]</a> *> \endhtmlonly * * Definition: * =========== * * SUBROUTINE CTRTTF( TRANSR, UPLO, N, A, LDA, ARF, INFO ) * * .. Scalar Arguments .. * CHARACTER TRANSR, UPLO * INTEGER INFO, N, LDA * .. * .. Array Arguments .. * COMPLEX A( 0: LDA-1, 0: * ), ARF( 0: * ) * .. * * *> \par Purpose: * ============= *> *> \verbatim *> *> CTRTTF copies a triangular matrix A from standard full format (TR) *> to rectangular full packed format (TF) . *> \endverbatim * * Arguments: * ========== * *> \param[in] TRANSR *> \verbatim *> TRANSR is CHARACTER*1 *> = 'N': ARF in Normal mode is wanted; *> = 'C': ARF in Conjugate Transpose mode is wanted; *> \endverbatim *> *> \param[in] UPLO *> \verbatim *> UPLO is CHARACTER*1 *> = 'U': A is upper triangular; *> = 'L': A is lower triangular. *> \endverbatim *> *> \param[in] N *> \verbatim *> N is INTEGER *> The order of the matrix A. N >= 0. *> \endverbatim *> *> \param[in] A *> \verbatim *> A is COMPLEX array, dimension ( LDA, N ) *> On entry, the triangular matrix A. If UPLO = 'U', the *> leading N-by-N upper triangular part of the array A contains *> the upper triangular matrix, and the strictly lower *> triangular part of A is not referenced. If UPLO = 'L', the *> leading N-by-N lower triangular part of the array A contains *> the lower triangular matrix, and the strictly upper *> triangular part of A is not referenced. *> \endverbatim *> *> \param[in] LDA *> \verbatim *> LDA is INTEGER *> The leading dimension of the matrix A. LDA >= max(1,N). *> \endverbatim *> *> \param[out] ARF *> \verbatim *> ARF is COMPLEX*16 array, dimension ( N*(N+1)/2 ), *> On exit, the upper or lower triangular matrix A stored in *> RFP format. For a further discussion see Notes below. *> \endverbatim *> *> \param[out] INFO *> \verbatim *> INFO is INTEGER *> = 0: successful exit *> < 0: if INFO = -i, the i-th argument had an illegal value *> \endverbatim * * Authors: * ======== * *> \author Univ. of Tennessee *> \author Univ. of California Berkeley *> \author Univ. of Colorado Denver *> \author NAG Ltd. * *> \date September 2012 * *> \ingroup complexOTHERcomputational * *> \par Further Details: * ===================== *> *> \verbatim *> *> We first consider Standard Packed Format when N is even. *> We give an example where N = 6. *> *> AP is Upper AP is Lower *> *> 00 01 02 03 04 05 00 *> 11 12 13 14 15 10 11 *> 22 23 24 25 20 21 22 *> 33 34 35 30 31 32 33 *> 44 45 40 41 42 43 44 *> 55 50 51 52 53 54 55 *> *> *> Let TRANSR = 'N'. RFP holds AP as follows: *> For UPLO = 'U' the upper trapezoid A(0:5,0:2) consists of the last *> three columns of AP upper. The lower triangle A(4:6,0:2) consists of *> conjugate-transpose of the first three columns of AP upper. *> For UPLO = 'L' the lower trapezoid A(1:6,0:2) consists of the first *> three columns of AP lower. The upper triangle A(0:2,0:2) consists of *> conjugate-transpose of the last three columns of AP lower. *> To denote conjugate we place -- above the element. This covers the *> case N even and TRANSR = 'N'. *> *> RFP A RFP A *> *> -- -- -- *> 03 04 05 33 43 53 *> -- -- *> 13 14 15 00 44 54 *> -- *> 23 24 25 10 11 55 *> *> 33 34 35 20 21 22 *> -- *> 00 44 45 30 31 32 *> -- -- *> 01 11 55 40 41 42 *> -- -- -- *> 02 12 22 50 51 52 *> *> Now let TRANSR = 'C'. RFP A in both UPLO cases is just the conjugate- *> transpose of RFP A above. One therefore gets: *> *> *> RFP A RFP A *> *> -- -- -- -- -- -- -- -- -- -- *> 03 13 23 33 00 01 02 33 00 10 20 30 40 50 *> -- -- -- -- -- -- -- -- -- -- *> 04 14 24 34 44 11 12 43 44 11 21 31 41 51 *> -- -- -- -- -- -- -- -- -- -- *> 05 15 25 35 45 55 22 53 54 55 22 32 42 52 *> *> *> We next consider Standard Packed Format when N is odd. *> We give an example where N = 5. *> *> AP is Upper AP is Lower *> *> 00 01 02 03 04 00 *> 11 12 13 14 10 11 *> 22 23 24 20 21 22 *> 33 34 30 31 32 33 *> 44 40 41 42 43 44 *> *> *> Let TRANSR = 'N'. RFP holds AP as follows: *> For UPLO = 'U' the upper trapezoid A(0:4,0:2) consists of the last *> three columns of AP upper. The lower triangle A(3:4,0:1) consists of *> conjugate-transpose of the first two columns of AP upper. *> For UPLO = 'L' the lower trapezoid A(0:4,0:2) consists of the first *> three columns of AP lower. The upper triangle A(0:1,1:2) consists of *> conjugate-transpose of the last two columns of AP lower. *> To denote conjugate we place -- above the element. This covers the *> case N odd and TRANSR = 'N'. *> *> RFP A RFP A *> *> -- -- *> 02 03 04 00 33 43 *> -- *> 12 13 14 10 11 44 *> *> 22 23 24 20 21 22 *> -- *> 00 33 34 30 31 32 *> -- -- *> 01 11 44 40 41 42 *> *> Now let TRANSR = 'C'. RFP A in both UPLO cases is just the conjugate- *> transpose of RFP A above. One therefore gets: *> *> *> RFP A RFP A *> *> -- -- -- -- -- -- -- -- -- *> 02 12 22 00 01 00 10 20 30 40 50 *> -- -- -- -- -- -- -- -- -- *> 03 13 23 33 11 33 11 21 31 41 51 *> -- -- -- -- -- -- -- -- -- *> 04 14 24 34 44 43 44 22 32 42 52 *> \endverbatim *> * ===================================================================== SUBROUTINE CTRTTF( TRANSR, UPLO, N, A, LDA, ARF, INFO ) * * -- LAPACK computational routine (version 3.4.2) -- * -- LAPACK is a software package provided by Univ. of Tennessee, -- * -- Univ. of California Berkeley, Univ. of Colorado Denver and NAG Ltd..-- * September 2012 * * .. Scalar Arguments .. CHARACTER TRANSR, UPLO INTEGER INFO, N, LDA * .. * .. Array Arguments .. COMPLEX A( 0: LDA-1, 0: * ), ARF( 0: * ) * .. * * ===================================================================== * * .. Parameters .. * .. * .. Local Scalars .. LOGICAL LOWER, NISODD, NORMALTRANSR INTEGER I, IJ, J, K, L, N1, N2, NT, NX2, NP1X2 * .. * .. External Functions .. LOGICAL LSAME EXTERNAL LSAME * .. * .. External Subroutines .. EXTERNAL XERBLA * .. * .. Intrinsic Functions .. INTRINSIC CONJG, MAX, MOD * .. * .. Executable Statements .. * * Test the input parameters. * INFO = 0 NORMALTRANSR = LSAME( TRANSR, 'N' ) LOWER = LSAME( UPLO, 'L' ) IF( .NOT.NORMALTRANSR .AND. .NOT.LSAME( TRANSR, 'C' ) ) THEN INFO = -1 ELSE IF( .NOT.LOWER .AND. .NOT.LSAME( UPLO, 'U' ) ) THEN INFO = -2 ELSE IF( N.LT.0 ) THEN INFO = -3 ELSE IF( LDA.LT.MAX( 1, N ) ) THEN INFO = -5 END IF IF( INFO.NE.0 ) THEN CALL XERBLA( 'CTRTTF', -INFO ) RETURN END IF * * Quick return if possible * IF( N.LE.1 ) THEN IF( N.EQ.1 ) THEN IF( NORMALTRANSR ) THEN ARF( 0 ) = A( 0, 0 ) ELSE ARF( 0 ) = CONJG( A( 0, 0 ) ) END IF END IF RETURN END IF * * Size of array ARF(1:2,0:nt-1) * NT = N*( N+1 ) / 2 * * set N1 and N2 depending on LOWER: for N even N1=N2=K * IF( LOWER ) THEN N2 = N / 2 N1 = N - N2 ELSE N1 = N / 2 N2 = N - N1 END IF * * If N is odd, set NISODD = .TRUE., LDA=N+1 and A is (N+1)--by--K2. * If N is even, set K = N/2 and NISODD = .FALSE., LDA=N and A is * N--by--(N+1)/2. * IF( MOD( N, 2 ).EQ.0 ) THEN K = N / 2 NISODD = .FALSE. IF( .NOT.LOWER ) $ NP1X2 = N + N + 2 ELSE NISODD = .TRUE. IF( .NOT.LOWER ) $ NX2 = N + N END IF * IF( NISODD ) THEN * * N is odd * IF( NORMALTRANSR ) THEN * * N is odd and TRANSR = 'N' * IF( LOWER ) THEN * * SRPA for LOWER, NORMAL and N is odd ( a(0:n-1,0:n1-1) ) * T1 -> a(0,0), T2 -> a(0,1), S -> a(n1,0) * T1 -> a(0), T2 -> a(n), S -> a(n1); lda=n * IJ = 0 DO J = 0, N2 DO I = N1, N2 + J ARF( IJ ) = CONJG( A( N2+J, I ) ) IJ = IJ + 1 END DO DO I = J, N - 1 ARF( IJ ) = A( I, J ) IJ = IJ + 1 END DO END DO * ELSE * * SRPA for UPPER, NORMAL and N is odd ( a(0:n-1,0:n2-1) * T1 -> a(n1+1,0), T2 -> a(n1,0), S -> a(0,0) * T1 -> a(n2), T2 -> a(n1), S -> a(0); lda=n * IJ = NT - N DO J = N - 1, N1, -1 DO I = 0, J ARF( IJ ) = A( I, J ) IJ = IJ + 1 END DO DO L = J - N1, N1 - 1 ARF( IJ ) = CONJG( A( J-N1, L ) ) IJ = IJ + 1 END DO IJ = IJ - NX2 END DO * END IF * ELSE * * N is odd and TRANSR = 'C' * IF( LOWER ) THEN * * SRPA for LOWER, TRANSPOSE and N is odd * T1 -> A(0,0) , T2 -> A(1,0) , S -> A(0,n1) * T1 -> A(0+0) , T2 -> A(1+0) , S -> A(0+n1*n1); lda=n1 * IJ = 0 DO J = 0, N2 - 1 DO I = 0, J ARF( IJ ) = CONJG( A( J, I ) ) IJ = IJ + 1 END DO DO I = N1 + J, N - 1 ARF( IJ ) = A( I, N1+J ) IJ = IJ + 1 END DO END DO DO J = N2, N - 1 DO I = 0, N1 - 1 ARF( IJ ) = CONJG( A( J, I ) ) IJ = IJ + 1 END DO END DO * ELSE * * SRPA for UPPER, TRANSPOSE and N is odd * T1 -> A(0,n1+1), T2 -> A(0,n1), S -> A(0,0) * T1 -> A(n2*n2), T2 -> A(n1*n2), S -> A(0); lda=n2 * IJ = 0 DO J = 0, N1 DO I = N1, N - 1 ARF( IJ ) = CONJG( A( J, I ) ) IJ = IJ + 1 END DO END DO DO J = 0, N1 - 1 DO I = 0, J ARF( IJ ) = A( I, J ) IJ = IJ + 1 END DO DO L = N2 + J, N - 1 ARF( IJ ) = CONJG( A( N2+J, L ) ) IJ = IJ + 1 END DO END DO * END IF * END IF * ELSE * * N is even * IF( NORMALTRANSR ) THEN * * N is even and TRANSR = 'N' * IF( LOWER ) THEN * * SRPA for LOWER, NORMAL, and N is even ( a(0:n,0:k-1) ) * T1 -> a(1,0), T2 -> a(0,0), S -> a(k+1,0) * T1 -> a(1), T2 -> a(0), S -> a(k+1); lda=n+1 * IJ = 0 DO J = 0, K - 1 DO I = K, K + J ARF( IJ ) = CONJG( A( K+J, I ) ) IJ = IJ + 1 END DO DO I = J, N - 1 ARF( IJ ) = A( I, J ) IJ = IJ + 1 END DO END DO * ELSE * * SRPA for UPPER, NORMAL, and N is even ( a(0:n,0:k-1) ) * T1 -> a(k+1,0) , T2 -> a(k,0), S -> a(0,0) * T1 -> a(k+1), T2 -> a(k), S -> a(0); lda=n+1 * IJ = NT - N - 1 DO J = N - 1, K, -1 DO I = 0, J ARF( IJ ) = A( I, J ) IJ = IJ + 1 END DO DO L = J - K, K - 1 ARF( IJ ) = CONJG( A( J-K, L ) ) IJ = IJ + 1 END DO IJ = IJ - NP1X2 END DO * END IF * ELSE * * N is even and TRANSR = 'C' * IF( LOWER ) THEN * * SRPA for LOWER, TRANSPOSE and N is even (see paper, A=B) * T1 -> A(0,1) , T2 -> A(0,0) , S -> A(0,k+1) : * T1 -> A(0+k) , T2 -> A(0+0) , S -> A(0+k*(k+1)); lda=k * IJ = 0 J = K DO I = K, N - 1 ARF( IJ ) = A( I, J ) IJ = IJ + 1 END DO DO J = 0, K - 2 DO I = 0, J ARF( IJ ) = CONJG( A( J, I ) ) IJ = IJ + 1 END DO DO I = K + 1 + J, N - 1 ARF( IJ ) = A( I, K+1+J ) IJ = IJ + 1 END DO END DO DO J = K - 1, N - 1 DO I = 0, K - 1 ARF( IJ ) = CONJG( A( J, I ) ) IJ = IJ + 1 END DO END DO * ELSE * * SRPA for UPPER, TRANSPOSE and N is even (see paper, A=B) * T1 -> A(0,k+1) , T2 -> A(0,k) , S -> A(0,0) * T1 -> A(0+k*(k+1)) , T2 -> A(0+k*k) , S -> A(0+0)); lda=k * IJ = 0 DO J = 0, K DO I = K, N - 1 ARF( IJ ) = CONJG( A( J, I ) ) IJ = IJ + 1 END DO END DO DO J = 0, K - 2 DO I = 0, J ARF( IJ ) = A( I, J ) IJ = IJ + 1 END DO DO L = K + 1 + J, N - 1 ARF( IJ ) = CONJG( A( K+1+J, L ) ) IJ = IJ + 1 END DO END DO * * Note that here J = K-1 * DO I = 0, J ARF( IJ ) = A( I, J ) IJ = IJ + 1 END DO * END IF * END IF * END IF * RETURN * * End of CTRTTF * END
gpl-2.0
QEF/q-e
Modules/rism1d_facade.f90
2
17124
! ! Copyright (C) 2015-2016 Satomichi Nishihara ! ! This file is distributed under the terms of the ! GNU General Public License. See the file `License' ! in the root directory of the present distribution, ! or http://www.gnu.org/copyleft/gpl.txt . ! !-------------------------------------------------------------------------- MODULE rism1d_facade !-------------------------------------------------------------------------- ! ! ... Facade (or Interface) of 1D-RISM's library. ! ... External codes, which utilize 1D-RISM, can access data and subroutines ! ... throught this module. ! USE err_rism, ONLY : stop_by_err_rism, IERR_RISM_NULL, IERR_RISM_NOT_CONVERGED USE io_global, ONLY : stdout, ionode USE io_rism_xml, ONLY : write_1drism, read_1drism USE kinds, ONLY : DP USE mp, ONLY : mp_rank, mp_size, mp_sum, mp_barrier, mp_comm_split USE mp_images, ONLY : intra_image_comm USE rism, ONLY : rism_type, clean_rism_data, allocate_1drism, deallocate_rism USE solvmol, ONLY : get_nsite_in_solVs ! IMPLICIT NONE SAVE PRIVATE ! ! ... define constants INTEGER, PARAMETER :: LEN_STR = 30 ! ! ... define variables LOGICAL :: lrism1d = .FALSE. ! to calculate 1D-RISM, or not INTEGER :: nproc_sub = 0 ! total size of MPI's subspace INTEGER :: nproc_switch = 0 ! size of MPI's subspace to switch algorithm LOGICAL :: has_any_corr = .FALSE. ! has nonzero correlations CHARACTER(LEN=LEN_STR) :: starting_corr = '' ! initial correlations: 'zero', 'file', 'fix' INTEGER :: niter = 0 ! maximum number of iteration REAL(DP) :: epsv = 0.0_DP ! convergence threshold REAL(DP) :: bond_width = 0.0_DP ! gaussian width of bonds (in bohr) INTEGER :: mdiis_size = 0 ! size of MDIIS REAL(DP) :: mdiis_step = 0.0_DP ! step of MDIIS REAL(DP) :: dielectric = 0.0_DP ! dielectric constant (for DRISM) REAL(DP) :: molesize = 0.0_DP ! size of molecule (in bohr, for DRISM) ! ! ... define 1D-RISM's main data TYPE(rism_type), POINTER :: rism1t => NULL() TYPE(rism_type), TARGET :: rism1t_right TYPE(rism_type), TARGET :: rism1t_left LOGICAL :: init_rism1t_right = .FALSE. LOGICAL :: init_rism1t_left = .FALSE. ! ! ... public components PUBLIC :: lrism1d PUBLIC :: nproc_sub PUBLIC :: nproc_switch PUBLIC :: starting_corr PUBLIC :: niter PUBLIC :: epsv PUBLIC :: bond_width PUBLIC :: mdiis_size PUBLIC :: mdiis_step PUBLIC :: dielectric PUBLIC :: molesize ! PUBLIC :: rism1t PUBLIC :: rism1d_iosys PUBLIC :: rism1d_summary PUBLIC :: rism1d_initialize PUBLIC :: rism1d_finalize PUBLIC :: rism1d_is_avail PUBLIC :: rism1d_activate_right PUBLIC :: rism1d_activate_left PUBLIC :: rism1d_prepare PUBLIC :: rism1d_run PUBLIC :: rism1d_write_to_show PUBLIC :: rism1d_write_to_restart PUBLIC :: rism1d_read_to_restart PUBLIC :: rism1d_print_clock ! CONTAINS ! !---------------------------------------------------------------------------- SUBROUTINE rism1d_iosys(trism, laue) !---------------------------------------------------------------------------- ! ! ... set variables and initialize this module ! IMPLICIT NONE ! LOGICAL, INTENT(IN) :: trism LOGICAL, OPTIONAL, INTENT(IN) :: laue ! LOGICAL :: laue_ ! lrism1d = trism ! IF (.NOT. lrism1d) THEN RETURN END IF ! IF (PRESENT(laue)) THEN laue_ = laue ELSE laue_ = .FALSE. END IF ! CALL iosys_1drism(laue_) ! END SUBROUTINE rism1d_iosys ! !---------------------------------------------------------------------------- SUBROUTINE rism1d_summary() !---------------------------------------------------------------------------- ! ! ... print conditions ! IMPLICIT NONE ! IF (.NOT. lrism1d) THEN RETURN END IF ! CALL summary_1drism() ! END SUBROUTINE rism1d_summary ! !---------------------------------------------------------------------------- SUBROUTINE rism1d_initialize(ngrid, rmax, lboth) !---------------------------------------------------------------------------- ! ! ... initialize this module ! ... ! ... Variables: ! ... ngrid: number of grids ! ... rmax: maximum radius of R-space (in bohr) ! ... lboth: initialize the both rism1t_right and rism1t_left, or not ! IMPLICIT NONE ! INTEGER, INTENT(IN) :: ngrid REAL(DP), INTENT(IN) :: rmax LOGICAL, INTENT(IN) :: lboth ! INTEGER :: nv INTEGER :: rism1d_comm INTEGER :: rism1d_root LOGICAL :: rism1d_primal LOGICAL :: mpi_radfft ! IF (.NOT. lrism1d) THEN RETURN END IF ! nv = get_nsite_in_solVs() ! ! ... initialize MPI's information CALL rism1d_mpi_init(rism1d_comm, rism1d_root, rism1d_primal, mpi_radfft) ! ! ... initialize rism1t_right init_rism1t_right = .TRUE. CALL allocate_1drism(rism1t_right, nv, ngrid, rmax, mpi_radfft, & & intra_image_comm, rism1d_root, rism1d_primal, rism1d_comm) ! IF (lboth) THEN ! ... initialize rism1t_left init_rism1t_left = .TRUE. CALL allocate_1drism(rism1t_left, nv, ngrid, rmax, mpi_radfft, & & intra_image_comm, rism1d_root, rism1d_primal, rism1d_comm) END IF ! ! ... activate rism1t_right CALL rism1d_activate_right() ! END SUBROUTINE rism1d_initialize ! !---------------------------------------------------------------------------- SUBROUTINE rism1d_mpi_init(rism1d_comm, rism1d_root, rism1d_primal, mpi_radfft) !---------------------------------------------------------------------------- ! IMPLICIT NONE ! INTEGER, INTENT(OUT) :: rism1d_comm INTEGER, INTENT(OUT) :: rism1d_root LOGICAL, INTENT(OUT) :: rism1d_primal LOGICAL, INTENT(OUT) :: mpi_radfft ! INTEGER :: color INTEGER :: irank INTEGER :: nproc ! irank = mp_rank(intra_image_comm) nproc = mp_size(intra_image_comm) ! IF (nproc <= nproc_sub) THEN rism1d_comm = intra_image_comm rism1d_root = 0 rism1d_primal = .TRUE. ! ELSE color = irank / nproc_sub rism1d_root = 0 IF (ionode) THEN color = 0 rism1d_root = irank END IF CALL mp_barrier(intra_image_comm) CALL mp_comm_split(intra_image_comm, color, irank, rism1d_comm) CALL mp_sum(rism1d_root, intra_image_comm) rism1d_primal = (color == 0) END IF ! IF (MIN(nproc, nproc_sub) > nproc_switch) THEN mpi_radfft = .TRUE. ELSE mpi_radfft = .FALSE. END IF ! END SUBROUTINE rism1d_mpi_init ! !---------------------------------------------------------------------------- SUBROUTINE rism1d_finalize() !---------------------------------------------------------------------------- ! ! ... finalize this module ! IMPLICIT NONE ! IF (.NOT. lrism1d) THEN RETURN END IF ! ! ... finalize rism1t IF (ASSOCIATED(rism1t)) THEN NULLIFY(rism1t) END IF ! ! ... finalize rism1t_right IF (init_rism1t_right) THEN init_rism1t_right = .FALSE. CALL deallocate_rism(rism1t_right, .TRUE.) END IF ! ! ... finalize rism1t_left IF (init_rism1t_left) THEN init_rism1t_left = .FALSE. CALL deallocate_rism(rism1t_left, .TRUE.) END IF ! END SUBROUTINE rism1d_finalize ! !---------------------------------------------------------------------------- FUNCTION rism1d_is_avail() RESULT(avail) !---------------------------------------------------------------------------- ! ! ... result of 1D-RISM is available, or not ! IMPLICIT NONE LOGICAL :: avail ! IF (.NOT. lrism1d) THEN avail = .FALSE. RETURN END IF ! IF (.NOT. (init_rism1t_right .OR. init_rism1t_left)) THEN avail = .FALSE. RETURN END IF ! avail = .TRUE. ! IF (init_rism1t_right) THEN avail = avail .AND. rism1t_right%avail END IF ! IF (init_rism1t_left) THEN avail = avail .AND. rism1t_left%avail END IF ! END FUNCTION rism1d_is_avail ! !---------------------------------------------------------------------------- SUBROUTINE rism1d_activate_right() !---------------------------------------------------------------------------- ! ! ... activate rism1t_right ! IMPLICIT NONE ! IF (.NOT. lrism1d) THEN RETURN END IF ! !IF (.NOT. init_rism1t_right) THEN ! CALL stop_by_err_rism('rism1d_activate_right', IERR_RISM_1DRISM_IS_NOT_AVAIL) !END IF ! rism1t => rism1t_right ! END SUBROUTINE rism1d_activate_right ! !---------------------------------------------------------------------------- SUBROUTINE rism1d_activate_left() !---------------------------------------------------------------------------- ! ! ... activate rism1t_left ! IMPLICIT NONE ! IF (.NOT. lrism1d) THEN RETURN END IF ! !IF (.NOT. init_rism1t_left) THEN ! CALL stop_by_err_rism('rism1d_activate_left', IERR_RISM_1DRISM_IS_NOT_AVAIL) !END IF ! rism1t => rism1t_left ! END SUBROUTINE rism1d_activate_left ! !---------------------------------------------------------------------------- SUBROUTINE rism1d_prepare() !---------------------------------------------------------------------------- ! ! ... prepare 1D-RISM's iterative calculation ! IMPLICIT NONE ! INTEGER :: ierr ! IF (.NOT. lrism1d) THEN RETURN END IF ! CALL start_clock('1DRISM_pre') ! ! ... initial calculation (potential, intra-molecular correlation, dielectric bridge) IF (init_rism1t_right) THEN CALL init_1drism(rism1t_right, bond_width, dielectric, molesize, .TRUE., ierr) ! IF (ierr /= IERR_RISM_NULL) THEN CALL stop_by_err_rism('rism1d_prepare', ierr) END IF END IF ! IF (init_rism1t_left) THEN CALL init_1drism(rism1t_left, bond_width, dielectric, molesize, .FALSE., ierr) ! IF (ierr /= IERR_RISM_NULL) THEN CALL stop_by_err_rism('rism1d_prepare', ierr) END IF END IF ! ! ... create initial correlation IF (TRIM(starting_corr) == 'file' .OR. TRIM(starting_corr) == 'fix') THEN WRITE(stdout, '()') WRITE(stdout, '(5X,"Correlation function is read from file")') WRITE(stdout, '()') ! IF (init_rism1t_right) THEN CALL clean_rism_data(rism1t_right) END IF IF (init_rism1t_left) THEN CALL clean_rism_data(rism1t_left) END IF ! CALL rism1d_read_to_restart() has_any_corr = .TRUE. ! IF (TRIM(starting_corr) == 'fix') THEN rism1t%avail = .TRUE. END IF ! ELSE !IF (TRIM(starting_corr) == 'zero') THEN IF (init_rism1t_right) THEN CALL clean_rism_data(rism1t_right) END IF IF (init_rism1t_left) THEN CALL clean_rism_data(rism1t_left) END IF ! has_any_corr = .FALSE. END IF ! CALL stop_clock('1DRISM_pre') ! END SUBROUTINE rism1d_prepare ! !---------------------------------------------------------------------------- SUBROUTINE rism1d_run(lconv) !---------------------------------------------------------------------------- ! ! ... perform 1D-RISM's iterative calculation ! IMPLICIT NONE ! LOGICAL, INTENT(OUT) :: lconv ! INTEGER :: ierr INTEGER :: ihand CHARACTER(LEN=64) :: title ! IF (.NOT. lrism1d) THEN lconv = .FALSE. RETURN END IF ! ! ... does not calculate, if 'fix' IF (TRIM(starting_corr) == 'fix') THEN lconv = .FALSE. WRITE(stdout, '()') WRITE(stdout, '(5X,"Correlation function is fixed")') WRITE(stdout, '()') RETURN END IF ! lconv = .TRUE. ! DO ihand = 1, 2 IF (ihand == 1) THEN IF (.NOT. init_rism1t_right) CYCLE ELSE IF (.NOT. init_rism1t_left) CYCLE END IF ! CALL start_clock('1DRISM_run') ! ! ... calculate 1D-RISM IF (ihand == 1) THEN title = '' IF (init_rism1t_right .AND. init_rism1t_left) THEN title = 'the right-hand side' END IF CALL do_1drism(rism1t_right, niter, epsv, mdiis_size, mdiis_step, bond_width, & & .TRUE., .NOT. has_any_corr, TRIM(ADJUSTL(title)), ierr) ! ELSE title = '' IF (init_rism1t_right .AND. init_rism1t_left) THEN title = 'the left-hand side' END IF CALL do_1drism(rism1t_left, niter, epsv, mdiis_size, mdiis_step, bond_width, & & .FALSE., .NOT. has_any_corr, TRIM(ADJUSTL(title)), ierr) END IF ! ! ... 1D-RISM has been converged ? IF (ierr == IERR_RISM_NOT_CONVERGED) THEN lconv = lconv .AND. .FALSE. ! ELSE IF (ierr == IERR_RISM_NULL) THEN lconv = lconv .AND. .TRUE. ! ELSE ! an error has been occurred lconv = lconv .AND. .FALSE. CALL stop_by_err_rism('rism1d_run', ierr) END IF ! CALL stop_clock('1DRISM_run') ! END DO ! ! ... here, correlation is nonzero. has_any_corr = .TRUE. ! END SUBROUTINE rism1d_run ! !---------------------------------------------------------------------------- SUBROUTINE rism1d_write_to_show() !---------------------------------------------------------------------------- ! ! ... write 1D-RISM's data (human readable) ! IMPLICIT NONE ! INTEGER :: ierr ! IF (.NOT. lrism1d) THEN RETURN END IF ! IF (init_rism1t_right .AND. init_rism1t_left) THEN CALL print_corr_vv(rism1t_right, '#right', ierr) CALL print_corr_vv(rism1t_left, '#left', ierr) ! ELSE IF (init_rism1t_right) THEN CALL print_corr_vv(rism1t_right, '', ierr) ! ELSE IF (init_rism1t_right) THEN CALL print_corr_vv(rism1t_left, '', ierr) ! END IF ! IF (ierr /= IERR_RISM_NULL) THEN CALL stop_by_err_rism('rism1d_write_to_show', ierr) END IF ! CALL mp_barrier(rism1t%super_comm) ! END SUBROUTINE rism1d_write_to_show ! !---------------------------------------------------------------------------- SUBROUTINE rism1d_write_to_restart(ext) !---------------------------------------------------------------------------- ! ! ... write 1D-RISM's data (for restart calculation) ! IMPLICIT NONE ! CHARACTER(LEN=*), OPTIONAL, INTENT(IN) :: ext ! IF (.NOT. lrism1d) THEN RETURN END IF ! IF (init_rism1t_right) THEN IF (PRESENT(ext)) THEN CALL write_1drism(rism1t_right, '1.' // TRIM(ADJUSTL(ext))) ELSE CALL write_1drism(rism1t_right, '1') END IF END IF ! IF (init_rism1t_left) THEN IF (PRESENT(ext)) THEN CALL write_1drism(rism1t_left, '2.' // TRIM(ADJUSTL(ext))) ELSE CALL write_1drism(rism1t_left, '2') END IF END IF ! CALL mp_barrier(rism1t%super_comm) ! END SUBROUTINE rism1d_write_to_restart ! !---------------------------------------------------------------------------- SUBROUTINE rism1d_read_to_restart(ext) !---------------------------------------------------------------------------- ! ! ... read 1D-RISM's data (for restart calculation) ! IMPLICIT NONE ! CHARACTER(LEN=*), OPTIONAL, INTENT(IN) :: ext ! IF (.NOT. lrism1d) THEN RETURN END IF ! IF (init_rism1t_right) THEN IF (PRESENT(ext)) THEN CALL read_1drism(rism1t_right, '1.' // TRIM(ADJUSTL(ext))) ELSE CALL read_1drism(rism1t_right, '1') END IF END IF ! IF (init_rism1t_left) THEN IF (PRESENT(ext)) THEN CALL read_1drism(rism1t_left, '2.' // TRIM(ADJUSTL(ext))) ELSE CALL read_1drism(rism1t_left, '2') END IF END IF ! END SUBROUTINE rism1d_read_to_restart ! !---------------------------------------------------------------------------- SUBROUTINE rism1d_print_clock() !---------------------------------------------------------------------------- ! ! ... print clock for 1D-RISM ! IMPLICIT NONE ! IF (.NOT. lrism1d) THEN RETURN END IF ! CALL print_clock('1DRISM_pre') CALL print_clock('1DRISM_run') #if defined (__DEBUG_RISM) CALL print_clock('1DRISM_eqn') CALL print_clock('1DRISM_clos') CALL print_clock('1DRISM_fft') CALL print_clock('1DRISM_mdiis') #endif ! END SUBROUTINE rism1d_print_clock ! END MODULE rism1d_facade
gpl-2.0
e-q/scipy
scipy/special/cdflib/algdiv.f
151
1850
DOUBLE PRECISION FUNCTION algdiv(a,b) C----------------------------------------------------------------------- C C COMPUTATION OF LN(GAMMA(B)/GAMMA(A+B)) WHEN B .GE. 8 C C -------- C C IN THIS ALGORITHM, DEL(X) IS THE FUNCTION DEFINED BY C LN(GAMMA(X)) = (X - 0.5)*LN(X) - X + 0.5*LN(2*PI) + DEL(X). C C----------------------------------------------------------------------- C .. Scalar Arguments .. DOUBLE PRECISION a,b C .. C .. Local Scalars .. DOUBLE PRECISION c,c0,c1,c2,c3,c4,c5,d,h,s11,s3,s5,s7,s9,t,u,v,w, + x,x2 C .. C .. External Functions .. DOUBLE PRECISION alnrel EXTERNAL alnrel C .. C .. Intrinsic Functions .. INTRINSIC dlog C .. C .. Data statements .. DATA c0/.833333333333333D-01/,c1/-.277777777760991D-02/, + c2/.793650666825390D-03/,c3/-.595202931351870D-03/, + c4/.837308034031215D-03/,c5/-.165322962780713D-02/ C .. C .. Executable Statements .. C------------------------ IF (a.LE.b) GO TO 10 h = b/a c = 1.0D0/ (1.0D0+h) x = h/ (1.0D0+h) d = a + (b-0.5D0) GO TO 20 10 h = a/b c = h/ (1.0D0+h) x = 1.0D0/ (1.0D0+h) d = b + (a-0.5D0) C C SET SN = (1 - X**N)/(1 - X) C 20 x2 = x*x s3 = 1.0D0 + (x+x2) s5 = 1.0D0 + (x+x2*s3) s7 = 1.0D0 + (x+x2*s5) s9 = 1.0D0 + (x+x2*s7) s11 = 1.0D0 + (x+x2*s9) C C SET W = DEL(B) - DEL(A + B) C t = (1.0D0/b)**2 w = ((((c5*s11*t+c4*s9)*t+c3*s7)*t+c2*s5)*t+c1*s3)*t + c0 w = w* (c/b) C C COMBINE THE RESULTS C u = d*alnrel(a/b) v = a* (dlog(b)-1.0D0) IF (u.LE.v) GO TO 30 algdiv = (w-v) - u RETURN 30 algdiv = (w-u) - v RETURN END
bsd-3-clause
florianziemen/bin
topfill.f
1
2767
program difftop c parameter(ie=2160,je=1080) c dimension top(ie,je),ao(ie,je),an(ie,je),ihead(4) c read(70)ihead read(70)top write (6,*)ihead c do j=1,je do i=1,ie if(top(i,j).lt.-4000.)then ao(i,j)=9. elseif(top(i,j).lt.0.)then ao(i,j)=1. else ao(i,j)=0. endif an(i,j)=ao(i,j) enddo enddo c write(71)0,1,1,ie*je c write(71)an iter=0 10 iter=iter+1 zaehl=0 do j=1,je jo=j-1 if(j.eq.1)jo=1 ju=j+1 if(j.eq.je)ju=je do i=1,ie il=i-1 if(il.lt.1)il=ie ir=i+1 if(ir.gt.ie)ir=1 zzz=an(i,j) if(an(i,j).eq.1.)an(i,j)=max(an(il,j),an(ir,j),an(i,jo) x ,an(i,ju),an(il,ju),an(ir,ju),an(il,jo),an(ir,jo)) if(an(i,j).ne.zzz)zaehl=zaehl+1 enddo enddo write(6,*)zaehl cc write(71)iter,1,1,ie*je cc write(71)an do j=je,1,-1 jo=j-1 if(j.eq.1)jo=1 ju=j+1 if(j.eq.je)ju=je do i=ie,1,-1 il=i-1 if(il.lt.1)il=ie ir=i+1 if(ir.gt.ie)ir=1 zzz=an(i,j) if(an(i,j).eq.1.)an(i,j)=max(an(il,j),an(ir,j),an(i,jo) x ,an(i,ju),an(il,ju),an(ir,ju),an(il,jo),an(ir,jo)) if(an(i,j).ne.zzz)zaehl=zaehl+1 enddo enddo write(6,*)zaehl cc write(71)iter,1,1,ie*je cc write(71)an do j=je,1,-1 jo=j-1 if(j.eq.1)jo=1 ju=j+1 if(j.eq.je)ju=je do i=1,ie il=i-1 if(il.lt.1)il=ie ir=i+1 if(ir.gt.ie)ir=1 zzz=an(i,j) if(an(i,j).eq.1.)an(i,j)=max(an(il,j),an(ir,j),an(i,jo) x ,an(i,ju),an(il,ju),an(ir,ju),an(il,jo),an(ir,jo)) if(an(i,j).ne.zzz)zaehl=zaehl+1 enddo enddo write(6,*)zaehl cc write(71)iter,1,1,ie*je cc write(71)an do j=1,je jo=j-1 if(j.eq.1)jo=1 ju=j+1 if(j.eq.je)ju=je do i=ie,1,-1 il=i-1 if(il.lt.1)il=ie ir=i+1 if(ir.gt.ie)ir=1 zzz=an(i,j) if(an(i,j).eq.1.)an(i,j)=max(an(il,j),an(ir,j),an(i,jo) x ,an(i,ju),an(il,ju),an(ir,ju),an(il,jo),an(ir,jo)) if(an(i,j).ne.zzz)zaehl=zaehl+1 enddo enddo write(6,*)zaehl c write(71)iter,1,1,ie*je c write(71)an if(zaehl.gt.0.5)goto 10 write(71)iter,1,1,ie*je write(71)an c stop end
gpl-3.0
QEF/q-e
Modules/autopilot.f90
2
31342
! autopilot.f90 !******************************************************************************** ! autopilot.f90 Copyright (c) 2005 Targacept, Inc. !******************************************************************************** ! The Autopilot Feature suite is a user level enhancement that enables the ! following features: ! automatic restart of a job; ! preconfiguration of job parameters; ! on-the-fly changes to job parameters; ! and pausing of a running job. ! ! For more information, see README.AUTOPILOT in document directory. ! ! This program is free software; you can redistribute it and/or modify it under ! the terms of the GNU General Public License as published by the Free Software ! Foundation; either version 2 of the License, or (at your option) any later version. ! This program is distributed in the hope that it will be useful, but WITHOUT ANY ! WARRANTY; without even the implied warranty of MERCHANTABILITY FOR A PARTICULAR ! PURPOSE. See the GNU General Public License at www.gnu.or/copyleft/gpl.txt for ! more details. ! ! THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. ! EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES ! PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESS OR IMPLIED, ! INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND ! FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND THE ! PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, ! YOU ASSUME THE COST OF ALL NECESSARY SERVICING, REPAIR OR CORRECTION. ! ! IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING, ! WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR REDISTRIBUTE ! THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY ! GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OR ! INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF DATA OR DATA ! BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD PARTIES OR A ! FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS), EVEN IF SUCH HOLDER ! OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. ! ! You should have received a copy of the GNU General Public License along with ! this program; if not, write to the ! Free Software Foundation, Inc., ! 51 Franklin Street, ! Fifth Floor, ! Boston, MA 02110-1301, USA. ! ! Targacept's address is ! 200 East First Street, Suite 300 ! Winston-Salem, North Carolina USA 27101-4165 ! Attn: Molecular Design. ! Email: atp@targacept.com ! ! This work was supported by the Advanced Technology Program of the ! National Institute of Standards and Technology (NIST), Award No. 70NANB3H3065 ! !******************************************************************************** MODULE autopilot !--------------------------------------------------------------------------- !! This module handles the Autopilot Feature Suite. ! !! Written by Lee Atkinson, with help from the ATP team at Targacept, Inc. !! Created June 2005. !! Modified by Yonas Abraham, Sept 2006. ! ! The address for Targacept, Inc. is: ! 200 East First Street, Suite ! 300, Winston-Salem, North Carolina 27101; ! Attn: Molecular Design. ! !! See README.AUTOPILOT in the Doc directory for more information. !--------------------------------------------------------------------------- USE kinds USE parser, ONLY : read_line IMPLICIT NONE SAVE INTEGER, parameter :: MAX_INT = huge(1) INTEGER, parameter :: max_event_step = 32 !right now there can be upto 32 Autopilot Events INTEGER, parameter :: n_auto_vars = 10 !right now there are only 10 Autopilot Variables INTEGER :: n_events INTEGER :: event_index = 0 INTEGER :: max_rules = 320 !(max_event_step * n_auto_vars) INTEGER :: n_rules INTEGER :: event_step(max_event_step) INTEGER :: current_nfi LOGICAL :: pilot_p = .FALSE. ! pilot property LOGICAL :: restart_p = .FALSE. ! restart property LOGICAL :: pause_p = .FALSE. ! pause property INTEGER :: pilot_unit = 42 ! perhaps move this to io_files CHARACTER(LEN=256) :: pilot_type ! AUTOPILOT VARIABLES ! These are the variable tables which change the actual variable ! dynamically during the course of a simulation. There are many ! parameters which govern a simulation, yet only these are allowed ! to be changed using the event rule mechanism. ! Each of these tables are typed according to their variable ! and begin with event_ ! &CONTROL INTEGER :: rule_isave(max_event_step) INTEGER :: rule_iprint(max_event_step) LOGICAL :: rule_tprint(max_event_step) REAL(DP) :: rule_dt(max_event_step) ! &SYSTEM ! &ELECTRONS REAL(DP) :: rule_emass(max_event_step) CHARACTER(LEN=80) :: rule_electron_dynamics(max_event_step) REAL(DP) :: rule_electron_damping(max_event_step) CHARACTER(LEN=80) :: rule_electron_orthogonalization(max_event_step) ! &IONS CHARACTER(LEN=80) :: rule_ion_dynamics(max_event_step) REAL(DP) :: rule_ion_damping(max_event_step) CHARACTER(LEN=80) :: rule_ion_temperature(max_event_step) REAL(DP) :: rule_tempw(max_event_step) INTEGER :: rule_nhpcl(max_event_step) REAL(DP) :: rule_fnosep(max_event_step) ! &CELL ! &PHONON ! Each rule also needs to be correlated (flagged) against the event time table ! This is used to flag the a given variable is to be changed on an ! event. Initially all set to false, a rule against an event makes it true ! Each of these flags are LOGICALs and begin with event_ ! &CONTROL LOGICAL :: event_isave(max_event_step) LOGICAL :: event_iprint(max_event_step) LOGICAL :: event_tprint(max_event_step) LOGICAL :: event_dt(max_event_step) ! &SYSTEM ! &ELECTRONS LOGICAL :: event_emass(max_event_step) LOGICAL :: event_electron_dynamics(max_event_step) LOGICAL :: event_electron_damping(max_event_step) LOGICAL :: event_electron_orthogonalization(max_event_step) ! &IONS LOGICAL :: event_ion_dynamics(max_event_step) LOGICAL :: event_ion_damping(max_event_step) LOGICAL :: event_ion_temperature(max_event_step) LOGICAL :: event_tempw(max_event_step) LOGICAL :: event_nhpcl(max_event_step) LOGICAL :: event_fnosep(max_event_step) ! &CELL ! &PHONON PRIVATE PUBLIC :: auto_check, init_autopilot, card_autopilot, add_rule, & & assign_rule, restart_p, max_event_step, event_index, event_step, rule_isave, & & rule_iprint, & & rule_tprint, & & rule_dt, rule_emass, rule_electron_dynamics, rule_electron_damping, & & rule_ion_dynamics, rule_ion_damping, rule_ion_temperature, rule_tempw, & & rule_electron_orthogonalization, & & event_isave, event_iprint, & & event_tprint, & & event_dt, event_emass, & & event_electron_dynamics, event_electron_damping, event_ion_dynamics, & & current_nfi, pilot_p, pilot_unit, pause_p,auto_error, parse_mailbox, & & event_ion_damping, event_ion_temperature, event_tempw, & & event_electron_orthogonalization, & & event_nhpcl, event_fnosep, rule_nhpcl, rule_fnosep CONTAINS !---------------------------------------------------------------------------- SUBROUTINE auto_error( calling_routine, message) !---------------------------------------------------------------------------- !! This routine calls errore based upon the pilot property flag. !! If the flag is TRUE, the simulation will not stop, !! but the pause property flag is set to TRUE, !! causing pilot to force a state of sleep, !! until the user can mail proper commands. !! Otherwise, its assumed that dynamics have not started !! and this call is an indirect result of read_cards. !! Thus the simulation will stop. !! Either way errore will always issues a warning message. ! IMPLICIT NONE ! CHARACTER(LEN=*), INTENT(IN) :: calling_routine !! the name of the calling calling_routine CHARACTER(LEN=*), INTENT(IN) :: message !! the output message ! INTEGER :: ierr ! the error flag IF (pilot_p) THEN ! if ierr < 0 errore writes the message but does not stop ierr = -1 pause_p = .TRUE. !call mp_bcast(pause_p, ionode_id, world_comm) ELSE ! if ierr > 0 it stops ierr = 1 ENDIF CALL errore( calling_routine, message, ierr ) END SUBROUTINE auto_error !----------------------------------------------------------------------- ! AUTO (restart) MODE ! ! Checks if restart files are present, just like what readfile_cp does, ! which calls cp_readfile which create a path to restart.xml. ! This could be checked with inquire, as in check_restartfile. ! If restart_mode=auto, and restart.xml is present, ! then restart_mode="restart", else its "from_scratch". ! Set other associated vars, appropriately. ! ! Put this in setcontrol_flags on the select statement !----------------------------------------------------------------------- LOGICAL FUNCTION auto_check (ndr, outdir) !--------------------------------------------------------------------- !! Checks if restart files are present. ! USE io_global, ONLY: ionode, ionode_id USE mp, ONLY : mp_bcast USE mp_world, ONLY : world_comm IMPLICIT NONE INTEGER, INTENT(IN) :: ndr !! I/O unit number CHARACTER(LEN=*), INTENT(IN) :: outdir !! output directory ! ! ... local variables ! CHARACTER(LEN=256) :: dirname, filename CHARACTER (LEN=6), EXTERNAL :: int_to_char LOGICAL :: restart_p = .FALSE. INTEGER :: strlen ! right now cp_readfile is called with outdir = ' ' ! so, in keeping with the current design, ! the responsibility of setting ! ndr and outdir is the calling program IF (ionode) THEN dirname = 'RESTART' // int_to_char( ndr ) IF ( LEN( outdir ) > 1 ) THEN strlen = index(outdir,' ') - 1 dirname = outdir(1:strlen) // '/' // dirname END IF filename = TRIM( dirname ) // '/' // 'restart.xml' INQUIRE( FILE = TRIM( filename ), EXIST = restart_p ) auto_check = restart_p END IF CALL mp_bcast(auto_check, ionode_id, world_comm) return END FUNCTION auto_check !----------------------------------------------------------------------- SUBROUTINE init_autopilot !--------------------------------------------------------------------- !! INITIALIZE AUTOPILOT: must be done, even if not in use. !! Add this as a call in read_cards.f90 sub: card_default_values. ! IMPLICIT NONE ! integer :: event pause_p = .FALSE. ! Initialize all events to an iteration that should never occur DO event=1,max_event_step event_step(event) = MAX_INT ENDDO n_events = 0 n_rules = 0 event_index = 1 ! Initialize here ! &CONTROL event_isave(:) = .false. event_iprint(:) = .false. event_tprint(:) = .false. event_dt(:) = .false. ! &SYSTEM ! &ELECTRONS event_emass(:) = .false. event_electron_dynamics(:) = .false. event_electron_damping(:) = .false. event_electron_orthogonalization(:) = .false. ! &IONS event_ion_dynamics(:) = .false. event_ion_damping(:) = .false. event_ion_temperature(:) = .false. event_tempw(:) = .false. ! &CELL ! &PHONON rule_isave(:) = 0 rule_iprint(:) = 0 rule_tprint(:) = .FALSE. rule_dt(:) = 0.0_DP rule_emass(:) = 0.0_DP rule_electron_dynamics(:) = 'NONE' rule_electron_damping(:) = 0.0_DP rule_ion_dynamics(:) = 'NONE' rule_ion_damping(:) = 0.0_DP rule_ion_temperature(:) = 'NOT_CONTROLLED' rule_tempw(:) = 0.01_DP END SUBROUTINE init_autopilot !----------------------------------------------------------------------- SUBROUTINE card_autopilot( input_line ) !-------------------------------------------------------------------- !! Called in READ_CARDS and in PARSE_MAILBOX. ! USE io_global, ONLY: ionode ! IMPLICIT NONE ! CHARACTER(LEN=256) :: input_line ! ! ... local variables ! INTEGER :: i, j, linelen LOGICAL :: process_this_line = .FALSE. LOGICAL :: endrules = .FALSE. LOGICAL :: tend = .FALSE. LOGICAL, SAVE :: tread = .FALSE. LOGICAL, EXTERNAL :: matches CHARACTER(LEN=1), EXTERNAL :: capital !ASU: copied this here since it seems not to be executed during each ! call of the routine. Needed for multiple rules in same block process_this_line = .FALSE. endrules = .FALSE. tend = .FALSE. tread = .FALSE. ! This is so we do not read a autopilot card twice from the input file IF (( .NOT. pilot_p ) .and. tread ) THEN CALL errore( ' card_autopilot ', ' two occurrences', 2 ) END IF ! If this routined has been called from parse_mailbox ! the pilot_type should be set IF ( pilot_p ) THEN ! IF its MANUAL then process this line first! ! other skip this line and get the next IF (TRIM(pilot_type) .eq. 'MANUAL') THEN process_this_line = .TRUE. ELSE IF (TRIM(pilot_type) .eq. 'PILOT') THEN process_this_line = .FALSE. ELSE IF (TRIM(pilot_type) .eq. 'AUTO') THEN process_this_line = .FALSE. ELSE IF( ionode ) WRITE(*,*) 'AUTOPILOT: UNRECOGNIZED PILOT TYPE!', TRIM(pilot_type), '====' GO TO 10 END IF ELSE ! this routine is called from read_cards pilot_type = 'AUTO' process_this_line = .FALSE. END IF j=0 ! must use a local (j) since n_rules may not get updated correctly DO WHILE ((.NOT. endrules) .and. j<=max_rules) j=j+1 IF (j > max_rules) THEN CALL auto_error( ' AutoPilot ','Maximum Number of Dynamic Rules May Have Been Execced!') go to 10 END IF ! Assume that pilot_p is an indicator and that ! this call to card_autopilot is from parse_mailbox ! and not from read_cards IF(pilot_p) THEN IF ( .NOT. process_this_line ) THEN ! get the next one CALL read_line( input_line, end_of_file = tend) END IF ELSE ! from read_cards CALL read_line( input_line, end_of_file = tend) END IF linelen = LEN_TRIM( input_line ) DO i = 1, linelen input_line( i : i ) = capital( input_line( i : i ) ) END DO ! If ENDRULES isnt found, add_rule will fail ! and we run out of line anyway IF ( tend .or. matches( 'ENDRULES', input_line ) ) GO TO 10 ! Assume this is a rule CALL ADD_RULE(input_line) ! now, do not process this line anymore ! make sure we get the next one process_this_line = .FALSE. END DO IF( ionode ) WRITE(*,*) 'AUTOPILOT SET' 10 CONTINUE END SUBROUTINE card_autopilot !----------------------------------------------------------------------- SUBROUTINE add_rule( input_line ) !--------------------------------------------------------------------- !! ADD RULE ! USE io_global, ONLY: ionode ! IMPLICIT NONE ! CHARACTER(LEN=256) :: input_line ! ! ... local variables ! integer :: i, linelen integer :: eq1_pos, eq2_pos, plus_pos, colon_pos CHARACTER(LEN=32) :: var_label CHARACTER(LEN=32) :: value_str INTEGER :: on_step, now_step, plus_step integer :: ios integer :: event LOGICAL, EXTERNAL :: matches LOGICAL :: new_event ! this is a temporary local variable event = n_events ! important for parsing i=0 eq1_pos = 0 eq2_pos = 0 plus_pos = 0 colon_pos = 0 linelen=LEN_TRIM( input_line ) ! Attempt to get PLUS SYMBOL i = 1 do while( (plus_pos .eq. 0) .and. (i <= linelen) ) i = i + 1 if(input_line( i : i ) .eq. '+') then plus_pos = i endif end do ! Attempt to get a colon i = 1 do while( (colon_pos .eq. 0) .and. (i <= linelen) ) i = i + 1 if(input_line( i : i ) .eq. ':') then colon_pos = i endif end do ! Attempt to get first equals i = 1 do while( (eq1_pos .eq. 0) .and. (i <= linelen) ) i = i + 1 if(input_line( i : i ) .eq. '=') then eq1_pos = i endif end do ! Attempt to get second equals if ((eq1_pos .ne. 0) .and. (eq1_pos < colon_pos)) then i = colon_pos + 1 do while( (eq2_pos .eq. 0) .and. (i <= linelen) ) i = i + 1 if(input_line( i : i ) .eq. '=') then eq2_pos = i endif end do endif ! Complain if there is a bad parse if (colon_pos .eq. 0) then call auto_error( ' AutoPilot ','Missing colon separator') go to 20 endif if (eq1_pos .eq. 0) then call auto_error( ' AutoPilot ','Missing equals sign') go to 20 endif if ((plus_pos > 0) .and. (eq1_pos < colon_pos)) then call auto_error( ' AutoPilot ','equals and plus found prior to colon') go to 20 endif !================================================================================ ! Detect events IF ( (pilot_type .eq. 'MANUAL') .or. (pilot_type .eq. 'PILOT') ) THEN !------------------------------------------- !Do the equivalent of the following: !READ(input_line, *) now_label, plus_label1, plus_step, colon_label, var_label, eq_label2, value_str !Format: ! [NOW [+ plus_step] :] var_label = value_str !------------------------------------------- ! if there is a NOW, get it and try to get plus and plus_step IF ( matches( 'NOW', input_line ) ) THEN ! Attempt to get PLUS_STEP plus_step = 0 ! if all is non-trivial, read a PLUS_STEP if ((plus_pos > 0) .and. (colon_pos > plus_pos)) then ! assume a number lies between read(input_line(plus_pos+1:colon_pos-1),*,iostat=ios) plus_step if(ios .ne. 0) then CALL auto_error( ' AutoPilot ','Value Type Mismatch on NOW line!') go to 20 end if end if ! set NOW event now_step = current_nfi + plus_step ELSE ! set NOW event now_step = current_nfi END IF !================================================================================ ! set event ! ! Heres where it get interesting ! We may have a new event , or not! :) IF ((event-1) .gt. 0) THEN IF ( now_step .lt. event_step(event-1)) THEN IF( ionode ) write(*,*) ' AutoPilot: current input_line', input_line CALL auto_error( ' AutoPilot ','Dynamic Rule Event Out of Order!') go to 20 ENDIF ENDIF IF (event .eq. 0) THEN new_event = .true. ELSEIF ( now_step .gt. event_step(event)) THEN new_event = .true. ELSE new_event = .false. ENDIF IF ( new_event ) THEN ! new event event = event + 1 IF (event > max_event_step) THEN IF( ionode ) write(*,*) ' AutoPilot: current input_line', input_line CALL auto_error( ' AutoPilot ','Maximum Number of Dynamic Rule Event Exceeded!') go to 20 ENDIF event_step(event) = now_step n_events = event ENDIF ELSE IF ( matches( 'ON_STEP', input_line ) ) THEN ! Assuming pilot_type is AUTO ! if it isnt and ON_STEP these rules wont take anyway !------------------------------------------- !Do the equivalent of the following: !READ(input_line, *) on_step_label, eq_label1, on_step, colon_label, var_label, eq_label2, value_str !Format: ! ON_STEP = on_step : var_label = value_str !------------------------------------------- IF( ionode ) write(*,*) 'ADD_RULE: POWER STEERING' ! Attempt to get ON_STEP on_step = MAX_INT ! if all is non-trivial, read a PLUS_STEP if ((eq1_pos > 0) .and. (colon_pos > eq1_pos)) then ! assume a number lies between read(input_line(eq1_pos+1:colon_pos-1),*,iostat=ios) on_step if(ios .ne. 0) then CALL auto_error( ' AutoPilot ','Value Type Mismatch on ON_STEP line!') go to 20 end if end if !================================================================================ ! set event ! ! Heres where it get interesting ! We may have a new event , or not! :) IF ( ((event-1) .gt. 0)) THEN IF ( on_step .lt. event_step(event-1)) THEN IF( ionode ) write(*,*) ' AutoPilot: current input_line', input_line CALL auto_error( ' AutoPilot ','Dynamic Rule Event Out of Order!') go to 20 ENDIF ENDIF IF (event .eq. 0) THEN new_event = .true. ELSEIF (on_step .gt. event_step(event)) THEN new_event = .true. ELSE new_event = .false. ENDIF IF (new_event) THEN ! new event event = event + 1 IF (event > max_event_step) THEN IF( ionode ) write(*,*) ' AutoPilot: current input_line', input_line CALL auto_error( ' AutoPilot ','Maximum Number of Dynamic Rule Event Exceeded!') go to 20 ENDIF event_step(event) = on_step n_events = event ENDIF END IF ! Event Detection Complete !------------------------------------- ! Now look for a label and a value !------------------------------------- if (eq2_pos .eq. 0) then var_label = input_line(colon_pos+1: eq1_pos-1) read( input_line(eq1_pos+1:linelen), *, iostat=ios) value_str if(ios .ne. 0) then CALL auto_error( ' AutoPilot ','Value Type Mismatch on NOW_STEP line!') go to 20 end if else var_label = input_line(colon_pos+1: eq2_pos-1) read( input_line(eq2_pos+1:linelen), *, iostat=ios) value_str if(ios .ne. 0) then CALL auto_error( ' AutoPilot ','Value Type Mismatch on ON_STEP line!') go to 20 end if endif ! The Assignment must lie outside the new event scope since ! there can exists more than one rule per event IF ( (n_rules+1) .gt. max_rules) THEN IF( ionode ) write(*,*) ' AutoPilot: current n_rules', n_rules CALL auto_error( ' AutoPilot ', ' invalid number of rules ') go to 20 END IF call assign_rule(event, var_label, value_str) !IF( ionode ) write(*,*) ' Number of rules: ', n_rules FLUSH(6) 20 CONTINUE END SUBROUTINE add_rule !----------------------------------------------------------------------- SUBROUTINE assign_rule(event, var, value) !--------------------------------------------------------------------- !! ASSIGN RULE ! USE io_global, ONLY: ionode ! IMPLICIT NONE ! INTEGER :: event CHARACTER(LEN=32) :: var CHARACTER(LEN=32) :: value ! ! ... local variables ! INTEGER :: i, varlen INTEGER :: int_value LOGICAL :: logical_value REAL :: real_value REAL(DP) :: realDP_value LOGICAL :: assigned LOGICAL, EXTERNAL :: matches CHARACTER(LEN=1), EXTERNAL :: capital var = TRIM(var) varlen = LEN_TRIM(var) DO i = 1, varlen var( i : i ) = capital( var( i : i ) ) END DO IF( ionode ) write(*,'(" Reading rule: ",A20,A20)' ) var, value assigned = .TRUE. IF ( matches( "ISAVE", var ) ) THEN read(value, *) int_value rule_isave(event) = int_value event_isave(event) = .true. ELSEIF ( matches( "IPRINT", var ) ) THEN read(value, *) int_value rule_iprint(event) = int_value event_iprint(event) = .true. ELSEIF ( matches( "TPRINT", var ) ) THEN read(value, *) logical_value rule_tprint(event) = logical_value event_tprint(event) = .true. ELSEIF ( matches( "DT", var ) ) THEN read(value, *) real_value rule_dt(event) = real_value event_dt(event) = .true. !IF( ionode ) write(*,*) 'RULE_DT', rule_dt(event), 'EVENT', event ELSEIF ( matches( "EMASS", var ) ) THEN read(value, *) realDP_value rule_emass(event) = realDP_value event_emass(event) = .true. ELSEIF ( matches( "ELECTRON_DYNAMICS", var ) ) THEN read(value, *) value if ((value .ne. 'SD') .and. (value .ne. 'VERLET') .and. (value .ne. 'DAMP') & .and. (value .ne. 'NONE') .and. (value .ne. 'CG') ) then call auto_error(' autopilot ',' unknown electron_dynamics '//trim(value) ) assigned = .FALSE. go to 40 endif rule_electron_dynamics(event) = value event_electron_dynamics(event) = .true. ELSEIF ( matches( "ELECTRON_DAMPING", var ) ) THEN read(value, *) realDP_value rule_electron_damping(event) = realDP_value event_electron_damping(event) = .true. ELSEIF ( matches( "ION_DYNAMICS", var ) ) THEN read(value, *) value if ((value .ne. 'SD') .and. (value .ne. 'VERLET') .and. (value .ne. 'DAMP') .and. (value .ne. 'NONE')) then call auto_error(' autopilot ',' unknown ion_dynamics '//trim(value) ) assigned = .FALSE. go to 40 endif rule_ion_dynamics(event) = value event_ion_dynamics(event) = .true. ELSEIF ( matches( "ORTHOGONALIZATION", var) ) THEN read(value, *) value if ( (value .ne. 'ORTHO') .and. (value .ne. 'GRAM-SCHMIDT') ) then call auto_error(' autopilot ',' unknown orthogonalization '//trim(value) ) assigned = .false. go to 40 endif rule_electron_orthogonalization(event) = value event_electron_orthogonalization(event) = .true. ELSEIF ( matches( "ION_DAMPING", var ) ) THEN read(value, *) realDP_value rule_ion_damping(event) = realDP_value event_ion_damping(event) = .true. ELSEIF ( matches( "ION_TEMPERATURE", var ) ) THEN read(value, *) value if ((value .ne. 'NOSE') .and. (value .ne. 'NOT_CONTROLLED') .and. (value .ne. 'RESCALING')) then call auto_error(' autopilot ',' unknown ion_temperature '//trim(value) ) assigned = .FALSE. go to 40 endif rule_ion_temperature(event) = value event_ion_temperature(event) = .true. ELSEIF ( matches( "TEMPW", var ) ) THEN read(value, *) realDP_value rule_tempw(event) = realDP_value event_tempw(event) = .true. ELSEIF ( matches( "NHPCL", var ) ) THEN read(value, *) int_value rule_nhpcl(event) = int_value event_nhpcl(event) = .true. ELSEIF ( matches( "FNOSEP", var ) ) THEN read(value, *) realDP_value rule_fnosep(event) = realDP_value event_fnosep(event) = .true. ELSE CALL auto_error( 'autopilot', ' ASSIGN_RULE: FAILED '//trim(var)//' '//trim(value) ) END IF 40 if (assigned) then n_rules = n_rules + 1 else IF( ionode ) write(*,*) ' Autopilot: Rule Assignment Failure ' CALL auto_error( 'autopilot', ' ASSIGN_RULE: FAILED '//trim(var)//' '//trim(value) ) endif END SUBROUTINE assign_rule !----------------------------------------------------------------------- SUBROUTINE parse_mailbox () !--------------------------------------------------------------------- !! Read the mailbox with a mailbox parser: ! !! * if it starts with ON_STEP, then apply to event table etc; !! * if not the try to establish that its a variable to set right now. ! USE io_global, ONLY: ionode ! IMPLICIT NONE ! INTEGER :: i CHARACTER(LEN=256) :: input_line LOGICAL :: tend CHARACTER(LEN=1), EXTERNAL :: capital LOGICAL, EXTERNAL :: matches ! we can use this parser routine, since parse_unit=pilot_unit CALL read_line( input_line, end_of_file=tend ) IF (tend) GO TO 50 DO i = 1, LEN_TRIM( input_line ) input_line( i : i ) = capital( input_line( i : i ) ) END DO ! This conditional implements the PAUSE feature calling init_auto_pilot, ! will reset this modules global PAUSE_P variable to FALSE IF ( matches( "PAUSE", input_line ) .or. & matches( "SLEEP", input_line ) .or. & matches( "HOVER", input_line ) .or. & matches( "WAIT", input_line ) .or. & matches( "HOLD", input_line ) ) THEN IF( ionode ) write(*,*) 'SLEEPING' IF( ionode ) write(*,*) 'INPUT_LINE=', input_line pause_p = .TRUE. ! now you can pass continue to resume ELSE IF (matches( "CONTINUE", input_line ) .or. & matches( "RESUME", input_line ) ) THEN IF( ionode ) write(*,*) 'RUNNING' IF( ionode ) write(*,*) 'INPUT_LINE=', input_line pause_p = .FALSE. ! Now just quit this subroutine ELSE ! Also, We didnt see a PAUSE cmd! pause_p = .FALSE. ! now lets detect the mode for card_autopilot ! even though this line will be passed to it the first time IF ( matches( "AUTOPILOT", TRIM(input_line) ) ) THEN IF( ionode ) WRITE(*,*) ' New autopilot course detected' pilot_type ='AUTO' ELSE IF (matches( "PILOT", TRIM(input_line) ) ) THEN IF( ionode ) WRITE(*,*) ' Relative pilot course correction detected' pilot_type ='PILOT' ELSE IF (matches( "NOW", TRIM(input_line) ) ) THEN IF( ionode ) WRITE(*,*) ' Manual piloting detected' pilot_type ='MANUAL' ELSE ! Well lets just pause since this guys is throwing trash IF( ionode ) WRITE(*,*) ' Mailbox contents not understood: pausing' pause_p = .TRUE. ENDIF END IF IF (pause_p) GO TO 50 ! ok if one adds a rule during steering` ! event table must be cleared (from steer point) forward ! ! Every nodes gets this (and the call to card_autopilot ! which calls add_rule, which calls assign_rule, etc ! In this way we sync the event table ! Then we shouldn't have to sync employ_rules variable ! changes, or their subroutine side effects (like ions_nose_init) CALL init_autopilot() CALL card_autopilot( input_line ) 50 CONTINUE end subroutine parse_mailbox END MODULE autopilot
gpl-2.0
QEF/q-e
PW/src/efermig.f90
2
9960
! ! Copyright (C) 2001-2003 PWSCF group ! This file is distributed under the terms of the ! GNU General Public License. See the file `License' ! in the root directory of the present distribution, ! or http://www.gnu.org/copyleft/gpl.txt . ! !-------------------------------------------------------------------- FUNCTION efermig( et, nbnd, nks, nelec, wk, Degauss, Ngauss, is, isk ) !-------------------------------------------------------------------- !! Finds the Fermi energy - Gaussian Broadening. !! (see Methfessel and Paxton, PRB 40, 3616 (1989 ) ! USE io_global, ONLY : stdout USE kinds, ONLY : DP USE constants, ONLY : rytoev USE mp, ONLY : mp_max, mp_min USE mp_pools, ONLY : inter_pool_comm ! IMPLICIT NONE ! INTEGER, INTENT(IN) :: nks !! number of k points in this pool INTEGER, INTENT(IN) :: nbnd !! number of bands INTEGER, INTENT(IN) :: Ngauss !! type of smearing technique INTEGER, INTENT(IN) :: is !! spin label (0 or 1,2) INTEGER, INTENT(IN) :: isk(nks) !! for each k-point: 1=spin up, 2=spin down REAL(DP), INTENT(IN) :: wk(nks) !! weight of k points REAL(DP), INTENT(IN) :: et(nbnd,nks) !! eigenvalues of the hamiltonian REAL(DP), INTENT(IN) :: Degauss !! smearing parameter REAL(DP), INTENT(IN) :: nelec !! number of electrons REAL(DP) :: efermig !! the Fermi energy ! ! ... local variables ! REAL(DP), PARAMETER :: eps = 1.0d-10, eps_cold_MP = 1.0d-2 !! tolerance for the number of electrons, important for bisection !! smaller tolerance for the number of electrons, important for M-P and Cold smearings INTEGER, PARAMETER :: maxiter = 300 ! REAL(DP) :: Ef, Eup, Elw, sumkup, sumklw, sumkmid REAL(DP), EXTERNAL :: sumkg, sumkg1, sumkg2 !! Function to compute the number of electrons for a given energy !! Function to compute the first derivative of the number of electrons !! Function to compute the second derivative of the number of electrons INTEGER :: i, kpoint, Ngauss_ INTEGER :: info, maxiter_aux ! ! ... find (very safe) bounds for the Fermi energy: ! Elw = lowest, Eup = highest energy among all k-points. ! Works with distributed k-points, also if nks=0 on some processor ! Elw = 1.0E+8 Eup =-1.0E+8 DO kpoint = 1, nks Elw = MIN( Elw, et(1,kpoint) ) Eup = MAX( Eup, et(nbnd,kpoint) ) ENDDO Eup = Eup + 10 * Degauss Elw = Elw - 10 * Degauss ! ! ... find min and max across pools ! CALL mp_max( eup, inter_pool_comm ) CALL mp_min( elw, inter_pool_comm ) ! ! For M-P and cold smearings, perform a preliminary determination with the Gaussian broadening ! to obtain an initial guess if( Ngauss .NE. -99 ) then Ngauss_ = 0 else ! If Fermi-Dirac smearing, the preliminary bisection can run with the F-D smearing itself Ngauss_ = Ngauss end if maxiter_aux = maxiter call bisection_find_efermi(num_electrons_minus_nelec, Elw, Eup, ef, eps, maxiter_aux, info) ! Error handling select case( info ) case( 1 ) IF (is /= 0) WRITE(stdout, '(5x,"Spin Component #",i3)') is WRITE( stdout, '(5x,"Warning: too many iterations in bisection" & & 5x,"Ef (eV) = ",f15.6," Num. electrons = ",f10.6)' ) & Ef * rytoev, num_electrons(Ef) case( 2 ) call errore( 'efermig', 'internal error, cannot bracket Ef', 1 ) end select ! If this initial guess already corresponds to the correct number of electron for the actual occupation function, the Fermi energy is found. Ngauss_ = Ngauss ! In case Ngauss = 0 or -99, the function returns here too. if( abs_num_electrons_minus_nelec(ef) < eps .or. Ngauss == 0 .or. Ngauss == -99) then efermig = ef goto 98765 end if ! If the initial prospected Ef did not provide the correct number of electrons, use Newton's methods to improve it. ! Use the prospected Ef as initial guess. maxiter_aux = maxiter if( Ngauss_ > 0 .or. Ngauss_ == -1 ) then ! If methfessel-paxton method or Cold smearing method call newton_minimization(dev1_sq_num_electrons, dev2_sq_num_electrons, ef, eps, maxiter_aux, info) end if ! Error handling select case( info ) case( 1 ) IF (is /= 0) WRITE(stdout, '(5x,"Spin Component #",i3)') is WRITE( stdout, '(5x,"Warning: too many iterations in Newtons minimization"/ & & 5x,"Ef (eV) = ",f15.6," Num. electrons = ",f10.6," Num. steps = ",i0)' ) & Ef * rytoev, num_electrons(Ef), maxiter end select if( (Ngauss_ == -1 .or. Ngauss_ > 0) .and. ( abs_num_electrons_minus_nelec(ef) < eps_cold_MP ) ) then efermig = ef else ! If Newton's minimization did not help. Just use bisection with the actual smearing, which reproduce the original behavior of this function Ngauss_ = Ngauss maxiter_aux = maxiter call bisection_find_efermi(num_electrons_minus_nelec, Elw, Eup, ef, eps, maxiter_aux, info) efermig = ef IF (is /= 0) WRITE(stdout, '(5x,"Spin Component #",i3)') is WRITE( stdout, '(5x,"Minimization algorithm failed to find Fermi energy: reverting to bisection",& & /,5x,"Possible cause: smearing is larger than the electronic band-gap.")' ) end if 98765 continue return contains function num_electrons_minus_nelec(x) real(DP), intent(in) :: x real(DP) :: num_electrons_minus_nelec num_electrons_minus_nelec = num_electrons(x) - nelec end function num_electrons_minus_nelec function num_electrons(ef) real(DP), intent(in) :: ef real(DP) :: num_electrons num_electrons = sumkg( et, nbnd, nks, wk, Degauss, Ngauss_, ef, is, isk ) end function num_electrons function abs_num_electrons_minus_nelec(ef) real(DP), intent(in) :: ef real(DP) :: abs_num_electrons_minus_nelec abs_num_electrons_minus_nelec = abs(num_electrons_minus_nelec(ef)) end function abs_num_electrons_minus_nelec function sq_num_electrons_minus_nelec(ef) real(DP), intent(in) :: ef real(DP) :: sq_num_electrons_minus_nelec sq_num_electrons_minus_nelec = (num_electrons_minus_nelec(ef))**2 end function sq_num_electrons_minus_nelec function dev1_num_electrons(ef) real(DP), intent(in) :: ef real(DP) :: dev1_num_electrons dev1_num_electrons = sumkg1( et, nbnd, nks, wk, Degauss, Ngauss_, ef, is, isk ) end function dev1_num_electrons function dev2_num_electrons(ef) real(DP), intent(in) :: ef real(DP) :: dev2_num_electrons dev2_num_electrons = sumkg2( et, nbnd, nks, wk, Degauss, Ngauss_, ef, is, isk ) end function dev2_num_electrons function dev1_sq_num_electrons(ef) real(DP), intent(in) :: ef real(DP) :: dev1_sq_num_electrons dev1_sq_num_electrons = 2.d0 * num_electrons_minus_nelec(ef) * dev1_num_electrons(ef) end function dev1_sq_num_electrons function dev2_sq_num_electrons(ef) real(DP), intent(in) :: ef real(DP) :: dev2_sq_num_electrons dev2_sq_num_electrons = 2.d0 * ( (dev1_num_electrons(ef))**2 + num_electrons_minus_nelec(ef) * dev2_num_electrons(ef) ) end function dev2_sq_num_electrons subroutine newton_minimization(f1, f2, x, tol, Nmax, info) real(DP), intent(inout) :: x !! Initial guess in the entry. Solution in the exit real(DP), intent(in) :: tol integer, intent(inout) :: Nmax integer, intent(out) :: info !! 0 = solution found; 1 = max number of step (Nmax) reached; 2 = second derivative is zero real(DP) :: abstol, x0, denominator, numerator, factor integer :: i real(DP) :: f1, f2 abstol = abs(tol) x0 = x factor = 1.0d0 do i = 1, Nmax numerator = f1(x) denominator = abs(f2(x)) ! Checking if the denominator is zero if( denominator > abstol ) then x = x0 - factor*numerator/denominator ! Checking if a stationary point was achieved if( abs(x0-x) < abstol .or. abs_num_electrons_minus_nelec(x) < abstol ) then info = 0 Nmax = i return ! If a stationary point was not achieved, continue else x0 = x end if ! If denominator is zero, return an error else info = 2 return end if end do ! Checking if max number of steps was reached if( i > Nmax ) then info = 1 return end if end subroutine newton_minimization subroutine bisection_find_efermi(f, energy_lower_bound, energy_upper_bound, x, tol, Nmax, info) real(DP), intent(in) :: energy_lower_bound real(DP), intent(in) :: energy_upper_bound real(DP), intent(out) :: x !! Found Fermi energy at exit real(DP), intent(in) :: tol integer, intent(inout) :: Nmax !! In entry: Max number of steps. In exit: number of step taken. integer, intent(out) :: info !! 0 = solution found; 1 = max number of step (Nmax) reached; 2 = cannot bracket root real(DP) :: abs_tol, fx, Elw_local, Eup_local integer :: i real(DP), EXTERNAL :: f abs_tol = abs(tol) Elw_local = energy_lower_bound Eup_local = energy_upper_bound if( f(Elw_local) > abs_tol .or. f(Eup_local) < -abs_tol ) then info = 2 return end if do i = 1, Nmax x = ( Eup_local + Elw_local ) * 0.5d0 fx = f(x) ! Was the root found? if( abs(fx) < abs_tol ) then info = 0 Nmax = i return else ! Choosing new boundaries if( fx < -abs_tol ) then Elw_local = x else Eup_local = x end if end if end do ! Checking if max number of steps was reached if( i > Nmax ) then info = 1 return end if end subroutine bisection_find_efermi END FUNCTION efermig
gpl-2.0
wilmarcardonac/hypermcmc
lapack-3.5.0/SRC/cupgtr.f
28
6108
*> \brief \b CUPGTR * * =========== DOCUMENTATION =========== * * Online html documentation available at * http://www.netlib.org/lapack/explore-html/ * *> \htmlonly *> Download CUPGTR + dependencies *> <a href="http://www.netlib.org/cgi-bin/netlibfiles.tgz?format=tgz&filename=/lapack/lapack_routine/cupgtr.f"> *> [TGZ]</a> *> <a href="http://www.netlib.org/cgi-bin/netlibfiles.zip?format=zip&filename=/lapack/lapack_routine/cupgtr.f"> *> [ZIP]</a> *> <a href="http://www.netlib.org/cgi-bin/netlibfiles.txt?format=txt&filename=/lapack/lapack_routine/cupgtr.f"> *> [TXT]</a> *> \endhtmlonly * * Definition: * =========== * * SUBROUTINE CUPGTR( UPLO, N, AP, TAU, Q, LDQ, WORK, INFO ) * * .. Scalar Arguments .. * CHARACTER UPLO * INTEGER INFO, LDQ, N * .. * .. Array Arguments .. * COMPLEX AP( * ), Q( LDQ, * ), TAU( * ), WORK( * ) * .. * * *> \par Purpose: * ============= *> *> \verbatim *> *> CUPGTR generates a complex unitary matrix Q which is defined as the *> product of n-1 elementary reflectors H(i) of order n, as returned by *> CHPTRD using packed storage: *> *> if UPLO = 'U', Q = H(n-1) . . . H(2) H(1), *> *> if UPLO = 'L', Q = H(1) H(2) . . . H(n-1). *> \endverbatim * * Arguments: * ========== * *> \param[in] UPLO *> \verbatim *> UPLO is CHARACTER*1 *> = 'U': Upper triangular packed storage used in previous *> call to CHPTRD; *> = 'L': Lower triangular packed storage used in previous *> call to CHPTRD. *> \endverbatim *> *> \param[in] N *> \verbatim *> N is INTEGER *> The order of the matrix Q. N >= 0. *> \endverbatim *> *> \param[in] AP *> \verbatim *> AP is COMPLEX array, dimension (N*(N+1)/2) *> The vectors which define the elementary reflectors, as *> returned by CHPTRD. *> \endverbatim *> *> \param[in] TAU *> \verbatim *> TAU is COMPLEX array, dimension (N-1) *> TAU(i) must contain the scalar factor of the elementary *> reflector H(i), as returned by CHPTRD. *> \endverbatim *> *> \param[out] Q *> \verbatim *> Q is COMPLEX array, dimension (LDQ,N) *> The N-by-N unitary matrix Q. *> \endverbatim *> *> \param[in] LDQ *> \verbatim *> LDQ is INTEGER *> The leading dimension of the array Q. LDQ >= max(1,N). *> \endverbatim *> *> \param[out] WORK *> \verbatim *> WORK is COMPLEX array, dimension (N-1) *> \endverbatim *> *> \param[out] INFO *> \verbatim *> INFO is INTEGER *> = 0: successful exit *> < 0: if INFO = -i, the i-th argument had an illegal value *> \endverbatim * * Authors: * ======== * *> \author Univ. of Tennessee *> \author Univ. of California Berkeley *> \author Univ. of Colorado Denver *> \author NAG Ltd. * *> \date November 2011 * *> \ingroup complexOTHERcomputational * * ===================================================================== SUBROUTINE CUPGTR( UPLO, N, AP, TAU, Q, LDQ, WORK, INFO ) * * -- LAPACK computational routine (version 3.4.0) -- * -- LAPACK is a software package provided by Univ. of Tennessee, -- * -- Univ. of California Berkeley, Univ. of Colorado Denver and NAG Ltd..-- * November 2011 * * .. Scalar Arguments .. CHARACTER UPLO INTEGER INFO, LDQ, N * .. * .. Array Arguments .. COMPLEX AP( * ), Q( LDQ, * ), TAU( * ), WORK( * ) * .. * * ===================================================================== * * .. Parameters .. COMPLEX CZERO, CONE PARAMETER ( CZERO = ( 0.0E+0, 0.0E+0 ), $ CONE = ( 1.0E+0, 0.0E+0 ) ) * .. * .. Local Scalars .. LOGICAL UPPER INTEGER I, IINFO, IJ, J * .. * .. External Functions .. LOGICAL LSAME EXTERNAL LSAME * .. * .. External Subroutines .. EXTERNAL CUNG2L, CUNG2R, XERBLA * .. * .. Intrinsic Functions .. INTRINSIC MAX * .. * .. Executable Statements .. * * Test the input arguments * INFO = 0 UPPER = LSAME( UPLO, 'U' ) IF( .NOT.UPPER .AND. .NOT.LSAME( UPLO, 'L' ) ) THEN INFO = -1 ELSE IF( N.LT.0 ) THEN INFO = -2 ELSE IF( LDQ.LT.MAX( 1, N ) ) THEN INFO = -6 END IF IF( INFO.NE.0 ) THEN CALL XERBLA( 'CUPGTR', -INFO ) RETURN END IF * * Quick return if possible * IF( N.EQ.0 ) $ RETURN * IF( UPPER ) THEN * * Q was determined by a call to CHPTRD with UPLO = 'U' * * Unpack the vectors which define the elementary reflectors and * set the last row and column of Q equal to those of the unit * matrix * IJ = 2 DO 20 J = 1, N - 1 DO 10 I = 1, J - 1 Q( I, J ) = AP( IJ ) IJ = IJ + 1 10 CONTINUE IJ = IJ + 2 Q( N, J ) = CZERO 20 CONTINUE DO 30 I = 1, N - 1 Q( I, N ) = CZERO 30 CONTINUE Q( N, N ) = CONE * * Generate Q(1:n-1,1:n-1) * CALL CUNG2L( N-1, N-1, N-1, Q, LDQ, TAU, WORK, IINFO ) * ELSE * * Q was determined by a call to CHPTRD with UPLO = 'L'. * * Unpack the vectors which define the elementary reflectors and * set the first row and column of Q equal to those of the unit * matrix * Q( 1, 1 ) = CONE DO 40 I = 2, N Q( I, 1 ) = CZERO 40 CONTINUE IJ = 3 DO 60 J = 2, N Q( 1, J ) = CZERO DO 50 I = J + 1, N Q( I, J ) = AP( IJ ) IJ = IJ + 1 50 CONTINUE IJ = IJ + 2 60 CONTINUE IF( N.GT.1 ) THEN * * Generate Q(2:n,2:n) * CALL CUNG2R( N-1, N-1, N-1, Q( 2, 2 ), LDQ, TAU, WORK, $ IINFO ) END IF END IF RETURN * * End of CUPGTR * END
gpl-2.0
mjhsieh/FF4MM
src/framework.f
1
1714
! Copyright (c) 2010, Mengjuei Hsieh, ! All rights reserved. - please read information in "LICENCSE.txt" ! Written by Mengjuei Hsieh, University of California Irvine #include "definitions.fpp" ! This will be the main module that should be providing ! 1. public storage of variables ! 2. interface for callers ! ! Rule 1: Use one dimension array so that it would be easier to ! do parallelisation. module tienchun ! Acquired data integer :: natom _REAL_, allocatable :: x(:) _REAL_, allocatable :: mass(:) _REAL_, allocatable :: r_vdw(:) ! Acquired or Computed data _REAL_, allocatable :: f(:) _REAL_, allocatable :: v(:) _REAL_, allocatable :: oldv(:) ! Computed system states ! RNDF_SOLUTE: net (real) number of degrees of freedom for solute ! RNDF_SOLVENT: net (real) number of degrees of freedom for solvent ! RNDF: total (real) number of degrees of freedom ! User Control: Geometry logical :: usePBC !(periodic boundary condition) logical :: usePIB !(particle in a box) _REAL_ :: xmin, ymin, zmin _REAL_ :: xmax, ymax, zmax ! User Control: Force _REAL_ :: vdwcutoff _REAL_ :: eelcutoff ! User Control: Types of computation logical :: doMD !Molecular Dynamics ! logical :: doMIN !Minimization ! logical :: doMC !Monte Carlo ! User Control: MD and MC _REAL_ :: dt !timestep, δt _REAL_ :: dt2 !2*δt _REAL_ :: dtsq !δt**2 end module tienchun ! The origin of module name, TienChun, is a town in central Taiwan.
bsd-3-clause
markusappel/McCode
support/MacOSX/pgplot/pgplot-src-mac/src/grsets.f
6
1746
C*GRSETS -- change size of view surface C+ SUBROUTINE GRSETS (IDENT,XSIZE,YSIZE) C C GRPCKG : change size of plotting area. The requested dimensions C will be reduced to the absolute maximum of the plot device if C necessary. C C Arguments: C C IDENT (input, integer): plot identifier from GROPEN. C XSIZE (input, real): new x dimension of plot area (absolute C units); if less than zero, the default dimension C will be used. C YSIZE (input, real): new y dimension of plot area (absolute C units); if less than zero, the default dimension C will be used. C-- C (1-Feb-1983) C 5-Aug-1986 - add GREXEC support [AFT]. C 5-Jan-1993 - set GRADJU [TJP]. C------------------------------------------------------------------------ INCLUDE 'grpckg1.inc' INTEGER I, IDENT, J, IX, IY, NBUF,LCHR REAL RBUF(6) CHARACTER CHR REAL XSIZE,YSIZE C CALL GRSLCT(IDENT) C write (*,*) 'GRSETS: old size', GRXMXA(IDENT), GRYMXA(IDENT) CALL GRPAGE IF ((XSIZE .LT. 0.0) .OR. (YSIZE .LT. 0.0)) THEN CALL GREXEC(GRGTYP, 6,RBUF,NBUF,CHR,LCHR) GRXMXA(IDENT) = RBUF(2) GRYMXA(IDENT) = RBUF(4) ELSE I = NINT(XSIZE) J = NINT(YSIZE) CALL GREXEC(GRGTYP, 2,RBUF,NBUF,CHR,LCHR) IX=RBUF(2) IY=RBUF(4) IF (IX.GT.0) I = MIN(I,IX) IF (IY.GT.0) J = MIN(J,IY) GRXMXA(IDENT) = I GRYMXA(IDENT) = J END IF C write (*,*) 'GRSETS: new size', GRXMXA(IDENT), GRYMXA(IDENT) GRXMIN(IDENT) = 0 GRXMAX(IDENT) = GRXMXA(IDENT) GRYMIN(IDENT) = 0 GRYMAX(IDENT) = GRYMXA(IDENT) GRADJU(IDENT) = .TRUE. C END
gpl-2.0
wilmarcardonac/hypermcmc
lapack-3.5.0/SRC/chesvxx.f
25
27120
*> \brief <b> CHESVXX computes the solution to system of linear equations A * X = B for HE matrices</b> * * =========== DOCUMENTATION =========== * * Online html documentation available at * http://www.netlib.org/lapack/explore-html/ * *> \htmlonly *> Download CHESVXX + dependencies *> <a href="http://www.netlib.org/cgi-bin/netlibfiles.tgz?format=tgz&filename=/lapack/lapack_routine/chesvxx.f"> *> [TGZ]</a> *> <a href="http://www.netlib.org/cgi-bin/netlibfiles.zip?format=zip&filename=/lapack/lapack_routine/chesvxx.f"> *> [ZIP]</a> *> <a href="http://www.netlib.org/cgi-bin/netlibfiles.txt?format=txt&filename=/lapack/lapack_routine/chesvxx.f"> *> [TXT]</a> *> \endhtmlonly * * Definition: * =========== * * SUBROUTINE CHESVXX( FACT, UPLO, N, NRHS, A, LDA, AF, LDAF, IPIV, * EQUED, S, B, LDB, X, LDX, RCOND, RPVGRW, BERR, * N_ERR_BNDS, ERR_BNDS_NORM, ERR_BNDS_COMP, * NPARAMS, PARAMS, WORK, RWORK, INFO ) * * .. Scalar Arguments .. * CHARACTER EQUED, FACT, UPLO * INTEGER INFO, LDA, LDAF, LDB, LDX, N, NRHS, NPARAMS, * $ N_ERR_BNDS * REAL RCOND, RPVGRW * .. * .. Array Arguments .. * INTEGER IPIV( * ) * COMPLEX A( LDA, * ), AF( LDAF, * ), B( LDB, * ), * $ WORK( * ), X( LDX, * ) * REAL S( * ), PARAMS( * ), BERR( * ), RWORK( * ), * $ ERR_BNDS_NORM( NRHS, * ), * $ ERR_BNDS_COMP( NRHS, * ) * .. * * *> \par Purpose: * ============= *> *> \verbatim *> *> CHESVXX uses the diagonal pivoting factorization to compute the *> solution to a complex system of linear equations A * X = B, where *> A is an N-by-N symmetric matrix and X and B are N-by-NRHS *> matrices. *> *> If requested, both normwise and maximum componentwise error bounds *> are returned. CHESVXX will return a solution with a tiny *> guaranteed error (O(eps) where eps is the working machine *> precision) unless the matrix is very ill-conditioned, in which *> case a warning is returned. Relevant condition numbers also are *> calculated and returned. *> *> CHESVXX accepts user-provided factorizations and equilibration *> factors; see the definitions of the FACT and EQUED options. *> Solving with refinement and using a factorization from a previous *> CHESVXX call will also produce a solution with either O(eps) *> errors or warnings, but we cannot make that claim for general *> user-provided factorizations and equilibration factors if they *> differ from what CHESVXX would itself produce. *> \endverbatim * *> \par Description: * ================= *> *> \verbatim *> *> The following steps are performed: *> *> 1. If FACT = 'E', real scaling factors are computed to equilibrate *> the system: *> *> diag(S)*A*diag(S) *inv(diag(S))*X = diag(S)*B *> *> Whether or not the system will be equilibrated depends on the *> scaling of the matrix A, but if equilibration is used, A is *> overwritten by diag(S)*A*diag(S) and B by diag(S)*B. *> *> 2. If FACT = 'N' or 'E', the LU decomposition is used to factor *> the matrix A (after equilibration if FACT = 'E') as *> *> A = U * D * U**T, if UPLO = 'U', or *> A = L * D * L**T, if UPLO = 'L', *> *> where U (or L) is a product of permutation and unit upper (lower) *> triangular matrices, and D is symmetric and block diagonal with *> 1-by-1 and 2-by-2 diagonal blocks. *> *> 3. If some D(i,i)=0, so that D is exactly singular, then the *> routine returns with INFO = i. Otherwise, the factored form of A *> is used to estimate the condition number of the matrix A (see *> argument RCOND). If the reciprocal of the condition number is *> less than machine precision, the routine still goes on to solve *> for X and compute error bounds as described below. *> *> 4. The system of equations is solved for X using the factored form *> of A. *> *> 5. By default (unless PARAMS(LA_LINRX_ITREF_I) is set to zero), *> the routine will use iterative refinement to try to get a small *> error and error bounds. Refinement calculates the residual to at *> least twice the working precision. *> *> 6. If equilibration was used, the matrix X is premultiplied by *> diag(R) so that it solves the original system before *> equilibration. *> \endverbatim * * Arguments: * ========== * *> \verbatim *> Some optional parameters are bundled in the PARAMS array. These *> settings determine how refinement is performed, but often the *> defaults are acceptable. If the defaults are acceptable, users *> can pass NPARAMS = 0 which prevents the source code from accessing *> the PARAMS argument. *> \endverbatim *> *> \param[in] FACT *> \verbatim *> FACT is CHARACTER*1 *> Specifies whether or not the factored form of the matrix A is *> supplied on entry, and if not, whether the matrix A should be *> equilibrated before it is factored. *> = 'F': On entry, AF and IPIV contain the factored form of A. *> If EQUED is not 'N', the matrix A has been *> equilibrated with scaling factors given by S. *> A, AF, and IPIV are not modified. *> = 'N': The matrix A will be copied to AF and factored. *> = 'E': The matrix A will be equilibrated if necessary, then *> copied to AF and factored. *> \endverbatim *> *> \param[in] UPLO *> \verbatim *> UPLO is CHARACTER*1 *> = 'U': Upper triangle of A is stored; *> = 'L': Lower triangle of A is stored. *> \endverbatim *> *> \param[in] N *> \verbatim *> N is INTEGER *> The number of linear equations, i.e., the order of the *> matrix A. N >= 0. *> \endverbatim *> *> \param[in] NRHS *> \verbatim *> NRHS is INTEGER *> The number of right hand sides, i.e., the number of columns *> of the matrices B and X. NRHS >= 0. *> \endverbatim *> *> \param[in,out] A *> \verbatim *> A is COMPLEX array, dimension (LDA,N) *> The symmetric matrix A. If UPLO = 'U', the leading N-by-N *> upper triangular part of A contains the upper triangular *> part of the matrix A, and the strictly lower triangular *> part of A is not referenced. If UPLO = 'L', the leading *> N-by-N lower triangular part of A contains the lower *> triangular part of the matrix A, and the strictly upper *> triangular part of A is not referenced. *> *> On exit, if FACT = 'E' and EQUED = 'Y', A is overwritten by *> diag(S)*A*diag(S). *> \endverbatim *> *> \param[in] LDA *> \verbatim *> LDA is INTEGER *> The leading dimension of the array A. LDA >= max(1,N). *> \endverbatim *> *> \param[in,out] AF *> \verbatim *> AF is COMPLEX array, dimension (LDAF,N) *> If FACT = 'F', then AF is an input argument and on entry *> contains the block diagonal matrix D and the multipliers *> used to obtain the factor U or L from the factorization A = *> U*D*U**T or A = L*D*L**T as computed by SSYTRF. *> *> If FACT = 'N', then AF is an output argument and on exit *> returns the block diagonal matrix D and the multipliers *> used to obtain the factor U or L from the factorization A = *> U*D*U**T or A = L*D*L**T. *> \endverbatim *> *> \param[in] LDAF *> \verbatim *> LDAF is INTEGER *> The leading dimension of the array AF. LDAF >= max(1,N). *> \endverbatim *> *> \param[in,out] IPIV *> \verbatim *> IPIV is INTEGER array, dimension (N) *> If FACT = 'F', then IPIV is an input argument and on entry *> contains details of the interchanges and the block *> structure of D, as determined by CHETRF. If IPIV(k) > 0, *> then rows and columns k and IPIV(k) were interchanged and *> D(k,k) is a 1-by-1 diagonal block. If UPLO = 'U' and *> IPIV(k) = IPIV(k-1) < 0, then rows and columns k-1 and *> -IPIV(k) were interchanged and D(k-1:k,k-1:k) is a 2-by-2 *> diagonal block. If UPLO = 'L' and IPIV(k) = IPIV(k+1) < 0, *> then rows and columns k+1 and -IPIV(k) were interchanged *> and D(k:k+1,k:k+1) is a 2-by-2 diagonal block. *> *> If FACT = 'N', then IPIV is an output argument and on exit *> contains details of the interchanges and the block *> structure of D, as determined by CHETRF. *> \endverbatim *> *> \param[in,out] EQUED *> \verbatim *> EQUED is CHARACTER*1 *> Specifies the form of equilibration that was done. *> = 'N': No equilibration (always true if FACT = 'N'). *> = 'Y': Both row and column equilibration, i.e., A has been *> replaced by diag(S) * A * diag(S). *> EQUED is an input argument if FACT = 'F'; otherwise, it is an *> output argument. *> \endverbatim *> *> \param[in,out] S *> \verbatim *> S is REAL array, dimension (N) *> The scale factors for A. If EQUED = 'Y', A is multiplied on *> the left and right by diag(S). S is an input argument if FACT = *> 'F'; otherwise, S is an output argument. If FACT = 'F' and EQUED *> = 'Y', each element of S must be positive. If S is output, each *> element of S is a power of the radix. If S is input, each element *> of S should be a power of the radix to ensure a reliable solution *> and error estimates. Scaling by powers of the radix does not cause *> rounding errors unless the result underflows or overflows. *> Rounding errors during scaling lead to refining with a matrix that *> is not equivalent to the input matrix, producing error estimates *> that may not be reliable. *> \endverbatim *> *> \param[in,out] B *> \verbatim *> B is COMPLEX array, dimension (LDB,NRHS) *> On entry, the N-by-NRHS right hand side matrix B. *> On exit, *> if EQUED = 'N', B is not modified; *> if EQUED = 'Y', B is overwritten by diag(S)*B; *> \endverbatim *> *> \param[in] LDB *> \verbatim *> LDB is INTEGER *> The leading dimension of the array B. LDB >= max(1,N). *> \endverbatim *> *> \param[out] X *> \verbatim *> X is COMPLEX array, dimension (LDX,NRHS) *> If INFO = 0, the N-by-NRHS solution matrix X to the original *> system of equations. Note that A and B are modified on exit if *> EQUED .ne. 'N', and the solution to the equilibrated system is *> inv(diag(S))*X. *> \endverbatim *> *> \param[in] LDX *> \verbatim *> LDX is INTEGER *> The leading dimension of the array X. LDX >= max(1,N). *> \endverbatim *> *> \param[out] RCOND *> \verbatim *> RCOND is REAL *> Reciprocal scaled condition number. This is an estimate of the *> reciprocal Skeel condition number of the matrix A after *> equilibration (if done). If this is less than the machine *> precision (in particular, if it is zero), the matrix is singular *> to working precision. Note that the error may still be small even *> if this number is very small and the matrix appears ill- *> conditioned. *> \endverbatim *> *> \param[out] RPVGRW *> \verbatim *> RPVGRW is REAL *> Reciprocal pivot growth. On exit, this contains the reciprocal *> pivot growth factor norm(A)/norm(U). The "max absolute element" *> norm is used. If this is much less than 1, then the stability of *> the LU factorization of the (equilibrated) matrix A could be poor. *> This also means that the solution X, estimated condition numbers, *> and error bounds could be unreliable. If factorization fails with *> 0<INFO<=N, then this contains the reciprocal pivot growth factor *> for the leading INFO columns of A. *> \endverbatim *> *> \param[out] BERR *> \verbatim *> BERR is REAL array, dimension (NRHS) *> Componentwise relative backward error. This is the *> componentwise relative backward error of each solution vector X(j) *> (i.e., the smallest relative change in any element of A or B that *> makes X(j) an exact solution). *> \endverbatim *> *> \param[in] N_ERR_BNDS *> \verbatim *> N_ERR_BNDS is INTEGER *> Number of error bounds to return for each right hand side *> and each type (normwise or componentwise). See ERR_BNDS_NORM and *> ERR_BNDS_COMP below. *> \endverbatim *> *> \param[out] ERR_BNDS_NORM *> \verbatim *> ERR_BNDS_NORM is REAL array, dimension (NRHS, N_ERR_BNDS) *> For each right-hand side, this array contains information about *> various error bounds and condition numbers corresponding to the *> normwise relative error, which is defined as follows: *> *> Normwise relative error in the ith solution vector: *> max_j (abs(XTRUE(j,i) - X(j,i))) *> ------------------------------ *> max_j abs(X(j,i)) *> *> The array is indexed by the type of error information as described *> below. There currently are up to three pieces of information *> returned. *> *> The first index in ERR_BNDS_NORM(i,:) corresponds to the ith *> right-hand side. *> *> The second index in ERR_BNDS_NORM(:,err) contains the following *> three fields: *> err = 1 "Trust/don't trust" boolean. Trust the answer if the *> reciprocal condition number is less than the threshold *> sqrt(n) * slamch('Epsilon'). *> *> err = 2 "Guaranteed" error bound: The estimated forward error, *> almost certainly within a factor of 10 of the true error *> so long as the next entry is greater than the threshold *> sqrt(n) * slamch('Epsilon'). This error bound should only *> be trusted if the previous boolean is true. *> *> err = 3 Reciprocal condition number: Estimated normwise *> reciprocal condition number. Compared with the threshold *> sqrt(n) * slamch('Epsilon') to determine if the error *> estimate is "guaranteed". These reciprocal condition *> numbers are 1 / (norm(Z^{-1},inf) * norm(Z,inf)) for some *> appropriately scaled matrix Z. *> Let Z = S*A, where S scales each row by a power of the *> radix so all absolute row sums of Z are approximately 1. *> *> See Lapack Working Note 165 for further details and extra *> cautions. *> \endverbatim *> *> \param[out] ERR_BNDS_COMP *> \verbatim *> ERR_BNDS_COMP is REAL array, dimension (NRHS, N_ERR_BNDS) *> For each right-hand side, this array contains information about *> various error bounds and condition numbers corresponding to the *> componentwise relative error, which is defined as follows: *> *> Componentwise relative error in the ith solution vector: *> abs(XTRUE(j,i) - X(j,i)) *> max_j ---------------------- *> abs(X(j,i)) *> *> The array is indexed by the right-hand side i (on which the *> componentwise relative error depends), and the type of error *> information as described below. There currently are up to three *> pieces of information returned for each right-hand side. If *> componentwise accuracy is not requested (PARAMS(3) = 0.0), then *> ERR_BNDS_COMP is not accessed. If N_ERR_BNDS .LT. 3, then at most *> the first (:,N_ERR_BNDS) entries are returned. *> *> The first index in ERR_BNDS_COMP(i,:) corresponds to the ith *> right-hand side. *> *> The second index in ERR_BNDS_COMP(:,err) contains the following *> three fields: *> err = 1 "Trust/don't trust" boolean. Trust the answer if the *> reciprocal condition number is less than the threshold *> sqrt(n) * slamch('Epsilon'). *> *> err = 2 "Guaranteed" error bound: The estimated forward error, *> almost certainly within a factor of 10 of the true error *> so long as the next entry is greater than the threshold *> sqrt(n) * slamch('Epsilon'). This error bound should only *> be trusted if the previous boolean is true. *> *> err = 3 Reciprocal condition number: Estimated componentwise *> reciprocal condition number. Compared with the threshold *> sqrt(n) * slamch('Epsilon') to determine if the error *> estimate is "guaranteed". These reciprocal condition *> numbers are 1 / (norm(Z^{-1},inf) * norm(Z,inf)) for some *> appropriately scaled matrix Z. *> Let Z = S*(A*diag(x)), where x is the solution for the *> current right-hand side and S scales each row of *> A*diag(x) by a power of the radix so all absolute row *> sums of Z are approximately 1. *> *> See Lapack Working Note 165 for further details and extra *> cautions. *> \endverbatim *> *> \param[in] NPARAMS *> \verbatim *> NPARAMS is INTEGER *> Specifies the number of parameters set in PARAMS. If .LE. 0, the *> PARAMS array is never referenced and default values are used. *> \endverbatim *> *> \param[in,out] PARAMS *> \verbatim *> PARAMS is REAL array, dimension NPARAMS *> Specifies algorithm parameters. If an entry is .LT. 0.0, then *> that entry will be filled with default value used for that *> parameter. Only positions up to NPARAMS are accessed; defaults *> are used for higher-numbered parameters. *> *> PARAMS(LA_LINRX_ITREF_I = 1) : Whether to perform iterative *> refinement or not. *> Default: 1.0 *> = 0.0 : No refinement is performed, and no error bounds are *> computed. *> = 1.0 : Use the double-precision refinement algorithm, *> possibly with doubled-single computations if the *> compilation environment does not support DOUBLE *> PRECISION. *> (other values are reserved for future use) *> *> PARAMS(LA_LINRX_ITHRESH_I = 2) : Maximum number of residual *> computations allowed for refinement. *> Default: 10 *> Aggressive: Set to 100 to permit convergence using approximate *> factorizations or factorizations other than LU. If *> the factorization uses a technique other than *> Gaussian elimination, the guarantees in *> err_bnds_norm and err_bnds_comp may no longer be *> trustworthy. *> *> PARAMS(LA_LINRX_CWISE_I = 3) : Flag determining if the code *> will attempt to find a solution with small componentwise *> relative error in the double-precision algorithm. Positive *> is true, 0.0 is false. *> Default: 1.0 (attempt componentwise convergence) *> \endverbatim *> *> \param[out] WORK *> \verbatim *> WORK is COMPLEX array, dimension (5*N) *> \endverbatim *> *> \param[out] RWORK *> \verbatim *> RWORK is REAL array, dimension (2*N) *> \endverbatim *> *> \param[out] INFO *> \verbatim *> INFO is INTEGER *> = 0: Successful exit. The solution to every right-hand side is *> guaranteed. *> < 0: If INFO = -i, the i-th argument had an illegal value *> > 0 and <= N: U(INFO,INFO) is exactly zero. The factorization *> has been completed, but the factor U is exactly singular, so *> the solution and error bounds could not be computed. RCOND = 0 *> is returned. *> = N+J: The solution corresponding to the Jth right-hand side is *> not guaranteed. The solutions corresponding to other right- *> hand sides K with K > J may not be guaranteed as well, but *> only the first such right-hand side is reported. If a small *> componentwise error is not requested (PARAMS(3) = 0.0) then *> the Jth right-hand side is the first with a normwise error *> bound that is not guaranteed (the smallest J such *> that ERR_BNDS_NORM(J,1) = 0.0). By default (PARAMS(3) = 1.0) *> the Jth right-hand side is the first with either a normwise or *> componentwise error bound that is not guaranteed (the smallest *> J such that either ERR_BNDS_NORM(J,1) = 0.0 or *> ERR_BNDS_COMP(J,1) = 0.0). See the definition of *> ERR_BNDS_NORM(:,1) and ERR_BNDS_COMP(:,1). To get information *> about all of the right-hand sides check ERR_BNDS_NORM or *> ERR_BNDS_COMP. *> \endverbatim * * Authors: * ======== * *> \author Univ. of Tennessee *> \author Univ. of California Berkeley *> \author Univ. of Colorado Denver *> \author NAG Ltd. * *> \date April 2012 * *> \ingroup complexHEsolve * * ===================================================================== SUBROUTINE CHESVXX( FACT, UPLO, N, NRHS, A, LDA, AF, LDAF, IPIV, $ EQUED, S, B, LDB, X, LDX, RCOND, RPVGRW, BERR, $ N_ERR_BNDS, ERR_BNDS_NORM, ERR_BNDS_COMP, $ NPARAMS, PARAMS, WORK, RWORK, INFO ) * * -- LAPACK driver routine (version 3.4.1) -- * -- LAPACK is a software package provided by Univ. of Tennessee, -- * -- Univ. of California Berkeley, Univ. of Colorado Denver and NAG Ltd..-- * April 2012 * * .. Scalar Arguments .. CHARACTER EQUED, FACT, UPLO INTEGER INFO, LDA, LDAF, LDB, LDX, N, NRHS, NPARAMS, $ N_ERR_BNDS REAL RCOND, RPVGRW * .. * .. Array Arguments .. INTEGER IPIV( * ) COMPLEX A( LDA, * ), AF( LDAF, * ), B( LDB, * ), $ WORK( * ), X( LDX, * ) REAL S( * ), PARAMS( * ), BERR( * ), RWORK( * ), $ ERR_BNDS_NORM( NRHS, * ), $ ERR_BNDS_COMP( NRHS, * ) * .. * * ================================================================== * * .. Parameters .. REAL ZERO, ONE PARAMETER ( ZERO = 0.0E+0, ONE = 1.0E+0 ) INTEGER FINAL_NRM_ERR_I, FINAL_CMP_ERR_I, BERR_I INTEGER RCOND_I, NRM_RCOND_I, NRM_ERR_I, CMP_RCOND_I INTEGER CMP_ERR_I, PIV_GROWTH_I PARAMETER ( FINAL_NRM_ERR_I = 1, FINAL_CMP_ERR_I = 2, $ BERR_I = 3 ) PARAMETER ( RCOND_I = 4, NRM_RCOND_I = 5, NRM_ERR_I = 6 ) PARAMETER ( CMP_RCOND_I = 7, CMP_ERR_I = 8, $ PIV_GROWTH_I = 9 ) * .. * .. Local Scalars .. LOGICAL EQUIL, NOFACT, RCEQU INTEGER INFEQU, J REAL AMAX, BIGNUM, SMIN, SMAX, SCOND, SMLNUM * .. * .. External Functions .. EXTERNAL LSAME, SLAMCH, CLA_HERPVGRW LOGICAL LSAME REAL SLAMCH, CLA_HERPVGRW * .. * .. External Subroutines .. EXTERNAL CHECON, CHEEQUB, CHETRF, CHETRS, CLACPY, $ CLAQHE, XERBLA, CLASCL2, CHERFSX * .. * .. Intrinsic Functions .. INTRINSIC MAX, MIN * .. * .. Executable Statements .. * INFO = 0 NOFACT = LSAME( FACT, 'N' ) EQUIL = LSAME( FACT, 'E' ) SMLNUM = SLAMCH( 'Safe minimum' ) BIGNUM = ONE / SMLNUM IF( NOFACT .OR. EQUIL ) THEN EQUED = 'N' RCEQU = .FALSE. ELSE RCEQU = LSAME( EQUED, 'Y' ) ENDIF * * Default is failure. If an input parameter is wrong or * factorization fails, make everything look horrible. Only the * pivot growth is set here, the rest is initialized in CHERFSX. * RPVGRW = ZERO * * Test the input parameters. PARAMS is not tested until CHERFSX. * IF( .NOT.NOFACT .AND. .NOT.EQUIL .AND. .NOT. $ LSAME( FACT, 'F' ) ) THEN INFO = -1 ELSE IF( .NOT.LSAME( UPLO, 'U' ) .AND. $ .NOT.LSAME( UPLO, 'L' ) ) THEN INFO = -2 ELSE IF( N.LT.0 ) THEN INFO = -3 ELSE IF( NRHS.LT.0 ) THEN INFO = -4 ELSE IF( LDA.LT.MAX( 1, N ) ) THEN INFO = -6 ELSE IF( LDAF.LT.MAX( 1, N ) ) THEN INFO = -8 ELSE IF( LSAME( FACT, 'F' ) .AND. .NOT. $ ( RCEQU .OR. LSAME( EQUED, 'N' ) ) ) THEN INFO = -9 ELSE IF ( RCEQU ) THEN SMIN = BIGNUM SMAX = ZERO DO 10 J = 1, N SMIN = MIN( SMIN, S( J ) ) SMAX = MAX( SMAX, S( J ) ) 10 CONTINUE IF( SMIN.LE.ZERO ) THEN INFO = -10 ELSE IF( N.GT.0 ) THEN SCOND = MAX( SMIN, SMLNUM ) / MIN( SMAX, BIGNUM ) ELSE SCOND = ONE END IF END IF IF( INFO.EQ.0 ) THEN IF( LDB.LT.MAX( 1, N ) ) THEN INFO = -12 ELSE IF( LDX.LT.MAX( 1, N ) ) THEN INFO = -14 END IF END IF END IF * IF( INFO.NE.0 ) THEN CALL XERBLA( 'CHESVXX', -INFO ) RETURN END IF * IF( EQUIL ) THEN * * Compute row and column scalings to equilibrate the matrix A. * CALL CHEEQUB( UPLO, N, A, LDA, S, SCOND, AMAX, WORK, INFEQU ) IF( INFEQU.EQ.0 ) THEN * * Equilibrate the matrix. * CALL CLAQHE( UPLO, N, A, LDA, S, SCOND, AMAX, EQUED ) RCEQU = LSAME( EQUED, 'Y' ) END IF END IF * * Scale the right-hand side. * IF( RCEQU ) CALL CLASCL2( N, NRHS, S, B, LDB ) * IF( NOFACT .OR. EQUIL ) THEN * * Compute the LDL^T or UDU^T factorization of A. * CALL CLACPY( UPLO, N, N, A, LDA, AF, LDAF ) CALL CHETRF( UPLO, N, AF, LDAF, IPIV, WORK, 5*MAX(1,N), INFO ) * * Return if INFO is non-zero. * IF( INFO.GT.0 ) THEN * * Pivot in column INFO is exactly 0 * Compute the reciprocal pivot growth factor of the * leading rank-deficient INFO columns of A. * IF( N.GT.0 ) $ RPVGRW = CLA_HERPVGRW( UPLO, N, INFO, A, LDA, AF, LDAF, $ IPIV, RWORK ) RETURN END IF END IF * * Compute the reciprocal pivot growth factor RPVGRW. * IF( N.GT.0 ) $ RPVGRW = CLA_HERPVGRW( UPLO, N, INFO, A, LDA, AF, LDAF, IPIV, $ RWORK ) * * Compute the solution matrix X. * CALL CLACPY( 'Full', N, NRHS, B, LDB, X, LDX ) CALL CHETRS( UPLO, N, NRHS, AF, LDAF, IPIV, X, LDX, INFO ) * * Use iterative refinement to improve the computed solution and * compute error bounds and backward error estimates for it. * CALL CHERFSX( UPLO, EQUED, N, NRHS, A, LDA, AF, LDAF, IPIV, $ S, B, LDB, X, LDX, RCOND, BERR, N_ERR_BNDS, ERR_BNDS_NORM, $ ERR_BNDS_COMP, NPARAMS, PARAMS, WORK, RWORK, INFO ) * * Scale solutions. * IF ( RCEQU ) THEN CALL CLASCL2 ( N, NRHS, S, X, LDX ) END IF * RETURN * * End of CHESVXX * END
gpl-2.0
RBigData/pbdSLAP
src/ScaLAPACK/pdlascl.f
4
17958
SUBROUTINE PDLASCL( TYPE, CFROM, CTO, M, N, A, IA, JA, DESCA, $ INFO ) * * -- ScaLAPACK auxiliary routine (version 1.7) -- * University of Tennessee, Knoxville, Oak Ridge National Laboratory, * and University of California, Berkeley. * May 1, 1997 * * .. Scalar Arguments .. CHARACTER TYPE INTEGER IA, INFO, JA, M, N DOUBLE PRECISION CFROM, CTO * .. * .. Array Arguments .. INTEGER DESCA( * ) DOUBLE PRECISION A( * ) * .. * * Purpose * ======= * * PDLASCL multiplies the M-by-N real distributed matrix sub( A ) * denoting A(IA:IA+M-1,JA:JA+N-1) by the real scalar CTO/CFROM. This * is done without over/underflow as long as the final result * CTO * A(I,J) / CFROM does not over/underflow. TYPE specifies that * sub( A ) may be full, upper triangular, lower triangular or upper * Hessenberg. * * Notes * ===== * * Each global data object is described by an associated description * vector. This vector stores the information required to establish * the mapping between an object element and its corresponding process * and memory location. * * Let A be a generic term for any 2D block cyclicly distributed array. * Such a global array has an associated description vector DESCA. * In the following comments, the character _ should be read as * "of the global array". * * NOTATION STORED IN EXPLANATION * --------------- -------------- -------------------------------------- * DTYPE_A(global) DESCA( DTYPE_ )The descriptor type. In this case, * DTYPE_A = 1. * CTXT_A (global) DESCA( CTXT_ ) The BLACS context handle, indicating * the BLACS process grid A is distribu- * ted over. The context itself is glo- * bal, but the handle (the integer * value) may vary. * M_A (global) DESCA( M_ ) The number of rows in the global * array A. * N_A (global) DESCA( N_ ) The number of columns in the global * array A. * MB_A (global) DESCA( MB_ ) The blocking factor used to distribute * the rows of the array. * NB_A (global) DESCA( NB_ ) The blocking factor used to distribute * the columns of the array. * RSRC_A (global) DESCA( RSRC_ ) The process row over which the first * row of the array A is distributed. * CSRC_A (global) DESCA( CSRC_ ) The process column over which the * first column of the array A is * distributed. * LLD_A (local) DESCA( LLD_ ) The leading dimension of the local * array. LLD_A >= MAX(1,LOCr(M_A)). * * Let K be the number of rows or columns of a distributed matrix, * and assume that its process grid has dimension p x q. * LOCr( K ) denotes the number of elements of K that a process * would receive if K were distributed over the p processes of its * process column. * Similarly, LOCc( K ) denotes the number of elements of K that a * process would receive if K were distributed over the q processes of * its process row. * The values of LOCr() and LOCc() may be determined via a call to the * ScaLAPACK tool function, NUMROC: * LOCr( M ) = NUMROC( M, MB_A, MYROW, RSRC_A, NPROW ), * LOCc( N ) = NUMROC( N, NB_A, MYCOL, CSRC_A, NPCOL ). * An upper bound for these quantities may be computed by: * LOCr( M ) <= ceil( ceil(M/MB_A)/NPROW )*MB_A * LOCc( N ) <= ceil( ceil(N/NB_A)/NPCOL )*NB_A * * Arguments * ========= * * TYPE (global input) CHARACTER * TYPE indices the storage type of the input distributed * matrix. * = 'G': sub( A ) is a full matrix, * = 'L': sub( A ) is a lower triangular matrix, * = 'U': sub( A ) is an upper triangular matrix, * = 'H': sub( A ) is an upper Hessenberg matrix. * * CFROM (global input) DOUBLE PRECISION * CTO (global input) DOUBLE PRECISION * The distributed matrix sub( A ) is multiplied by CTO/CFROM. * A(I,J) is computed without over/underflow if the final * result CTO * A(I,J) / CFROM can be represented without * over/underflow. CFROM must be nonzero. * * M (global input) INTEGER * The number of rows to be operated on i.e the number of rows * of the distributed submatrix sub( A ). M >= 0. * * N (global input) INTEGER * The number of columns to be operated on i.e the number of * columns of the distributed submatrix sub( A ). N >= 0. * * A (local input/local output) DOUBLE PRECISION pointer into the * local memory to an array of dimension (LLD_A,LOCc(JA+N-1)). * This array contains the local pieces of the distributed * matrix sub( A ). On exit, this array contains the local * pieces of the distributed matrix multiplied by CTO/CFROM. * * IA (global input) INTEGER * The row index in the global array A indicating the first * row of sub( A ). * * JA (global input) INTEGER * The column index in the global array A indicating the * first column of sub( A ). * * DESCA (global and local input) INTEGER array of dimension DLEN_. * The array descriptor for the distributed matrix A. * * INFO (local output) INTEGER * = 0: successful exit * < 0: If the i-th argument is an array and the j-entry had * an illegal value, then INFO = -(i*100+j), if the i-th * argument is a scalar and had an illegal value, then * INFO = -i. * * ===================================================================== * * .. Parameters .. INTEGER BLOCK_CYCLIC_2D, CSRC_, CTXT_, DLEN_, DTYPE_, $ LLD_, MB_, M_, NB_, N_, RSRC_ PARAMETER ( BLOCK_CYCLIC_2D = 1, DLEN_ = 9, DTYPE_ = 1, $ CTXT_ = 2, M_ = 3, N_ = 4, MB_ = 5, NB_ = 6, $ RSRC_ = 7, CSRC_ = 8, LLD_ = 9 ) DOUBLE PRECISION ONE, ZERO PARAMETER ( ZERO = 0.0D0, ONE = 1.0D0 ) * .. * .. Local Scalars .. LOGICAL DONE INTEGER IACOL, IAROW, ICOFFA, ICTXT, ICURCOL, ICURROW, $ IIA, II, INXTROW, IOFFA, IROFFA, ITYPE, J, JB, $ JJA, JJ, JN, KK, LDA, LL, MYCOL, MYROW, MP, $ NPCOL, NPROW, NQ DOUBLE PRECISION BIGNUM, CFROM1, CFROMC, CTO1, CTOC, MUL, SMLNUM * .. * .. External Subroutines .. EXTERNAL BLACS_GRIDINFO, CHK1MAT, INFOG2L, PXERBLA * .. * .. External Functions .. LOGICAL LSAME, DISNAN INTEGER ICEIL, NUMROC DOUBLE PRECISION PDLAMCH EXTERNAL DISNAN, ICEIL, LSAME, NUMROC, PDLAMCH * .. * .. Intrinsic Functions .. INTRINSIC ABS, MIN, MOD * .. * .. Executable Statements .. * * Get grid parameters * ICTXT = DESCA( CTXT_ ) CALL BLACS_GRIDINFO( ICTXT, NPROW, NPCOL, MYROW, MYCOL ) * * Test the input parameters * IF( NPROW.EQ.-1 ) THEN INFO = -907 ELSE INFO = 0 CALL CHK1MAT( M, 4, N, 6, IA, JA, DESCA, 9, INFO ) IF( INFO.EQ.0 ) THEN IF( LSAME( TYPE, 'G' ) ) THEN ITYPE = 0 ELSE IF( LSAME( TYPE, 'L' ) ) THEN ITYPE = 1 ELSE IF( LSAME( TYPE, 'U' ) ) THEN ITYPE = 2 ELSE IF( LSAME( TYPE, 'H' ) ) THEN ITYPE = 3 ELSE ITYPE = -1 END IF IF( ITYPE.EQ.-1 ) THEN INFO = -1 ELSE IF( CFROM.EQ.ZERO .OR. DISNAN(CFROM) ) THEN INFO = -4 ELSE IF( DISNAN(CTO) ) THEN INFO = -5 END IF END IF END IF * IF( INFO.NE.0 ) THEN CALL PXERBLA( ICTXT, 'PDLASCL', -INFO ) RETURN END IF * * Quick return if possible * IF( N.EQ.0 .OR. M.EQ.0 ) $ RETURN * * Get machine parameters * SMLNUM = PDLAMCH( ICTXT, 'S' ) BIGNUM = ONE / SMLNUM * CFROMC = CFROM CTOC = CTO * * Compute local indexes * LDA = DESCA( LLD_ ) IROFFA = MOD( IA-1, DESCA( MB_ ) ) ICOFFA = MOD( JA-1, DESCA( NB_ ) ) JN = MIN( ICEIL( JA, DESCA( NB_ ) ) * DESCA( NB_ ), JA+N-1 ) CALL INFOG2L( IA, JA, DESCA, NPROW, NPCOL, MYROW, MYCOL, IIA, JJA, $ IAROW, IACOL ) MP = NUMROC( M+IROFFA, DESCA( MB_ ), MYROW, IAROW, NPROW ) IF( MYROW.EQ.IAROW ) $ MP = MP - IROFFA NQ = NUMROC( N+ICOFFA, DESCA( NB_ ), MYCOL, IACOL, NPCOL ) IF( MYCOL.EQ.IACOL ) $ NQ = NQ - ICOFFA * 10 CONTINUE CFROM1 = CFROMC*SMLNUM IF( CFROM1.EQ.CFROMC ) THEN ! CFROMC is an inf. Multiply by a correctly signed zero for ! finite CTOC, or a NaN if CTOC is infinite. MUL = CTOC / CFROMC DONE = .TRUE. CTO1 = CTOC ELSE CTO1 = CTOC / BIGNUM IF( CTO1.EQ.CTOC ) THEN ! CTOC is either 0 or an inf. In both cases, CTOC itself ! serves as the correct multiplication factor. MUL = CTOC DONE = .TRUE. CFROMC = ONE ELSE IF( ABS( CFROM1 ).GT.ABS( CTOC ) .AND. CTOC.NE.ZERO ) THEN MUL = SMLNUM DONE = .FALSE. CFROMC = CFROM1 ELSE IF( ABS( CTO1 ).GT.ABS( CFROMC ) ) THEN MUL = BIGNUM DONE = .FALSE. CTOC = CTO1 ELSE MUL = CTOC / CFROMC DONE = .TRUE. END IF END IF * IOFFA = ( JJA - 1 ) * LDA ICURROW = IAROW ICURCOL = IACOL * IF( ITYPE.EQ.0 ) THEN * * Full matrix * DO 30 JJ = JJA, JJA+NQ-1 DO 20 II = IIA, IIA+MP-1 A( IOFFA+II ) = A( IOFFA+II ) * MUL 20 CONTINUE IOFFA = IOFFA + LDA 30 CONTINUE * ELSE IF( ITYPE.EQ.1 ) THEN * * Lower triangular matrix * II = IIA JJ = JJA JB = JN-JA+1 * IF( MYCOL.EQ.ICURCOL ) THEN IF( MYROW.EQ.ICURROW ) THEN DO 50 LL = JJ, JJ + JB -1 DO 40 KK = II+LL-JJ, IIA+MP-1 A( IOFFA+KK ) = A( IOFFA+KK ) * MUL 40 CONTINUE IOFFA = IOFFA + LDA 50 CONTINUE ELSE DO 70 LL = JJ, JJ + JB -1 DO 60 KK = II, IIA+MP-1 A( IOFFA+KK ) = A( IOFFA+KK ) * MUL 60 CONTINUE IOFFA = IOFFA + LDA 70 CONTINUE END IF JJ = JJ + JB END IF * IF( MYROW.EQ.ICURROW ) $ II = II + JB ICURROW = MOD( ICURROW+1, NPROW ) ICURCOL = MOD( ICURCOL+1, NPCOL ) * * Loop over remaining block of columns * DO 120 J = JN+1, JA+N-1, DESCA( NB_ ) JB = MIN( JA+N-J, DESCA( NB_ ) ) * IF( MYCOL.EQ.ICURCOL ) THEN IF( MYROW.EQ.ICURROW ) THEN DO 90 LL = JJ, JJ + JB -1 DO 80 KK = II+LL-JJ, IIA+MP-1 A( IOFFA+KK ) = A( IOFFA+KK ) * MUL 80 CONTINUE IOFFA = IOFFA + LDA 90 CONTINUE ELSE DO 110 LL = JJ, JJ + JB -1 DO 100 KK = II, IIA+MP-1 A( IOFFA+KK ) = A( IOFFA+KK ) * MUL 100 CONTINUE IOFFA = IOFFA + LDA 110 CONTINUE END IF JJ = JJ + JB END IF * IF( MYROW.EQ.ICURROW ) $ II = II + JB ICURROW = MOD( ICURROW+1, NPROW ) ICURCOL = MOD( ICURCOL+1, NPCOL ) * 120 CONTINUE * ELSE IF( ITYPE.EQ.2 ) THEN * * Upper triangular matrix * II = IIA JJ = JJA JB = JN-JA+1 * IF( MYCOL.EQ.ICURCOL ) THEN IF( MYROW.EQ.ICURROW ) THEN DO 140 LL = JJ, JJ + JB -1 DO 130 KK = IIA, MIN(II+LL-JJ,IIA+MP-1) A( IOFFA+KK ) = A( IOFFA+KK ) * MUL 130 CONTINUE IOFFA = IOFFA + LDA 140 CONTINUE ELSE DO 160 LL = JJ, JJ + JB -1 DO 150 KK = IIA, MIN(II-1,IIA+MP-1) A( IOFFA+KK ) = A( IOFFA+KK ) * MUL 150 CONTINUE IOFFA = IOFFA + LDA 160 CONTINUE END IF JJ = JJ + JB END IF * IF( MYROW.EQ.ICURROW ) $ II = II + JB ICURROW = MOD( ICURROW+1, NPROW ) ICURCOL = MOD( ICURCOL+1, NPCOL ) * * Loop over remaining block of columns * DO 210 J = JN+1, JA+N-1, DESCA( NB_ ) JB = MIN( JA+N-J, DESCA( NB_ ) ) * IF( MYCOL.EQ.ICURCOL ) THEN IF( MYROW.EQ.ICURROW ) THEN DO 180 LL = JJ, JJ + JB -1 DO 170 KK = IIA, MIN(II+LL-JJ,IIA+MP-1) A( IOFFA+KK ) = A( IOFFA+KK )*MUL 170 CONTINUE IOFFA = IOFFA + LDA 180 CONTINUE ELSE DO 200 LL = JJ, JJ + JB -1 DO 190 KK = IIA, MIN(II-1,IIA+MP-1) A( IOFFA+KK ) = A( IOFFA+KK ) * MUL 190 CONTINUE IOFFA = IOFFA + LDA 200 CONTINUE END IF JJ = JJ + JB END IF * IF( MYROW.EQ.ICURROW ) $ II = II + JB ICURROW = MOD( ICURROW+1, NPROW ) ICURCOL = MOD( ICURCOL+1, NPCOL ) * 210 CONTINUE * ELSE IF( ITYPE.EQ.3 ) THEN * * Upper Hessenberg matrix * II = IIA JJ = JJA JB = JN-JA+1 * * Only one process row * IF( NPROW.EQ.1 ) THEN * * Handle first block of columns separately * IF( MYCOL.EQ.ICURCOL ) THEN DO 230 LL = JJ, JJ+JB-1 DO 220 KK = IIA, MIN( II+LL-JJ+1, IIA+MP-1 ) A( IOFFA+KK ) = A( IOFFA+KK )*MUL 220 CONTINUE IOFFA = IOFFA + LDA 230 CONTINUE JJ = JJ + JB END IF * ICURCOL = MOD( ICURCOL+1, NPCOL ) * * Loop over remaining block of columns * DO 260 J = JN+1, JA+N-1, DESCA( NB_ ) JB = MIN( JA+N-J, DESCA( NB_ ) ) * IF( MYCOL.EQ.ICURCOL ) THEN DO 250 LL = JJ, JJ+JB-1 DO 240 KK = IIA, MIN( II+LL-JJ+1, IIA+MP-1 ) A( IOFFA+KK ) = A( IOFFA+KK )*MUL 240 CONTINUE IOFFA = IOFFA + LDA 250 CONTINUE JJ = JJ + JB END IF * II = II + JB ICURCOL = MOD( ICURCOL+1, NPCOL ) * 260 CONTINUE * ELSE * * Handle first block of columns separately * INXTROW = MOD( ICURROW+1, NPROW ) IF( MYCOL.EQ.ICURCOL ) THEN IF( MYROW.EQ.ICURROW ) THEN DO 280 LL = JJ, JJ + JB -1 DO 270 KK = IIA, MIN(II+LL-JJ+1,IIA+MP-1) A( IOFFA+KK ) = A( IOFFA+KK ) * MUL 270 CONTINUE IOFFA = IOFFA + LDA 280 CONTINUE ELSE DO 300 LL = JJ, JJ + JB -1 DO 290 KK = IIA, MIN(II-1,IIA+MP-1) A( IOFFA+KK ) = A( IOFFA+KK ) * MUL 290 CONTINUE IOFFA = IOFFA + LDA 300 CONTINUE IF( MYROW.EQ.INXTROW .AND. II.LE.IIA+MP-1 ) $ A( II+(JJ+JB-2)*LDA ) = A( II+(JJ+JB-2)*LDA ) * MUL END IF JJ = JJ + JB END IF * IF( MYROW.EQ.ICURROW ) $ II = II + JB ICURROW = INXTROW ICURROW = MOD( ICURROW+1, NPROW ) ICURCOL = MOD( ICURCOL+1, NPCOL ) * * Loop over remaining block of columns * DO 350 J = JN+1, JA+N-1, DESCA( NB_ ) JB = MIN( JA+N-J, DESCA( NB_ ) ) * IF( MYCOL.EQ.ICURCOL ) THEN IF( MYROW.EQ.ICURROW ) THEN DO 320 LL = JJ, JJ + JB -1 DO 310 KK = IIA, MIN( II+LL-JJ+1, IIA+MP-1 ) A( IOFFA+KK ) = A( IOFFA+KK ) * MUL 310 CONTINUE IOFFA = IOFFA + LDA 320 CONTINUE ELSE DO 340 LL = JJ, JJ + JB -1 DO 330 KK = IIA, MIN( II-1, IIA+MP-1 ) A( IOFFA+KK ) = A( IOFFA+KK ) * MUL 330 CONTINUE IOFFA = IOFFA + LDA 340 CONTINUE IF( MYROW.EQ.INXTROW .AND. II.LE.IIA+MP-1 ) $ A( II+(JJ+JB-2)*LDA ) = A( II+(JJ+JB-2)*LDA ) * $ MUL END IF JJ = JJ + JB END IF * IF( MYROW.EQ.ICURROW ) $ II = II + JB ICURROW = INXTROW ICURROW = MOD( ICURROW+1, NPROW ) ICURCOL = MOD( ICURCOL+1, NPCOL ) * 350 CONTINUE * END IF * END IF * IF( .NOT.DONE ) $ GO TO 10 * RETURN * * End of PDLASCL * END
mpl-2.0
wilmarcardonac/hypermcmc
lapack-3.5.0/SRC/slag2d.f
24
3518
*> \brief \b SLAG2D converts a single precision matrix to a double precision matrix. * * =========== DOCUMENTATION =========== * * Online html documentation available at * http://www.netlib.org/lapack/explore-html/ * *> \htmlonly *> Download SLAG2D + dependencies *> <a href="http://www.netlib.org/cgi-bin/netlibfiles.tgz?format=tgz&filename=/lapack/lapack_routine/slag2d.f"> *> [TGZ]</a> *> <a href="http://www.netlib.org/cgi-bin/netlibfiles.zip?format=zip&filename=/lapack/lapack_routine/slag2d.f"> *> [ZIP]</a> *> <a href="http://www.netlib.org/cgi-bin/netlibfiles.txt?format=txt&filename=/lapack/lapack_routine/slag2d.f"> *> [TXT]</a> *> \endhtmlonly * * Definition: * =========== * * SUBROUTINE SLAG2D( M, N, SA, LDSA, A, LDA, INFO ) * * .. Scalar Arguments .. * INTEGER INFO, LDA, LDSA, M, N * .. * .. Array Arguments .. * REAL SA( LDSA, * ) * DOUBLE PRECISION A( LDA, * ) * .. * * *> \par Purpose: * ============= *> *> \verbatim *> *> SLAG2D converts a SINGLE PRECISION matrix, SA, to a DOUBLE *> PRECISION matrix, A. *> *> Note that while it is possible to overflow while converting *> from double to single, it is not possible to overflow when *> converting from single to double. *> *> This is an auxiliary routine so there is no argument checking. *> \endverbatim * * Arguments: * ========== * *> \param[in] M *> \verbatim *> M is INTEGER *> The number of lines of the matrix A. M >= 0. *> \endverbatim *> *> \param[in] N *> \verbatim *> N is INTEGER *> The number of columns of the matrix A. N >= 0. *> \endverbatim *> *> \param[in] SA *> \verbatim *> SA is REAL array, dimension (LDSA,N) *> On entry, the M-by-N coefficient matrix SA. *> \endverbatim *> *> \param[in] LDSA *> \verbatim *> LDSA is INTEGER *> The leading dimension of the array SA. LDSA >= max(1,M). *> \endverbatim *> *> \param[out] A *> \verbatim *> A is DOUBLE PRECISION array, dimension (LDA,N) *> On exit, the M-by-N coefficient matrix A. *> \endverbatim *> *> \param[in] LDA *> \verbatim *> LDA is INTEGER *> The leading dimension of the array A. LDA >= max(1,M). *> \endverbatim *> *> \param[out] INFO *> \verbatim *> INFO is INTEGER *> = 0: successful exit *> \endverbatim * * Authors: * ======== * *> \author Univ. of Tennessee *> \author Univ. of California Berkeley *> \author Univ. of Colorado Denver *> \author NAG Ltd. * *> \date September 2012 * *> \ingroup auxOTHERauxiliary * * ===================================================================== SUBROUTINE SLAG2D( M, N, SA, LDSA, A, LDA, INFO ) * * -- LAPACK auxiliary routine (version 3.4.2) -- * -- LAPACK is a software package provided by Univ. of Tennessee, -- * -- Univ. of California Berkeley, Univ. of Colorado Denver and NAG Ltd..-- * September 2012 * * .. Scalar Arguments .. INTEGER INFO, LDA, LDSA, M, N * .. * .. Array Arguments .. REAL SA( LDSA, * ) DOUBLE PRECISION A( LDA, * ) * .. * * ===================================================================== * * .. Local Scalars .. INTEGER I, J * .. * .. Executable Statements .. * INFO = 0 DO 20 J = 1, N DO 10 I = 1, M A( I, J ) = SA( I, J ) 10 CONTINUE 20 CONTINUE RETURN * * End of SLAG2D * END
gpl-2.0
QEF/q-e
XClib/xc_wrapper_d_gga.f90
2
14176
! ! Copyright (C) 2020 Quantum ESPRESSO group ! This file is distributed under the terms of the ! GNU General Public License. See the file `License' ! in the root directory of the present distribution, ! or http://www.gnu.org/copyleft/gpl.txt . ! !--------------------------------------------------------------------- SUBROUTINE dgcxc( length, sp, r_in, g_in, dvxc_rr, dvxc_sr, dvxc_ss, gpu_args_ ) !--------------------------------------------------------------------- !! Wrapper routine. Calls dgcx-driver routines from internal libraries !! or from the external libxc, depending on the input choice. ! USE kind_l, ONLY: DP ! IMPLICIT NONE ! INTEGER, INTENT(IN) :: length !! length of the I/O arrays INTEGER, INTENT(IN) :: sp !! number of spin components REAL(DP), INTENT(IN) :: r_in(length,sp) !! charge density REAL(DP), INTENT(IN) :: g_in(length,3,sp) !! gradient REAL(DP), INTENT(OUT) :: dvxc_rr(length,sp,sp), dvxc_sr(length,sp,sp), & dvxc_ss(length,sp,sp) LOGICAL, OPTIONAL, INTENT(IN) :: gpu_args_ !! whether you wish to run on gpu in case use_gpu is true ! LOGICAL :: gpu_args ! gpu_args = .FALSE. IF ( PRESENT(gpu_args_) ) gpu_args = gpu_args_ ! IF ( gpu_args ) THEN ! !$acc data present( r_in, g_in, dvxc_rr, dvxc_sr, dvxc_ss ) CALL dgcxc_( length, sp, r_in, g_in, dvxc_rr, dvxc_sr, dvxc_ss ) !$acc end data ! ELSE ! !$acc data copyin( r_in, g_in ), copyout( dvxc_rr, dvxc_sr, dvxc_ss ) CALL dgcxc_( length, sp, r_in, g_in, dvxc_rr, dvxc_sr, dvxc_ss ) !$acc end data ! ENDIF ! RETURN ! END SUBROUTINE ! !--------------------------------------------------------------------- SUBROUTINE dgcxc_( length, sp, r_in, g_in, dvxc_rr, dvxc_sr, dvxc_ss ) !--------------------------------------------------------------------- !! Wrapper routine. Calls dgcx-driver routines from internal libraries !! or from the external libxc, depending on the input choice. ! USE constants_l, ONLY: e2 USE kind_l, ONLY: DP USE dft_setting_params, ONLY: igcx, igcc, is_libxc, rho_threshold_gga, & grho_threshold_gga, rho_threshold_lda USE qe_drivers_d_gga #if defined(__LIBXC) #include "xc_version.h" USE xc_f03_lib_m USE dft_setting_params, ONLY: xc_func, xc_info #endif ! IMPLICIT NONE ! INTEGER, INTENT(IN) :: length !! length of the I/O arrays INTEGER, INTENT(IN) :: sp !! number of spin components REAL(DP), INTENT(IN) :: r_in(length,sp) !! charge density REAL(DP), INTENT(IN) :: g_in(length,3,sp) !! gradient REAL(DP), INTENT(OUT) :: dvxc_rr(length,sp,sp), dvxc_sr(length,sp,sp), & dvxc_ss(length,sp,sp) ! ! ... local variables ! REAL(DP), ALLOCATABLE :: vrrx(:,:), vsrx(:,:), vssx(:,:) REAL(DP), ALLOCATABLE :: vrrc(:,:), vsrc(:,:), vssc(:), vrzc(:,:) ! #if defined(__LIBXC) INTEGER :: fkind=-10 REAL(DP), ALLOCATABLE :: rho_lxc(:) REAL(DP), ALLOCATABLE :: v2rho2_x(:), v2rhosigma_x(:), v2sigma2_x(:) REAL(DP), ALLOCATABLE :: v2rho2_c(:), v2rhosigma_c(:), v2sigma2_c(:) #if (XC_MAJOR_VERSION > 4) INTEGER(8) :: lengthxc #else INTEGER :: lengthxc #endif #endif ! INTEGER :: k, length_dlxc REAL(DP) :: rht, zeta REAL(DP), ALLOCATABLE :: sigma(:) REAL(DP), PARAMETER :: small = 1.E-10_DP, rho_trash = 0.5_DP REAL(DP), PARAMETER :: epsr=1.0d-6, epsg=1.0d-6 ! !$acc data present( r_in, g_in, dvxc_rr, dvxc_sr, dvxc_ss ) ! IF ( ANY(.NOT.is_libxc(3:4)) ) THEN rho_threshold_gga = small ; grho_threshold_gga = small ENDIF ! !$acc kernels dvxc_rr(:,:,:) = 0._DP dvxc_sr(:,:,:) = 0._DP dvxc_ss(:,:,:) = 0._DP !$acc end kernels ! #if defined(__LIBXC) ! IF ( ANY(is_libxc(3:4)) ) THEN ! lengthxc = length ! length_dlxc = length IF (sp == 2) length_dlxc = length*3 ! ALLOCATE( rho_lxc(length*sp), sigma(length_dlxc) ) !$acc data copyout( rho_lxc, sigma ) ! ! ... set libxc input SELECT CASE( sp ) CASE( 1 ) ! !$acc parallel loop DO k = 1, length rho_lxc(k) = r_in(k,1) sigma(k) = g_in(k,1,1)**2 + g_in(k,2,1)**2 + g_in(k,3,1)**2 ENDDO ! CASE( 2 ) ! !$acc parallel loop DO k = 1, length rho_lxc(2*k-1) = r_in(k,1) rho_lxc(2*k) = r_in(k,2) ! sigma(3*k-2) = g_in(k,1,1)**2 + g_in(k,2,1)**2 + g_in(k,3,1)**2 sigma(3*k-1) = g_in(k,1,1) * g_in(k,1,2) + g_in(k,2,1) * g_in(k,2,2) + & g_in(k,3,1) * g_in(k,3,2) sigma(3*k) = g_in(k,1,2)**2 + g_in(k,2,2)**2 + g_in(k,3,2)**2 ENDDO ! CASE( 4 ) ! CALL xclib_error( 'dgcxc', 'The Libxc derivative of the XC potential & &is not available for noncollinear case', 1 ) ! CASE DEFAULT ! CALL xclib_error( 'dgcxc', 'Wrong number of spin dimensions', 2 ) ! END SELECT ! !$acc end data ! ENDIF ! ! ... LIBXC DERIVATIVE FOR EXCHANGE ! IF ( is_libxc(3) .AND. igcx/=0 ) THEN ALLOCATE( v2rho2_x(length_dlxc), v2rhosigma_x(length_dlxc*sp), & v2sigma2_x(length_dlxc*sp) ) v2rho2_x = 0._DP ; v2rhosigma_x = 0._DP ; v2sigma2_x = 0._DP CALL xc_f03_func_set_dens_threshold( xc_func(3), epsr ) CALL xc_f03_gga_fxc( xc_func(3), lengthxc, rho_lxc(1), sigma(1), v2rho2_x(1), & v2rhosigma_x(1), v2sigma2_x(1) ) !$acc data copyin( v2rho2_x, v2rhosigma_x, v2sigma2_x ) ! IF (sp==1) THEN !$acc parallel loop DO k = 1, length IF ( rho_lxc(k)>small .AND. SQRT(ABS(sigma(k)))>small ) THEN IF ( rho_lxc(k)>rho_threshold_lda ) THEN dvxc_rr(k,1,1) = dvxc_rr(k,1,1) + e2 * v2rho2_x(k) dvxc_sr(k,1,1) = dvxc_sr(k,1,1) + e2 * v2rhosigma_x(k)*2._DP ENDIF dvxc_ss(k,1,1) = dvxc_ss(k,1,1) + e2 * v2sigma2_x(k)*4._DP ENDIF ENDDO ELSEIF (sp==2) THEN !$acc parallel loop DO k = 1, length IF ( (r_in(k,1)>epsr .AND. SQRT(ABS(sigma(3*k-2)))>epsg) .AND. & (r_in(k,2)>epsr .AND. SQRT(ABS(sigma(3*k))) >epsg) ) THEN dvxc_rr(k,1,1) = dvxc_rr(k,1,1) + e2 * v2rho2_x(3*k-2) dvxc_ss(k,1,1) = dvxc_ss(k,1,1) + e2 * v2sigma2_x(6*k-5)*4._DP dvxc_rr(k,2,2) = dvxc_rr(k,2,2) + e2 * v2rho2_x(3*k) dvxc_ss(k,2,2) = dvxc_ss(k,2,2) + e2 * v2sigma2_x(6*k)*4._DP dvxc_rr(k,1,2) = dvxc_rr(k,1,2) + e2 * v2rho2_x(3*k-1) dvxc_sr(k,1,1) = dvxc_sr(k,1,1) + e2 * v2rhosigma_x(6*k-5)*2._DP dvxc_rr(k,2,1) = dvxc_rr(k,2,1) + e2 * v2rho2_x(3*k-1) dvxc_sr(k,2,2) = dvxc_sr(k,2,2) + e2 * v2rhosigma_x(6*k)*2._DP ENDIF ENDDO ENDIF !$acc end data DEALLOCATE( v2rho2_x, v2rhosigma_x, v2sigma2_x ) ! ENDIF ! ! ... LIBXC DERIVATIVE FOR CORRELATION ! IF ( is_libxc(4) .AND. igcc/=0 ) THEN ALLOCATE( v2rho2_c(length_dlxc), v2rhosigma_c(length_dlxc*sp), & v2sigma2_c(length_dlxc*sp) ) ! ... DERIVATIVE FOR CORRELATION v2rho2_c = 0._DP ; v2rhosigma_c = 0._DP ; v2sigma2_c = 0._DP fkind = xc_f03_func_info_get_kind( xc_info(4) ) CALL xc_f03_func_set_dens_threshold( xc_func(4), epsr ) CALL xc_f03_gga_fxc( xc_func(4), lengthxc, rho_lxc(1), sigma(1), v2rho2_c(1), & v2rhosigma_c(1), v2sigma2_c(1) ) !$acc data copyin( v2rho2_c, v2rhosigma_c, v2sigma2_c ) ! IF (sp==1) THEN !$acc parallel loop DO k = 1, length IF ( rho_lxc(k)>small .AND. SQRT(ABS(sigma(k)))>small ) THEN IF ( rho_lxc(k)>rho_threshold_lda ) THEN dvxc_rr(k,1,1) = dvxc_rr(k,1,1) + e2 * v2rho2_c(k) dvxc_sr(k,1,1) = dvxc_sr(k,1,1) + e2 * v2rhosigma_c(k)*2._DP ENDIF dvxc_ss(k,1,1) = dvxc_ss(k,1,1) + e2 * v2sigma2_c(k)*4._DP ENDIF ENDDO ELSEIF (sp==2) THEN !$acc parallel loop DO k = 1, length IF ( (r_in(k,1)>epsr .AND. SQRT(ABS(sigma(3*k-2)))>epsg) .AND. & (r_in(k,2)>epsr .AND. SQRT(ABS(sigma(3*k))) >epsg) ) THEN dvxc_rr(k,1,1) = dvxc_rr(k,1,1) + e2 * v2rho2_c(3*k-2) dvxc_rr(k,1,2) = dvxc_rr(k,1,2) + e2 * v2rho2_c(3*k-1) dvxc_rr(k,2,1) = dvxc_rr(k,2,1) + e2 * v2rho2_c(3*k-1) dvxc_rr(k,2,2) = dvxc_rr(k,2,2) + e2 * v2rho2_c(3*k) dvxc_sr(k,1,1) = dvxc_sr(k,1,1) + e2 * v2rhosigma_c(6*k-5)*2.d0 dvxc_ss(k,1,1) = dvxc_ss(k,1,1) + e2 * v2sigma2_c(6*k)*4.d0 dvxc_sr(k,1,2) = dvxc_sr(k,1,2) + e2 * v2rhosigma_c(6*k-4) dvxc_sr(k,2,1) = dvxc_sr(k,2,1) + e2 * v2rhosigma_c(6*k-1) dvxc_ss(k,1,2) = dvxc_ss(k,1,2) + e2 * v2sigma2_c(6*k-2) dvxc_ss(k,2,1) = dvxc_ss(k,2,1) + e2 * v2sigma2_c(6*k-2) dvxc_sr(k,2,2) = dvxc_sr(k,2,2) + e2 * v2rhosigma_c(6*k)*2.d0 dvxc_ss(k,2,2) = dvxc_ss(k,2,2) + e2 * v2sigma2_c(6*k)*4.d0 ENDIF ENDDO ENDIF ! !$acc end data DEALLOCATE( v2rho2_c, v2rhosigma_c, v2sigma2_c ) ! ENDIF ! ! ... QE DERIVATIVE FOR EXCHANGE AND CORRELATION ! IF ( ((.NOT.is_libxc(3).AND.igcx/=0) .OR. (.NOT.is_libxc(4).AND.igcc/=0)) & .AND. fkind/=XC_EXCHANGE_CORRELATION ) THEN ! ALLOCATE( vrrx(length,sp), vsrx(length,sp), vssx(length,sp) ) ALLOCATE( vrrc(length,sp), vsrc(length,sp), vssc(length) ) !$acc data create( vrrx, vsrx, vssx, vrrc, vsrc, vssc ) ! IF ( sp == 1 ) THEN ! IF (.NOT. ALLOCATED(sigma)) THEN ALLOCATE( sigma(length) ) sigma(:) = g_in(:,1,1)**2 + g_in(:,2,1)**2 + g_in(:,3,1)**2 ENDIF ! !$acc data copyin( sigma ) CALL dgcxc_unpol( length, r_in(:,1), sigma, vrrx(:,1), vsrx(:,1), vssx(:,1), & vrrc(:,1), vsrc(:,1), vssc ) !$acc end data ! !$acc parallel loop DO k = 1, length dvxc_rr(k,1,1) = dvxc_rr(k,1,1) + e2 * (vrrx(k,1) + vrrc(k,1)) dvxc_sr(k,1,1) = dvxc_sr(k,1,1) + e2 * (vsrx(k,1) + vsrc(k,1)) dvxc_ss(k,1,1) = dvxc_ss(k,1,1) + e2 * (vssx(k,1) + vssc(k) ) ENDDO ! ELSEIF ( sp == 2 ) THEN ! ALLOCATE( vrzc(length,sp) ) !$acc data create( vrzc ) ! CALL dgcxc_spin( length, r_in, g_in, vrrx, vsrx, vssx, vrrc, vsrc, vssc, vrzc ) ! !$acc parallel loop DO k = 1, length rht = r_in(k,1) + r_in(k,2) IF (rht > epsr) THEN zeta = (r_in(k,1) - r_in(k,2))/rht ! dvxc_rr(k,1,1) = dvxc_rr(k,1,1) + e2*(vrrx(k,1) + vrrc(k,1) + & vrzc(k,1)*(1.d0 - zeta)/rht) dvxc_rr(k,1,2) = dvxc_rr(k,1,2) + e2*(vrrc(k,1) - vrzc(k,1)*(1.d0 + zeta)/rht) dvxc_rr(k,2,1) = dvxc_rr(k,2,1) + e2*(vrrc(k,2) + vrzc(k,2)*(1.d0 - zeta)/rht) dvxc_rr(k,2,2) = dvxc_rr(k,2,2) + e2*(vrrx(k,2) + vrrc(k,2) - & vrzc(k,2)*(1.d0 + zeta)/rht) ENDIF ! dvxc_sr(k,1,1) = dvxc_sr(k,1,1) + e2 * (vsrx(k,1) + vsrc(k,1)) dvxc_sr(k,1,2) = dvxc_sr(k,1,2) + e2 * vsrc(k,1) dvxc_sr(k,2,1) = dvxc_sr(k,2,1) + e2 * vsrc(k,2) dvxc_sr(k,2,2) = dvxc_sr(k,2,2) + e2 * (vsrx(k,2) + vsrc(k,2)) ! dvxc_ss(k,1,1) = dvxc_ss(k,1,1) + e2 * (vssx(k,1) + vssc(k)) dvxc_ss(k,1,2) = dvxc_ss(k,1,2) + e2 * vssc(k) dvxc_ss(k,2,1) = dvxc_ss(k,2,1) + e2 * vssc(k) dvxc_ss(k,2,2) = dvxc_ss(k,2,2) + e2 * (vssx(k,2) + vssc(k)) ENDDO ! !$acc end data DEALLOCATE( vrzc ) ! ENDIF ! !$acc end data DEALLOCATE( vrrx, vsrx, vssx ) DEALLOCATE( vrrc, vsrc, vssc ) ! ENDIF ! IF ( ANY(is_libxc(3:4))) DEALLOCATE( rho_lxc ) IF ( ALLOCATED(sigma) ) DEALLOCATE( sigma ) ! #else ! ALLOCATE( vrrx(length,sp), vsrx(length,sp), vssx(length,sp) ) ALLOCATE( vrrc(length,sp), vsrc(length,sp), vssc(length) ) !$acc data create( vrrx, vsrx, vssx, vrrc, vsrc, vssc ) ! SELECT CASE( sp ) CASE( 1 ) ! ALLOCATE( sigma(length) ) !$acc data create( sigma ) ! !$acc parallel loop DO k = 1, length sigma(k) = g_in(k,1,1)**2 + g_in(k,2,1)**2 + g_in(k,3,1)**2 ENDDO ! CALL dgcxc_unpol( length, r_in(:,1), sigma, vrrx(:,1), vsrx(:,1), vssx(:,1), & vrrc(:,1), vsrc(:,1), vssc ) ! !$acc end data DEALLOCATE( sigma ) ! !$acc parallel loop DO k = 1, length dvxc_rr(k,1,1) = e2*(vrrx(k,1) + vrrc(k,1)) dvxc_sr(k,1,1) = e2*(vsrx(k,1) + vsrc(k,1)) dvxc_ss(k,1,1) = e2*(vssx(k,1) + vssc(k) ) ENDDO ! CASE( 2 ) ! ALLOCATE( vrzc(length,sp) ) !$acc data create( vrzc ) ! CALL dgcxc_spin( length, r_in, g_in, vrrx, vsrx, vssx, vrrc, vsrc, vssc, vrzc ) ! !$acc parallel loop DO k = 1, length ! rht = r_in(k,1) + r_in(k,2) IF (rht > epsr) THEN zeta = (r_in(k,1) - r_in(k,2))/rht ! dvxc_rr(k,1,1) = e2*(vrrx(k,1) + vrrc(k,1) + vrzc(k,1)*(1.d0 - zeta)/rht) dvxc_rr(k,1,2) = e2*(vrrc(k,1) - vrzc(k,1)*(1.d0 + zeta)/rht) dvxc_rr(k,2,1) = e2*(vrrc(k,2) + vrzc(k,2)*(1.d0 - zeta)/rht) dvxc_rr(k,2,2) = e2*(vrrx(k,2) + vrrc(k,2) - vrzc(k,2)*(1.d0 + zeta)/rht) ENDIF ! dvxc_sr(k,1,1) = e2 * (vsrx(k,1) + vsrc(k,1)) dvxc_sr(k,1,2) = e2 * vsrc(k,1) dvxc_sr(k,2,1) = e2 * vsrc(k,2) dvxc_sr(k,2,2) = e2 * (vsrx(k,2) + vsrc(k,2)) ! dvxc_ss(k,1,1) = e2 * (vssx(k,1) + vssc(k)) dvxc_ss(k,1,2) = e2 * vssc(k) dvxc_ss(k,2,1) = e2 * vssc(k) dvxc_ss(k,2,2) = e2 * (vssx(k,2) + vssc(k)) ENDDO ! !$acc end data DEALLOCATE( vrzc ) ! CASE DEFAULT ! CALL xclib_error( 'dgcxc', 'Wrong ns input', 4 ) ! END SELECT ! !$acc end data DEALLOCATE( vrrx, vsrx, vssx ) DEALLOCATE( vrrc, vsrc, vssc ) ! #endif ! !$acc end data ! RETURN ! END SUBROUTINE dgcxc_
gpl-2.0
e-q/scipy
scipy/sparse/linalg/eigen/arpack/ARPACK/SRC/cnapps.f
38
17542
c\BeginDoc c c\Name: cnapps c c\Description: c Given the Arnoldi factorization c c A*V_{k} - V_{k}*H_{k} = r_{k+p}*e_{k+p}^T, c c apply NP implicit shifts resulting in c c A*(V_{k}*Q) - (V_{k}*Q)*(Q^T* H_{k}*Q) = r_{k+p}*e_{k+p}^T * Q c c where Q is an orthogonal matrix which is the product of rotations c and reflections resulting from the NP bulge change sweeps. c The updated Arnoldi factorization becomes: c c A*VNEW_{k} - VNEW_{k}*HNEW_{k} = rnew_{k}*e_{k}^T. c c\Usage: c call cnapps c ( N, KEV, NP, SHIFT, V, LDV, H, LDH, RESID, Q, LDQ, c WORKL, WORKD ) c c\Arguments c N Integer. (INPUT) c Problem size, i.e. size of matrix A. c c KEV Integer. (INPUT/OUTPUT) c KEV+NP is the size of the input matrix H. c KEV is the size of the updated matrix HNEW. c c NP Integer. (INPUT) c Number of implicit shifts to be applied. c c SHIFT Complex array of length NP. (INPUT) c The shifts to be applied. c c V Complex N by (KEV+NP) array. (INPUT/OUTPUT) c On INPUT, V contains the current KEV+NP Arnoldi vectors. c On OUTPUT, V contains the updated KEV Arnoldi vectors c in the first KEV columns of V. c c LDV Integer. (INPUT) c Leading dimension of V exactly as declared in the calling c program. c c H Complex (KEV+NP) by (KEV+NP) array. (INPUT/OUTPUT) c On INPUT, H contains the current KEV+NP by KEV+NP upper c Hessenberg matrix of the Arnoldi factorization. c On OUTPUT, H contains the updated KEV by KEV upper Hessenberg c matrix in the KEV leading submatrix. c c LDH Integer. (INPUT) c Leading dimension of H exactly as declared in the calling c program. c c RESID Complex array of length N. (INPUT/OUTPUT) c On INPUT, RESID contains the the residual vector r_{k+p}. c On OUTPUT, RESID is the update residual vector rnew_{k} c in the first KEV locations. c c Q Complex KEV+NP by KEV+NP work array. (WORKSPACE) c Work array used to accumulate the rotations and reflections c during the bulge chase sweep. c c LDQ Integer. (INPUT) c Leading dimension of Q exactly as declared in the calling c program. c c WORKL Complex work array of length (KEV+NP). (WORKSPACE) c Private (replicated) array on each PE or array allocated on c the front end. c c WORKD Complex work array of length 2*N. (WORKSPACE) c Distributed array used in the application of the accumulated c orthogonal matrix Q. c c\EndDoc c c----------------------------------------------------------------------- c c\BeginLib c c\Local variables: c xxxxxx Complex c c\References: c 1. D.C. Sorensen, "Implicit Application of Polynomial Filters in c a k-Step Arnoldi Method", SIAM J. Matr. Anal. Apps., 13 (1992), c pp 357-385. c c\Routines called: c ivout ARPACK utility routine that prints integers. c arscnd ARPACK utility routine for timing. c cmout ARPACK utility routine that prints matrices c cvout ARPACK utility routine that prints vectors. c clacpy LAPACK matrix copy routine. c clanhs LAPACK routine that computes various norms of a matrix. c clartg LAPACK Givens rotation construction routine. c claset LAPACK matrix initialization routine. c slabad LAPACK routine for defining the underflow and overflow c limits. c slamch LAPACK routine that determines machine constants. c slapy2 LAPACK routine to compute sqrt(x**2+y**2) carefully. c cgemv Level 2 BLAS routine for matrix vector multiplication. c caxpy Level 1 BLAS that computes a vector triad. c ccopy Level 1 BLAS that copies one vector to another. c cscal Level 1 BLAS that scales a vector. c c\Author c Danny Sorensen Phuong Vu c Richard Lehoucq CRPC / Rice University c Dept. of Computational & Houston, Texas c Applied Mathematics c Rice University c Houston, Texas c c\SCCS Information: @(#) c FILE: napps.F SID: 2.3 DATE OF SID: 3/28/97 RELEASE: 2 c c\Remarks c 1. In this version, each shift is applied to all the sublocks of c the Hessenberg matrix H and not just to the submatrix that it c comes from. Deflation as in LAPACK routine clahqr (QR algorithm c for upper Hessenberg matrices ) is used. c Upon output, the subdiagonals of H are enforced to be non-negative c real numbers. c c\EndLib c c----------------------------------------------------------------------- c subroutine cnapps & ( n, kev, np, shift, v, ldv, h, ldh, resid, q, ldq, & workl, workd ) c c %----------------------------------------------------% c | Include files for debugging and timing information | c %----------------------------------------------------% c include 'debug.h' include 'stat.h' c c %------------------% c | Scalar Arguments | c %------------------% c integer kev, ldh, ldq, ldv, n, np c c %-----------------% c | Array Arguments | c %-----------------% c Complex & h(ldh,kev+np), resid(n), shift(np), & v(ldv,kev+np), q(ldq,kev+np), workd(2*n), workl(kev+np) c c %------------% c | Parameters | c %------------% c Complex & one, zero Real & rzero parameter (one = (1.0E+0, 0.0E+0), zero = (0.0E+0, 0.0E+0), & rzero = 0.0E+0) c c %------------------------% c | Local Scalars & Arrays | c %------------------------% c integer i, iend, istart, j, jj, kplusp, msglvl logical first Complex & cdum, f, g, h11, h21, r, s, sigma, t Real & c, ovfl, smlnum, ulp, unfl, tst1 save first, ovfl, smlnum, ulp, unfl c c %----------------------% c | External Subroutines | c %----------------------% c external caxpy, ccopy, cgemv, cscal, clacpy, clartg, & cvout, claset, slabad, cmout, arscnd, ivout c c %--------------------% c | External Functions | c %--------------------% c Real & clanhs, slamch, slapy2 external clanhs, slamch, slapy2 c c %----------------------% c | Intrinsics Functions | c %----------------------% c intrinsic abs, aimag, conjg, cmplx, max, min, real c c %---------------------% c | Statement Functions | c %---------------------% c Real & cabs1 cabs1( cdum ) = abs( real( cdum ) ) + abs( aimag( cdum ) ) c c %----------------% c | Data statments | c %----------------% c data first / .true. / c c %-----------------------% c | Executable Statements | c %-----------------------% c if (first) then c c %-----------------------------------------------% c | Set machine-dependent constants for the | c | stopping criterion. If norm(H) <= sqrt(OVFL), | c | overflow should not occur. | c | REFERENCE: LAPACK subroutine clahqr | c %-----------------------------------------------% c unfl = slamch( 'safe minimum' ) ovfl = real(one / unfl) call slabad( unfl, ovfl ) ulp = slamch( 'precision' ) smlnum = unfl*( n / ulp ) first = .false. end if c c %-------------------------------% c | Initialize timing statistics | c | & message level for debugging | c %-------------------------------% c call arscnd (t0) msglvl = mcapps c kplusp = kev + np c c %--------------------------------------------% c | Initialize Q to the identity to accumulate | c | the rotations and reflections | c %--------------------------------------------% c call claset ('All', kplusp, kplusp, zero, one, q, ldq) c c %----------------------------------------------% c | Quick return if there are no shifts to apply | c %----------------------------------------------% c if (np .eq. 0) go to 9000 c c %----------------------------------------------% c | Chase the bulge with the application of each | c | implicit shift. Each shift is applied to the | c | whole matrix including each block. | c %----------------------------------------------% c do 110 jj = 1, np sigma = shift(jj) c if (msglvl .gt. 2 ) then call ivout (logfil, 1, jj, ndigit, & '_napps: shift number.') call cvout (logfil, 1, sigma, ndigit, & '_napps: Value of the shift ') end if c istart = 1 20 continue c do 30 i = istart, kplusp-1 c c %----------------------------------------% c | Check for splitting and deflation. Use | c | a standard test as in the QR algorithm | c | REFERENCE: LAPACK subroutine clahqr | c %----------------------------------------% c tst1 = cabs1( h( i, i ) ) + cabs1( h( i+1, i+1 ) ) if( tst1.eq.rzero ) & tst1 = clanhs( '1', kplusp-jj+1, h, ldh, workl ) if ( abs(real(h(i+1,i))) & .le. max(ulp*tst1, smlnum) ) then if (msglvl .gt. 0) then call ivout (logfil, 1, i, ndigit, & '_napps: matrix splitting at row/column no.') call ivout (logfil, 1, jj, ndigit, & '_napps: matrix splitting with shift number.') call cvout (logfil, 1, h(i+1,i), ndigit, & '_napps: off diagonal element.') end if iend = i h(i+1,i) = zero go to 40 end if 30 continue iend = kplusp 40 continue c if (msglvl .gt. 2) then call ivout (logfil, 1, istart, ndigit, & '_napps: Start of current block ') call ivout (logfil, 1, iend, ndigit, & '_napps: End of current block ') end if c c %------------------------------------------------% c | No reason to apply a shift to block of order 1 | c | or if the current block starts after the point | c | of compression since we'll discard this stuff | c %------------------------------------------------% c if ( istart .eq. iend .or. istart .gt. kev) go to 100 c h11 = h(istart,istart) h21 = h(istart+1,istart) f = h11 - sigma g = h21 c do 80 i = istart, iend-1 c c %------------------------------------------------------% c | Construct the plane rotation G to zero out the bulge | c %------------------------------------------------------% c call clartg (f, g, c, s, r) if (i .gt. istart) then h(i,i-1) = r h(i+1,i-1) = zero end if c c %---------------------------------------------% c | Apply rotation to the left of H; H <- G'*H | c %---------------------------------------------% c do 50 j = i, kplusp t = c*h(i,j) + s*h(i+1,j) h(i+1,j) = -conjg(s)*h(i,j) + c*h(i+1,j) h(i,j) = t 50 continue c c %---------------------------------------------% c | Apply rotation to the right of H; H <- H*G | c %---------------------------------------------% c do 60 j = 1, min(i+2,iend) t = c*h(j,i) + conjg(s)*h(j,i+1) h(j,i+1) = -s*h(j,i) + c*h(j,i+1) h(j,i) = t 60 continue c c %-----------------------------------------------------% c | Accumulate the rotation in the matrix Q; Q <- Q*G' | c %-----------------------------------------------------% c do 70 j = 1, min(i+jj, kplusp) t = c*q(j,i) + conjg(s)*q(j,i+1) q(j,i+1) = - s*q(j,i) + c*q(j,i+1) q(j,i) = t 70 continue c c %---------------------------% c | Prepare for next rotation | c %---------------------------% c if (i .lt. iend-1) then f = h(i+1,i) g = h(i+2,i) end if 80 continue c c %-------------------------------% c | Finished applying the shift. | c %-------------------------------% c 100 continue c c %---------------------------------------------------------% c | Apply the same shift to the next block if there is any. | c %---------------------------------------------------------% c istart = iend + 1 if (iend .lt. kplusp) go to 20 c c %---------------------------------------------% c | Loop back to the top to get the next shift. | c %---------------------------------------------% c 110 continue c c %---------------------------------------------------% c | Perform a similarity transformation that makes | c | sure that the compressed H will have non-negative | c | real subdiagonal elements. | c %---------------------------------------------------% c do 120 j=1,kev if ( real( h(j+1,j) ) .lt. rzero .or. & aimag( h(j+1,j) ) .ne. rzero ) then t = h(j+1,j) / slapy2(real(h(j+1,j)),aimag(h(j+1,j))) call cscal( kplusp-j+1, conjg(t), h(j+1,j), ldh ) call cscal( min(j+2, kplusp), t, h(1,j+1), 1 ) call cscal( min(j+np+1,kplusp), t, q(1,j+1), 1 ) h(j+1,j) = cmplx( real( h(j+1,j) ), rzero ) end if 120 continue c do 130 i = 1, kev c c %--------------------------------------------% c | Final check for splitting and deflation. | c | Use a standard test as in the QR algorithm | c | REFERENCE: LAPACK subroutine clahqr. | c | Note: Since the subdiagonals of the | c | compressed H are nonnegative real numbers, | c | we take advantage of this. | c %--------------------------------------------% c tst1 = cabs1( h( i, i ) ) + cabs1( h( i+1, i+1 ) ) if( tst1 .eq. rzero ) & tst1 = clanhs( '1', kev, h, ldh, workl ) if( real( h( i+1,i ) ) .le. max( ulp*tst1, smlnum ) ) & h(i+1,i) = zero 130 continue c c %-------------------------------------------------% c | Compute the (kev+1)-st column of (V*Q) and | c | temporarily store the result in WORKD(N+1:2*N). | c | This is needed in the residual update since we | c | cannot GUARANTEE that the corresponding entry | c | of H would be zero as in exact arithmetic. | c %-------------------------------------------------% c if ( real( h(kev+1,kev) ) .gt. rzero ) & call cgemv ('N', n, kplusp, one, v, ldv, q(1,kev+1), 1, zero, & workd(n+1), 1) c c %----------------------------------------------------------% c | Compute column 1 to kev of (V*Q) in backward order | c | taking advantage of the upper Hessenberg structure of Q. | c %----------------------------------------------------------% c do 140 i = 1, kev call cgemv ('N', n, kplusp-i+1, one, v, ldv, & q(1,kev-i+1), 1, zero, workd, 1) call ccopy (n, workd, 1, v(1,kplusp-i+1), 1) 140 continue c c %-------------------------------------------------% c | Move v(:,kplusp-kev+1:kplusp) into v(:,1:kev). | c %-------------------------------------------------% c call clacpy ('A', n, kev, v(1,kplusp-kev+1), ldv, v, ldv) c c %--------------------------------------------------------------% c | Copy the (kev+1)-st column of (V*Q) in the appropriate place | c %--------------------------------------------------------------% c if ( real( h(kev+1,kev) ) .gt. rzero ) & call ccopy (n, workd(n+1), 1, v(1,kev+1), 1) c c %-------------------------------------% c | Update the residual vector: | c | r <- sigmak*r + betak*v(:,kev+1) | c | where | c | sigmak = (e_{kev+p}'*Q)*e_{kev} | c | betak = e_{kev+1}'*H*e_{kev} | c %-------------------------------------% c call cscal (n, q(kplusp,kev), resid, 1) if ( real( h(kev+1,kev) ) .gt. rzero ) & call caxpy (n, h(kev+1,kev), v(1,kev+1), 1, resid, 1) c if (msglvl .gt. 1) then call cvout (logfil, 1, q(kplusp,kev), ndigit, & '_napps: sigmak = (e_{kev+p}^T*Q)*e_{kev}') call cvout (logfil, 1, h(kev+1,kev), ndigit, & '_napps: betak = e_{kev+1}^T*H*e_{kev}') call ivout (logfil, 1, kev, ndigit, & '_napps: Order of the final Hessenberg matrix ') if (msglvl .gt. 2) then call cmout (logfil, kev, kev, h, ldh, ndigit, & '_napps: updated Hessenberg matrix H for next iteration') end if c end if c 9000 continue call arscnd (t1) tcapps = tcapps + (t1 - t0) c return c c %---------------% c | End of cnapps | c %---------------% c end
bsd-3-clause
wilmarcardonac/hypermcmc
lapack-3.5.0/INSTALL/dlamch.f
139
5329
*> \brief \b DLAMCH * * =========== DOCUMENTATION =========== * * Online html documentation available at * http://www.netlib.org/lapack/explore-html/ * * Definition: * =========== * * DOUBLE PRECISION FUNCTION DLAMCH( CMACH ) * * *> \par Purpose: * ============= *> *> \verbatim *> *> DLAMCH determines double precision machine parameters. *> \endverbatim * * Arguments: * ========== * *> \param[in] CMACH *> \verbatim *> Specifies the value to be returned by DLAMCH: *> = 'E' or 'e', DLAMCH := eps *> = 'S' or 's , DLAMCH := sfmin *> = 'B' or 'b', DLAMCH := base *> = 'P' or 'p', DLAMCH := eps*base *> = 'N' or 'n', DLAMCH := t *> = 'R' or 'r', DLAMCH := rnd *> = 'M' or 'm', DLAMCH := emin *> = 'U' or 'u', DLAMCH := rmin *> = 'L' or 'l', DLAMCH := emax *> = 'O' or 'o', DLAMCH := rmax *> where *> eps = relative machine precision *> sfmin = safe minimum, such that 1/sfmin does not overflow *> base = base of the machine *> prec = eps*base *> t = number of (base) digits in the mantissa *> rnd = 1.0 when rounding occurs in addition, 0.0 otherwise *> emin = minimum exponent before (gradual) underflow *> rmin = underflow threshold - base**(emin-1) *> emax = largest exponent before overflow *> rmax = overflow threshold - (base**emax)*(1-eps) *> \endverbatim * * Authors: * ======== * *> \author Univ. of Tennessee *> \author Univ. of California Berkeley *> \author Univ. of Colorado Denver *> \author NAG Ltd. * *> \date November 2011 * *> \ingroup auxOTHERauxiliary * * ===================================================================== DOUBLE PRECISION FUNCTION DLAMCH( CMACH ) * * -- LAPACK auxiliary routine (version 3.4.0) -- * -- LAPACK is a software package provided by Univ. of Tennessee, -- * -- Univ. of California Berkeley, Univ. of Colorado Denver and NAG Ltd..-- * November 2011 * * .. Scalar Arguments .. CHARACTER CMACH * .. * * .. Scalar Arguments .. DOUBLE PRECISION A, B * .. * * ===================================================================== * * .. Parameters .. DOUBLE PRECISION ONE, ZERO PARAMETER ( ONE = 1.0D+0, ZERO = 0.0D+0 ) * .. * .. Local Scalars .. DOUBLE PRECISION RND, EPS, SFMIN, SMALL, RMACH * .. * .. External Functions .. LOGICAL LSAME EXTERNAL LSAME * .. * .. Intrinsic Functions .. INTRINSIC DIGITS, EPSILON, HUGE, MAXEXPONENT, $ MINEXPONENT, RADIX, TINY * .. * .. Executable Statements .. * * * Assume rounding, not chopping. Always. * RND = ONE * IF( ONE.EQ.RND ) THEN EPS = EPSILON(ZERO) * 0.5 ELSE EPS = EPSILON(ZERO) END IF * IF( LSAME( CMACH, 'E' ) ) THEN RMACH = EPS ELSE IF( LSAME( CMACH, 'S' ) ) THEN SFMIN = TINY(ZERO) SMALL = ONE / HUGE(ZERO) IF( SMALL.GE.SFMIN ) THEN * * Use SMALL plus a bit, to avoid the possibility of rounding * causing overflow when computing 1/sfmin. * SFMIN = SMALL*( ONE+EPS ) END IF RMACH = SFMIN ELSE IF( LSAME( CMACH, 'B' ) ) THEN RMACH = RADIX(ZERO) ELSE IF( LSAME( CMACH, 'P' ) ) THEN RMACH = EPS * RADIX(ZERO) ELSE IF( LSAME( CMACH, 'N' ) ) THEN RMACH = DIGITS(ZERO) ELSE IF( LSAME( CMACH, 'R' ) ) THEN RMACH = RND ELSE IF( LSAME( CMACH, 'M' ) ) THEN RMACH = MINEXPONENT(ZERO) ELSE IF( LSAME( CMACH, 'U' ) ) THEN RMACH = tiny(zero) ELSE IF( LSAME( CMACH, 'L' ) ) THEN RMACH = MAXEXPONENT(ZERO) ELSE IF( LSAME( CMACH, 'O' ) ) THEN RMACH = HUGE(ZERO) ELSE RMACH = ZERO END IF * DLAMCH = RMACH RETURN * * End of DLAMCH * END ************************************************************************ *> \brief \b DLAMC3 *> \details *> \b Purpose: *> \verbatim *> DLAMC3 is intended to force A and B to be stored prior to doing *> the addition of A and B , for use in situations where optimizers *> might hold one of these in a register. *> \endverbatim *> \author LAPACK is a software package provided by Univ. of Tennessee, Univ. of California Berkeley, Univ. of Colorado Denver and NAG Ltd.. *> \date November 2011 *> \ingroup auxOTHERauxiliary *> *> \param[in] A *> \verbatim *> A is a DOUBLE PRECISION *> \endverbatim *> *> \param[in] B *> \verbatim *> B is a DOUBLE PRECISION *> The values A and B. *> \endverbatim *> DOUBLE PRECISION FUNCTION DLAMC3( A, B ) * * -- LAPACK auxiliary routine (version 3.4.0) -- * Univ. of Tennessee, Univ. of California Berkeley and NAG Ltd.. * November 2010 * * .. Scalar Arguments .. DOUBLE PRECISION A, B * .. * ===================================================================== * * .. Executable Statements .. * DLAMC3 = A + B * RETURN * * End of DLAMC3 * END * ************************************************************************
gpl-2.0
wilmarcardonac/hypermcmc
lapack-3.5.0/SRC/cla_syamv.f
24
13178
*> \brief \b CLA_SYAMV computes a matrix-vector product using a symmetric indefinite matrix to calculate error bounds. * * =========== DOCUMENTATION =========== * * Online html documentation available at * http://www.netlib.org/lapack/explore-html/ * *> \htmlonly *> Download CLA_SYAMV + dependencies *> <a href="http://www.netlib.org/cgi-bin/netlibfiles.tgz?format=tgz&filename=/lapack/lapack_routine/cla_syamv.f"> *> [TGZ]</a> *> <a href="http://www.netlib.org/cgi-bin/netlibfiles.zip?format=zip&filename=/lapack/lapack_routine/cla_syamv.f"> *> [ZIP]</a> *> <a href="http://www.netlib.org/cgi-bin/netlibfiles.txt?format=txt&filename=/lapack/lapack_routine/cla_syamv.f"> *> [TXT]</a> *> \endhtmlonly * * Definition: * =========== * * SUBROUTINE CLA_SYAMV( UPLO, N, ALPHA, A, LDA, X, INCX, BETA, Y, * INCY ) * * .. Scalar Arguments .. * REAL ALPHA, BETA * INTEGER INCX, INCY, LDA, N * INTEGER UPLO * .. * .. Array Arguments .. * COMPLEX A( LDA, * ), X( * ) * REAL Y( * ) * .. * * *> \par Purpose: * ============= *> *> \verbatim *> *> CLA_SYAMV performs the matrix-vector operation *> *> y := alpha*abs(A)*abs(x) + beta*abs(y), *> *> where alpha and beta are scalars, x and y are vectors and A is an *> n by n symmetric matrix. *> *> This function is primarily used in calculating error bounds. *> To protect against underflow during evaluation, components in *> the resulting vector are perturbed away from zero by (N+1) *> times the underflow threshold. To prevent unnecessarily large *> errors for block-structure embedded in general matrices, *> "symbolically" zero components are not perturbed. A zero *> entry is considered "symbolic" if all multiplications involved *> in computing that entry have at least one zero multiplicand. *> \endverbatim * * Arguments: * ========== * *> \param[in] UPLO *> \verbatim *> UPLO is INTEGER *> On entry, UPLO specifies whether the upper or lower *> triangular part of the array A is to be referenced as *> follows: *> *> UPLO = BLAS_UPPER Only the upper triangular part of A *> is to be referenced. *> *> UPLO = BLAS_LOWER Only the lower triangular part of A *> is to be referenced. *> *> Unchanged on exit. *> \endverbatim *> *> \param[in] N *> \verbatim *> N is INTEGER *> On entry, N specifies the number of columns of the matrix A. *> N must be at least zero. *> Unchanged on exit. *> \endverbatim *> *> \param[in] ALPHA *> \verbatim *> ALPHA is REAL . *> On entry, ALPHA specifies the scalar alpha. *> Unchanged on exit. *> \endverbatim *> *> \param[in] A *> \verbatim *> A is COMPLEX array of DIMENSION ( LDA, n ). *> Before entry, the leading m by n part of the array A must *> contain the matrix of coefficients. *> Unchanged on exit. *> \endverbatim *> *> \param[in] LDA *> \verbatim *> LDA is INTEGER *> On entry, LDA specifies the first dimension of A as declared *> in the calling (sub) program. LDA must be at least *> max( 1, n ). *> Unchanged on exit. *> \endverbatim *> *> \param[in] X *> \verbatim *> X is COMPLEX array, dimension *> ( 1 + ( n - 1 )*abs( INCX ) ) *> Before entry, the incremented array X must contain the *> vector x. *> Unchanged on exit. *> \endverbatim *> *> \param[in] INCX *> \verbatim *> INCX is INTEGER *> On entry, INCX specifies the increment for the elements of *> X. INCX must not be zero. *> Unchanged on exit. *> \endverbatim *> *> \param[in] BETA *> \verbatim *> BETA is REAL . *> On entry, BETA specifies the scalar beta. When BETA is *> supplied as zero then Y need not be set on input. *> Unchanged on exit. *> \endverbatim *> *> \param[in,out] Y *> \verbatim *> Y is REAL array, dimension *> ( 1 + ( n - 1 )*abs( INCY ) ) *> Before entry with BETA non-zero, the incremented array Y *> must contain the vector y. On exit, Y is overwritten by the *> updated vector y. *> \endverbatim *> *> \param[in] INCY *> \verbatim *> INCY is INTEGER *> On entry, INCY specifies the increment for the elements of *> Y. INCY must not be zero. *> Unchanged on exit. *> \endverbatim * * Authors: * ======== * *> \author Univ. of Tennessee *> \author Univ. of California Berkeley *> \author Univ. of Colorado Denver *> \author NAG Ltd. * *> \date September 2012 * *> \ingroup complexSYcomputational * *> \par Further Details: * ===================== *> *> \verbatim *> *> Level 2 Blas routine. *> *> -- Written on 22-October-1986. *> Jack Dongarra, Argonne National Lab. *> Jeremy Du Croz, Nag Central Office. *> Sven Hammarling, Nag Central Office. *> Richard Hanson, Sandia National Labs. *> -- Modified for the absolute-value product, April 2006 *> Jason Riedy, UC Berkeley *> \endverbatim *> * ===================================================================== SUBROUTINE CLA_SYAMV( UPLO, N, ALPHA, A, LDA, X, INCX, BETA, Y, $ INCY ) * * -- LAPACK computational routine (version 3.4.2) -- * -- LAPACK is a software package provided by Univ. of Tennessee, -- * -- Univ. of California Berkeley, Univ. of Colorado Denver and NAG Ltd..-- * September 2012 * * .. Scalar Arguments .. REAL ALPHA, BETA INTEGER INCX, INCY, LDA, N INTEGER UPLO * .. * .. Array Arguments .. COMPLEX A( LDA, * ), X( * ) REAL Y( * ) * .. * * ===================================================================== * * .. Parameters .. REAL ONE, ZERO PARAMETER ( ONE = 1.0E+0, ZERO = 0.0E+0 ) * .. * .. Local Scalars .. LOGICAL SYMB_ZERO REAL TEMP, SAFE1 INTEGER I, INFO, IY, J, JX, KX, KY COMPLEX ZDUM * .. * .. External Subroutines .. EXTERNAL XERBLA, SLAMCH REAL SLAMCH * .. * .. External Functions .. EXTERNAL ILAUPLO INTEGER ILAUPLO * .. * .. Intrinsic Functions .. INTRINSIC MAX, ABS, SIGN, REAL, AIMAG * .. * .. Statement Functions .. REAL CABS1 * .. * .. Statement Function Definitions .. CABS1( ZDUM ) = ABS( REAL ( ZDUM ) ) + ABS( AIMAG ( ZDUM ) ) * .. * .. Executable Statements .. * * Test the input parameters. * INFO = 0 IF ( UPLO.NE.ILAUPLO( 'U' ) .AND. $ UPLO.NE.ILAUPLO( 'L' ) )THEN INFO = 1 ELSE IF( N.LT.0 )THEN INFO = 2 ELSE IF( LDA.LT.MAX( 1, N ) )THEN INFO = 5 ELSE IF( INCX.EQ.0 )THEN INFO = 7 ELSE IF( INCY.EQ.0 )THEN INFO = 10 END IF IF( INFO.NE.0 )THEN CALL XERBLA( 'SSYMV ', INFO ) RETURN END IF * * Quick return if possible. * IF( ( N.EQ.0 ).OR.( ( ALPHA.EQ.ZERO ).AND.( BETA.EQ.ONE ) ) ) $ RETURN * * Set up the start points in X and Y. * IF( INCX.GT.0 )THEN KX = 1 ELSE KX = 1 - ( N - 1 )*INCX END IF IF( INCY.GT.0 )THEN KY = 1 ELSE KY = 1 - ( N - 1 )*INCY END IF * * Set SAFE1 essentially to be the underflow threshold times the * number of additions in each row. * SAFE1 = SLAMCH( 'Safe minimum' ) SAFE1 = (N+1)*SAFE1 * * Form y := alpha*abs(A)*abs(x) + beta*abs(y). * * The O(N^2) SYMB_ZERO tests could be replaced by O(N) queries to * the inexact flag. Still doesn't help change the iteration order * to per-column. * IY = KY IF ( INCX.EQ.1 ) THEN IF ( UPLO .EQ. ILAUPLO( 'U' ) ) THEN DO I = 1, N IF ( BETA .EQ. ZERO ) THEN SYMB_ZERO = .TRUE. Y( IY ) = 0.0 ELSE IF ( Y( IY ) .EQ. ZERO ) THEN SYMB_ZERO = .TRUE. ELSE SYMB_ZERO = .FALSE. Y( IY ) = BETA * ABS( Y( IY ) ) END IF IF ( ALPHA .NE. ZERO ) THEN DO J = 1, I TEMP = CABS1( A( J, I ) ) SYMB_ZERO = SYMB_ZERO .AND. $ ( X( J ) .EQ. ZERO .OR. TEMP .EQ. ZERO ) Y( IY ) = Y( IY ) + ALPHA*CABS1( X( J ) )*TEMP END DO DO J = I+1, N TEMP = CABS1( A( I, J ) ) SYMB_ZERO = SYMB_ZERO .AND. $ ( X( J ) .EQ. ZERO .OR. TEMP .EQ. ZERO ) Y( IY ) = Y( IY ) + ALPHA*CABS1( X( J ) )*TEMP END DO END IF IF ( .NOT.SYMB_ZERO ) $ Y( IY ) = Y( IY ) + SIGN( SAFE1, Y( IY ) ) IY = IY + INCY END DO ELSE DO I = 1, N IF ( BETA .EQ. ZERO ) THEN SYMB_ZERO = .TRUE. Y( IY ) = 0.0 ELSE IF ( Y( IY ) .EQ. ZERO ) THEN SYMB_ZERO = .TRUE. ELSE SYMB_ZERO = .FALSE. Y( IY ) = BETA * ABS( Y( IY ) ) END IF IF ( ALPHA .NE. ZERO ) THEN DO J = 1, I TEMP = CABS1( A( I, J ) ) SYMB_ZERO = SYMB_ZERO .AND. $ ( X( J ) .EQ. ZERO .OR. TEMP .EQ. ZERO ) Y( IY ) = Y( IY ) + ALPHA*CABS1( X( J ) )*TEMP END DO DO J = I+1, N TEMP = CABS1( A( J, I ) ) SYMB_ZERO = SYMB_ZERO .AND. $ ( X( J ) .EQ. ZERO .OR. TEMP .EQ. ZERO ) Y( IY ) = Y( IY ) + ALPHA*CABS1( X( J ) )*TEMP END DO END IF IF ( .NOT.SYMB_ZERO ) $ Y( IY ) = Y( IY ) + SIGN( SAFE1, Y( IY ) ) IY = IY + INCY END DO END IF ELSE IF ( UPLO .EQ. ILAUPLO( 'U' ) ) THEN DO I = 1, N IF ( BETA .EQ. ZERO ) THEN SYMB_ZERO = .TRUE. Y( IY ) = 0.0 ELSE IF ( Y( IY ) .EQ. ZERO ) THEN SYMB_ZERO = .TRUE. ELSE SYMB_ZERO = .FALSE. Y( IY ) = BETA * ABS( Y( IY ) ) END IF JX = KX IF ( ALPHA .NE. ZERO ) THEN DO J = 1, I TEMP = CABS1( A( J, I ) ) SYMB_ZERO = SYMB_ZERO .AND. $ ( X( J ) .EQ. ZERO .OR. TEMP .EQ. ZERO ) Y( IY ) = Y( IY ) + ALPHA*CABS1( X( JX ) )*TEMP JX = JX + INCX END DO DO J = I+1, N TEMP = CABS1( A( I, J ) ) SYMB_ZERO = SYMB_ZERO .AND. $ ( X( J ) .EQ. ZERO .OR. TEMP .EQ. ZERO ) Y( IY ) = Y( IY ) + ALPHA*CABS1( X( JX ) )*TEMP JX = JX + INCX END DO END IF IF ( .NOT.SYMB_ZERO ) $ Y( IY ) = Y( IY ) + SIGN( SAFE1, Y( IY ) ) IY = IY + INCY END DO ELSE DO I = 1, N IF ( BETA .EQ. ZERO ) THEN SYMB_ZERO = .TRUE. Y( IY ) = 0.0 ELSE IF ( Y( IY ) .EQ. ZERO ) THEN SYMB_ZERO = .TRUE. ELSE SYMB_ZERO = .FALSE. Y( IY ) = BETA * ABS( Y( IY ) ) END IF JX = KX IF ( ALPHA .NE. ZERO ) THEN DO J = 1, I TEMP = CABS1( A( I, J ) ) SYMB_ZERO = SYMB_ZERO .AND. $ ( X( J ) .EQ. ZERO .OR. TEMP .EQ. ZERO ) Y( IY ) = Y( IY ) + ALPHA*CABS1( X( JX ) )*TEMP JX = JX + INCX END DO DO J = I+1, N TEMP = CABS1( A( J, I ) ) SYMB_ZERO = SYMB_ZERO .AND. $ ( X( J ) .EQ. ZERO .OR. TEMP .EQ. ZERO ) Y( IY ) = Y( IY ) + ALPHA*CABS1( X( JX ) )*TEMP JX = JX + INCX END DO END IF IF ( .NOT.SYMB_ZERO ) $ Y( IY ) = Y( IY ) + SIGN( SAFE1, Y( IY ) ) IY = IY + INCY END DO END IF END IF * RETURN * * End of CLA_SYAMV * END
gpl-2.0
linzhaoming/origin
vendor/gonum.org/v1/gonum/lapack/internal/testdata/dsterftest/dlamch.f
139
5329
*> \brief \b DLAMCH * * =========== DOCUMENTATION =========== * * Online html documentation available at * http://www.netlib.org/lapack/explore-html/ * * Definition: * =========== * * DOUBLE PRECISION FUNCTION DLAMCH( CMACH ) * * *> \par Purpose: * ============= *> *> \verbatim *> *> DLAMCH determines double precision machine parameters. *> \endverbatim * * Arguments: * ========== * *> \param[in] CMACH *> \verbatim *> Specifies the value to be returned by DLAMCH: *> = 'E' or 'e', DLAMCH := eps *> = 'S' or 's , DLAMCH := sfmin *> = 'B' or 'b', DLAMCH := base *> = 'P' or 'p', DLAMCH := eps*base *> = 'N' or 'n', DLAMCH := t *> = 'R' or 'r', DLAMCH := rnd *> = 'M' or 'm', DLAMCH := emin *> = 'U' or 'u', DLAMCH := rmin *> = 'L' or 'l', DLAMCH := emax *> = 'O' or 'o', DLAMCH := rmax *> where *> eps = relative machine precision *> sfmin = safe minimum, such that 1/sfmin does not overflow *> base = base of the machine *> prec = eps*base *> t = number of (base) digits in the mantissa *> rnd = 1.0 when rounding occurs in addition, 0.0 otherwise *> emin = minimum exponent before (gradual) underflow *> rmin = underflow threshold - base**(emin-1) *> emax = largest exponent before overflow *> rmax = overflow threshold - (base**emax)*(1-eps) *> \endverbatim * * Authors: * ======== * *> \author Univ. of Tennessee *> \author Univ. of California Berkeley *> \author Univ. of Colorado Denver *> \author NAG Ltd. * *> \date November 2011 * *> \ingroup auxOTHERauxiliary * * ===================================================================== DOUBLE PRECISION FUNCTION DLAMCH( CMACH ) * * -- LAPACK auxiliary routine (version 3.4.0) -- * -- LAPACK is a software package provided by Univ. of Tennessee, -- * -- Univ. of California Berkeley, Univ. of Colorado Denver and NAG Ltd..-- * November 2011 * * .. Scalar Arguments .. CHARACTER CMACH * .. * * .. Scalar Arguments .. DOUBLE PRECISION A, B * .. * * ===================================================================== * * .. Parameters .. DOUBLE PRECISION ONE, ZERO PARAMETER ( ONE = 1.0D+0, ZERO = 0.0D+0 ) * .. * .. Local Scalars .. DOUBLE PRECISION RND, EPS, SFMIN, SMALL, RMACH * .. * .. External Functions .. LOGICAL LSAME EXTERNAL LSAME * .. * .. Intrinsic Functions .. INTRINSIC DIGITS, EPSILON, HUGE, MAXEXPONENT, $ MINEXPONENT, RADIX, TINY * .. * .. Executable Statements .. * * * Assume rounding, not chopping. Always. * RND = ONE * IF( ONE.EQ.RND ) THEN EPS = EPSILON(ZERO) * 0.5 ELSE EPS = EPSILON(ZERO) END IF * IF( LSAME( CMACH, 'E' ) ) THEN RMACH = EPS ELSE IF( LSAME( CMACH, 'S' ) ) THEN SFMIN = TINY(ZERO) SMALL = ONE / HUGE(ZERO) IF( SMALL.GE.SFMIN ) THEN * * Use SMALL plus a bit, to avoid the possibility of rounding * causing overflow when computing 1/sfmin. * SFMIN = SMALL*( ONE+EPS ) END IF RMACH = SFMIN ELSE IF( LSAME( CMACH, 'B' ) ) THEN RMACH = RADIX(ZERO) ELSE IF( LSAME( CMACH, 'P' ) ) THEN RMACH = EPS * RADIX(ZERO) ELSE IF( LSAME( CMACH, 'N' ) ) THEN RMACH = DIGITS(ZERO) ELSE IF( LSAME( CMACH, 'R' ) ) THEN RMACH = RND ELSE IF( LSAME( CMACH, 'M' ) ) THEN RMACH = MINEXPONENT(ZERO) ELSE IF( LSAME( CMACH, 'U' ) ) THEN RMACH = tiny(zero) ELSE IF( LSAME( CMACH, 'L' ) ) THEN RMACH = MAXEXPONENT(ZERO) ELSE IF( LSAME( CMACH, 'O' ) ) THEN RMACH = HUGE(ZERO) ELSE RMACH = ZERO END IF * DLAMCH = RMACH RETURN * * End of DLAMCH * END ************************************************************************ *> \brief \b DLAMC3 *> \details *> \b Purpose: *> \verbatim *> DLAMC3 is intended to force A and B to be stored prior to doing *> the addition of A and B , for use in situations where optimizers *> might hold one of these in a register. *> \endverbatim *> \author LAPACK is a software package provided by Univ. of Tennessee, Univ. of California Berkeley, Univ. of Colorado Denver and NAG Ltd.. *> \date November 2011 *> \ingroup auxOTHERauxiliary *> *> \param[in] A *> \verbatim *> A is a DOUBLE PRECISION *> \endverbatim *> *> \param[in] B *> \verbatim *> B is a DOUBLE PRECISION *> The values A and B. *> \endverbatim *> DOUBLE PRECISION FUNCTION DLAMC3( A, B ) * * -- LAPACK auxiliary routine (version 3.4.0) -- * Univ. of Tennessee, Univ. of California Berkeley and NAG Ltd.. * November 2010 * * .. Scalar Arguments .. DOUBLE PRECISION A, B * .. * ===================================================================== * * .. Executable Statements .. * DLAMC3 = A + B * RETURN * * End of DLAMC3 * END * ************************************************************************
apache-2.0
QEF/q-e
CPV/src/eigs0.f90
1
10446
! ! Copyright (C) 2002-2005 FPMD-CPV groups ! This file is distributed under the terms of the ! GNU General Public License. See the file `License' ! in the root directory of the present distribution, ! or http://www.gnu.org/copyleft/gpl.txt . ! !----------------------------------------------------------------------- subroutine eigs0( ei, nudx, tprint, nspin, nupdwn, iupdwn, lf, f, nx, lambda, nlam, idesc ) !----------------------------------------------------------------------- !! Computes eigenvalues (wr) of the real symmetric matrix \(\text{lambda}\). !! Note that \(\text{lambda}\) as calculated is multiplied by occupation numbers, !! so empty states yield zero. Eigenvalues are printed out in eV. ! use kinds, only : DP use io_global, only : stdout use constants, only : autoev USE sic_module, only : self_interaction USE mp, only : mp_sum, mp_bcast USE mp_global, only : intra_bgrp_comm, root_bgrp, me_bgrp implicit none include 'laxlib.fh' ! input logical, intent(in) :: tprint, lf integer, intent(in) :: nspin, nx, nudx, nupdwn(nspin), iupdwn(nspin), nlam integer, intent(in) :: idesc( LAX_DESC_SIZE, nspin ) real(DP), intent(in) :: lambda( nlam, nlam, nspin ), f( nx ) real(DP), intent(out) :: ei( nudx, nspin ) ! local variables real(DP), allocatable :: ap(:), wr(:) real(DP) zr(1,1) integer :: iss, j, i, ierr, k, n, ndim, nspin_eig, npaired INTEGER :: ir, ic, nr, nc, nrl, nrlx, comm, np, me logical :: tsic CHARACTER(LEN=80) :: msg ! tsic = ( ABS( self_interaction) /= 0 ) IF( tsic ) THEN nspin_eig = 1 npaired = nupdwn(2) ELSE nspin_eig = nspin npaired = 0 END IF do iss = 1, nspin_eig IF( nudx < nupdwn(iss) ) THEN WRITE( msg, 100 ) nudx, SIZE( ei, 1 ), nupdwn(iss) 100 FORMAT( ' wrong dimension array ei = ', 3I10 ) CALL errore( ' eigs0 ', msg, 1 ) END IF IF( tsic ) THEN n = npaired ELSE n = nupdwn(iss) END IF allocate( wr( n ) ) IF( idesc( LAX_DESC_ACTIVE_NODE, iss ) > 0 ) THEN np = idesc( LAX_DESC_NPC, iss ) * idesc( LAX_DESC_NPR, iss ) IF( np > 1 ) THEN ! matrix is distributed CALL laxlib_pdsyevd( .false., n, idesc(:,iss), lambda(:,:,iss), nlam, wr ) ELSE ! matrix is not distributed allocate( ap( n * ( n + 1 ) / 2 ) ) k = 0 do i = 1, n do j = i, n k = k + 1 ap( k ) = lambda( j, i, iss ) end do end do CALL dspev_drv( 'N', 'L', n, ap, wr, zr, 1 ) deallocate( ap ) END IF END IF call mp_bcast( wr, root_bgrp, intra_bgrp_comm ) if( lf ) then do i = 1, n if ( f(iupdwn(iss)-1+i).gt.1.e-6) then wr(i)=wr(i)/f(iupdwn(iss)-1+i) else wr(i)=wr(i)/2.0d0 * nspin ! fake occupation factor to print empty states end if end do end if ! ! store eigenvalues ! ei( 1:n, iss ) = wr( 1:n ) IF( tsic ) THEN ! ! store unpaired state ! ei( 1:n, 1 ) = ei( 1:n, 1 ) / 2.0d0 ei( nupdwn(1), 1 ) = 0.0d0 if( idesc( LAX_DESC_ACTIVE_NODE, iss ) > 0 ) then IF( idesc( LAX_DESC_MYC, iss ) == idesc( LAX_DESC_MYR, iss ) ) THEN ir = idesc( LAX_DESC_IR, iss ) nr = idesc( LAX_DESC_NR, iss ) IF( nupdwn(1) >= ir .AND. nupdwn(1) < ir + nr ) then ei( nupdwn(1), 1 ) = lambda( nupdwn(1)-ir+1, nupdwn(1)-ir+1, 1 ) end if END IF endif call mp_sum( ei( nupdwn(1), 1 ), intra_bgrp_comm ) ! END IF ! WRITE( stdout,*) '---- DEBUG ----' ! debug ! WRITE( stdout,14) ( wr( i ) * autoev / 2.0d0, i = 1, nupdwn(iss) ) ! debug deallocate( wr ) end do ! ! do iss = 1, nspin IF( tsic .AND. iss == 2 ) THEN ei( 1:npaired, 2 ) = ei( 1:npaired, 1 ) END IF IF( tprint ) THEN ! ! print out eigenvalues ! WRITE( stdout,12) 0.d0, 0.d0, 0.d0 WRITE( stdout,14) ( ei( i, iss ) * autoev, i = 1, nupdwn(iss) ) ENDIF end do IF( tprint ) WRITE( stdout,*) 12 format(//' eigenvalues at k-point: ',3f6.3) 14 format(10f8.2) ! return end subroutine eigs0 !----------------------------------------------------------------------- SUBROUTINE rpackgam_x( gam, f, aux ) !----------------------------------------------------------------------- USE kinds, ONLY: DP USE mp_global, ONLY: me_bgrp, nproc_bgrp, intra_bgrp_comm USE mp, ONLY: mp_sum IMPLICIT NONE REAL(DP), INTENT(INOUT) :: gam(:,:) REAL(DP), INTENT(OUT), OPTIONAL :: aux(:) REAL(DP), INTENT(IN) :: f(:) INTEGER n, nrl, i, j, k, jl nrl = SIZE(gam, 1) n = SIZE(gam, 2) IF( PRESENT( aux ) ) THEN aux = 0.0d0 IF( me_bgrp < n ) THEN DO i = 1, n j = me_bgrp + 1 DO jl = 1, nrl IF( j >= i ) THEN ! maps (j,i) index to low-tri packed (k) index k = (i-1)*n + j - i*(i-1)/2 aux(k) = gam(jl,i) / f(j) END IF j = j + nproc_bgrp END DO END DO END IF CALL mp_sum(aux, intra_bgrp_comm) ELSE IF( me_bgrp < n ) THEN DO i = 1, n j = me_bgrp + 1 DO jl = 1, nrl gam(jl,i) = gam(jl,i) / f(j) j = j + nproc_bgrp END DO END DO END IF END IF RETURN END SUBROUTINE rpackgam_x !----------------------------------------------------------------------- SUBROUTINE fermi_energy_x(eig, occ, wke, ef, qtot, temp, sume) !----------------------------------------------------------------------- !! This routine computes Fermi energy and weights of occupied states !! using an improved Gaussian-smearing method. !! Refs: C.L.Fu and K.M.Ho, Phys.Rev. B28, 5480 (1983) !! M.Methfessel and A.T.Paxton Phys.Rev. B40 (15 aug. 89). ! !! Taken from APW code by J. Soler and A. Williams (jk+ss). !! Added computation of occupation numbers without k-point weight USE kinds, ONLY: DP USE io_global, ONLY: stdout USE electrons_base, ONLY: nspin, iupdwn IMPLICIT NONE ! ... declare subroutine arguments REAL(DP) :: occ(:) REAL(DP) ef, qtot, temp, sume REAL(DP) eig(:,:), wke(:,:) REAL(DP), PARAMETER :: tol = 1.d-10 INTEGER, PARAMETER :: nitmax = 100 INTEGER ne, nk ! ... declare other variables REAL(DP) sumq,emin,emax,fac,t,drange INTEGER ik,ispin,ie,iter ! end of declarations ! ---------------------------------------------- nk = 1 ne = SIZE( occ, 1) sumq=0.d0 sume=0.d0 emin=eig(1,1) emax=eig(1,1) fac=2.d0 IF (nspin.EQ.2) fac=1.d0 DO ik=1,nk DO ispin=1,nspin DO ie=1,ne wke(ie,ispin) = fac occ(ie+iupdwn(ispin)-1) = fac sumq=sumq+wke(ie,ispin) sume=sume+wke(ie,ispin)*eig(ie,ispin) emin=MIN(emin,eig(ie,ispin)) emax=MAX(emax,eig(ie,ispin)) END DO END DO END DO ef=emax IF (abs(sumq-qtot).LT.tol) RETURN IF (sumq.LT.qtot) THEN WRITE( stdout,*) 'FERMIE: NOT ENOUGH STATES' WRITE( stdout,*) 'FERMIE: QTOT,SUMQ=',qtot,sumq STOP END IF t = MAX(temp,1.d-6) drange = t * SQRT( - LOG( tol*.01d0) ) emin = emin - drange emax = emax + drange DO iter = 1, nitmax ef = 0.5d0 * (emin+emax) sumq = 0.d0 sume = 0.d0 DO ik = 1, nk DO ispin = 1, nspin DO ie = 1, ne wke(ie,ispin) = fac / 2.d0 * stepf((eig(ie,ispin)-ef)/t) occ(ie+iupdwn(ispin)-1) = fac / 2.d0 * stepf((eig(ie,ispin)-ef)/t) sumq = sumq + wke(ie,ispin) sume = sume + wke(ie,ispin) * eig(ie,ispin) END DO END DO END DO IF (ABS(sumq-qtot).LT.tol) RETURN IF (sumq.LE.qtot) emin=ef IF (sumq.GE.qtot) emax=ef END DO WRITE( stdout,*) 'FERMIE: ITERATION HAS NOT CONVERGED.' WRITE( stdout,*) 'FERMIE: QTOT,SUMQ=',qtot,sumq STOP CONTAINS DOUBLE PRECISION FUNCTION stepf(x) USE kinds IMPLICIT NONE REAL(DP) :: x REAL(DP), PARAMETER :: c=0.5641895835D0 ! REAL(DP), EXTERNAL :: erfc ! stepf=erfc(x) stepf=1.d0/(exp(min(x,100.d0))+1.d0) END FUNCTION stepf END SUBROUTINE fermi_energy_x ! ! ! !----------------------------------------------------------------------- SUBROUTINE cp_eigs_x( nfi, lambdap, lambda, idesc ) !----------------------------------------------------------------------- USE kinds, ONLY: DP use ensemble_dft, only: tens use electrons_base, only: nbspx, f, nspin use electrons_base, only: iupdwn, nupdwn, nudx use electrons_module, only: ei use io_global, only: stdout IMPLICIT NONE INTEGER :: nfi REAL(DP) :: lambda( :, :, : ), lambdap( :, :, : ) INTEGER, INTENT(IN) :: idesc( :, : ) if( .not. tens ) then call eigs0( ei, nudx, .false. , nspin, nupdwn, iupdwn, .true. , f, nbspx, lambda, SIZE(lambda,1), idesc ) else call eigs0( ei, nudx, .false. , nspin, nupdwn, iupdwn, .false. , f, nbspx, lambdap, SIZE(lambdap,1), idesc ) endif RETURN END SUBROUTINE cp_eigs_x
gpl-2.0
QEF/q-e
GWW/gww/polarization.f90
3
73199
! ! Copyright (C) 2001-2013 Quantum ESPRESSO group ! This file is distributed under the terms of the ! GNU General Public License. See the file `License' ! in the root directory of the present distribution, ! or http://www.gnu.org/copyleft/gpl.txt . ! ! MODULE polarization !this module describes the structure for the polarization P ! and dressed iteraction W, imaginary time/frequency USE kinds, ONLY : DP TYPE polaw !this structure describe a generic P or W function !usually in the space of orthonormalized products of wanniers INTEGER :: label!label to read/write to disk LOGICAL :: ontime!if .true. is on imaginary time, otherwise frequency REAL(kind=DP) :: time!imaginary time or frequency INTEGER :: numpw!number of states (products of wanniers) REAL(kind=DP), DIMENSION(:,:), POINTER :: pw!the P or W COMPLEX(kind=DP) :: factor!complex factor to be multiplied to the real matrix pw END TYPE polaw CONTAINS SUBROUTINE initialize_polaw(pw) !this subroutine initializes polaw implicit none TYPE(polaw) :: pw nullify(pw%pw) return END SUBROUTINE initialize_polaw SUBROUTINE free_memory_polaw(pw) !this subroutine deallocates the green descriptor implicit none TYPE(polaw) pw if(associated(pw%pw)) deallocate(pw%pw) nullify(pw%pw) return END SUBROUTINE SUBROUTINE conjugate_polaw(pw) ! this subroutine calculculates the conjugate of the polaw matrix implicit none TYPE(polaw) pw pw%label=-pw%label return END SUBROUTINE conjugate_polaw SUBROUTINE write_polaw(pw,debug) !this subroutine writes the green function on disk !the file name is taken from the label USE io_files, ONLY : prefix,tmp_dir implicit none INTEGER, EXTERNAL :: find_free_unit TYPE(polaw) :: pw!the green function to be written LOGICAL :: debug! if .true. produces formatted output LOGICAL :: direct_file = .true.!if true uses direct- access file to write matrix on disk INTEGER :: iw, jw, iung CHARACTER(5) :: nfile if(pw%label >= 0 ) then write(nfile,'(5i1)') & & pw%label/10000,mod(pw%label,10000)/1000,mod(pw%label,1000)/100,mod(pw%label,100)/10,mod(pw%label,10) iung = find_free_unit() if(.not.debug) then open( unit=iung, file=trim(tmp_dir)//trim(prefix)//'-'//'polaw.'// nfile, status='unknown',form='unformatted') else open( unit=iung, file=trim(tmp_dir)//trim(prefix)//'-'//'polaw.'// nfile, status='unknown',form='formatted') endif else write(nfile,'(5i1)') & & -pw%label/10000,mod(-pw%label,10000)/1000,mod(-pw%label,1000)/100,mod(-pw%label,100)/10,mod(-pw%label,10) iung = find_free_unit() if(.not.debug) then open( unit=iung, file=trim(tmp_dir)//trim(prefix)//'-'//'polaw.-'// nfile, status='unknown',form='unformatted') else open( unit=iung, file=trim(tmp_dir)//trim(prefix)//'-'//'polaw.-'// nfile, status='unknown',form='formatted') endif endif if(.not.debug) then write(iung) pw%label write(iung) pw%ontime write(iung) pw%time write(iung) pw%numpw write(iung) pw%factor if(.not. direct_file) then do iw=1,pw%numpw write(iung) pw%pw(1:pw%numpw,iw) enddo endif else write(iung,*) pw%label write(iung,*) pw%ontime write(iung,*) pw%time write(iung,*) pw%numpw write(iung,*) pw%factor if(.not. direct_file) then do iw=1,pw%numpw do jw=1,pw%numpw write(iung,*) pw%pw(jw,iw) enddo enddo endif endif close(iung) if(direct_file) then iung = find_free_unit() if(pw%label >= 0 ) then open( unit=iung, file=trim(tmp_dir)//trim(prefix)//'-'//'polawd.'// nfile, & &status='unknown',recl=pw%numpw*DP,access='direct') else open( unit=iung, file=trim(tmp_dir)//trim(prefix)//'-'//'polawd.-'// nfile, & &status='unknown',recl=pw%numpw*DP,access='direct') endif do iw=1,pw%numpw write(unit=iung, rec=iw) pw%pw(:,iw) enddo close(iung) endif return END SUBROUTINE SUBROUTINE read_polaw(label, pw,debug,l_verbose) !this subroutine reads the green function from disk !the file name is taken from the label USE io_files, ONLY : prefix,tmp_dir USE io_global, ONLY : stdout implicit none INTEGER, EXTERNAL :: find_free_unit TYPE(polaw) :: pw!the green function to be read INTEGER :: label! the label identifing the required green function LOGICAL :: debug!if true formatted files LOGICAL, INTENT(in) :: l_verbose LOGICAL :: direct_file = .true.!if true uses direct- access file to read matrix from disk INTEGER :: iw, jw, iung CHARACTER(5) :: nfile if(l_verbose) write(stdout,*) 'Read polaw'!ATTENZIONE !first deallocate call free_memory_polaw(pw) if(l_verbose) write(stdout,*) 'Read polaw2'!ATTENZIONE if(label >= 0 ) then write(nfile,'(5i1)') label/10000,mod(label,10000)/1000,mod(label,1000)/100,mod(label,100)/10,mod(label,10) iung = find_free_unit() if(.not.debug) then open( unit=iung, file=trim(tmp_dir)//trim(prefix)//'-'//'polaw.'// nfile, status='old',form='unformatted') else open( unit=iung, file=trim(tmp_dir)//trim(prefix)//'-'//'polaw.'// nfile, status='old',form='formatted') endif else write(nfile,'(5i1)') -label/10000,mod(-label,10000)/1000,mod(-label,1000)/100,mod(-label,100)/10,mod(-label,10) iung = find_free_unit() if(.not.debug) then open( unit=iung, file=trim(tmp_dir)//trim(prefix)//'-'//'polaw.-'// nfile, status='old',form='unformatted') else open( unit=iung, file=trim(tmp_dir)//trim(prefix)//'-'//'polaw.-'// nfile, status='old',form='formatted') endif endif if(.not.debug) then read(iung) pw%label read(iung) pw%ontime read(iung) pw%time read(iung) pw%numpw read(iung) pw%factor else read(iung,*) pw%label read(iung,*) pw%ontime read(iung,*) pw%time read(iung,*) pw%numpw read(iung,*) pw%factor endif write(stdout,*) 'Read polaw',pw%numpw!ATTENZIONE !now allocate allocate(pw%pw(pw%numpw,pw%numpw)) if(.not. direct_file) then if(.not.debug) then do iw=1,pw%numpw read(iung) pw%pw(1:pw%numpw,iw) enddo else do iw=1,pw%numpw do jw=1,pw%numpw read(iung,*) pw%pw(jw,iw) enddo enddo endif endif close(iung) if(l_verbose) write(stdout,*) 'Read polaw4'!ATTENZIONE if(direct_file) then iung = find_free_unit() if(label >= 0 ) then open( unit=iung, file=trim(tmp_dir)//trim(prefix)//'-'//'polawd.'// nfile, & &status='unknown',recl=pw%numpw*DP,access='direct') else open( unit=iung, file=trim(tmp_dir)//trim(prefix)//'-'//'polawd.-'// nfile, & &status='unknown',recl=pw%numpw*DP,access='direct') endif if(l_verbose) write(stdout,*) 'Read polaw5'!ATTENZIONE do iw=1,pw%numpw read(unit=iung, rec=iw) pw%pw(:,iw) enddo close(iung) endif if(l_verbose) write(stdout,*) 'Read polaw6'!ATTENZIONE return END SUBROUTINE SUBROUTINE read_polaw_global(label, pw) !this subroutine reads the green function from disk !the file name is taken from the label !the ionode_id distribute to all the processors USE io_files, ONLY : prefix,tmp_dir USE io_global, ONLY : stdout, ionode, ionode_id USE mp, ONLY : mp_barrier, mp_bcast USE mp_world, ONLY : world_comm implicit none INTEGER, EXTERNAL :: find_free_unit TYPE(polaw) :: pw!the green function to be read INTEGER :: label! the label identifing the required green function LOGICAL :: direct_file = .true.!if true uses direct- access file to read matrix from disk INTEGER :: iw, jw, iung CHARACTER(5) :: nfile !first deallocate call free_memory_polaw(pw) if(ionode) then if(label >= 0 ) then write(nfile,'(5i1)') label/10000,mod(label,10000)/1000,mod(label,1000)/100,mod(label,100)/10,mod(label,10) iung = find_free_unit() open( unit=iung, file=trim(tmp_dir)//trim(prefix)//'-'//'polaw.'// nfile, status='old',form='unformatted') else write(nfile,'(5i1)') -label/10000,mod(-label,10000)/1000,mod(-label,1000)/100,mod(-label,100)/10,mod(-label,10) iung = find_free_unit() open( unit=iung, file=trim(tmp_dir)//trim(prefix)//'-'//'polaw.-'// nfile, status='old',form='unformatted') endif read(iung) pw%label read(iung) pw%ontime read(iung) pw%time read(iung) pw%numpw read(iung) pw%factor endif call mp_bcast(pw%label,ionode_id,world_comm) call mp_bcast(pw%ontime,ionode_id,world_comm) call mp_bcast(pw%time,ionode_id,world_comm) call mp_bcast(pw%numpw,ionode_id,world_comm) call mp_bcast(pw%factor,ionode_id,world_comm) allocate(pw%pw(pw%numpw,pw%numpw)) if(ionode) then if(.not. direct_file) then do iw=1,pw%numpw read(iung) pw%pw(1:pw%numpw,iw) enddo endif close(iung) if(direct_file) then iung = find_free_unit() if(label >= 0 ) then open( unit=iung, file=trim(tmp_dir)//trim(prefix)//'-'//'polawd.'// nfile, & &status='unknown',recl=pw%numpw*DP,access='direct') else open( unit=iung, file=trim(tmp_dir)//trim(prefix)//'-'//'polawd.-'// nfile, & &status='unknown',recl=pw%numpw*DP,access='direct') endif do iw=1,pw%numpw read(unit=iung, rec=iw) pw%pw(:,iw) enddo close(iung) endif endif do iw=1,pw%numpw call mp_barrier( world_comm ) call mp_bcast(pw%pw(:,iw),ionode_id,world_comm) enddo return END SUBROUTINE read_polaw_global SUBROUTINE write_polaw_range( pw, debug, range_min, range_max, full_range ) !this subroutine writes the green function on disk !the file name is taken from the label !writes column from range_min to range_max USE io_files, ONLY : prefix,tmp_dir USE io_global, ONLY : stdout implicit none INTEGER, EXTERNAL :: find_free_unit TYPE(polaw) :: pw!the green function to be written LOGICAL :: debug! if .true. produces formatted output INTEGER, INTENT(in) :: range_min, range_max!range of column LOGICAL, INTENT(IN) :: full_range LOGICAL :: direct_file = .true.!if true uses direct- access file to write matrix on disk INTEGER :: iw, jw, iung, iww CHARACTER(5) :: nfile !check range if(range_min<1 .or. range_max> pw%numpw) then write(stdout,*) 'write_polaw_range: out of range = ', range_min, range_max stop endif if(pw%label >= 0 ) then write(nfile,'(5i1)') & & pw%label/10000,mod(pw%label,10000)/1000,mod(pw%label,1000)/100,mod(pw%label,100)/10,mod(pw%label,10) iung = find_free_unit() if(.not.debug) then open( unit=iung, file=trim(tmp_dir)//trim(prefix)//'-'//'polaw.'// nfile, status='unknown',form='unformatted') else open( unit=iung, file=trim(tmp_dir)//trim(prefix)//'-'//'polaw.'// nfile, status='unknown',form='formatted') endif else write(nfile,'(5i1)') & & -pw%label/10000,mod(-pw%label,10000)/1000,mod(-pw%label,1000)/100,mod(-pw%label,100)/10,mod(-pw%label,10) iung = find_free_unit() if(.not.debug) then open( unit=iung, file=trim(tmp_dir)//trim(prefix)//'-'//'polaw.-'// nfile, status='unknown',form='unformatted') else open( unit=iung, file=trim(tmp_dir)//trim(prefix)//'-'//'polaw.-'// nfile, status='unknown',form='formatted') endif endif if(.not.debug) then write(iung) pw%label write(iung) pw%ontime write(iung) pw%time write(iung) pw%numpw write(iung) pw%factor if(.not. direct_file) then do iw=1,pw%numpw write(iung) pw%pw(1:pw%numpw,iw) enddo endif else write(iung,*) pw%label write(iung,*) pw%ontime write(iung,*) pw%time write(iung,*) pw%numpw write(iung,*) pw%factor if(.not. direct_file) then do iw=1,pw%numpw do jw=1,pw%numpw write(iung,*) pw%pw(jw,iw) enddo enddo endif endif close(iung) if(direct_file) then iung = find_free_unit() if(pw%label >= 0 ) then open( unit=iung, file=trim(tmp_dir)//trim(prefix)//'-'//'polawd.'// nfile, & &status='unknown',recl=pw%numpw*DP,access='direct') else open( unit=iung, file=trim(tmp_dir)//trim(prefix)//'-'//'polawd.-'// nfile, & &status='unknown',recl=pw%numpw*DP,access='direct') endif do iw=range_min,range_max iww = iw if( .not. full_range ) iww = iw - range_min + 1 write(unit=iung, rec=iw) pw%pw(:,iww) enddo close(iung) endif return END SUBROUTINE write_polaw_range SUBROUTINE read_polaw_range(label, pw,debug,range_min,range_max, full_range ) !this subroutine reads the green function from disk !the file name is taken from the label !reads columns from range_min to range_max USE io_files, ONLY : prefix,tmp_dir USE io_global, ONLY : stdout implicit none INTEGER, EXTERNAL :: find_free_unit TYPE(polaw) :: pw!the green function to be read INTEGER :: label! the label identifing the required green function LOGICAL :: debug!if true formatted files INTEGER, INTENT(in) :: range_min, range_max!defining range LOGICAL, INTENT(IN) :: full_range LOGICAL :: direct_file = .true.!if true uses direct- access file to read matrix from disk INTEGER :: iw, jw, iung, iww CHARACTER(5) :: nfile !check if(range_min<1 ) then write(stdout,*) 'read_polaw_range: out of range ', range_min, range_max stop endif !first deallocate call free_memory_polaw(pw) if(label >= 0 ) then write(nfile,'(5i1)') label/10000,mod(label,10000)/1000,mod(label,1000)/100,mod(label,100)/10,mod(label,10) iung = find_free_unit() if(.not.debug) then open( unit=iung, file=trim(tmp_dir)//trim(prefix)//'-'//'polaw.'// nfile, status='old',form='unformatted') else open( unit=iung, file=trim(tmp_dir)//trim(prefix)//'-'//'polaw.'// nfile, status='old',form='formatted') endif else write(nfile,'(5i1)') -label/10000,mod(-label,10000)/1000,mod(-label,1000)/100,mod(-label,100)/10,mod(-label,10) iung = find_free_unit() if(.not.debug) then open( unit=iung, file=trim(tmp_dir)//trim(prefix)//'-'//'polaw.-'// nfile, status='old',form='unformatted') else open( unit=iung, file=trim(tmp_dir)//trim(prefix)//'-'//'polaw.-'// nfile, status='old',form='formatted') endif endif if(.not.debug) then read(iung) pw%label read(iung) pw%ontime read(iung) pw%time read(iung) pw%numpw read(iung) pw%factor else read(iung,*) pw%label read(iung,*) pw%ontime read(iung,*) pw%time read(iung,*) pw%numpw read(iung,*) pw%factor endif !now allocate if( full_range ) then allocate(pw%pw(pw%numpw,pw%numpw)) else allocate( pw%pw( pw%numpw, range_max - range_min + 1 ) ) endif if(.not. direct_file) then if(.not.debug) then do iw=1,pw%numpw read(iung) pw%pw(1:pw%numpw,iw) enddo else do iw=1,pw%numpw do jw=1,pw%numpw read(iung,*) pw%pw(jw,iw) enddo enddo endif endif close(iung) if(direct_file) then !check if(range_max > pw%numpw ) then write(stdout,*) 'read_polaw_range: out of range = ', range_min, range_max stop endif iung = find_free_unit() if(label >= 0 ) then open( unit=iung, file=trim(tmp_dir)//trim(prefix)//'-'//'polawd.'// nfile, & &status='unknown',recl=pw%numpw*DP,access='direct') else open( unit=iung, file=trim(tmp_dir)//trim(prefix)//'-'//'polawd.-'// nfile, & &status='unknown',recl=pw%numpw*DP,access='direct') endif do iw=range_min, range_max iww = iw if( .not. full_range ) iww = iw - range_min + 1 read(unit=iung, rec=iw) pw%pw(:,iww) enddo close(iung) endif return END SUBROUTINE read_polaw_range SUBROUTINE create_polarization(time,pr,gf_p,gf_m,qm,debug) !this subroutine set the polarization in imaginary time ! as P(r,r',it)=G(r,r',it)*G(r,r',-it) ! for our basis ! P_{i,j}=\sum_{l,n,m,o} Q_{i,lm}Q_{j,mo}G_{lm}(it)G_{no}(-it) !THERE IS ALSO A SPIN FACTOR 2 USE basic_structures, ONLY : q_mat,wannier_P USE green_function, ONLY : green USE io_global, ONLY : stdout USE constants, ONLY : eps8 implicit none REAL(kind=DP) :: time!imaginary time t, just a check TYPE(polaw) :: pr!polarization P(it) to be created TYPE(green) :: gf_p!green function G(it) TYPE(green) :: gf_m!green function G(-it) TYPE(q_mat) :: qm!overlap matrix Q LOGICAL :: debug!if true check for hermeticity INTEGER :: iw,jw, ip,jp INTEGER :: l,n,m,o !first annihilation call free_memory_polaw(pr) !check time if((abs(gf_p%time - time)>=eps8) .OR. (abs(gf_m%time + time) >= eps8)) then!times are wrong write(stdout,*) 'Subroutine polarization: times are wrong',gf_p%time,gf_m%time stop endif !set pr pr%ontime=.true. pr%time=time pr%numpw=qm%numpw !allocate allocate(pr%pw( pr%numpw,pr%numpw)) pr%pw(:,:) =(0.d0,0.d0) do iw=1,pr%numpw do jw=iw,pr%numpw do ip=1,qm%wp(iw)%numij do jp=1,qm%wp(jw)%numij l=qm%wp(iw)%ij(1,ip) n=qm%wp(iw)%ij(2,ip) m=qm%wp(jw)%ij(1,jp) o=qm%wp(jw)%ij(2,jp) pr%pw(iw,jw)=pr%pw(iw,jw)+qm%wp(iw)%o(ip)*qm%wp(jw)%o(jp)* & & gf_p%gf(l,m,1)*gf_m%gf(n,o,1) !couples are NOT ordered if(l/=n) then pr%pw(iw,jw)=pr%pw(iw,jw)+qm%wp(iw)%o(ip)*qm%wp(jw)%o(jp)* & & gf_p%gf(n,m,1)*gf_m%gf(l,o,1) endif if(m/=o) then pr%pw(iw,jw)=pr%pw(iw,jw)+qm%wp(iw)%o(ip)*qm%wp(jw)%o(jp)* & & gf_p%gf(l,o,1)*gf_m%gf(n,m,1) endif if(l/=n .AND. m/=o) then pr%pw(iw,jw)=pr%pw(iw,jw)+qm%wp(iw)%o(ip)*qm%wp(jw)%o(jp)* & & gf_p%gf(n,o,1)*gf_m%gf(l,m,1) endif enddo pr%pw(jw,iw)=pr%pw(iw,jw) enddo enddo enddo pr%factor=(0.d0,-1.d0) !now spin factor pr%pw(:,:)=2.d0*pr%pw(:,:) return END subroutine SUBROUTINE calculate_w(vp,pp,ww,xc_together,l_symm_epsilon,l_head_epsilon,agz,head,l_divergence,inv_epsi, & &l_wing_epsilon, awing, l_verbose) !this subroutine calculates W=(1+vp)^{-1}v !this is meaningful only on frequency domain !lapack routines are used USE io_global, ONLY : stdout USE basic_structures, ONLY : v_pot, head_epsilon implicit none TYPE(v_pot) :: vp!coulomb potential TYPE(polaw) :: pp!polarization on imaginary frequency, destroyed on exit TYPE(polaw) :: ww!dressed interaction to be calculated LOGICAL :: xc_together!if true the entire W is taken, otherwise W-v LOGICAL :: l_symm_epsilon! if true uses the symmetrized form of the dielectric matrix !for calculating W LOGICAL :: l_head_epsilon!if true add to the symmetrized form of the dielectric matrix !the head terms REAL(kind=DP), DIMENSION(:) :: agz!terms A_ij<\tilde{w^P_j}|G=0> REAL(kind=DP) :: head!term (G=0,G=0) of the symmetric dielectric matrix LOGICAL, INTENT(in) :: l_divergence!if true calculate the head of the inverse dielectric matrix REAL(kind=DP), INTENT(out) :: inv_epsi!head of the inverse dielectric matrix LOGICAL, INTENT(in) :: l_wing_epsilon!if true calculate the wings of the symmetrized dielectric matrix REAL(kind=DP), DIMENSION(:) :: awing!the terms A_ij wing_j LOGICAL, INTENT(in) :: l_verbose INTEGER iw,jw,kw REAL(kind=DP), ALLOCATABLE, DIMENSION(:,:) :: dtmp!temporary array INTEGER, ALLOCATABLE, DIMENSION(:) :: ipiv INTEGER :: info REAL(kind=DP),ALLOCATABLE, DIMENSION(:) :: work INTEGER :: lwork REAL(kind=DP) sca REAL(kind=DP) :: workd !deallocate if the case call free_memory_polaw(ww) !check and set if(pp%ontime) then write(stdout,*) 'Routine calculate_w: frequencies required' stop endif if(pp%numpw /= vp%numpw) then write(stdout,*) 'Routine calculate_w: basis set does not correspond',pp%numpw,vp%numpw stop endif ww%ontime=.false. ww%time=pp%time ww%label=pp%label ww%numpw=pp%numpw allocate(ww%pw(ww%numpw,ww%numpw)) allocate(dtmp(ww%numpw,ww%numpw)) allocate(ipiv(ww%numpw)) if(.not.l_symm_epsilon) then !not symmetric case calculates -vP call dgemm('N','N',ww%numpw,ww%numpw,ww%numpw,-1.d0*dble(pp%factor),& & vp%vmat,ww%numpw,pp%pw,ww%numpw,0.d0,dtmp,ww%numpw) else !symmetric case calculates -v^1/2 P v^1/2 call dgemm('N','N',ww%numpw,ww%numpw,ww%numpw,-1.d0*dble(pp%factor),& & vp%vmat,ww%numpw,pp%pw,ww%numpw,0.d0,dtmp,ww%numpw) pp%pw(:,:)=dtmp(:,:) call dgemm('N','N',ww%numpw,ww%numpw,ww%numpw,1.d0,& & pp%pw,ww%numpw,vp%vmat,ww%numpw,0.d0,dtmp,ww%numpw) endif !if required add the head if(l_symm_epsilon .and.l_head_epsilon) then do jw=1,ww%numpw do iw=1,ww%numpw dtmp(iw,jw)=dtmp(iw,jw)+agz(iw)*agz(jw)*head enddo enddo endif !if required add the wings if(l_symm_epsilon .and.l_wing_epsilon) then do jw=1,ww%numpw do iw=1,ww%numpw dtmp(iw,jw)=dtmp(iw,jw)+agz(iw)*awing(jw)+agz(jw)*awing(iw) enddo enddo endif do iw=1,ww%numpw dtmp(iw,iw)=dtmp(iw,iw)+1.d0 enddo !inverse zmat call dgetrf(ww%numpw,ww%numpw,dtmp,ww%numpw,ipiv,info) if(info /= 0) then write(stdout,*) 'Routine calculate_w: problem with dgetrf :', info stop endif call dgetri(ww%numpw,dtmp,ww%numpw,ipiv,workd,-1,info) if(l_verbose) write(stdout,*) 'Dimension', workd!ATTENZIONE allocate(work(int(workd))) call dgetri(ww%numpw,dtmp,ww%numpw,ipiv,work,int(workd),info) if(info /= 0) then write(stdout,*) 'Routine calculate_w: problem with zgetri :', info stop endif if(.not.xc_together) then do iw=1,ww%numpw dtmp(iw,iw)=dtmp(iw,iw)-1.d0 enddo endif !if required calculates the head (G=0,G=0) of \epsilon^-1 if(l_divergence) then inv_epsi=0.d0 do jw=1,ww%numpw do iw=1,ww%numpw inv_epsi = inv_epsi+dtmp(iw,jw)*agz(iw)*agz(jw) enddo enddo do iw=1,ww%numpw dtmp(iw,iw)=dtmp(iw,iw)-inv_epsi enddo endif if(l_verbose) write(stdout,*) 'INV EPSI G=0,G=0', inv_epsi if(.not. l_symm_epsilon) then !calculates (e-1 -1)v call dgemm('N','N',ww%numpw,ww%numpw,ww%numpw,1.d0,& & dtmp,ww%numpw,vp%vmat,ww%numpw,0.d0,ww%pw,ww%numpw) else !calculates v^1/2 (e-1-1)v^1/2 call dgemm('N','N',ww%numpw,ww%numpw,ww%numpw,1.d0,& & vp%vmat,ww%numpw,dtmp,ww%numpw,0.d0,pp%pw,ww%numpw) call dgemm('N','N',ww%numpw,ww%numpw,ww%numpw,1.d0,& & pp%pw,ww%numpw,vp%vmat,ww%numpw,0.d0,ww%pw,ww%numpw) endif ww%factor=(1.d0,0.d0) ! if(.not.xc_together) then ! do iw=1,ww%numpw ! do jw=1,ww%numpw ! ww%pw(iw,jw)=ww%pw(iw,jw)-vp%vmat(iw,jw) ! enddo ! enddo ! endif deallocate(dtmp,ipiv,work) return END SUBROUTINE SUBROUTINE create_polarization_contraction(time,pr,cp,uu,l_hf_energies, ene_hf) !this subroutine set the polarization in imaginary time ! as P(r,r',it)=G(r,r',it)*G(r,r',-it) ! for our basis !uses contractions !THERE IS ALSO A SPIN FACTOR 2 !if required uses HF energies USE io_global, ONLY : stdout USE constants, ONLY : eps8 USE compact_product, ONLY : contraction_pola USE basic_structures, ONLY : wannier_u implicit none REAL(kind=DP) :: time!imaginary time t, just a check TYPE(polaw) :: pr!polarization P(it) to be created TYPE(contraction_pola) :: cp!the contracted products descriptor TYPE(wannier_u) :: uu!for the KS energies LOGICAL, INTENT(in) :: l_hf_energies!if true uses HF energies REAL(kind=DP), INTENT(in) :: ene_hf(:)!HF energies INTEGER :: iw,jw, vv, cc INTEGER :: l,n,m,o REAL(kind=DP) :: offset REAL(kind=DP),ALLOCATABLE :: expene(:)!to calculate the exponentials just once !first annihilation call free_memory_polaw(pr) !set pr pr%ontime=.true. pr%time=time pr%numpw=cp%numpw !calculates energy offset if(.not.l_hf_energies) then if(cp%nums > cp%nums_occ) then offset=-(uu%ene(cp%nums_occ+1,1)+uu%ene(cp%nums_occ,1))/2.d0 else offset=-uu%ene(cp%nums_occ,1) endif else if(cp%nums > cp%nums_occ) then offset=-(ene_hf(cp%nums_occ+1)+ene_hf(cp%nums_occ))/2.d0 else offset=-ene_hf(cp%nums_occ) endif endif !calcualte exponentials of ks energies allocate(expene(cp%nums)) if(.not.l_hf_energies) then do vv=1,cp%nums_occ expene(vv)=exp((uu%ene(vv,1)+offset)*time) enddo do cc=cp%nums_occ+1,cp%nums expene(cc)=exp(-(uu%ene(cc,1)+offset)*time) enddo else do vv=1,cp%nums_occ expene(vv)=exp((ene_hf(vv)+offset)*time) enddo do cc=cp%nums_occ+1,cp%nums expene(cc)=exp(-(ene_hf(cc)+offset)*time) enddo endif !allocate allocate(pr%pw( pr%numpw,pr%numpw)) pr%pw(:,:)=(0.d0,0.d0) do iw=1,pr%numpw do jw=iw,pr%numpw do vv=1,cp%nums_occ do cc=1,cp%nums-cp%nums_occ pr%pw(iw,jw)=pr%pw(iw,jw) + cp%ou(iw,vv,cc)*conjg(cp%ou(jw,vv,cc))*& & expene(vv)*expene(cc+cp%nums_occ) enddo enddo pr%pw(jw,iw)=pr%pw(iw,jw) enddo enddo pr%factor=(0.d0,-1.d0) !now spin factor pr%pw(:,:)=2.d0*pr%pw(:,:) deallocate(expene) return END SUBROUTINE SUBROUTINE invert_ortho_polaw(op,opi) !this subroutine inverts the orthonormalization matrix !acting of products of wanniers USE io_global, ONLY : stdout USE basic_structures, ONLY : ortho_polaw, free_memory implicit none TYPE(ortho_polaw), INTENT(in) :: op !the descriptor of the orthonormalization matrix to be inverted TYPE(ortho_polaw), INTENT(out) :: opi !the descriptor of the orthonormalization matrix to be inverted INTEGER :: info,lwork INTEGER, ALLOCATABLE, DIMENSION(:) :: ipiv REAL(kind=DP), ALLOCATABLE, DIMENSION(:) :: work lwork=op%numpw allocate(ipiv(op%numpw)) allocate(work(lwork)) call free_memory(opi) opi%numpw=op%numpw allocate(opi%on_mat( opi%numpw, opi%numpw)) opi%on_mat(:,:)=op%on_mat(:,:) call dgetrf(opi%numpw,opi%numpw,opi%on_mat,opi%numpw,ipiv,info) if(info /= 0) then write(stdout,*) 'Routine invert_ortho_polaw: problem with dgetrf :', info stop endif call dgetri(opi%numpw,opi%on_mat,opi%numpw,ipiv,work,lwork,info) if(info /= 0) then write(stdout,*) 'Routine invert_ortho_polaw: problem with dgetri :', info stop endif if(op%inverse) then opi%inverse=.false. else opi%inverse=.true. endif deallocate(ipiv,work) return END SUBROUTINE SUBROUTINE distribute_ortho_polaw(op,opd) !this subroutine distributes the orthonormalization matrix ! among processors USE io_global, ONLY : stdout USE basic_structures, ONLY : ortho_polaw, free_memory USE mp_world, ONLY : nproc,mpime implicit none TYPE(ortho_polaw), INTENT(in) :: op !the descriptor of the orthonormalization matrix to be distributed TYPE(ortho_polaw), INTENT(out) :: opd!distributed orthonormalization matrix INTEGER :: l_blk,nbegin,nend,ii call free_memory(opd) opd%numpw = op%numpw opd%inverse = op%inverse l_blk= op%numpw/nproc if(l_blk*nproc < op%numpw) l_blk = l_blk+1 nbegin=mpime*l_blk+1 nend=nbegin+l_blk-1 if(nend > op%numpw) nend = op%numpw allocate(opd%on_mat(op%numpw,l_blk)) do ii=nbegin,nend opd%on_mat(:,ii-nbegin+1)=op%on_mat(:,ii) enddo return END SUBROUTINE distribute_ortho_polaw SUBROUTINE collect_ortho_polaw(op,opd) !this subroutine collects the orthonormalization matrix ! among processors USE io_global, ONLY : stdout USE basic_structures, ONLY : ortho_polaw, free_memory USE mp_world, ONLY : nproc,mpime,world_comm!group USE parallel_include implicit none TYPE(ortho_polaw), INTENT(out) :: op !the descriptor of the orthonormalization matrix to be distributed TYPE(ortho_polaw), INTENT(in) :: opd!distributed orthonormalization matrix INTEGER :: l_blk,nbegin,nend,ierr call free_memory(op) op%numpw = opd%numpw op%inverse = opd%inverse l_blk= op%numpw/nproc if(l_blk*nproc < op%numpw) l_blk = l_blk+1 nbegin=mpime*l_blk+1 nend=nbegin+l_blk-1 if(nend > op%numpw) nend = op%numpw allocate(op%on_mat(op%numpw,l_blk*nproc)) #if defined(__MPI) call MPI_ALLGATHER(opd%on_mat,l_blk*op%numpw,MPI_DOUBLE_PRECISION, op%on_mat, & & l_blk*op%numpw, MPI_DOUBLE_PRECISION,world_comm, ierr) #else op%on_mat(:,:)=opd%on_mat #endif return END SUBROUTINE collect_ortho_polaw SUBROUTINE orthonormalize(op,pw) !this subroutine rotates the pw data on the basis of the trasform op !perform the trasform \sum_{i',j'} B_{i,i'}P_{i',j'}B_{j,j'} USE io_global, ONLY : stdout USE basic_structures, ONLY : ortho_polaw implicit none TYPE(polaw), INTENT(inout) :: pw!data TYPE(ortho_polaw), INTENT(in) :: op!trasform INTEGER :: iw,jw,kw REAL(kind=DP), ALLOCATABLE :: mat(:,:) if(op%numpw /= pw%numpw) then write(stdout,*) 'ROUTINE ORTHONORMALIZE: BASIS INCONSISTENT' stop endif allocate(mat(op%numpw,op%numpw)) call dgemm('N','N',op%numpw,op%numpw,op%numpw,1.d0,& & op%on_mat,op%numpw,pw%pw,op%numpw,0.d0,mat,op%numpw) call dgemm('N','T',op%numpw,op%numpw,op%numpw,1.d0,& & mat,op%numpw,op%on_mat,op%numpw,0.d0,pw%pw,op%numpw) deallocate(mat) return END SUBROUTINE SUBROUTINE orthonormalize_inverse(op,pw) !this subroutine rotates the pw data on the basis of the trasform op !perform the trasform \sum_{i',j'} B_{i',i}P_{i',j'}B_{j',j} USE io_global, ONLY : stdout USE basic_structures, ONLY : ortho_polaw implicit none TYPE(polaw), INTENT(inout) :: pw!data TYPE(ortho_polaw), INTENT(in) :: op!trasform INTEGER :: iw,jw,kw REAL(kind=DP), ALLOCATABLE :: mat(:,:) if(op%numpw /= pw%numpw) then write(stdout,*) 'ROUTINE ORTHONORMALIZE: BASIS INCONSISTENT' stop endif allocate(mat(op%numpw,op%numpw)) call dgemm('T','N',op%numpw,op%numpw,op%numpw,1.d0,& & op%on_mat,op%numpw,pw%pw,op%numpw,0.d0,mat,op%numpw) call dgemm('N','N',op%numpw,op%numpw,op%numpw,1.d0,& & mat,op%numpw,op%on_mat,op%numpw,0.d0,pw%pw,op%numpw) deallocate(mat) return END SUBROUTINE SUBROUTINE orthonormalize_vpot_inverse(op,vp) !this subroutine rotates the v_pot data on the basis of the trasform op !perform the trasform \sum_{i',j'} B_{i',i}P_{i',j'}B_{j',j} USE io_global, ONLY : stdout USE basic_structures, ONLY : v_pot, ortho_polaw implicit none TYPE(v_pot), INTENT(inout) :: vp!data TYPE(ortho_polaw), INTENT(in) :: op!trasform INTEGER :: iw,jw,kw REAL(kind=DP), ALLOCATABLE :: mat(:,:) if(op%numpw /= vp%numpw) then write(stdout,*) 'ROUTINE ORTHONORMALIZE: BASIS INCONSISTENT' stop endif allocate(mat(op%numpw,op%numpw)) ! mat(:,:)=0.d0 ! do iw=1,op%numpw ! do jw=1,op%numpw ! do kw=1,op%numpw ! mat(iw,jw)=mat(iw,jw)+op%on_mat(kw,iw)*vp%vmat(kw,jw) ! enddo ! enddo ! enddo call dgemm('T','N',op%numpw,op%numpw,op%numpw,1.d0,op%on_mat,op%numpw,vp%vmat,op%numpw,0.d0,mat,op%numpw) ! vp%vmat(:,:)=0.d0 ! do iw=1,op%numpw ! do kw=1,op%numpw ! do jw=1,op%numpw ! vp%vmat(iw,jw)=vp%vmat(iw,jw)+op%on_mat(kw,jw)*mat(iw,kw) ! enddo ! enddo ! enddo call dgemm('N','N',op%numpw,op%numpw,op%numpw,1.d0,mat,op%numpw,op%on_mat,op%numpw,0.d0,vp%vmat,op%numpw) deallocate(mat) return END SUBROUTINE SUBROUTINE orthonormalize_vpot(op,vp) !this subroutine rotates the v_pot data on the basis of the trasform op !perform the trasform \sum_{i',j'} B_{i,i'}P_{i',j'}B_{j,j'} USE io_global, ONLY : stdout USE basic_structures, ONLY : v_pot, ortho_polaw implicit none TYPE(v_pot), INTENT(inout) :: vp!data TYPE(ortho_polaw), INTENT(in) :: op!trasform INTEGER :: iw,jw,kw REAL(kind=DP), ALLOCATABLE :: mat(:,:) if(op%numpw /= vp%numpw) then write(stdout,*) 'ROUTINE ORTHONORMALIZE: BASIS INCONSISTENT' stop endif allocate(mat(op%numpw,op%numpw)) ! mat(:,:)=0.d0 ! do iw=1,op%numpw ! do jw=1,op%numpw ! do kw=1,op%numpw ! mat(iw,jw)=mat(iw,jw)+op%on_mat(iw,kw)*vp%vmat(kw,jw) ! enddo ! enddo ! enddo call dgemm('N','N',op%numpw,op%numpw,op%numpw,1.d0,op%on_mat,op%numpw,vp%vmat,op%numpw,0.d0,mat,op%numpw) ! vp%vmat(:,:)=0.d0 ! do iw=1,op%numpw ! do jw=1,op%numpw ! do kw=1,op%numpw ! vp%vmat(iw,jw)=vp%vmat(iw,jw)+op%on_mat(jw,kw)*mat(iw,kw) ! enddo ! enddo ! enddo call dgemm('N','T',op%numpw,op%numpw,op%numpw,1.d0,mat,op%numpw,op%on_mat,op%numpw,0.d0,vp%vmat,op%numpw) deallocate(mat) return END SUBROUTINE orthonormalize_vpot SUBROUTINE orthonormalize_vpot_para(op,vp) !this subroutine rotates the v_pot data on the basis of the trasform op !perform the trasform \sum_{i',j'} B_{i,i'}P_{i',j'}B_{j,j'} !parallel version USE io_global, ONLY : stdout USE basic_structures, ONLY : v_pot, ortho_polaw USE mp_world, ONLY : mpime, nproc, world_comm USE mp, ONLY : mp_sum implicit none TYPE(v_pot), INTENT(inout) :: vp!data TYPE(ortho_polaw), INTENT(in) :: op!trasform INTEGER :: iw,jw,kw REAL(kind=DP), ALLOCATABLE :: mat(:,:) if(op%numpw /= vp%numpw) then write(stdout,*) 'ROUTINE ORTHONORMALIZE: BASIS INCONSISTENT' stop endif allocate(mat(op%numpw,op%numpw)) mat(:,:)=0.d0 do iw=1,op%numpw do jw=1,op%numpw if(mod(jw,nproc)==mpime) then do kw=1,op%numpw mat(iw,jw)=mat(iw,jw)+op%on_mat(iw,kw)*vp%vmat(kw,jw) enddo endif enddo call mp_sum(mat(iw,:),world_comm) enddo vp%vmat(:,:)=0.d0 do iw=1,op%numpw do jw=1,op%numpw if(mod(jw,nproc)==mpime) then do kw=1,op%numpw vp%vmat(iw,jw)=vp%vmat(iw,jw)+op%on_mat(jw,kw)*mat(iw,kw) enddo endif enddo call mp_sum(vp%vmat(iw,:),world_comm) enddo deallocate(mat) return END SUBROUTINE orthonormalize_vpot_para SUBROUTINE invert_v_pot(vp,vpi) !this subroutine inverts the coulombian matrix !acting on space of orthonormal products of wanniers USE io_global, ONLY : stdout USE basic_structures, ONLY : v_pot, free_memory implicit none TYPE(v_pot), INTENT(in) :: vp !the descriptor of the coulombian matrix to be inverted TYPE(v_pot), INTENT(inout) :: vpi !the descriptor of the inverted coulombian matrix INTEGER :: info,lwork,i,j INTEGER, ALLOCATABLE, DIMENSION(:) :: ipiv REAL(kind=DP), ALLOCATABLE, DIMENSION(:) :: work call free_memory(vpi) lwork=vp%numpw allocate(ipiv(vp%numpw)) allocate(work(lwork)) vpi%numpw=vp%numpw allocate(vpi%vmat( vpi%numpw, vpi%numpw)) !write(stdout,*) size(vpi%vmat,1), size(vpi%vmat,2), size(vp%vmat,1), size(vp%vmat,2) ! vpi%vmat(:,:)=vp%vmat(:,:) ! bug do j = 1, size(vpi%vmat,2) do i = 1, size(vpi%vmat,1) vpi%vmat(i,j)=vp%vmat(i,j) end do end do call dgetrf(vpi%numpw,vpi%numpw,vpi%vmat,vpi%numpw,ipiv,info) if(info /= 0) then write(stdout,*) 'Invert V: problem with dgetrf :', info stop endif call dgetri(vpi%numpw,vpi%vmat,vpi%numpw,ipiv,work,lwork,info) if(info /= 0) then write(stdout,*) 'Invert V: problem with dgetri :', info stop endif deallocate(ipiv,work) return END SUBROUTINE invert_v_pot SUBROUTINE fake_polarization_io(n) !this subroutine just call mp_barrier 2*n+1 times USE mp, ONLY : mp_barrier USE mp_world, ONLY : world_comm implicit none INTEGER :: n INTEGER :: i !we take advantage of the t ==> -t symmetry ! do i=-n,n do i=0,n call mp_barrier( world_comm ) enddo return END SUBROUTINE fake_polarization_io SUBROUTINE orthonormalize_vpot_inverse_para(op,vp) !this subroutine rotates the v_pot data on the basis of the trasform op !perform the trasform \sum_{i',j'} B_{i',i}P_{i',j'}B_{j',j} !parallel version USE io_global, ONLY : stdout USE basic_structures, ONLY : v_pot, ortho_polaw USE mp_world, ONLY : world_comm, mpime, nproc USE mp, ONLY : mp_sum implicit none TYPE(v_pot), INTENT(inout) :: vp!data TYPE(ortho_polaw), INTENT(in) :: op!trasform INTEGER :: iw,jw,kw REAL(kind=DP), ALLOCATABLE :: mat(:,:) if(op%numpw /= vp%numpw) then write(stdout,*) 'ROUTINE ORTHONORMALIZE: BASIS INCONSISTENT' stop endif allocate(mat(op%numpw,op%numpw)) mat(:,:)=0.d0 do iw=1,op%numpw do jw=1,op%numpw if(mod(jw,nproc)==mpime) then do kw=1,op%numpw mat(iw,jw)=mat(iw,jw)+op%on_mat(kw,iw)*vp%vmat(kw,jw) enddo endif enddo call mp_sum(mat(iw,:),world_comm) enddo vp%vmat(:,:)=0.d0 do iw=1,op%numpw do jw=1,op%numpw if(mod(jw,nproc)==mpime) then do kw=1,op%numpw vp%vmat(iw,jw)=vp%vmat(iw,jw)+op%on_mat(kw,jw)*mat(iw,kw) enddo endif enddo call mp_sum(vp%vmat(iw,:),world_comm) enddo deallocate(mat) return END SUBROUTINE orthonormalize_vpot_inverse_para SUBROUTINE create_polarization_contraction_state(time,pr,uu,l_hf_energies, ene_hf,options) !this subroutine set the polarization in imaginary time ! as P(r,r',it)=G(r,r',it)*G(r,r',-it) ! for our basis !uses contractions !THERE IS ALSO A SPIN FACTOR 2 !if required uses HF energies !use single occupied state contractions USE io_global, ONLY : stdout USE constants, ONLY : eps8 USE compact_product, ONLY : contraction_pola_state, free_memory_contraction_pola_state, & &read_contraction_pola_state USE basic_structures, ONLY : wannier_u USE input_gw, ONLY : input_options implicit none REAL(kind=DP) :: time!imaginary time t, just a check TYPE(polaw) :: pr!polarization P(it) to be created TYPE(wannier_u) :: uu!for the KS energies LOGICAL, INTENT(in) :: l_hf_energies!if true uses HF energies REAL(kind=DP), INTENT(in) :: ene_hf(:)!HF energies TYPE(input_options) :: options!for i/o purpoose INTEGER :: iw,jw, vv, cc INTEGER :: l,n,m,o REAL(kind=DP) :: offset REAL(kind=DP),ALLOCATABLE :: expene(:)!to calculate the exponentials just once REAL(kind=DP),ALLOCATABLE :: exptmp(:)!temporary arrays for speed-up REAL(kind=DP),ALLOCATABLE :: outmp(:,:) REAL(kind=DP),ALLOCATABLE :: tmpc(:) TYPE(contraction_pola_state) :: cps !first annihilation call free_memory_polaw(pr) !set pr pr%ontime=.true. pr%time=time !the following for accessing dimension of polarization matrix cps%state=1 call read_contraction_pola_state(cps,options) pr%numpw=cps%numpw !calculates energy offset if(.not.l_hf_energies) then if(uu%nums > uu%nums_occ(1)) then offset=-(uu%ene(uu%nums_occ(1)+1,1)+uu%ene(uu%nums_occ(1),1))/2.d0 else offset=-uu%ene(uu%nums_occ(1),1) endif else if(uu%nums > uu%nums_occ(1)) then offset=-(ene_hf(uu%nums_occ(1)+1)+ene_hf(uu%nums_occ(1)))/2.d0 else offset=-ene_hf(uu%nums_occ(1)) endif endif !calcualte exponentials of ks energies allocate(expene(uu%nums)) if(.not.l_hf_energies) then do vv=1,uu%nums_occ(1) expene(vv)=exp((uu%ene(vv,1)+offset)*time) enddo do cc=uu%nums_occ(1)+1,uu%nums expene(cc)=exp(-(uu%ene(cc,1)+offset)*time) enddo else do vv=1,uu%nums_occ(1) expene(vv)=exp((ene_hf(vv)+offset)*time) enddo do cc=uu%nums_occ(1)+1,uu%nums expene(cc)=exp(-(ene_hf(cc)+offset)*time) enddo endif !allocate allocate(pr%pw( pr%numpw,pr%numpw)) pr%pw(:,:)=0.d0 allocate(exptmp(cps%nums-cps%nums_occ)) allocate(outmp(cps%nums-cps%nums_occ,pr%numpw)) allocate(tmpc(cps%nums-cps%nums_occ)) do vv=1,cps%nums_occ cps%state=vv write(stdout,*) 'read_contraction_pola_state' if(vv /= 1) call read_contraction_pola_state(cps,options) write(stdout,*) 'read_contraction_pola_state', vv do cc=1,cps%nums-cps%nums_occ exptmp(cc)=expene(vv)*expene(cc+cps%nums_occ) enddo do iw=1,pr%numpw do cc=1,cps%nums-cps%nums_occ outmp(cc,iw)=cps%ou(cc,iw)*exptmp(cc) enddo enddo write(stdout,*) 'calculus1' ! do jw=1,pr%numpw ! do iw=jw,pr%numpw ! do cc=1,cps%nums-cps%nums_occ ! tmpc(cc)=cps%ou(cc,iw)*outmp(cc,jw) ! enddo ! pr%pw(iw,jw)=pr%pw(iw,jw)+sum(tmpc(:)) ! enddo ! enddo call dgemm('T','N',pr%numpw,pr%numpw,cps%nums-cps%nums_occ,1.d0,cps%ou,cps%nums-cps%nums_occ, & outmp,cps%nums-cps%nums_occ,1.d0,pr%pw,pr%numpw) call free_memory_contraction_pola_state(cps) enddo do jw=1,pr%numpw do iw=jw,pr%numpw pr%pw(jw,iw)=pr%pw(iw,jw) enddo enddo ! pr%pw(:,:)=(0.d0,-1.d0)*pr%pw(:,:) pr%factor=(0.d0,-1.d0) !now spin factor pr%pw(:,:)=2.d0*pr%pw(:,:) deallocate(expene) deallocate(exptmp) deallocate(outmp) deallocate(tmpc) return END SUBROUTINE create_polarization_contraction_state SUBROUTINE distribute_v_pot(vp,vpd) !this subroutine distributes the coulomb matrix ! among processors USE io_global, ONLY : stdout USE basic_structures, ONLY : v_pot, free_memory USE mp_world, ONLY : nproc,mpime implicit none TYPE(v_pot), INTENT(in) :: vp !the descriptor of the coulomb matrix to be distributed TYPE(v_pot), INTENT(out) :: vpd!distributed coulomb matrix INTEGER :: l_blk,nbegin,nend,ii call free_memory(vpd) vpd%numpw = vp%numpw l_blk= vp%numpw/nproc if(l_blk*nproc < vp%numpw) l_blk = l_blk+1 nbegin=mpime*l_blk+1 nend=nbegin+l_blk-1 if(nend > vp%numpw) nend = vp%numpw allocate(vpd%vmat(vp%numpw,l_blk)) do ii=nbegin,nend vpd%vmat(:,ii-nbegin+1)=vp%vmat(:,ii) enddo return END SUBROUTINE distribute_v_pot SUBROUTINE collect_v_pot(vp,vpd) !this subroutine collects the coulomb matrix ! among processors USE io_global, ONLY : stdout USE basic_structures, ONLY : v_pot, free_memory USE mp_world, ONLY : nproc,mpime,world_comm!group USE parallel_include implicit none TYPE(v_pot), INTENT(out) :: vp !the descriptor of the coulomb matrix to be distributed TYPE(v_pot), INTENT(in) :: vpd!distributed coulomb matrix INTEGER :: l_blk,nbegin,nend,ierr call free_memory(vp) vp%numpw = vpd%numpw l_blk= vp%numpw/nproc if(l_blk*nproc < vp%numpw) l_blk = l_blk+1 nbegin=mpime*l_blk+1 nend=nbegin+l_blk-1 if(nend > vp%numpw) nend = vp%numpw allocate(vp%vmat(vp%numpw,l_blk*nproc)) #if defined(__MPI) call MPI_ALLGATHER(vpd%vmat,l_blk*vp%numpw,MPI_DOUBLE_PRECISION, vp%vmat, & & l_blk*vp%numpw, MPI_DOUBLE_PRECISION,world_comm, ierr) #else vp%vmat(:,:)=vpd%vmat(:,:) #endif return END SUBROUTINE collect_v_pot SUBROUTINE calculate_w_g(vp,pp,ww,xc_together,l_symm_epsilon,l_head_epsilon,agz,head,l_divergence,inv_epsi, & &l_wing_epsilon, awing, awing_c) !this subroutine calculates W=(1+vp)^{-1}v !this is meaningful only on frequency domain !lapack routines are used !it use exteded basis for G=0 term USE io_global, ONLY : stdout USE basic_structures, ONLY : v_pot, head_epsilon implicit none TYPE(v_pot) :: vp!coulomb potential TYPE(polaw) :: pp!polarization on imaginary frequency, destroyed on exit TYPE(polaw) :: ww!dressed interaction to be calculated LOGICAL :: xc_together!if true the entire W is taken, otherwise W-v LOGICAL :: l_symm_epsilon! if true uses the symmetrized form of the dielectric matrix !for calculating W LOGICAL :: l_head_epsilon!if true add to the symmetrized form of the dielectric matrix !the head terms REAL(kind=DP), DIMENSION(:) :: agz!terms A_ij<\tilde{w^P_j}|G=0> REAL(kind=DP) :: head!term (G=0,G=0) of the symmetric dielectric matrix LOGICAL, INTENT(in) :: l_divergence!if true calculate the head of the inverse dielectric matrix REAL(kind=DP), INTENT(out) :: inv_epsi!head of the inverse dielectric matrix LOGICAL, INTENT(in) :: l_wing_epsilon!if true calculate the wings of the symmetrized dielectric matrix REAL(kind=DP), DIMENSION(:) :: awing!the terms A_ij wing_j REAL(kind=DP), DIMENSION(:) :: awing_c!the terms A_ij wing_j INTEGER iw,jw,kw REAL(kind=DP), ALLOCATABLE, DIMENSION(:,:) :: dtmp!temporary array INTEGER, ALLOCATABLE, DIMENSION(:) :: ipiv INTEGER :: info REAL(kind=DP),ALLOCATABLE, DIMENSION(:) :: work INTEGER :: lwork REAL(kind=DP) sca REAL(kind=DP) :: workd REAL(kind=DP) alpha !deallocate if the case call free_memory_polaw(ww) !check and set if(pp%ontime) then write(stdout,*) 'Routine calculate_w: frequencies required' stop endif if(pp%numpw /= vp%numpw) then write(stdout,*) 'Routine calculate_w: basis set does not correspond',pp%numpw,vp%numpw stop endif ww%ontime=.false. ww%time=pp%time ww%label=pp%label ww%numpw=pp%numpw allocate(ww%pw(ww%numpw,ww%numpw)) allocate(dtmp(ww%numpw+1,ww%numpw+1)) allocate(ipiv(ww%numpw+1)) dtmp(:,:)=0.d0 if(.not.l_symm_epsilon) then !not symmetric case calculates -vP call dgemm('N','N',ww%numpw,ww%numpw,ww%numpw,-1.d0*dble(pp%factor),& & vp%vmat,ww%numpw,pp%pw,ww%numpw,0.d0,dtmp,ww%numpw+1) else !symmetric case calculates -v^1/2 P v^1/2 call dgemm('N','N',ww%numpw,ww%numpw,ww%numpw,-1.d0*dble(pp%factor),& & vp%vmat,ww%numpw,pp%pw,ww%numpw,0.d0,dtmp,ww%numpw+1) pp%pw(1:ww%numpw,1:ww%numpw)=dtmp(1:ww%numpw,1:ww%numpw) call dgemm('N','N',ww%numpw,ww%numpw,ww%numpw,1.d0,& & pp%pw,ww%numpw,vp%vmat,ww%numpw,0.d0,dtmp,ww%numpw+1) endif !calculate normalization factor alpha sca=1.d0 do iw=1,ww%numpw sca=sca-agz(iw)**2.d0 enddo alpha=1.d0/sqrt(sca) write(stdout,*) 'ALPHA :', alpha FLUSH(stdout) !calculate elements 0',0' 0',i i,O' dtmp(ww%numpw+1,:)=0.d0 dtmp(:,ww%numpw+1)=0.d0 do iw=1,ww%numpw do jw=1,ww%numpw dtmp(ww%numpw+1,ww%numpw+1)=dtmp(ww%numpw+1,ww%numpw+1) & & + alpha**2.d0 * agz(iw)* agz(jw)*dtmp(iw,jw) enddo enddo do iw=1,ww%numpw do jw=1,ww%numpw dtmp(ww%numpw+1,iw)=dtmp(ww%numpw+1,iw)-alpha*dtmp(jw,iw)*agz(jw) enddo enddo do iw=1,ww%numpw dtmp(iw,ww%numpw+1)=dtmp(ww%numpw+1,iw) enddo !if required add the head if(l_symm_epsilon .and.l_head_epsilon) then ! terms i,j do jw=1,ww%numpw do iw=1,ww%numpw dtmp(iw,jw)=dtmp(iw,jw)+agz(iw)*agz(jw)*head enddo enddo endif !term O',0' 0',i i,0' dtmp(ww%numpw+1,ww%numpw+1)= dtmp(ww%numpw+1,ww%numpw+1) + & &head/alpha**2.d0 do iw=1,ww%numpw dtmp(ww%numpw+1,iw)=dtmp(ww%numpw+1,iw)+head*agz(iw)/alpha dtmp(iw,ww%numpw+1)=dtmp(iw,ww%numpw+1)+head*agz(iw)/alpha enddo !if required add the wings !TODO ATTENZIONE if(l_symm_epsilon .and.l_wing_epsilon) then !elements i,j do jw=1,ww%numpw do iw=1,ww%numpw dtmp(iw,jw)=dtmp(iw,jw)+agz(iw)*awing_c(jw)+agz(jw)*awing_c(iw) enddo enddo ! 0',0' do iw=1,ww%numpw dtmp(ww%numpw+1,ww%numpw+1)=dtmp(ww%numpw+1,ww%numpw+1) & & - 2.d0*agz(iw)*awing_c(iw) enddo ! 0',i ',0' do iw=1,ww%numpw dtmp(ww%numpw+1,iw)=dtmp(ww%numpw+1,iw)+awing(iw)/alpha do jw=1,ww%numpw dtmp(ww%numpw+1,iw)=dtmp(ww%numpw+1,iw)-alpha*agz(iw)*awing_c(jw)*agz(jw) enddo dtmp(iw,ww%numpw+1)=dtmp(ww%numpw+1,iw) enddo endif do iw=1,ww%numpw+1 dtmp(iw,iw)=dtmp(iw,iw)+1.d0 enddo !inverse zmat write(stdout,*) 'Before inversion' FLUSH(stdout) call dgetrf(ww%numpw+1,ww%numpw+1,dtmp,ww%numpw+1,ipiv,info) if(info /= 0) then write(stdout,*) 'Routine calculate_w: problem with dgetrf :', info stop endif write(stdout,*) 'Before inversion2' FLUSH(stdout) call dgetri(ww%numpw+1,dtmp,ww%numpw+1,ipiv,workd,-1,info) write(stdout,*) 'Dimension', workd,ww%numpw,info!ATTENZIONE FLUSH(stdout) allocate(work(int(workd))) call dgetri(ww%numpw+1,dtmp,ww%numpw+1,ipiv,work,int(workd),info) write(stdout,*) 'Out of dgetri' FLUSH(stdout) if(info /= 0) then write(stdout,*) 'Routine calculate_w: problem with zgetri :', info stop endif if(.not.xc_together) then do iw=1,ww%numpw+1 dtmp(iw,iw)=dtmp(iw,iw)-1.d0 enddo endif !if required calculates the head (G=0,G=0) of \epsilon^-1 if(l_divergence) then inv_epsi=0.d0 !term i,j do jw=1,ww%numpw do iw=1,ww%numpw inv_epsi = inv_epsi+dtmp(iw,jw)*agz(iw)*agz(jw) enddo enddo !term 0',0' inv_epsi=inv_epsi+dtmp(ww%numpw+1,ww%numpw+1)/alpha**2.d0 !terms 0',i i,0' do iw=1,ww%numpw inv_epsi=inv_epsi+2.d0*agz(iw)*dtmp(ww%numpw+1,iw)/alpha enddo do iw=1,ww%numpw+1 dtmp(iw,iw)=dtmp(iw,iw)-inv_epsi enddo endif write(stdout,*) 'INV EPSI G=0,G=0', inv_epsi, dtmp(ww%numpw+1,ww%numpw+1) FLUSH(stdout) if(l_symm_epsilon .and.l_head_epsilon) then!ATTENZIONE !take away the G=0,G=0 term ! terms i,j write(stdout,*) 'Extract G=0,G=0 term' do jw=1,ww%numpw do iw=1,ww%numpw dtmp(iw,jw)=dtmp(iw,jw)-agz(iw)*agz(jw)*inv_epsi enddo enddo endif if(.not. l_symm_epsilon) then !calculates (e-1 -1)v call dgemm('N','N',ww%numpw,ww%numpw,ww%numpw,1.d0,& & dtmp,ww%numpw+1,vp%vmat,ww%numpw,0.d0,ww%pw,ww%numpw) else !calculates v^1/2 (e-1-1)v^1/2 call dgemm('N','N',ww%numpw,ww%numpw,ww%numpw,1.d0,& & vp%vmat,ww%numpw,dtmp,ww%numpw+1,0.d0,pp%pw,ww%numpw) call dgemm('N','N',ww%numpw,ww%numpw,ww%numpw,1.d0,& & pp%pw,ww%numpw,vp%vmat,ww%numpw,0.d0,ww%pw,ww%numpw) endif ww%factor=(1.d0,0.d0) ! if(.not.xc_together) then ! do iw=1,ww%numpw ! do jw=1,ww%numpw ! ww%pw(iw,jw)=ww%pw(iw,jw)-vp%vmat(iw,jw) ! enddo ! enddo ! endif deallocate(dtmp,ipiv,work) return END SUBROUTINE calculate_w_g SUBROUTINE create_polarization_file(uu, tf, prefix) USE basic_structures, ONLY : wannier_u, cprim_prod, free_memory, & &initialize_memory_cprim_prod USE times_gw, ONLY : times_freqs USE mp_world, ONLY : world_comm, nproc,mpime USE io_global, ONLY : stdout USE mp, ONLY : mp_barrier implicit none TYPE(wannier_u), INTENT(in) :: uu!for the energies TYPE(times_freqs) :: tf CHARACTER(LEN=256), INTENT(in) :: prefix!to designate the PW files INTEGER :: l_blk, nbegin, nend INTEGER :: it,iv,ic, iw, jw TYPE(polaw) :: pp TYPE(cprim_prod) :: cpp LOGICAL :: ok_read REAL(kind=DP), ALLOCATABLE :: exp_table(:) LOGICAL :: l_first!trick for gaining access to numpw, quite BAD REAL(kind=DP), ALLOCATABLE :: cpmat_tmp(:,:) write(stdout,*) 'Routine create_polarization_file' allocate(exp_table(uu%nums-uu%nums_occ(1))) !loop on time l_blk= (tf%n+1)/nproc if(l_blk*nproc < (tf%n+1)) l_blk = l_blk+1 nbegin=mpime*l_blk nend=nbegin+l_blk-1 do it=nbegin,nend if(it<= tf%n) then call initialize_polaw(pp) l_first=.true. do iv=1,uu%nums_occ(1) !loop on v write(stdout,*) 'STATE', iv FLUSH(stdout) !set table of exponentials do ic=uu%nums_occ(1)+1,uu%nums exp_table(ic-uu%nums_occ(1))=exp((uu%ene(iv,1)-uu%ene(ic,1))*tf%times(it)) enddo call mp_barrier( world_comm ) call initialize_memory_cprim_prod(cpp) !!read in Svci cpp%cprim=iv call read_data_pw_cprim_prod(cpp, prefix, .true., ok_read, .true.,.false.) !if required allocate polaw if(l_first) then allocate(pp%pw(cpp%numpw,cpp%numpw)) pp%pw(:,:)=0.d0 pp%numpw=cpp%numpw l_first=.false. endif !!!!the following for using blas routine allocate(cpmat_tmp(cpp%nums_cond,cpp%numpw)) call mytranspose(cpp%cpmat, cpp%numpw, cpmat_tmp, cpp%nums_cond, cpp%numpw, cpp%nums_cond) do iw=1,cpp%numpw cpmat_tmp(:,iw)=cpmat_tmp(:,iw)*exp_table(:) enddo !!! !calculate term ! do ic=1,cpp%nums_cond ! do jw=1,cpp%numpw ! do iw=1,cpp%numpw ! pp%pw(iw,jw)=pp%pw(iw,jw)+cpp%cpmat(iw,ic)*cpp%cpmat(jw,ic)*exp_table(ic) ! enddo ! enddo ! enddo call dgemm('N','N',cpp%numpw,cpp%numpw,cpp%nums_cond,1.d0,cpp%cpmat,cpp%numpw,& &cpmat_tmp,cpp%nums_cond,1.d0,pp%pw,cpp%numpw) deallocate(cpmat_tmp) call free_memory(cpp) enddo !write polaw on file ! pp%label=it pp%time=tf%times(it) pp%factor=(0.d0,-1.d0) pp%numpw=cpp%numpw pp%ontime=.true. pp%pw(:,:)=pp%pw(:,:)*2.d0!for spin multiplicity call write_polaw(pp,.false.) call free_memory_polaw(pp) else !just parallelel reading of file do iv=1,uu%nums_occ(1) call mp_barrier( world_comm ) call initialize_memory_cprim_prod(cpp) cpp%cprim=iv call read_data_pw_cprim_prod(cpp, prefix, .true., ok_read, .true.,.false.) call free_memory(cpp) enddo endif enddo deallocate(exp_table) return END SUBROUTINE create_polarization_file SUBROUTINE square_root_polaw(pw,numpw) !this subroutine calculate the square root of the polaw matrix !it is done by calculating the eigenvalues and eigenvectors !it assumes that the matrix is symmetric and positive definite USE io_global, ONLY : stdout implicit none REAL(kind=DP) :: pw(numpw,numpw)!the matrix to be operated INTEGER :: numpw!dimension of the matrix REAL(kind=DP), ALLOCATABLE :: e_va(:), work(:) REAL(kind=DP), ALLOCATABLE :: tmp_pw(:,:) INTEGER :: lwork, info REAL(kind=DP) :: loptwork INTEGER :: iw,jw,kw #if defined(_OPENMP) INTEGER :: ntids INTEGER :: omp_get_num_threads, omp_get_max_threads EXTERNAL omp_set_num_threads, omp_get_num_threads, omp_get_max_threads #endif allocate(e_va(numpw)) allocate(tmp_pw(numpw, numpw)) tmp_pw(:,:)=pw(:,:) #if defined(_OPENMP) ! go single-thread ntids = omp_get_max_threads() call omp_set_num_threads(1) #endif !check for optimal dimension call DSYEV( 'V', 'U', numpw, tmp_pw, numpw, e_va, loptwork, -1, info) lwork=int(loptwork) allocate(work(lwork)) !calculate the eigenvalues, eigenvectors call DSYEV( 'V', 'U', numpw, tmp_pw, numpw, e_va, work, lwork,info ) if(info /= 0) then write(stdout,*) 'Problem with dsyev', info stop endif #if defined(_OPENMP) ! go multi-thread call omp_set_num_threads(ntids) #endif !do square root of eigenvector do iw=1,numpw if(e_va(iw) < 0.d0) then write(stdout,*) 'Problem with eigenvalue', iw stop endif e_va(iw)=dsqrt(e_va(iw)) enddo !reform the matrix pw(:,:)=0.d0 ! Carlo substitute with DGEMM do kw=1,numpw do jw=1,numpw do iw=1,numpw pw(iw,jw)=pw(iw,jw)+tmp_pw(iw,kw)*tmp_pw(jw,kw)*e_va(kw) enddo enddo enddo deallocate(tmp_pw) deallocate(work) deallocate(e_va) return END SUBROUTINE square_root_polaw SUBROUTINE create_polarization_beta(time, pr, uu, qm) !this subroutine create the polarization with the strategy beta: !P_ij(\tau)=\int dr dr' <\omega^{P'}_i(r)U_{v,v'}exp(E_v\tau)\tilde{\omega_v'}(r)*U_{v,v''}\tilde{\omega_v''}(r') ! *U_{c,c'}exp(E_c\tau)\tilde{\omega_c'}(r)U_{c,c''}\tilde{\omega_c''}(r)\omega^{P'}_j(r') !it makes use of S_{i,vc}=\int dr \omega^{P'}_i(r)\tilde{\omega_v}(r)\tilde{\omega_c}(r) USE basic_structures, ONLY : wannier_u, free_memory,q_mat, wannier_P USE times_gw, ONLY : times_freqs USE io_global, ONLY : stdout implicit none REAL(kind=DP), INTENT(in) :: time! imaginary time tau TYPE(wannier_u), INTENT(in) :: uu!for the energies and trasformation matrix TYPE(polaw), INTENT(out) :: pr!polarization P(it) to be created TYPE(q_mat), INTENT(in) :: qm ! for S matrices INTEGER :: i,j,k, ip, ii, jj INTEGER :: nums_cond!number of conduction states INTEGER :: iw,jw REAL(kind=DP), ALLOCATABLE :: v_val(:,:), exp_table_v(:), v_cond(:,:), exp_table_c(:) REAL(kind=DP), ALLOCATABLE :: tmp_mat1(:,:), tmp_mat2(:,:) REAL(kind=DP) :: fermi_en REAL(kind=DP), ALLOCATABLE :: q(:,:),t(:,:), v(:) REAL(kind=DP), EXTERNAL :: ddot write(stdout,*) 'Routine create_polarization_beta' !0)set polarization structure pr%ontime=.true. pr%time=time pr%numpw=qm%numpw pr%factor=(0.d0,-1.d0) !allocate allocate(pr%pw( pr%numpw,pr%numpw)) pr%pw(:,:) =(0.d0,0.d0) !1)calculate V_v'v''= U_{vv'}U_{v,v''}exp(E_v \tau} allocate(v_val(uu%nums_occ(1),uu%nums_occ(1))) allocate(exp_table_v(uu%nums_occ(1))) !fermi_en is used to reduce the numerical error fermi_en=(uu%ene(uu%nums_occ(1)+1,1)+uu%ene(uu%nums_occ(1),1))/2.d0 exp_table_v(1:uu%nums_occ(1))=exp((uu%ene(1:uu%nums_occ(1),1)-fermi_en)*abs(time)) v_val(:,:)=0.d0 allocate(tmp_mat1(uu%nums_occ(1),uu%nums_occ(1)), tmp_mat2(uu%nums_occ(1),uu%nums_occ(1))) tmp_mat1(1:uu%nums_occ(1),1:uu%nums_occ(1))=dble(uu%umat(1:uu%nums_occ(1),1:uu%nums_occ(1),1)) do i=1,uu%nums_occ(1) do j=1,uu%nums_occ(1) tmp_mat2(i,j)=dble(uu%umat(i,j,1))*exp_table_v(i) enddo enddo call dgemm('T','N',uu%nums_occ(1),uu%nums_occ(1),uu%nums_occ(1),1.d0,tmp_mat2,uu%nums_occ(1),tmp_mat1,uu%nums_occ(1),& &0.d0,v_val,uu%nums_occ(1)) deallocate(tmp_mat1,tmp_mat2) deallocate(exp_table_v) !2) calculate V_c'c''= U_{c,c'}U_{c,c''}exp(-E_c \tau} nums_cond=uu%nums-uu%nums_occ(1) allocate(v_cond(nums_cond,nums_cond)) allocate(exp_table_c(nums_cond)) exp_table_c(1:nums_cond)=exp((-uu%ene(uu%nums_occ(1)+1:uu%nums,1) +fermi_en)*abs(time)) allocate(tmp_mat1(nums_cond,nums_cond), tmp_mat2(nums_cond,nums_cond)) tmp_mat1(1:nums_cond,1:nums_cond)=dble(uu%umat(uu%nums_occ(1)+1:uu%nums,uu%nums_occ(1)+1:uu%nums,1)) do i=1,nums_cond do j=1,nums_cond tmp_mat2(i,j)=dble(uu%umat(uu%nums_occ(1)+i,uu%nums_occ(1)+j,1))*exp_table_c(i) enddo enddo call dgemm('T','N',nums_cond,nums_cond,nums_cond,1.d0,tmp_mat2,nums_cond,tmp_mat1,nums_cond,& &0.d0,v_cond,nums_cond) deallocate(tmp_mat1,tmp_mat2) deallocate(exp_table_c) do iw=1,pr%numpw !calculate T_v''c'=S_{i,v'c'}V_{v',v''} allocate(t(uu%nums_occ(1),nums_cond)) t(:,:)=0.d0 do ip=1,qm%wp(iw)%numij i=qm%wp(iw)%ij(1,ip)!valence only j=qm%wp(iw)%ij(2,ip)!valence and conduction if(i>uu%nums_occ(1)) then write(stdout,*) 'create_polarization_beta ERROR' FLUSH(stdout) stop endif !only valence*conduction products are required if(j>uu%nums_occ(1)) then do ii=1,uu%nums_occ(1) t(ii,j-uu%nums_occ(1))=t(ii,j-uu%nums_occ(1))+qm%wp(iw)%o(ip)*v_val(i,ii) enddo endif enddo !calculate Q v''c''=T_{v''c'}V_{c'c''} allocate( q(uu%nums_occ(1),nums_cond)) call dgemm('N','N',uu%nums_occ(1),nums_cond,nums_cond,1.d0,t,uu%nums_occ(1),v_cond,nums_cond,0.d0,& &q,uu%nums_occ(1)) deallocate(t) !put q on a right order for multiplication with S_{j,v''c''} !WARNING WARNING ATTENZIONE !it suppose that the wp(:)%ij are all the same allocate(v(qm%wp(1)%numij)) v(:)=0.d0 do ip=1,qm%wp(iw)%numij i=qm%wp(iw)%ij(1,ip)!valence only j=qm%wp(iw)%ij(2,ip)!valence and conduction if(j > uu%nums_occ(1)) then v(ip)=q(i,j-uu%nums_occ(1)) endif enddo deallocate(q) !product with jw do jw=iw,pr%numpw pr%pw(iw,jw)= ddot(qm%wp(iw)%numij,qm%wp(jw)%o,1,v,1) pr%pw(jw,iw)=pr%pw(iw,jw) enddo deallocate(v) enddo !now spin factor pr%pw(:,:)=2.d0*pr%pw(:,:) deallocate(v_val,v_cond) return END SUBROUTINE create_polarization_beta SUBROUTINE create_polarization_upper(uu, tf, prefix) !this subroutine adds to the polarization the part from upper reduced states USE basic_structures, ONLY : wannier_u, cprim_prod, free_memory, & &initialize_memory, upper_states USE times_gw, ONLY : times_freqs USE mp_world, ONLY : nproc,mpime USE io_global, ONLY : stdout implicit none TYPE(wannier_u), INTENT(in) :: uu!for the energies TYPE(times_freqs), INTENT(in) :: tf !for grid on imaginary time CHARACTER(LEN=256), INTENT(in) :: prefix!to designate the PW files INTEGER :: l_blk, nbegin, nend INTEGER :: it,iv,ic, iw, jw TYPE(upper_states) :: us TYPE(polaw) :: pp TYPE(cprim_prod) :: cpp LOGICAL :: ok_read REAL(kind=DP), ALLOCATABLE :: exp_table(:) REAL(kind=DP), ALLOCATABLE :: cpmat_tmp(:,:) write(stdout,*) 'Routine create_polarization_upper' !read-in upper states call initialize_memory(us) call read_data_pw_upper_states(us,prefix) allocate(exp_table(us%nums_reduced)) !loop on time l_blk= (tf%n+1)/nproc if(l_blk*nproc < (tf%n+1)) l_blk = l_blk+1 nbegin=mpime*l_blk nend=nbegin+l_blk-1 do it=nbegin,nend if(it<= tf%n) then !read polarization call initialize_polaw(pp) call read_polaw(it,pp,.false.,.false.) do iv=1,uu%nums_occ(1) !loop on v write(stdout,*) 'STATE', iv FLUSH(stdout) !set table of exponentials do ic=1,us%nums_reduced exp_table(ic)=exp((uu%ene(iv,1)-us%ene(ic))*tf%times(it)) enddo call initialize_memory(cpp) !!read in Svci cpp%cprim=iv call read_data_pw_cprim_prod(cpp, prefix, .true., ok_read, .true.,.true.) !if required allocate polaw !!!!the following for using blas routine allocate(cpmat_tmp(us%nums_reduced,cpp%numpw)) call mytranspose(cpp%cpmat, cpp%numpw, cpmat_tmp, us%nums_reduced, cpp%numpw, us%nums_reduced) do iw=1,cpp%numpw cpmat_tmp(:,iw)=cpmat_tmp(:,iw)*exp_table(:) enddo !!! !calculate term ! do ic=1,cpp%nums_cond ! do jw=1,cpp%numpw ! do iw=1,cpp%numpw ! pp%pw(iw,jw)=pp%pw(iw,jw)+cpp%cpmat(iw,ic)*cpp%cpmat(jw,ic)*exp_table(ic) ! enddo ! enddo ! enddo !factor 2 for spin multiplicity call dgemm('N','N',cpp%numpw,cpp%numpw,us%nums_reduced,2.d0,cpp%cpmat,cpp%numpw,& &cpmat_tmp,us%nums_reduced,1.d0,pp%pw,cpp%numpw) deallocate(cpmat_tmp) call free_memory(cpp) enddo !write polaw on file ! call write_polaw(pp,.false.) call free_memory_polaw(pp) else !just parallelel reading of file do iv=1,uu%nums_occ(1) call initialize_memory(cpp) cpp%cprim=iv call read_data_pw_cprim_prod(cpp, prefix, .true., ok_read, .true.,.true.) call free_memory(cpp) enddo endif enddo deallocate(exp_table) call free_memory(us) return END SUBROUTINE create_polarization_upper SUBROUTINE calculate_w_g_l(vp,pp,ww,xc_together,l_head_epsilon,head,inv_epsi, & &l_wing_epsilon, awing, awing_c, l_verbose) !this subroutine calculates W=(1+vp)^{-1}v !this is meaningful only on frequency domain !lapack routines are used !it use exteded basis for G=0 term !version for lanczos chain scheme USE io_global, ONLY : stdout USE basic_structures, ONLY : v_pot, head_epsilon implicit none TYPE(v_pot) :: vp!coulomb potential TYPE(polaw) :: pp!polarization on imaginary frequency, destroyed on exit TYPE(polaw) :: ww!dressed interaction to be calculated LOGICAL :: xc_together!if true the entire W is taken, otherwise W-v LOGICAL :: l_head_epsilon!if true add to the symmetrized form of the dielectric matrix !the head terms REAL(kind=DP) :: head(3)!term (G=0,G=0) of the symmetric dielectric matrix REAL(kind=DP), INTENT(out) :: inv_epsi!head of the inverse dielectric matrix LOGICAL, INTENT(in) :: l_wing_epsilon!if true calculate the wings of the symmetrized dielectric matrix REAL(kind=DP), DIMENSION(pp%numpw,3) :: awing!the terms A_ij wing_j REAL(kind=DP), DIMENSION(pp%numpw,3) :: awing_c!the terms A_ij wing_j LOGICAL, INTENT(in) :: l_verbose INTEGER iw,jw,kw,ipol REAL(kind=DP), ALLOCATABLE, DIMENSION(:,:) :: dtmp!temporary array INTEGER, ALLOCATABLE, DIMENSION(:) :: ipiv INTEGER :: info REAL(kind=DP),ALLOCATABLE, DIMENSION(:) :: work INTEGER :: lwork REAL(kind=DP) sca REAL(kind=DP) :: workd(1) REAL(kind=DP) alpha REAL(kind=DP) head_v REAL(kind=DP), ALLOCATABLE :: pw_save(:,:) !deallocate if the case call free_memory_polaw(ww) !check and set if(pp%ontime) then write(stdout,*) 'Routine calculate_w: frequencies required' stop endif if(pp%numpw /= vp%numpw) then write(stdout,*) 'Routine calculate_w: basis set does not correspond',pp%numpw,vp%numpw stop endif ww%ontime=.false. ww%time=pp%time ww%label=pp%label ww%numpw=pp%numpw allocate(ww%pw(ww%numpw,ww%numpw)) allocate(dtmp(ww%numpw,ww%numpw)) allocate(ipiv(ww%numpw)) ww%pw(:,:)=0.d0 allocate(pw_save(pp%numpw,pp%numpw)) do ipol=1,3 if(l_verbose) write(stdout,*) 'MAX P:', maxval(pp%pw(:,:)), 'MIN P:', minval(pp%pw(:,:)) FLUSH(stdout) if(ipol==1) then pw_save(:,:)=pp%pw(:,:) else pp%pw(:,:)=pw_save(:,:) endif dtmp(:,:)=0.d0 head_v=vp%vmat(vp%numpw,vp%numpw) !DEBUG if(l_verbose) write(stdout,*) 'IRR POLA HEAD', pp%pw(pp%numpw,pp%numpw) if(l_verbose) write(stdout,*) 'IRR POLA FIRST', pp%pw(1,1), l_wing_epsilon ! vp%vmat(vp%numpw,1:vp%numpw)=0.d0 !ATTENZIONE DEBUG ! vp%vmat(1:vp%numpw,vp%numpw)=0.d0 pp%pw(pp%numpw,1:pp%numpw)=0.d0 pp%pw(1:pp%numpw,pp%numpw)=0.d0 if(l_wing_epsilon) then!ATTENZIONE ! 0',i ',0' do iw=1,ww%numpw-1 pp%pw(ww%numpw,iw)=awing(iw,ipol) pp%pw(iw,ww%numpw)=pp%pw(ww%numpw,iw) enddo endif !symmetric case calculates -v^1/2 P v^1/2 call dgemm('N','N',ww%numpw,ww%numpw,ww%numpw,-1.d0*dble(pp%factor),& &vp%vmat,ww%numpw,pp%pw,ww%numpw,0.d0,dtmp,ww%numpw) pp%pw(1:ww%numpw,1:ww%numpw)=dtmp(1:ww%numpw,1:ww%numpw) call dgemm('N','N',ww%numpw,ww%numpw,ww%numpw,1.d0,& & pp%pw,ww%numpw,vp%vmat,ww%numpw,0.d0,dtmp,ww%numpw) !if required add the head if(l_head_epsilon) then !term O',0' 0',i i,0' dtmp(ww%numpw,ww%numpw)= head(ipol) if(l_verbose) write(stdout,*) 'APPLYING HEAD', head!DEBUG endif do iw=1,ww%numpw dtmp(iw,iw)=dtmp(iw,iw)+1.d0 enddo !inverse zmat if(l_verbose) write(stdout,*) 'MAX D:', maxval(dtmp(:,:)), 'MIN D', minval(dtmp(:,:)) if(l_verbose) write(stdout,*) 'Before inversion' FLUSH(stdout) call dgetrf(ww%numpw,ww%numpw,dtmp,ww%numpw,ipiv,info) if(info /= 0) then write(stdout,*) 'Routine calculate_w: problem with dgetrf :', info stop endif if(l_verbose) write(stdout,*) 'Before inversion2' FLUSH(stdout) call dgetri(ww%numpw,dtmp,ww%numpw,ipiv,workd,-1,info) if(l_verbose) write(stdout,*) 'Dimension', workd,ww%numpw,info!ATTENZIONE FLUSH(stdout) allocate(work(int(workd(1)))) call dgetri(ww%numpw,dtmp,ww%numpw,ipiv,work,int(workd(1)),info) if(l_verbose) write(stdout,*) 'Out of dgetri' FLUSH(stdout) if(l_verbose) write(stdout,*) 'MAX D1:', maxval(dtmp(:,:)), 'MIN D1:', minval(dtmp(:,:)) if(info /= 0) then write(stdout,*) 'Routine calculate_w: problem with zgetri :', info stop endif if(.not.xc_together) then do iw=1,ww%numpw dtmp(iw,iw)=dtmp(iw,iw)-1.d0 enddo endif inv_epsi=0.d0 !term i,j !term 0',0' inv_epsi=dtmp(ww%numpw,ww%numpw) write(stdout,*) 'INV EPSI G=0,G=0', inv_epsi, head_v FLUSH(stdout) vp%vmat(vp%numpw,vp%numpw)=head_v dtmp(ww%numpw,1:ww%numpw-1)=0.d0 dtmp(1:ww%numpw-1,ww%numpw)=0.d0 !DEBUG ! dtmp(:,:)=0.d0 ! do iw=1,ww%numpw ! dtmp(iw,iw)=inv_epsi ! enddo ! dtmp(ww%numpw,ww%numpw)=0.d0 !DEBUG if(l_verbose) write(stdout,*) 'MAX D2:', maxval(dtmp(:,:)), 'MIN D2:', minval(dtmp(:,:)) FLUSH(stdout) !calculates v^1/2 (e-1-1)v^1/2 call dgemm('N','N',ww%numpw,ww%numpw,ww%numpw,1.d0,& & vp%vmat,ww%numpw,dtmp,ww%numpw,0.d0,pp%pw,ww%numpw) call dgemm('N','N',ww%numpw,ww%numpw,ww%numpw,1.d0,& & pp%pw,ww%numpw,vp%vmat,ww%numpw,1.d0,ww%pw,ww%numpw) if(l_verbose) write(stdout,*) 'MAX W:', maxval(ww%pw(:,:)), 'MIN W:', minval(ww%pw(:,:)) FLUSH(stdout) deallocate(work) enddo deallocate(pw_save) ww%pw(:,:)=ww%pw(:,:)/3.d0 ! ww%pw(1:ww%numpw-1,1:ww%numpw-1)=0.d0 ! ww%pw(:,ww%numpw)=0.d0 ww%factor=(1.d0,0.d0) if(l_verbose) write(stdout,*) 'MAX:', maxval(ww%pw(:,:)), 'MIN:', minval(ww%pw(:,:)) FLUSH(stdout) deallocate(dtmp,ipiv) return END SUBROUTINE calculate_w_g_l END MODULE polarization
gpl-2.0