LCOV - code coverage report
Current view: top level - src/79_seqpar_mpi - m_lobpcg.F90 (source / functions) Coverage Total Hit
Test: coverage.info Lines: 76.9 % 39 30
Test Date: 2026-11-06 14:42:53 Functions: 100.0 % 1 1
Branches: 19.6 % 230 45

             Branch data     Line data    Source code
       1                 :             : !!****m* ABINIT/m_lobpcg
       2                 :             : !! NAME
       3                 :             : !!  m_lobpcg
       4                 :             : !!
       5                 :             : !! FUNCTION
       6                 :             : !!  This module provides the procedures used in the LOBPCGWF routine.
       7                 :             : !!  They permit to hide the complex/real form of the WFs.
       8                 :             : !!
       9                 :             : !! COPYRIGHT
      10                 :             : !! Copyright (C) 2009-2026 ABINIT group (FBottin,CS,FDahm,MT)
      11                 :             : !! This file is distributed under the terms of the
      12                 :             : !! GNU General Public License, see ~abinit/COPYING
      13                 :             : !! or http://www.gnu.org/copyleft/gpl.txt .
      14                 :             : !! For the initials of contributors, see ~abinit/doc/developers/contributors.txt.
      15                 :             : !!
      16                 :             : !! NOTES
      17                 :             : !!
      18                 :             : !! SOURCE
      19                 :             : 
      20                 :             : #if defined HAVE_CONFIG_H
      21                 :             : #include "config.h"
      22                 :             : #endif
      23                 :             : 
      24                 :             : #include "abi_common.h"
      25                 :             : 
      26                 :             : MODULE m_lobpcg
      27                 :             : 
      28                 :             :  use defs_basis
      29                 :             :  use m_abicore
      30                 :             :  use m_errors
      31                 :             :  use m_wfutils
      32                 :             :  use m_abi_linalg
      33                 :             :  use m_cgtools
      34                 :             :  use m_dtset
      35                 :             : 
      36                 :             :  use defs_abitypes,       only : mpi_type
      37                 :             :  use m_time,              only : timab
      38                 :             : 
      39                 :             :  implicit none
      40                 :             : 
      41                 :             :  private
      42                 :             : 
      43                 :             : !public procedures.
      44                 :             :  public :: xprecon
      45                 :             : !!***
      46                 :             : 
      47                 :             : CONTAINS
      48                 :             : !----------------------------------------------------------------------
      49                 :             : 
      50                 :             : 
      51                 :             : !! NAME
      52                 :             : !!  xprecon
      53                 :             : !!
      54                 :             : !! FUNCTION
      55                 :             : !!  precondition $<G|(H-e_{n,k})|C_{n,k}>$
      56                 :             : !!  for a block of band (band-FFT parallelisation)
      57                 :             : !!
      58                 :             : !! COPYRIGHT
      59                 :             : !! Copyright (C) 1998-2026 ABINIT group (FBottin,CS)
      60                 :             : !! this file is distributed under the terms of the
      61                 :             : !! gnu general public license, see ~abinit/COPYING
      62                 :             : !! or http://www.gnu.org/copyleft/gpl.txt .
      63                 :             : !! for the initials of contributors, see ~abinit/doc/developers/contributors.txt .
      64                 :             : !!
      65                 :             : !! INPUTS
      66                 :             : !!  blocksize= size of blocks of bands
      67                 :             : !!  $cg(vectsize,blocksize)=<G|C_{n,k}> for a block of bands$.
      68                 :             : !!  $eval(blocksize,blocksize)=current block of bands eigenvalues=<C_{n,k}|H|C_{n,k}>$.
      69                 :             : !!  $ghc(vectsize,blocksize)=<G|H|C_{n,k}> for a block of bands$.
      70                 :             : !!  iterationnumber=number of iterative minimizations in LOBPCG
      71                 :             : !!  kinpw(npw)=(modified) kinetic energy for each plane wave (Hartree)
      72                 :             : !!  mpi_enreg=information about MPI parallelization
      73                 :             : !!  nspinor=number of spinorial components of the wavefunctions (on current proc)
      74                 :             : !!  $vect(vectsize,blocksize)=<G|H|C_{n,k}> for a block of bands$.
      75                 :             : !!  npw=number of planewaves at this k point.
      76                 :             : !!  optekin= 1 if the kinetic energy used in preconditionning is modified
      77                 :             : !!             according to Kresse, Furthmuller, PRB 54, 11169 (1996) [[cite:Kresse1996]]
      78                 :             : !!           0 otherwise
      79                 :             : !!  optpcon= 0 the TPA preconditionning matrix does not depend on band
      80                 :             : !!           1 the TPA preconditionning matrix (not modified)
      81                 :             : !!           2 the TPA preconditionning matrix is independant of iterationnumber
      82                 :             : !!  vectsize= size of vectors
      83                 :             : !!
      84                 :             : !! OUTPUT
      85                 :             : !!  vect(2,npw)=<g|(h-eval)|c_{n,k}>*(polynomial ratio)
      86                 :             : !!
      87                 :             : !! SOURCE
      88                 :             : 
      89                 :       34551 : subroutine xprecon(cg,eval,blocksize,iterationnumber,kinpw,&
      90                 :       34551 : &  mpi_enreg,npw,nspinor,optekin,optpcon,pcon,ghc,vect,vectsize,&
      91                 :             : &  timopt,tim_xprecon,kinpw_kp,pcon_kp) ! optional arguments
      92                 :             : 
      93                 :             : !Arguments ------------------------------------
      94                 :             : !scalars
      95                 :             :  integer,intent(in) :: blocksize,iterationnumber,npw,nspinor,optekin
      96                 :             :  integer,intent(in) :: optpcon,vectsize
      97                 :             :  integer, intent(in), optional :: timopt,tim_xprecon
      98                 :             :  type(mpi_type),intent(in) :: mpi_enreg
      99                 :             : !arrays
     100                 :             :  real(dp),intent(inout) :: cg(vectsize,blocksize),eval(blocksize,blocksize)
     101                 :             :  real(dp),intent(in) :: kinpw(npw)
     102                 :             :  real(dp),intent(in),optional :: kinpw_kp(npw)
     103                 :             :  real(dp),intent(inout) :: ghc(vectsize,blocksize)
     104                 :             :  real(dp),intent(inout) :: pcon(npw,blocksize),vect(vectsize,blocksize)
     105                 :             :  real(dp),intent(inout),optional :: pcon_kp(npw,blocksize)
     106                 :             : 
     107                 :             : !Local variables-------------------------------
     108                 :       34551 :  complex(dp),dimension(:,:),allocatable :: z_cg,z_eval,z_ghc,z_vect
     109                 :             :  real(dp) :: tsec(2)
     110                 :             : ! *********************************************************************
     111                 :             : 
     112         [ +  - ]:       34551 :  if (present(tim_xprecon).and.present(timopt)) then
     113         [ -  + ]:       34551 :    if(abs(timopt)==3) then
     114                 :           0 :     call timab(tim_xprecon,1,tsec)
     115                 :             :    end if
     116                 :             :  end if
     117                 :             : 
     118         [ -  + ]:       34551 :  if (present(kinpw_kp)) then
     119         [ #  # ]:           0 :    ABI_CHECK(present(pcon_kp),"kinpw_kp and pcon_kp must be provided together")
     120         [ #  # ]:           0 :    ABI_CHECK(nspinor == 2,"GBT LOBPCG preconditioning requires two local spinor components")
     121         [ #  # ]:           0 :    ABI_CHECK(vectsize == 2*npw,"GBT LOBPCG preconditioning requires istwfk=1")
     122                 :             :  end if
     123                 :             : 
     124         [ +  + ]:       34551 :  if ( x_cplx == 1 ) then
     125         [ +  - ]:        2079 :    if (.not.present(kinpw_kp)) then
     126                 :             :      call cg_precon_block(cg,eval,blocksize,iterationnumber,kinpw,&
     127                 :        2079 : &      npw,nspinor,mpi_enreg%me_g0,optekin,optpcon,pcon,ghc,vect,vectsize,mpi_enreg%comm_bandspinorfft)
     128                 :             :    else
     129                 :             :      call cg_precon_block(cg(1:npw,:),eval,blocksize,iterationnumber,kinpw,&
     130                 :             : &      npw,1,mpi_enreg%me_g0,optekin,optpcon,pcon,ghc(1:npw,:),vect(1:npw,:),npw,&
     131   [ #  #  #  #  :           0 : &      mpi_enreg%comm_bandspinorfft)
          #  #  #  #  #  
          #  #  #  #  #  
          #  #  #  #  #  
          #  #  #  #  #  
          #  #  #  #  #  
             #  #  #  #  
                      # ]
     132                 :             :      call cg_precon_block(cg(npw+1:2*npw,:),eval,blocksize,iterationnumber,kinpw_kp,&
     133                 :             : &      npw,1,mpi_enreg%me_g0,optekin,optpcon,pcon_kp,ghc(npw+1:2*npw,:),vect(npw+1:2*npw,:),npw,&
     134   [ #  #  #  #  :           0 : &      mpi_enreg%comm_bandspinorfft)
          #  #  #  #  #  
          #  #  #  #  #  
          #  #  #  #  #  
          #  #  #  #  #  
          #  #  #  #  #  
             #  #  #  #  
                      # ]
     135                 :             :    end if
     136                 :             :  else
     137   [ -  +  +  -  :      129888 :    ABI_MALLOC(z_cg,(vectsize,blocksize))
          -  +  +  -  +  
          -  +  -  -  +  
                   -  + ]
     138   [ -  +  +  -  :      129888 :    ABI_MALLOC(z_eval,(blocksize,blocksize))
          -  +  +  -  +  
          -  +  -  -  +  
                   -  + ]
     139   [ -  +  +  -  :       97416 :    ABI_MALLOC(z_ghc,(vectsize,blocksize))
          -  +  +  -  -  
                +  -  + ]
     140   [ -  +  +  -  :       97416 :    ABI_MALLOC(z_vect,(vectsize,blocksize))
          -  +  +  -  -  
                +  -  + ]
     141                 :             : 
     142                 :       32472 :    call abi_xcopy(x_cplx*vectsize*blocksize,cg,1,z_cg,1)
     143                 :       32472 :    call abi_xcopy(x_cplx*vectsize*blocksize,ghc,1,z_ghc,1)
     144                 :       32472 :    call abi_xcopy(x_cplx*vectsize*blocksize,vect,1,z_vect,1)
     145                 :       32472 :    call abi_xcopy(x_cplx*blocksize*blocksize,eval,1,z_eval,1)
     146                 :             : 
     147         [ +  - ]:       32472 :    if (.not.present(kinpw_kp)) then
     148                 :             :      call cg_zprecon_block(z_cg,z_eval,blocksize,iterationnumber,kinpw,&
     149                 :       32472 : &      npw,nspinor,optekin,optpcon,pcon,z_ghc,z_vect,vectsize,mpi_enreg%comm_bandspinorfft)
     150                 :             :    else
     151                 :             :      call cg_zprecon_block(z_cg(1:npw,:),z_eval,blocksize,iterationnumber,kinpw,&
     152   [ #  #  #  #  :           0 : &      npw,1,optekin,optpcon,pcon,z_ghc(1:npw,:),z_vect(1:npw,:),npw,mpi_enreg%comm_bandspinorfft)
          #  #  #  #  #  
          #  #  #  #  #  
          #  #  #  #  #  
          #  #  #  #  #  
          #  #  #  #  #  
             #  #  #  #  
                      # ]
     153                 :             :      call cg_zprecon_block(z_cg(npw+1:2*npw,:),z_eval,blocksize,iterationnumber,kinpw_kp,&
     154                 :             : &      npw,1,optekin,optpcon,pcon_kp,z_ghc(npw+1:2*npw,:),z_vect(npw+1:2*npw,:),npw,&
     155   [ #  #  #  #  :           0 : &      mpi_enreg%comm_bandspinorfft)
          #  #  #  #  #  
          #  #  #  #  #  
          #  #  #  #  #  
          #  #  #  #  #  
          #  #  #  #  #  
             #  #  #  #  
                      # ]
     156                 :             :    end if
     157                 :             : 
     158                 :       32472 :    call abi_xcopy(x_cplx*vectsize*blocksize,z_cg,1,cg,1)
     159                 :       32472 :    call abi_xcopy(x_cplx*vectsize*blocksize,z_ghc,1,ghc,1)
     160                 :       32472 :    call abi_xcopy(x_cplx*vectsize*blocksize,z_vect,1,vect,1)
     161                 :       32472 :    call abi_xcopy(x_cplx*blocksize*blocksize,z_eval,1,eval,1)
     162                 :             : 
     163         [ -  + ]:       32472 :    ABI_FREE(z_cg)
     164         [ -  + ]:       32472 :    ABI_FREE(z_eval)
     165         [ -  + ]:       32472 :    ABI_FREE(z_ghc)
     166         [ -  + ]:       32472 :    ABI_FREE(z_vect)
     167                 :             :  endif
     168                 :             : 
     169         [ +  - ]:       34551 :  if (present(tim_xprecon).and.present(timopt)) then
     170         [ -  + ]:       34551 :    if(abs(timopt)==3) then
     171                 :           0 :      call timab(tim_xprecon,2,tsec)
     172                 :             :    end if
     173                 :             :  end if
     174                 :             : 
     175   [ -  +  -  +  :       34551 : end subroutine xprecon
             -  +  -  + ]
     176                 :             : !!***
     177                 :             : 
     178                 :             : !----------------------------------------------------------------------
     179                 :             : 
     180                 :             : END MODULE m_lobpcg
     181                 :             : !!***
        

Generated by: LCOV version 2.3-1