LCOV - code coverage report
Current view: top level - shared/common/src/10_defs - defs_basis.F90 (source / functions) Coverage Total Hit
Test: coverage.info Lines: 80.5 % 41 33
Test Date: 2026-11-10 11:05:29 Functions: 12.2 % 41 5
Branches: 37.5 % 32 12

             Branch data     Line data    Source code
       1                 :             : !!****m* ABINIT/defs_basis
       2                 :             : !! NAME
       3                 :             : !! defs_basis
       4                 :             : !!
       5                 :             : !! FUNCTION
       6                 :             : !! This module contains definitions for a number of named constants and
       7                 :             : !! physical constants, as well as associated datatypes and methods.
       8                 :             : !!
       9                 :             : !! COPYRIGHT
      10                 :             : !! Copyright (C) 2000-2026 ABINIT group (HM, XG,XW, EB)
      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                 :             : !!
      15                 :             : !! NOTES
      16                 :             : !! Of the named constants,
      17                 :             : !! by far the most important are those that define the 'kind' types of
      18                 :             : !! virtually all the variables used in a (well-written) FORTRAN 90 code
      19                 :             : !! the content of this file is derived from 'Numerical Recipes in Fortran 90'
      20                 :             : !! W.H. Press et al., volume 2 of 'Fortran Numerical Recipes', Cambridge
      21                 :             : !! University Press, Second Edition (1996), p. 937 and 1361
      22                 :             : !!
      23                 :             : !! SOURCE
      24                 :             : 
      25                 :             : #if defined HAVE_CONFIG_H
      26                 :             : #include "config.h"
      27                 :             : #endif
      28                 :             : 
      29                 :             : module defs_basis
      30                 :             : 
      31                 :             : !#ifdef HAVE_FC_ISO_FORTRAN_2008
      32                 :             : ! use ISO_FORTRAN_ENV, only : input_unit, output_unit, error_unit
      33                 :             : !#endif
      34                 :             : 
      35                 :             :  implicit none
      36                 :             : 
      37                 :             : !Keyword 'integer' stands for default integer type
      38                 :             : !and may be used whenever integer are presumed to be small
      39                 :             : 
      40                 :             : !nb of bytes related to an integer subtype n such as -10^(argument) < n < 10^(argument) (this is standard F90)
      41                 :             :  integer, parameter :: i1b=selected_int_kind(2)
      42                 :             :  integer, parameter :: i2b=selected_int_kind(4)
      43                 :             :  integer, parameter :: i4b=selected_int_kind(9)
      44                 :             :  integer, parameter :: i8b=selected_int_kind(18)
      45                 :             : 
      46                 :             : !nb of bytes related to default simple-precision real/complex subtypes
      47                 :             : !(= 4 for many machine architectures, = 8 for e.g. Cray)
      48                 :             :  integer, parameter :: sp=kind(1.0)          ! Single precision should not be used
      49                 :             : 
      50                 :             : !nb of bytes related to default double-precision real/complex subtypes
      51                 :             : !(= 8 for many machine architectures)
      52                 :             :  integer, parameter :: dp=kind(1.0d0)
      53                 :             : 
      54                 :             : ! Please DO NOT USE use complex(dpc) as complex(dp) is completely equivalent.
      55                 :             : ! dpc is still needed because nvfortran with ELPA (eos_nvhpc_23.9_elpa), for unknown reasons,
      56                 :             : ! raises an internal compiler error when compiling m_slk if dpc is not declared here.
      57                 :             :  integer, parameter :: dpc=kind((1.0_dp,1.0_dp))
      58                 :             : 
      59                 :             : !nb of bytes related to GW arrays, that can be tuned from sp to dp independently
      60                 :             : !of other variables in ABINIT. Presently single-precision is the default (see config/specs/options.conf)..
      61                 :             : #if defined HAVE_GW_DPC
      62                 :             :  integer, parameter :: gwp=kind(1.0d0)
      63                 :             : #else
      64                 :             :  integer, parameter :: gwp=kind(1.0)
      65                 :             : #endif
      66                 :             : 
      67                 :             : !The default lengths
      68                 :             : ! TODO: We should increase fnlen to be able to handle multiple pseudos paths in the input file
      69                 :             : ! but it seems that increasing this value triggers bugs in the rest of code because people
      70                 :             : ! do not trim input strings and use character(len=500) :: msg
      71                 :             : 
      72                 :             :  !integer, parameter :: fnlen=264     ! maximum length of file name variables
      73                 :             :  integer, parameter :: fnlen=400     ! maximum length of file name variables
      74                 :             :  integer, parameter :: strlen=2000000 ! maximum length of input string
      75                 :             : 
      76                 :             :  ! The input file used to run the code, allocated and set by parsefile.
      77                 :             :  ! It will be added to the netcdf files in ntck_open_create
      78                 :             :  character(len=:), allocatable, save :: INPUT_STRING
      79                 :             : 
      80                 :             :  integer, parameter :: md5_slen = 32 ! length of strings storing the pseudos' md5 checksum.
      81                 :             :  character(len=md5_slen),parameter :: md5_none = "None"
      82                 :             : 
      83                 :             :  integer, parameter :: abi_slen=80 ! maximum length of string variables
      84                 :             : 
      85                 :             : !Some constants:
      86                 :             : 
      87                 :             : ! UNIX unit numbers: standard input, standard output, ab_out, and a number for temporary access to a file.
      88                 :             : ! Please, use these named constants instead of write(*,*),
      89                 :             : ! it makes the code more readable and easier to change.
      90                 :             : 
      91                 :             : !Default values
      92                 :             :  !integer, parameter :: std_in = input_unit
      93                 :             :  !integer, parameter :: ab_in = input_unit
      94                 :             :  !integer, parameter :: std_out_default = output_unit
      95                 :             :  !integer, parameter :: ab_out_default=7
      96                 :             :  !integer, parameter :: std_err = error_unit
      97                 :             :  integer, parameter :: std_in=5
      98                 :             :  integer, parameter :: ab_in=5
      99                 :             :  integer, parameter :: std_out_default=6
     100                 :             :  integer, parameter :: ab_out_default=7    ! TODO: This should be initialized at run-time.
     101                 :             :  integer, parameter :: std_err=0
     102                 :             : 
     103                 :             :  integer, parameter :: dev_null=-1       ! Fake unit number used to skip the printing in wrtout.
     104                 :             :  integer, parameter :: ab_xml_out = 50   ! this unit is used to print output into an XML file
     105                 :             :  integer, parameter :: tmp_unit=9,tmp_unit2=10
     106                 :             : 
     107                 :             : !These vars should be private and only modifiable via an appropriate method (see below)
     108                 :             :  integer, public, save :: ab_out = ab_out_default
     109                 :             :  integer, public, save :: std_out =  std_out_default
     110                 :             : !It should be put to xmpi_world (but it is not possible for the moment - v6.9)
     111                 :             :  integer, public, save :: abinit_comm_output = -1 !This default value has to be changed at start !!!
     112                 :             : 
     113                 :             : ! the maximum length of a record in a file connected for sequential access.
     114                 :             :  integer,public,parameter :: ABI_RECL=524288  ! 2**19
     115                 :             : 
     116                 :             :  integer,public,parameter :: MAX_NSHIFTK = 210
     117                 :             :  ! Maximum number of shifts in input k-mesh.
     118                 :             : 
     119                 :             : !Real dp constants
     120                 :             :  real(dp), parameter :: zero=0._dp
     121                 :             :  real(dp), parameter :: one=1._dp
     122                 :             :  real(dp), parameter :: two=2._dp
     123                 :             :  real(dp), parameter :: three=3._dp
     124                 :             :  real(dp), parameter :: four=4._dp
     125                 :             :  real(dp), parameter :: five=5._dp
     126                 :             :  real(dp), parameter :: six=6._dp
     127                 :             :  real(dp), parameter :: seven=7._dp
     128                 :             :  real(dp), parameter :: eight=8._dp
     129                 :             :  real(dp), parameter :: nine=9._dp
     130                 :             :  real(dp), parameter :: ten=10._dp
     131                 :             : 
     132                 :             : !Real sp constants
     133                 :             :  real(sp), parameter :: zero_sp=0._sp
     134                 :             :  real(sp), parameter :: one_sp=1._sp
     135                 :             : 
     136                 :             : !Fractionary real constants
     137                 :             :  real(dp), parameter :: half=0.50_dp
     138                 :             :  real(dp), parameter :: onehalf=1.50_dp
     139                 :             :  real(dp), parameter :: third=one/three
     140                 :             :  real(dp), parameter :: quarter=0.25_dp
     141                 :             :  real(dp), parameter :: fifth=0.20_dp
     142                 :             :  real(dp), parameter :: sixth=one/six
     143                 :             :  real(dp), parameter :: seventh=one/seven
     144                 :             :  real(dp), parameter :: eighth=0.125_dp
     145                 :             :  real(dp), parameter :: ninth=one/nine
     146                 :             :  real(dp), parameter :: two_thirds=two*third
     147                 :             :  real(dp), parameter :: four_thirds=four*third
     148                 :             :  real(dp), parameter :: five_thirds=five*third
     149                 :             :  real(dp), parameter :: three_quarters=0.75_dp
     150                 :             :  real(dp), parameter :: three_fifth=three/five
     151                 :             : 
     152                 :             : !Real constants related to the golden number
     153                 :             :  real(dp), parameter :: gold=1.618033988749894848204586834365638117720309179_dp
     154                 :             :  real(dp), parameter :: goldenratio=two-gold
     155                 :             : 
     156                 :             : !Real constants derived from pi
     157                 :             :  real(dp), parameter :: pi=3.141592653589793238462643383279502884197_dp
     158                 :             :  real(dp), parameter :: two_pi=two*pi
     159                 :             :  real(dp), parameter :: four_pi=four*pi
     160                 :             :  real(dp), parameter :: piinv=one/pi
     161                 :             : !The following are not used
     162                 :             : !real(dp), parameter :: rad_to_deg=180._dp/pi
     163                 :             : !real(dp), parameter :: deg_to_rad=one/rad_to_deg
     164                 :             : !real(dp), parameter :: half_pi=pi*half
     165                 :             : !real(dp), parameter :: third_pi=pi*third
     166                 :             : !real(dp), parameter :: quarter_pi=pi*quarter
     167                 :             : !real(dp), parameter :: two_thirds_pi=two_thirds*pi
     168                 :             : 
     169                 :             : !Real precision
     170                 :             :  real(dp), parameter :: greatest_real = huge(one)
     171                 :             :  real(dp), parameter :: smallest_real = -greatest_real
     172                 :             :  real(dp), parameter :: tol1= 0.1_dp
     173                 :             :  real(dp), parameter :: tol2= 0.01_dp
     174                 :             :  real(dp), parameter :: tol3= 0.001_dp
     175                 :             :  real(dp), parameter :: tol4= 0.0001_dp
     176                 :             :  real(dp), parameter :: tol5= 0.00001_dp
     177                 :             :  real(dp), parameter :: tol6= 0.000001_dp
     178                 :             :  real(dp), parameter :: tol7= 0.0000001_dp
     179                 :             :  real(dp), parameter :: tol8= 0.00000001_dp
     180                 :             :  real(dp), parameter :: tol9= 0.000000001_dp
     181                 :             :  real(dp), parameter :: tol10=0.0000000001_dp
     182                 :             :  real(dp), parameter :: tol11=0.00000000001_dp
     183                 :             :  real(dp), parameter :: tol12=0.000000000001_dp
     184                 :             :  real(dp), parameter :: tol13=0.0000000000001_dp
     185                 :             :  real(dp), parameter :: tol14=0.00000000000001_dp
     186                 :             :  real(dp), parameter :: tol15=0.000000000000001_dp
     187                 :             :  real(dp), parameter :: tol16=0.0000000000000001_dp
     188                 :             :  real(dp), parameter :: tol17=0.00000000000000001_dp
     189                 :             :  real(dp), parameter :: tol18=0.000000000000000001_dp
     190                 :             :  real(dp), parameter :: tol19=0.0000000000000000001_dp
     191                 :             :  real(dp), parameter :: tol20=0.00000000000000000001_dp
     192                 :             :  real(dp), parameter :: tol30=1.0e-30_dp
     193                 :             : 
     194                 :             : !real constants derived from sqrt(n.)
     195                 :             :  real(dp), parameter :: sqrt2=1.4142135623730950488016887242096939_dp
     196                 :             :  real(dp), parameter :: half_sqrt2=0.70710678118654752440084436210484697_dp
     197                 :             :  real(dp), parameter :: sqrt3=1.7320508075688772935274463415058739_dp
     198                 :             :  real(dp), parameter :: half_sqrt3=0.86602540378443864676372317075293693_dp
     199                 :             :  real(dp), parameter :: sqrthalf=0.70710678118654752440084436210484697_dp
     200                 :             : 
     201                 :             : !Conversion factors of common use, not directly related to physical quantities.
     202                 :             :  real(dp), parameter :: b2Mb=one/1024.0_dp**2  ! conversion factor bytes --> Mbytes
     203                 :             :  real(dp), parameter :: b2Gb=b2Mb/1024.0_dp    ! conversion factor bytes --> Gbytes
     204                 :             : 
     205                 :             :  ! This value is used as sentinel to initialize real values that are "undefined" i.e.
     206                 :             :  ! values that cannot be computed or values that do not make any sense in a particular context
     207                 :             :  ! e.g. stress tensor in NSCF calculations. The sentinel is used the yaml routines to print "undef" instead of the
     208                 :             :  ! numerical value.
     209                 :             :  real(dp),parameter :: MAGIC_UNDEF = 9.9999999999D+99
     210                 :             : 
     211                 :             :  ! Max Memory in Mb available for a MPI processor
     212                 :             :  ! This quantity might be used at runtime to determine how to distribute memory.
     213                 :             :  ! The default value (2Gb) can be changed at runtime via the command line interface.
     214                 :             :  real(dp), save, protected :: mem_per_cpu_mb = two * 1024_dp
     215                 :             : 
     216                 :             :  ! Number of cpus (cores) per MPI process, e.g. OpenMP threads. Used to obtain the memory available
     217                 :             :  ! per MPI process from mem_per_cpu_mb, see mem_per_rank_mb. Can be changed via the command line interface.
     218                 :             :  integer, save, protected :: cpus_per_task = 1
     219                 :             : 
     220                 :             :  ! Where the value of mem_per_cpu_mb comes from: "default", "command line" or the name of the Slurm variable.
     221                 :             :  character(len=24), save, protected :: mem_source = "default"
     222                 :             : 
     223                 :             : !=========================================================
     224                 :             : !First part of physical constant definitions
     225                 :             : 
     226                 :             : ! Previous values from NIST 2006 from http://physics.nist.gov/cuu/Constants/index.html
     227                 :             : 
     228                 :             : !real(dp), parameter :: Bohr_Ang=0.52917720859_dp    ! 1 Bohr, in Angstrom
     229                 :             : !real(dp), parameter :: Ang_Bohr = one / Bohr_Ang  ! 1 Angstrom in Bohr
     230                 :             : !real(dp), parameter :: Bohr_meter=Bohr_Ang * 1.d-10 ! 1 Bohr in meter
     231                 :             : !real(dp), parameter :: Bohr_cm=Bohr_meter * 100_dp ! 1 Bohr in cm
     232                 :             : !real(dp), parameter :: Ha_cmm1=219474.6313705_dp  ! 1 Hartree in cm^-1
     233                 :             : !real(dp), parameter :: Ha_eV=27.21138386_dp ! 1 Hartree in eV
     234                 :             : !real(dp), parameter :: eV_Ha=one/Ha_eV      ! 1 eV in Hartree
     235                 :             : !real(dp), parameter :: Ha_meV=Ha_eV*1000_dp ! 1 Hartree in meV
     236                 :             : !real(dp), parameter :: Ha_K=315774.65_dp ! 1Hartree in Kelvin
     237                 :             : !real(dp), parameter :: Ha_THz=6579.683920722_dp ! 1 Hartree in THz
     238                 :             : !real(dp), parameter :: Ha_s=Ha_THz*1e12*two_pi ! 1 Hartree in s
     239                 :             : !real(dp), parameter :: Ha_J=4.35974394d-18    !1 Hartree in J
     240                 :             : 
     241                 :             : !real(dp), parameter :: e_Cb=1.602176487d-19 ! minus the electron charge in Coulomb
     242                 :             : !real(dp), parameter :: kb_SI=1.380649d-23  ! Boltzmann constant in Joule/K (CODATA 2017 value.)
     243                 :             : !real(dp), parameter :: Avogadro=6.02214179d23 ! per mole
     244                 :             : !real(dp), parameter :: Speed_Light_SI=2.99792458d8 ! speed of light in SI
     245                 :             : 
     246                 :             : ! 09/2025 [SP] update with 2022 NIST values from the same website.
     247                 :             : !         See also P. J. Mohr et al., Review Mod. Phys. 97, 025002 (2025)
     248                 :             : !
     249                 :             :  real(dp), parameter :: Bohr_Ang     = 0.529177210544_dp      ! 1 Bohr, in Angstrom
     250                 :             :  real(dp), parameter :: Ang_Bohr     = one / Bohr_Ang         ! 1 Angstrom in Bohr
     251                 :             :  real(dp), parameter :: Bohr_meter   = Bohr_Ang * 1.d-10      ! 1 Bohr in meter
     252                 :             :  real(dp), parameter :: Bohr_cm      = Bohr_meter * 100_dp    ! 1 Bohr in cm
     253                 :             :  real(dp), parameter :: Ha_eV        = 27.211386245981_dp     ! 1 Hartree in eV
     254                 :             :  real(dp), parameter :: Ha_cmm1      = 219474.63136314_dp     ! 1 Hartree in cm^-1
     255                 :             :  real(dp), parameter :: eV_Ha        = one / Ha_eV            ! 1 eV in Hartree
     256                 :             :  real(dp), parameter :: Ha_meV       = Ha_eV * 1000_dp        ! 1 Hartree in meV
     257                 :             :  real(dp), parameter :: Ha_K         = 315775.02480398_dp     ! 1 Hartree in Kelvin
     258                 :             :  real(dp), parameter :: Ha_THz       = 6579.6839204999_dp     ! 1 Hartree in THz
     259                 :             :  real(dp), parameter :: Ha_s         = Ha_THz * 1e12 * two_pi ! 1 Hartree in s
     260                 :             :  real(dp), parameter :: Ha_J         = 4.3597447222060d-18    ! 1 Hartree in J
     261                 :             : 
     262                 :             :  ! Since 2019, the following constants have been defined and are now exact [SP].
     263                 :             :  real(dp), parameter :: e_Cb         = 1.602176634d-19        ! minus the electron charge in Coulomb
     264                 :             :  real(dp), parameter :: kb_SI        = 1.380649d-23           ! Boltzmann constant in Joule/K
     265                 :             :  real(dp), parameter :: Avogadro     = 6.02214076d23          ! per mole
     266                 :             :  real(dp), parameter :: Speed_Light_SI     = 299792458_dp           ! Speed of light in vacuum (m/s)
     267                 :             :  ! Note: In SI, c is fixed and the fine structure constant (alpha) is measured.
     268                 :             :  !       In a.u., alpha is fixed and c is measured. Be carefull when using them.
     269                 :             :  !       Here we define c.
     270                 :             : 
     271                 :             : !=========================================================
     272                 :             : !Second part of physical constant definitions
     273                 :             : 
     274                 :             : ! Previous values from NIST 2006 from http://physics.nist.gov/cuu/Constants/index.html
     275                 :             : 
     276                 :             : !real(dp), parameter :: kb_HaK=8.617343d-5/Ha_eV ! Boltzmann constant in Ha/K
     277                 :             : !real(dp), parameter :: kb_THzK=kb_HaK*Ha_THz ! Boltzmann constant in THz/K
     278                 :             : !real(dp), parameter :: amu_emass=1.660538782d-27/9.10938215d-31 ! 1 atomic mass unit in electronic mass
     279                 :             : !real(dp), parameter :: HaBohr3_GPa=Ha_eV/Bohr_Ang**3*e_Cb*1.0d+21 ! 1 Ha/Bohr^3 in GPa
     280                 :             : !real(dp), parameter :: Ohmcm=two*pi*Ha_THz*ninth*ten ! 1 Ohm.cm in atomic units
     281                 :             : !!real(dp), parameter :: eps0=8.854187817d-12 ! permittivity of free space in F/m
     282                 :             : !real(dp), parameter :: eps0=one/(four_pi*0.0000001_dp*299792458.0_dp**2)
     283                 :             : !real(dp), parameter :: AmuBohr2_Cm2=e_Cb*1.0d20/(Bohr_Ang*Bohr_Ang)
     284                 :             : 
     285                 :             : ! 09/2025 [SP] update with 2022 NIST values from the same website.
     286                 :             : !         See also P. J. Mohr et al., Review Mod. Phys. 97, 025002 (2025)
     287                 :             : 
     288                 :             :  real(dp), parameter :: kb_HaK       = kb_SI / Ha_J           ! Boltzmann constant in Ha/K
     289                 :             :  real(dp), parameter :: kb_THzK      = kb_HaK * Ha_THz        ! Boltzmann constant in THz/K
     290                 :             :  real(dp), parameter :: amu_emass    = 1.66053906892d-27 / 9.1093837139d-31         ! 1 atomic mass unit in electronic mass
     291                 :             :  real(dp), parameter :: HaBohr3_GPa  = Ha_eV / Bohr_Ang**3 * e_Cb * 1.0d+21         ! 1 Ha/Bohr^3 in GPa
     292                 :             :  real(dp), parameter :: Ohmcm        = two * pi * Ha_THz * ninth * ten              ! 1 Ohm.cm in atomic units
     293                 :             :  real(dp), parameter :: eps0         = one / (four_pi * 0.0000001_dp * Speed_Light_SI**2) ! permittivity of free space in F/m
     294                 :             :  real(dp), parameter :: AmuBohr2_Cm2 = e_Cb * 1.0d20 / (Bohr_Ang * Bohr_Ang)
     295                 :             : 
     296                 :             : !=========================================================
     297                 :             : !Third part of physical constant definitions
     298                 :             : 
     299                 :             : ! Real physical constants
     300                 :             : ! Previous values from NIST 2006 from http://physics.nist.gov/cuu/Constants/index.html
     301                 :             : 
     302                 :             : !real(dp), parameter :: InvFineStruct=137.035999679_dp  ! Inverse of fine structure constant
     303                 :             : !real(dp), parameter :: FineStructureConstant=0.0072973525664_dp ! 2014 CODATA value
     304                 :             : !real(dp), parameter :: FineStructureConstant2=0.000053251354478_dp ! Square of fine structure constant
     305                 :             : !real(dp), parameter :: Speed_Light=Speed_light_SI/2.1876912633d6 ! speed of light in atomic units
     306                 :             : !real(dp), parameter :: Time_Sec=2.418884326505D-17 !  Atomic unit of time in seconds
     307                 :             : 
     308                 :             : ! 09/2025 [SP] update with 2022 NIST values from the same website.
     309                 :             : !         See also P. J. Mohr et al., Review Mod. Phys. 97, 025002 (2025)
     310                 :             : !
     311                 :             : ! Note: In SI, c is fixed and the fine structure constant (alpha) is measured.
     312                 :             : !       In a.u., alpha is fixed and c is measured. Be carefull when used them.
     313                 :             : !       Here we defined c.
     314                 :             : 
     315                 :             :  real(dp), parameter :: InvFineStruct= 137.035999177_dp                   ! Inverse of fine structure constant
     316                 :             :  real(dp), parameter :: FineStructureConstant  = 0.0072973525643_dp       ! Fine structure constant
     317                 :             :  real(dp), parameter :: FineStructureConstant2 = FineStructureConstant**2 ! Square of fine structure constant
     318                 :             : 
     319                 :             : !Works until now
     320                 :             : 
     321                 :             : !The compiler nvhpc has a problem with this line ?!?
     322                 :             :  real(dp), parameter :: Speed_Light        = InvFineStruct                      ! Speed of light in atomic units
     323                 :             : !So, replace with this line with straight value of Speed_Light
     324                 :             : !real(dp), parameter :: Speed_Light= 137.035999177_dp
     325                 :             : 
     326                 :             : !
     327                 :             :  real(dp), parameter :: Time_Sec     = 2.4188843265864D-17                ! Atomic unit of time in seconds
     328                 :             : 
     329                 :             : !=========================================================
     330                 :             : !Fourth part of physical constant definitions
     331                 :             : 
     332                 :             : ! Real physical constants
     333                 :             : ! Previous values from NIST 2006 from http://physics.nist.gov/cuu/Constants/index.html
     334                 :             : 
     335                 :             : ! real(dp), parameter :: BField_Tesla=4.254383d-6 ! Tesla in a.u.
     336                 :             : ! real(dp), parameter :: dipole_moment_debye=0.393430307_dp ! Debye unit in a.u.
     337                 :             : ! real(dp), parameter :: siemens_SI=e_Cb**2 / Ha_J / Time_Sec ! Siemens in SI: A/V = C^2 / (J * s)
     338                 :             : ! real(dp), parameter :: volt_SI=Ha_J/e_Cb ! Volt in SI: J/C
     339                 :             : !!EB suppress *0.5_dp  ! Atomic unit of induction field (in Tesla) * mu_B (in atomic units).
     340                 :             : ! real(dp), parameter :: mu_B_SI=9.274009994D-24   ! Bohr magneton in SI
     341                 :             : ! real(dp), parameter :: mu_B = 0.5_dp             ! Bohr magneton in atomic units
     342                 :             : 
     343                 :             : ! 09/2025 [SP] update with 2022 NIST values from the same website.
     344                 :             : !         See also P. J. Mohr et al., Review Mod. Phys. 97, 025002 (2025)
     345                 :             : !
     346                 :             : ! Note: In SI, c is fixed and the fine structure constant (alpha) is measured.
     347                 :             : !       In a.u., alpha is fixed and c is measured. Be carefull when used them. Here we defined c.
     348                 :             : 
     349                 :             :  real(dp), parameter :: mu_B_SI      = 9.2740100657D-24                   ! Bohr magneton in SI
     350                 :             :  real(dp), parameter :: mu_0_SI      = 1.25663706127d-6  ! Vacuum permeability in atomic units
     351                 :             :  real(dp), parameter :: mu_B         = 0.5_dp                             ! Bohr magneton in atomic units
     352                 :             :  real(dp), parameter :: BField_Tesla = mu_B_SI / (Ha_J * mu_B)            ! Tesla in a.u.
     353                 :             :  real(dp), parameter :: dipole_moment_debye = 0.393430307_dp              ! Debye unit in a.u.
     354                 :             :  real(dp), parameter :: siemens_SI   = e_Cb**2 / Ha_J / Time_Sec          ! Siemens in SI: A/V = C^2 / (J * s)
     355                 :             :  real(dp), parameter :: volt_SI      = Ha_J / e_Cb                        ! Volt in SI: J/C
     356                 :             :  real(dp), parameter :: EFG_SI       = volt_SI / Bohr_meter**2            ! E-field gradient in SI : Volt/m^2
     357                 :             : 
     358                 :             : !End of physical constants
     359                 :             : !=========================================================
     360                 :             : 
     361                 :             : !Complex constants
     362                 :             :  !double precision
     363                 :             :  complex(dp), parameter :: czero = (0._dp,0._dp)
     364                 :             :  complex(dp), parameter :: cone  = (1._dp,0._dp)
     365                 :             :  complex(dp), parameter :: ctwo  = (2._dp,0._dp)
     366                 :             :  complex(dp), parameter :: j_dpc = (0._dp,1.0_dp)
     367                 :             : 
     368                 :             :  ! single-precision
     369                 :             :  complex(sp), parameter :: czero_sp = (0._sp,0._sp)
     370                 :             :  complex(sp), parameter :: cone_sp  = (1._sp,0._sp)
     371                 :             :  complex(sp), parameter :: ctwo_sp  = (2._sp,0._sp)
     372                 :             :  complex(sp), parameter :: j_sp     = (0._sp,1.0_sp)
     373                 :             : 
     374                 :             : !Pauli matrix
     375                 :             :  complex(dp), parameter :: pauli_mat(2,2,0:3) = reshape([cone,czero,czero,cone, &
     376                 :             :                                                          czero,cone,cone,czero,&
     377                 :             :                                                          czero,j_dpc,-j_dpc,czero,&
     378                 :             :                                                          cone,czero,czero,-cone], [2,2,4])
     379                 :             : 
     380                 :             : !Character constants
     381                 :             :  character(len=1), parameter :: ch10 = char(10)
     382                 :             :  character(len=fnlen),parameter :: ABI_NOFILE="__None__"
     383                 :             : 
     384                 :             :  ! File used to dump the error message in m_error.
     385                 :             :  ! Extremely useful when we run on many CPUs since logging, in this case, is automatically disabled
     386                 :             :  ! As a consequence, we get error messages in the main log only if the problem is encountered by the master node!
     387                 :             :  ! Note that the file is removed in xmpi_init (if present).
     388                 :             :  character(len=fnlen),parameter :: ABI_MPIABORTFILE="__ABI_MPIABORTFILE__"
     389                 :             : 
     390                 :             :  ! Error codes used by the bindings.
     391                 :             :  integer, parameter, public :: AB7_NO_ERROR                 =  0
     392                 :             :  integer, parameter, public :: AB7_ERROR_OBJ                =  1
     393                 :             :  integer, parameter, public :: AB7_ERROR_ARG                =  2
     394                 :             :  integer, parameter, public :: AB7_ERROR_INVARS_ATT         =  3
     395                 :             :  integer, parameter, public :: AB7_ERROR_INVARS_ID          =  4
     396                 :             :  integer, parameter, public :: AB7_ERROR_INVARS_SIZE        =  5
     397                 :             :  integer, parameter, public :: AB7_ERROR_SYM_NOT_PRIMITIVE  =  6
     398                 :             :  integer, parameter, public :: AB7_ERROR_SYM_BRAVAIS_XRED   =  7
     399                 :             :  integer, parameter, public :: AB7_ERROR_MIXING_ARG         =  8
     400                 :             :  integer, parameter, public :: AB7_ERROR_MIXING_CONVERGENCE =  9
     401                 :             :  integer, parameter, public :: AB7_ERROR_MIXING_INTERNAL    = 10
     402                 :             :  integer, parameter, public :: AB7_ERROR_MIXING_INC_NNSLOOP = 11
     403                 :             : 
     404                 :             : ! Values of optdriver corresponding to the different run-levels.
     405                 :             :  integer, parameter, public :: RUNL_GSTATE     = 0
     406                 :             :  integer, parameter, public :: RUNL_RESPFN     = 1
     407                 :             :  integer, parameter, public :: RUNL_SCREENING  = 3
     408                 :             :  integer, parameter, public :: RUNL_SIGMA      = 4
     409                 :             :  integer, parameter, public :: RUNL_NONLINEAR  = 5
     410                 :             :  integer, parameter, public :: RUNL_GWR        = 6
     411                 :             :  integer, parameter, public :: RUNL_EPH        = 7
     412                 :             :  integer, parameter, public :: RUNL_WFK        = 8
     413                 :             :  integer, parameter, public :: RUNL_RTTDDFT    = 9
     414                 :             :  integer, parameter, public :: RUNL_GWLS       = 66
     415                 :             :  integer, parameter, public :: RUNL_BSE        = 99
     416                 :             :  integer, parameter, public :: RUNL_LONGWAVE   = 10
     417                 :             : 
     418                 :             :  ! Integer flags defining the task to be performed in wfk_analyze
     419                 :             :  integer,public,parameter :: WFK_TASK_NONE      = 0
     420                 :             :  integer,public,parameter :: WFK_TASK_FULLBZ    = 1
     421                 :             :  integer,public,parameter :: WFK_TASK_CLASSIFY  = 2
     422                 :             :  integer,public,parameter :: WFK_TASK_PAW_AEPSI = 3
     423                 :             :  integer,public,parameter :: WFK_TASK_EINTERP   = 4
     424                 :             :  integer,public,parameter :: WFK_TASK_DDK       = 5
     425                 :             :  integer,public,parameter :: WFK_TASK_DDK_DIAGO = 6
     426                 :             :  integer,public,parameter :: WFK_TASK_OPTICS_FULLBZ = 7
     427                 :             :  integer,public,parameter :: WFK_TASK_KPTS_ERANGE= 8
     428                 :             :  integer,public,parameter :: WFK_TASK_CHECK_SYMTAB = 9
     429                 :             :  integer,public,parameter :: WFK_TASK_WANNIER = 10
     430                 :             :  integer,public,parameter :: WFK_TASK_PSEUDOBANDS = 11
     431                 :             : 
     432                 :             : ! Flags defining the method used for performing IO (input variable iomode)
     433                 :             :  integer, parameter, public :: IO_MODE_FORTRAN_MASTER = -1
     434                 :             :  integer, parameter, public :: IO_MODE_FORTRAN        =  0
     435                 :             :  integer, parameter, public :: IO_MODE_MPI            =  1
     436                 :             :  integer, parameter, public :: IO_MODE_NETCDF         =  2 ! Only for legacy code, should not be used for new implementations.
     437                 :             :  integer, parameter, public :: IO_MODE_ETSF           =  3
     438                 :             : 
     439                 :             : ! FFT libraries (correspond to fftalga = ngfft(7)/100)
     440                 :             :  integer,parameter,public :: FFT_SG     = 1
     441                 :             :  integer,parameter,public :: FFT_FFTW3  = 3
     442                 :             :  integer,parameter,public :: FFT_SG2002 = 4
     443                 :             :  integer,parameter,public :: FFT_DFTI   = 5
     444                 :             : 
     445                 :             : ! Parameters for non-local algorithm (were previously stored in nloalg(3) and nloalg(4)
     446                 :             :   integer,parameter,public :: NLO_MBLKPW = 199
     447                 :             :   integer,parameter,public :: NLO_MINCAT = 10
     448                 :             : 
     449                 :             : ! This is used to compute the maximum index of the perturbation as 2*natom + MPERT_MAX
     450                 :             : ! GA: But this is not actually the maximum perturbation, see m_dfpt_loopert
     451                 :             :   integer,parameter,public :: MPERT_MAX = 11
     452                 :             : 
     453                 :             : ! Parameters for the GPU implementation(s)
     454                 :             :  ! GPU implementation undetermined
     455                 :             :  integer,parameter,public :: ABI_GPU_UNKNOWN  =-1
     456                 :             :  ! Not using any GPU implementation, implies running on CPU
     457                 :             :  integer,parameter,public :: ABI_GPU_DISABLED = 0
     458                 :             :  ! Legacy GPU implementation relying on NVIDIA CUDA kernels, not preferred
     459                 :             :  integer,parameter,public :: ABI_GPU_LEGACY   = 1
     460                 :             :  ! GPU implementation relying on OpenMP v5 "TARGET" construct
     461                 :             :  integer,parameter,public :: ABI_GPU_OPENMP   = 2
     462                 :             :  ! GPU implementation relying on Kokkos + cuda framework
     463                 :             :  integer,parameter,public :: ABI_GPU_KOKKOS   = 3
     464                 :             :  ! Please note that a GPU linalg library supported in gpu_toolbox (ie: CUDA) backs up OpenMP and Kokkos variants.
     465                 :             : 
     466                 :             : !Parameters for LOG/STATUS files treatment
     467                 :             : !This variables tell the code if some lines have to be written in a LOG/STATUS file
     468                 :             :  logical, public, save :: do_write_log   =.true.
     469                 :             :  logical, public, save :: do_write_status=.true.
     470                 :             : ! Max. numbers of CPU core for the writing of LOG/STATUS file for each CPU
     471                 :             : ! (if more than NPROC_NO_EXTRA_LOG cpu core are used, no *_LOG_Pxxx is written;
     472                 :             : !  the same for the *_STATUS_Pxxx file)
     473                 :             :  integer, parameter, public :: NPROC_NO_EXTRA_LOG    = 2  !@WC
     474                 :             :  integer, parameter, public :: NPROC_NO_EXTRA_STATUS = 2  !@WC
     475                 :             : !Name of the file that (if present in current directory)
     476                 :             : !will avoid creation of LOG/STATUS files
     477                 :             :  character(len=fnlen),parameter :: ABI_NO_LOG_FILE="_NOLOG"
     478                 :             : !Name of the file that (if present in current directory)
     479                 :             : !will enforce creation of LOG/STATUS files
     480                 :             :  character(len=fnlen),parameter :: ABI_ENFORCE_LOG_FILE="_LOG"
     481                 :             : !Name of the file that (if present in current directory)
     482                 :             : !will enforce creation of LOG file only for master proc
     483                 :             :  character(len=fnlen),parameter :: ABI_MAIN_LOG_FILE="_MAINLOG"
     484                 :             : 
     485                 :             : ! Arrays
     486                 :             :  integer,parameter :: identity_3d(3,3) = reshape([1,0,0,0,1,0,0,0,1], [3,3])
     487                 :             :  integer,parameter :: inversion_3d(3,3) = reshape([-1,0,0,0,-1,0,0,0,-1], [3,3])
     488                 :             : 
     489                 :             : !A collection of small datatypes for ragged arrays
     490                 :             : !A small datatype for ragged integer 1D-arrays
     491                 :             :  type coeffi1_type
     492                 :             :   integer :: size
     493                 :             :   integer, allocatable :: value(:)
     494                 :             :  end type coeffi1_type
     495                 :             : !A small datatype for ragged integer 2D-arrays
     496                 :             :  type coeffi2_type
     497                 :             :   integer :: size
     498                 :             :   integer, allocatable :: value(:,:)
     499                 :             :  end type coeffi2_type
     500                 :             : !A small datatype for ragged integer 3D-arrays
     501                 :             :  type coeffi3_type
     502                 :             :   integer :: size
     503                 :             :   integer, allocatable :: value(:,:,:)
     504                 :             :  end type coeffi3_type
     505                 :             : !A small datatype for ragged integer 4D-arrays
     506                 :             :  type coeffi4_type
     507                 :             :   integer :: size
     508                 :             :   integer, allocatable :: value(:,:,:,:)
     509                 :             :  end type coeffi4_type
     510                 :             : !A small datatype for ragged integer 5D-arrays
     511                 :             :  type coeffi5_type
     512                 :             :   integer :: size
     513                 :             :   integer, allocatable :: value(:,:,:,:,:)
     514                 :             :  end type coeffi5_type
     515                 :             : !A small datatype for ragged complex 1D-arrays
     516                 :             :  type coeff1c_type
     517                 :             :   complex(dp), allocatable :: value(:)
     518                 :             :  end type coeff1c_type
     519                 :             : !A small datatype for ragged complex 2D-arrays
     520                 :             :  type coeff2c_type
     521                 :             :   complex(dp), allocatable :: value(:,:)
     522                 :             :  end type coeff2c_type
     523                 :             : !A small datatype for ragged complex 3D-arrays
     524                 :             :  type coeff3c_type
     525                 :             :   complex(dp), allocatable :: value(:,:,:)
     526                 :             :  end type coeff3c_type
     527                 :             : !A small datatype for ragged complex 4D-arrays
     528                 :             :  type coeff4c_type
     529                 :             :   complex(dp), allocatable :: value(:,:,:,:)
     530                 :             :  end type coeff4c_type
     531                 :             : !A small datatype for ragged complex 5D-arrays
     532                 :             :  type coeff5c_type
     533                 :             :   complex(dp), allocatable :: value(:,:,:,:,:)
     534                 :             :  end type coeff5c_type
     535                 :             : !A small datatype for ragged real 1D-arrays
     536                 :             :  type coeff1_type
     537                 :             :   real(dp), allocatable :: value(:)
     538                 :             :  end type coeff1_type
     539                 :             : !A small datatype for ragged real 2D-arrays
     540                 :             :  type coeff2_type
     541                 :             :   real(dp), allocatable :: value(:,:)
     542                 :             :  end type coeff2_type
     543                 :             : !A small datatype for ragged real 3D-arrays
     544                 :             :  type coeff3_type
     545                 :             :   real(dp), allocatable :: value(:,:,:)
     546                 :             :  end type coeff3_type
     547                 :             : !A small datatype for ragged real 4D-arrays
     548                 :             :  type coeff4_type
     549                 :             :   real(dp), allocatable :: value(:,:,:,:)
     550                 :             :  end type coeff4_type
     551                 :             : !A small datatype for ragged real 5D-arrays
     552                 :             :  type coeff5_type
     553                 :             :   real(dp), allocatable :: value(:,:,:,:,:)
     554                 :             :  end type coeff5_type
     555                 :             : !A small datatype for ragged real 6D-arrays
     556                 :             :  type coeff6_type
     557                 :             :   real(dp), allocatable :: value(:,:,:,:,:,:)
     558                 :             :  end type coeff6_type
     559                 :             : !A small datatype for ragged real 7D-arrays.
     560                 :             :  type coeff7_type
     561                 :             :   real(dp), allocatable :: value(:,:,:,:,:,:,:)
     562                 :             :  end type coeff7_type
     563                 :             : 
     564                 :             : CONTAINS  !==============================================================================
     565                 :             : !!***
     566                 :             : 
     567                 :             : !!****f* defs_basis/abi_log_status_state
     568                 :             : !! NAME
     569                 :             : !!  abi_log_status_state
     570                 :             : !!
     571                 :             : !! FUNCTION
     572                 :             : !!  Change values of do_write_log and do_write_status flags.
     573                 :             : !!  These flags tell the code to write (or not) a LOG/STATUS file.
     574                 :             : !!
     575                 :             : !! INPUTS
     576                 :             : !!  new_do_write_log=new value for do_write_log
     577                 :             : !!  new_do_write_status=new value for do_write_status
     578                 :             : !!
     579                 :             : !! SOURCE
     580                 :             : 
     581                 :         562 : subroutine abi_log_status_state(new_do_write_log,new_do_write_status)
     582                 :             : 
     583                 :             : !Arguments ------------------------------------
     584                 :             :  logical,optional,intent(in) :: new_do_write_log,new_do_write_status
     585                 :             : !************************************************************************
     586                 :             : 
     587         [ +  + ]:         562 :  if (PRESENT(new_do_write_log))    do_write_log   =new_do_write_log
     588         [ +  + ]:         562 :  if (PRESENT(new_do_write_status)) do_write_status=new_do_write_status
     589                 :             : 
     590                 :         562 : end subroutine abi_log_status_state
     591                 :             : !!***
     592                 :             : 
     593                 :             : !----------------------------------------------------------------------
     594                 :             : 
     595                 :             : !!****f* defs_basis/abi_io_redirect
     596                 :             : !! NAME
     597                 :             : !!  abi_io_redirect
     598                 :             : !!
     599                 :             : !! FUNCTION
     600                 :             : !!  Redirect unit numbers (and|or) change the MPI communicator for the IO (output and log file).
     601                 :             : !!  This routine can be used in client code (e.g. bigdft)
     602                 :             : !!  that wants to call the abinit routines packed in an external library.
     603                 :             : !!
     604                 :             : !! INPUTS
     605                 :             : !!  new_ab_out=new value for output file unit
     606                 :             : !!  new_std_out=new value for standard output unit
     607                 :             : !!  new_io_comm=new value for IO MPI communicator
     608                 :             : !!
     609                 :             : !! SOURCE
     610                 :             : 
     611                 :       25089 : subroutine abi_io_redirect(new_ab_out,new_std_out,new_io_comm)
     612                 :             : 
     613                 :             : !Arguments ------------------------------------
     614                 :             :  integer,optional,intent(in) :: new_std_out,new_ab_out,new_io_comm
     615                 :             : !************************************************************************
     616                 :             : 
     617         [ +  + ]:       25089 :  if (PRESENT(new_ab_out))  ab_out  = new_ab_out
     618         [ +  + ]:       25089 :  if (PRESENT(new_std_out)) std_out = new_std_out
     619         [ +  + ]:       25089 :  if (PRESENT(new_io_comm)) abinit_comm_output = new_io_comm
     620                 :             : 
     621                 :       25089 : end subroutine abi_io_redirect
     622                 :             : !!***
     623                 :             : 
     624                 :             : !----------------------------------------------------------------------
     625                 :             : 
     626                 :             : !!****f* defs_basis/print_kinds
     627                 :             : !! NAME
     628                 :             : !! print_kinds
     629                 :             : !!
     630                 :             : !! FUNCTION
     631                 :             : !! Prints info on the basic data types, e.g. kind, precision...
     632                 :             : !!
     633                 :             : !! INPUTS
     634                 :             : !!   unit = Unit number for output file.
     635                 :             : !!
     636                 :             : !! SOURCE
     637                 :             : 
     638                 :        1160 : subroutine print_kinds(unit)
     639                 :             : 
     640                 :             : !Arguments-------------------------------------
     641                 :             :  integer,optional,intent(in) :: unit
     642                 :             : 
     643                 :             : !Local variables-------------------------------
     644                 :             :  integer :: my_unt
     645                 :             : ! *********************************************************************
     646                 :             : 
     647         [ +  - ]:        1160 :  my_unt=std_out; if (PRESENT(unit)) my_unt = unit
     648                 :             : 
     649                 :        1160 :  write(my_unt,'(a)')' DATA TYPE INFORMATION: '
     650                 :             : 
     651                 :             :  write(my_unt,'(a,/,2(a,i6,/),2(a,e16.8e3,/),a,e16.8e3)')&
     652                 :        1160 :    ' REAL:      Data type name: REAL(DP) ',&
     653                 :        1160 :    '            Kind value: ',KIND(0.0_dp),&
     654                 :        1160 :    '            Precision:  ',PRECISION(0.0_dp),&
     655                 :        1160 :    '            Smallest nonnegligible quantity relative to 1: ',EPSILON(0.0_dp),&
     656                 :        1160 :    '            Smallest positive number:                      ',TINY(0.0_dp),&
     657                 :        2320 :    '            Largest representable number:                  ',HUGE(0.0_dp)
     658                 :             : 
     659                 :             :  write(my_unt,'(a,/,2(a,i0,/),a,i0)')&
     660                 :        1160 :    ' INTEGER:   Data type name: INTEGER(default) ', &
     661                 :        1160 :    '            Kind value: ',KIND(0),              &
     662                 :        1160 :    '            Bit size:   ',BIT_SIZE(0),          &
     663                 :        2320 :    '            Largest representable number: ',HUGE(0)
     664                 :             : 
     665                 :             :  write(my_unt,'(a,/,a,i0)')&
     666                 :        1160 :    ' LOGICAL:   Data type name: LOGICAL ',&
     667                 :        2320 :    '            Kind value: ',KIND(.TRUE.)
     668                 :             : 
     669                 :             :  write(my_unt,'(2a,i0)')&
     670                 :        1160 :   ' CHARACTER: Data type name: CHARACTER ',&
     671                 :        2320 :   '            Kind value: ',KIND('C')
     672                 :             : 
     673                 :        1160 : end subroutine print_kinds
     674                 :             : !!***
     675                 :             : 
     676                 :             : !!****f* defs_basis/str2wfktask
     677                 :             : !! NAME
     678                 :             : !!  str2wfktask
     679                 :             : !!
     680                 :             : !! FUNCTION
     681                 :             : !!  Convert a string into one of the integer flags WFK_TASK_*
     682                 :             : !!  Return WFK_TASK_NONE if string is invalid.
     683                 :             : !!
     684                 :             : !! SOURCE
     685                 :             : 
     686                 :          16 : integer pure function str2wfktask(str) result(wfk_task)
     687                 :             : 
     688                 :             : !Arguments ------------------------------------
     689                 :             :  character(len=*),intent(in) :: str
     690                 :             : !************************************************************************
     691                 :             : 
     692                 :             :  select case (str)
     693                 :             :  case ("wfk_fullbz")
     694                 :             :    wfk_task = WFK_TASK_FULLBZ
     695                 :             :  case ("classify")
     696                 :             :    wfk_task = WFK_TASK_CLASSIFY
     697                 :             :  case ("paw_aepsi")
     698                 :             :    wfk_task = WFK_TASK_PAW_AEPSI
     699                 :             :  case ("wfk_einterp")
     700                 :             :    wfk_task = WFK_TASK_EINTERP
     701                 :             :  case ("wfk_ddk")
     702                 :             :    wfk_task = WFK_TASK_DDK
     703                 :             :  case ("wfk_ddk_diago")
     704                 :             :    wfk_task = WFK_TASK_DDK_DIAGO
     705                 :             :  case ("wfk_kpts_erange")
     706                 :             :    wfk_task = WFK_TASK_KPTS_ERANGE
     707                 :             :  case ("optics_fullbz", "wfk_optics_fullbz")
     708                 :             :    wfk_task = WFK_TASK_OPTICS_FULLBZ
     709                 :             :  case ("check_symtab")
     710                 :             :    wfk_task = WFK_TASK_CHECK_SYMTAB
     711                 :             :  case ("wannier")
     712                 :             :    wfk_task = WFK_TASK_WANNIER
     713                 :             :  case ("pseudobands")
     714                 :             :    wfk_task = WFK_TASK_PSEUDOBANDS
     715                 :             :  case default
     716         [ +  - ]:          16 :    wfk_task = WFK_TASK_NONE
     717                 :             :  end select
     718                 :             : 
     719                 :          16 : end function str2wfktask
     720                 :             : !!***
     721                 :             : 
     722                 :             : !----------------------------------------------------------------------
     723                 :             : 
     724                 :             : !!****f* defs_basis/set_mem_per_cpu_mb
     725                 :             : !! NAME
     726                 :             : !! set_mem_per_cpu_mb
     727                 :             : !!
     728                 :             : !! FUNCTION
     729                 :             : !!  Set the value of global variable `mem_per_cpu_mb`
     730                 :             : !!
     731                 :             : !! INPUTS
     732                 :             : !!  mem_mb: memory per cpu in Mb.
     733                 :             : !!  [source]: where the value comes from (stored in `mem_source`). Default: "command line".
     734                 :             : !!
     735                 :             : !! SOURCE
     736                 :             : 
     737                 :           0 : subroutine set_mem_per_cpu_mb(mem_mb, source)
     738                 :             : 
     739                 :             : !Arguments-------------------------------------
     740                 :             :  real(dp),intent(in) :: mem_mb
     741                 :             :  character(len=*),optional,intent(in) :: source
     742                 :             : ! *********************************************************************
     743                 :             : 
     744                 :             :  !print *, "Setting mem_per_cpu_mb to", mem_mb
     745                 :           0 :  mem_per_cpu_mb = mem_mb
     746         [ #  # ]:           0 :  mem_source = "command line"; if (present(source)) mem_source = source
     747                 :             : 
     748         [ #  # ]:           0 : end subroutine set_mem_per_cpu_mb
     749                 :             : !!***
     750                 :             : 
     751                 :             : !----------------------------------------------------------------------
     752                 :             : 
     753                 :             : !!****f* defs_basis/set_cpus_per_task
     754                 :             : !! NAME
     755                 :             : !! set_cpus_per_task
     756                 :             : !!
     757                 :             : !! FUNCTION
     758                 :             : !!  Set the value of global variable `cpus_per_task` (values < 1 are ignored).
     759                 :             : !!
     760                 :             : !! SOURCE
     761                 :             : 
     762                 :           0 : subroutine set_cpus_per_task(ncpus)
     763                 :             : 
     764                 :             : !Arguments-------------------------------------
     765                 :             :  integer,intent(in) :: ncpus
     766                 :             : ! *********************************************************************
     767                 :             : 
     768         [ #  # ]:           0 :  if (ncpus >= 1) cpus_per_task = ncpus
     769                 :             : 
     770                 :           0 : end subroutine set_cpus_per_task
     771                 :             : !!***
     772                 :             : 
     773                 :             : !----------------------------------------------------------------------
     774                 :             : 
     775                 :             : !!****f* defs_basis/mem_per_rank_mb
     776                 :             : !! NAME
     777                 :             : !! mem_per_rank_mb
     778                 :             : !!
     779                 :             : !! FUNCTION
     780                 :             : !!  Memory in Mb available for one MPI process: mem_per_cpu_mb times the number of cpus of the process
     781                 :             : !!  (with Slurm, the memory per cpu is given to each cpu of the task).
     782                 :             : !!
     783                 :             : !! SOURCE
     784                 :             : 
     785                 :       36863 : real(dp) pure function mem_per_rank_mb()
     786                 :             : 
     787                 :       36863 :  mem_per_rank_mb = mem_per_cpu_mb * cpus_per_task
     788                 :             : 
     789                 :       36863 : end function mem_per_rank_mb
     790                 :             : !!***
     791                 :             : 
     792                 :             : !----------------------------------------------------------------------
     793                 :             : 
     794   [ #  #  #  #  :           0 : end module defs_basis
          #  #  #  #  #  
                #  #  # ]
     795                 :             : !!***
        

Generated by: LCOV version 2.3-1