LCOV - code coverage report
Current view: top level - src/xc - xc_gauxc_cache.F (source / functions) Coverage Total Hit
Test: CP2K Regtests (git:1be8651) Lines: 72.2 % 176 127
Test Date: 2026-11-24 01:22:08 Functions: 42.9 % 14 6

            Line data    Source code
       1              : !--------------------------------------------------------------------------------------------------!
       2              : !   CP2K: A general program to perform molecular dynamics simulations                              !
       3              : !   Copyright 2000-2026 CP2K developers group <https://cp2k.org>                                   !
       4              : !                                                                                                  !
       5              : !   SPDX-License-Identifier: GPL-2.0-or-later                                                      !
       6              : !--------------------------------------------------------------------------------------------------!
       7              : 
       8              : #ifdef __GAUXC
       9              : #include "gauxc/gauxc_config.f"
      10              : #endif
      11              : 
      12              : MODULE xc_gauxc_cache
      13              : 
      14              :    USE cp_log_handling,                 ONLY: cp_logger_get_default_io_unit
      15              :    USE iso_c_binding,                   ONLY: c_double
      16              :    USE kinds,                           ONLY: default_path_length,&
      17              :                                               default_string_length
      18              :    USE message_passing,                 ONLY: mp_comm_self,&
      19              :                                               mp_para_env_type
      20              :    USE particle_types,                  ONLY: particle_type
      21              :    USE qs_kind_types,                   ONLY: qs_kind_type
      22              :    USE xc_gauxc_gradient_policy,        ONLY: gauxc_resolve_gradient_policy
      23              :    USE xc_gauxc_interface,              ONLY: &
      24              :         cp_gauxc_basisset_type, cp_gauxc_grid_type, cp_gauxc_integrator_type, &
      25              :         cp_gauxc_molecule_type, cp_gauxc_status_type, gauxc_check_status, gauxc_create_basisset, &
      26              :         gauxc_create_grid, gauxc_create_integrator, gauxc_create_molecule, gauxc_destroy_basisset, &
      27              :         gauxc_destroy_grid, gauxc_destroy_integrator, gauxc_destroy_molecule
      28              : #include "../base/base_uses.f90"
      29              : 
      30              :    IMPLICIT NONE
      31              :    PRIVATE
      32              : 
      33              :    TYPE cp_gauxc_cache_params
      34              :       INTEGER                                      :: natom = -1
      35              :       INTEGER                                      :: nspins = -1
      36              :       INTEGER                                      :: batch_size = -1
      37              :       REAL(c_double)                               :: device_runtime_fill_fraction = 0.0_c_double
      38              :       CHARACTER(LEN=default_string_length)         :: xc_fun_name = ""
      39              :       CHARACTER(LEN=default_string_length)         :: grid_type = ""
      40              :       CHARACTER(LEN=default_string_length)         :: radial_quadrature = ""
      41              :       CHARACTER(LEN=default_string_length)         :: pruning_scheme = ""
      42              :       CHARACTER(LEN=default_string_length)         :: lb_exec_space = ""
      43              :       CHARACTER(LEN=default_string_length)         :: int_exec_space = ""
      44              :       CHARACTER(LEN=default_path_length)           :: model_eval_name = ""
      45              :       CHARACTER(len=default_string_length)         :: lwd_kernel = ""
      46              :       CHARACTER(len=default_string_length)         :: gradient_runtime = "AUTO"
      47              :       LOGICAL                                      :: need_xc_gradient = .FALSE.
      48              :       LOGICAL                                      :: gapw_method = .FALSE.
      49              :       LOGICAL                                      :: force_fd_gradient = .FALSE.
      50              :       LOGICAL                                      :: use_gradient_mpi_runtime = .FALSE.
      51              :       LOGICAL                                      :: use_self_runtime = .FALSE.
      52              :       LOGICAL                                      :: use_gradient_self_runtime = .FALSE.
      53              :       LOGICAL                                      :: use_fd_gradient = .FALSE.
      54              :       LOGICAL                                      :: use_gauxc_model = .FALSE.
      55              :    END TYPE cp_gauxc_cache_params
      56              : 
      57              :    TYPE, extends(cp_gauxc_cache_params)            :: cp_gauxc_cache_type
      58              :       TYPE(cp_gauxc_molecule_type)                 :: molecule = cp_gauxc_molecule_type()
      59              :       TYPE(cp_gauxc_basisset_type)                 :: basisset = cp_gauxc_basisset_type()
      60              :       TYPE(cp_gauxc_grid_type)                     :: grid = cp_gauxc_grid_type()
      61              :       TYPE(cp_gauxc_grid_type)                     :: gradient_grid = cp_gauxc_grid_type()
      62              :       TYPE(cp_gauxc_integrator_type)               :: integrator = cp_gauxc_integrator_type()
      63              :       TYPE(cp_gauxc_integrator_type)               :: gradient_integrator = cp_gauxc_integrator_type()
      64              :       INTEGER                                      :: mpi_comm = -1
      65              :       LOGICAL                                      :: is_init = .FALSE.
      66              :       LOGICAL                                      :: gradient_is_init = .FALSE.
      67              :       LOGICAL                                      :: gradient_notice_printed = .FALSE.
      68              :       REAL(c_double), DIMENSION(:, :), ALLOCATABLE :: last_positions
      69              :    CONTAINS
      70              : 
      71              :       PROCEDURE, PUBLIC                            :: has_gradient_grid => gauxc_cache_type_has_gradient_grid
      72              :       PROCEDURE, PUBLIC                            :: max_l => gauxc_cache_type_max_l
      73              :    END TYPE cp_gauxc_cache_type
      74              : 
      75              :    PUBLIC :: &
      76              :       cp_gauxc_cache_type, &
      77              :       gauxc_cache_init, &
      78              :       gauxc_cache_is_valid, &
      79              :       gauxc_cache_ensure_gradient, &
      80              :       gauxc_cache_release, cp_gauxc_cache_params
      81              : 
      82              :    LOGICAL, SAVE :: execution_spaces_logged = .FALSE.
      83              : 
      84              : CONTAINS
      85              : 
      86              : ! **************************************************************************************************
      87              : !> \brief ...
      88              : !> \param this ...
      89              : !> \return ...
      90              : ! **************************************************************************************************
      91           74 :    FUNCTION gauxc_cache_type_has_gradient_grid(this) RESULT(res)
      92              :       class(cp_gauxc_cache_type) :: this
      93              :       LOGICAL :: res
      94              : 
      95           74 :       res = this%gradient_is_init
      96           74 :    END FUNCTION gauxc_cache_type_has_gradient_grid
      97              : 
      98              : ! **************************************************************************************************
      99              : !> \brief ...
     100              : !> \param this ...
     101              : !> \return ...
     102              : ! **************************************************************************************************
     103           74 :    FUNCTION gauxc_cache_type_max_l(this) RESULT(res)
     104              :       class(cp_gauxc_cache_type) :: this
     105              :       INTEGER :: res
     106              : 
     107           74 :       res = this%basisset%max_l
     108           74 :    END FUNCTION gauxc_cache_type_max_l
     109              : 
     110              : ! **************************************************************************************************
     111              : !> \brief ...
     112              : !> \param cache ...
     113              : !> \param params ...
     114              : !> \param para_env ...
     115              : !> \param particle_set ...
     116              : !> \param qs_kind_set ...
     117              : !> \param status ...
     118              : ! **************************************************************************************************
     119          670 :    SUBROUTINE gauxc_cache_init( &
     120              :       cache, &
     121              :       params, &
     122              :       para_env, &
     123              :       particle_set, &
     124              :       qs_kind_set, &
     125              :       status)
     126              : 
     127              :       TYPE(cp_gauxc_cache_type), INTENT(inout)           :: cache
     128              :       TYPE(cp_gauxc_cache_params), INTENT(inout)         :: params
     129              :       TYPE(mp_para_env_type), INTENT(in), POINTER        :: para_env
     130              :       TYPE(particle_type), DIMENSION(:), INTENT(in), &
     131              :          POINTER                                         :: particle_set
     132              :       TYPE(qs_kind_type), DIMENSION(:), INTENT(in), &
     133              :          POINTER                                         :: qs_kind_set
     134              :       TYPE(cp_gauxc_status_type), INTENT(inout)          :: status
     135              : 
     136              : #ifdef __GAUXC
     137              :       INTEGER                                            :: gradient_error, unit_nr
     138              : 
     139          670 :       IF (gauxc_cache_is_valid( &
     140              :           cache, &
     141              :           params, &
     142              :           para_env, &
     143              :           particle_set)) THEN
     144          596 :          params%use_fd_gradient = cache%use_fd_gradient
     145          596 :          params%use_gradient_mpi_runtime = cache%use_gradient_mpi_runtime
     146          596 :          params%use_gradient_self_runtime = cache%use_gradient_self_runtime
     147          596 :          status%status%code = 0
     148          596 :          RETURN
     149              :       END IF
     150              : 
     151           74 :       CALL gauxc_cache_release(cache)
     152              : 
     153              :       cache%molecule = gauxc_create_molecule( &
     154              :                        particle_set, &
     155           74 :                        status)
     156           74 :       IF (status%status%code /= 0) THEN
     157            0 :          CALL cleanup_after_molecule()
     158            0 :          RETURN
     159              :       END IF
     160              : 
     161              :       cache%basisset = gauxc_create_basisset( &
     162              :                        qs_kind_set, &
     163              :                        particle_set, &
     164           74 :                        status)
     165           74 :       IF (status%status%code /= 0) THEN
     166            0 :          CALL cleanup_after_basisset()
     167            0 :          RETURN
     168              :       END IF
     169              : 
     170              :       CALL gauxc_resolve_gradient_policy( &
     171              :          .TRUE., params%gapw_method, cache%max_l(), params%use_gauxc_model, para_env%num_pe, &
     172              :          params%use_self_runtime, TRIM(params%gradient_runtime), params%force_fd_gradient, &
     173           74 :          params%use_fd_gradient, params%use_gradient_mpi_runtime, params%use_gradient_self_runtime, gradient_error)
     174            0 :       SELECT CASE (gradient_error)
     175              :       CASE (1)
     176              :          CALL cp_abort(__LOCATION__, &
     177            0 :                        "MODEL_GRADIENT_RUNTIME MPI requires verified GauXC OneDFT gradient support (PR #222).")
     178              :       CASE (2)
     179              :          CALL cp_abort(__LOCATION__, &
     180              :                        "MODEL_GRADIENT_RUNTIME MPI requires an MPI energy/VXC runtime. "// &
     181            0 :                        "Use AUTO/SELF to retain the open-shell replicated-runtime safeguard.")
     182              :       CASE (3)
     183              :          CALL cp_abort(__LOCATION__, &
     184            0 :                        "MODEL_GRADIENT_RUNTIME MPI is incompatible with FORCE_NUMERICAL_GRADIENT.")
     185              :       CASE (4)
     186           74 :          CALL cp_abort(__LOCATION__, "Unknown GAUXC%MODEL_GRADIENT_RUNTIME value.")
     187              :       END SELECT
     188              : 
     189           74 :       IF (params%use_self_runtime .OR. .NOT. params%use_gauxc_model) THEN
     190              :          ! SKALA currently needs a replicated molecular runtime for reproducible
     191              :          ! open-shell densities across CP2K MPI ranks.
     192              :          ! Conventional GauXC also uses a replicated runtime here: CP2K has
     193              :          ! already allreduced the dense AO density matrix on every rank.
     194              :          cache%grid = gauxc_create_grid( &
     195              :                       cache%molecule, &
     196              :                       cache%basisset, &
     197              :                       params%grid_type, &
     198              :                       params%radial_quadrature, &
     199              :                       params%pruning_scheme, &
     200              :                       params%lb_exec_space, &
     201              :                       params%batch_size, &
     202              :                       params%device_runtime_fill_fraction, &
     203              :                       status, &
     204              :                       mpi_comm=mp_comm_self%get_handle(), &
     205              :                       force_new_runtime=.TRUE., &
     206           46 :                       int_exec_space=params%int_exec_space)
     207              :       ELSE
     208              :          ! Use the QS force-evaluation communicator rather than GauXC's global
     209              :          ! runtime.  In mixed CDFT the diabatic states can be built on disjoint
     210              :          ! MPI subgroups; using the global communicator would make GauXC wait
     211              :          ! for ranks that are working on another state.
     212              :          cache%grid = gauxc_create_grid( &
     213              :                       cache%molecule, &
     214              :                       cache%basisset, &
     215              :                       params%grid_type, &
     216              :                       params%radial_quadrature, &
     217              :                       params%pruning_scheme, &
     218              :                       params%lb_exec_space, &
     219              :                       params%batch_size, &
     220              :                       params%device_runtime_fill_fraction, &
     221              :                       status, &
     222              :                       mpi_comm=para_env%get_handle(), &
     223           28 :                       int_exec_space=params%int_exec_space)
     224              :       END IF
     225           74 :       IF (status%status%code /= 0) THEN
     226            0 :          CALL cleanup_after_grid()
     227            0 :          RETURN
     228              :       END IF
     229              : 
     230              :       cache%integrator = gauxc_create_integrator( &
     231              :                          TRIM(params%xc_fun_name), &
     232              :                          cache%grid, &
     233              :                          params%int_exec_space, &
     234              :                          params%lwd_kernel, &
     235              :                          params%nspins, &
     236           74 :                          status)
     237           74 :       IF (status%status%code /= 0) THEN
     238            0 :          CALL cleanup_after_integrator()
     239            0 :          RETURN
     240              :       END IF
     241              : 
     242           74 :       IF (.NOT. execution_spaces_logged .AND. para_env%mepos == 0) THEN
     243           11 :          unit_nr = cp_logger_get_default_io_unit()
     244           11 :          IF (unit_nr > 0) THEN
     245              :             WRITE (unit_nr, '(A)') " GAUXC| Execution spaces: LB "// &
     246              :                TRIM(params%lb_exec_space)//", INT "//TRIM(params%int_exec_space)// &
     247           22 :                ", runtime "//MERGE("DEVICE", "HOST  ", cache%grid%uses_device_runtime)
     248              :          END IF
     249           11 :          execution_spaces_logged = .TRUE.
     250              :       END IF
     251              : 
     252           74 :       cache%gradient_is_init = .FALSE.
     253           74 :       cache%gradient_notice_printed = .FALSE.
     254              : 
     255           74 :       cache%natom = params%natom
     256           74 :       cache%nspins = params%nspins
     257           74 :       cache%batch_size = params%batch_size
     258           74 :       cache%device_runtime_fill_fraction = REAL(params%device_runtime_fill_fraction, c_double)
     259           74 :       cache%xc_fun_name = TRIM(params%xc_fun_name)
     260           74 :       cache%grid_type = TRIM(params%grid_type)
     261           74 :       cache%radial_quadrature = TRIM(params%radial_quadrature)
     262           74 :       cache%pruning_scheme = TRIM(params%pruning_scheme)
     263           74 :       cache%lb_exec_space = TRIM(params%lb_exec_space)
     264           74 :       cache%int_exec_space = TRIM(params%int_exec_space)
     265           74 :       cache%model_eval_name = TRIM(params%model_eval_name)
     266           74 :       cache%lwd_kernel = TRIM(params%lwd_kernel)
     267           74 :       cache%gradient_runtime = params%gradient_runtime
     268           74 :       cache%need_xc_gradient = params%need_xc_gradient
     269           74 :       cache%gapw_method = params%gapw_method
     270           74 :       cache%force_fd_gradient = params%force_fd_gradient
     271           74 :       cache%use_gauxc_model = params%use_gauxc_model
     272           74 :       cache%use_gradient_mpi_runtime = params%use_gradient_mpi_runtime
     273           74 :       cache%use_gradient_self_runtime = params%use_gradient_self_runtime
     274           74 :       cache%use_self_runtime = params%use_self_runtime
     275           74 :       cache%use_fd_gradient = params%use_fd_gradient
     276           74 :       IF (ALLOCATED(cache%last_positions)) THEN
     277            0 :          DEALLOCATE (cache%last_positions)
     278              :       END IF
     279          222 :       ALLOCATE (cache%last_positions(3, params%natom))
     280              : 
     281              :       BLOCK
     282              :          INTEGER :: iatom
     283          254 :          DO iatom = 1, params%natom
     284          794 :             cache%last_positions(:, iatom) = REAL(particle_set(iatom)%r(:), c_double)
     285              :          END DO
     286              :       END BLOCK
     287              : 
     288           74 :       cache%mpi_comm = para_env%get_handle()
     289           74 :       cache%is_init = .TRUE.
     290              : 
     291              : #else
     292              :       MARK_USED(params)
     293              :       MARK_USED(para_env)
     294              :       MARK_USED(particle_set)
     295              :       MARK_USED(qs_kind_set)
     296              :       MARK_USED(status)
     297              :       cache%is_init = .FALSE.
     298              : #endif
     299              : 
     300              :    CONTAINS
     301              : ! **************************************************************************************************
     302              : !> \brief ...
     303              : ! **************************************************************************************************
     304            0 :       SUBROUTINE cleanup_after_integrator()
     305            0 :          CALL gauxc_destroy_integrator(cache%integrator, status)
     306            0 :          CALL gauxc_check_status(status)
     307            0 :          CALL cleanup_after_grid()
     308            0 :       END SUBROUTINE cleanup_after_integrator
     309              : 
     310              : ! **************************************************************************************************
     311              : !> \brief ...
     312              : ! **************************************************************************************************
     313            0 :       SUBROUTINE cleanup_after_grid()
     314            0 :          CALL gauxc_destroy_grid(cache%grid, status)
     315            0 :          CALL gauxc_check_status(status)
     316            0 :          CALL cleanup_after_basisset()
     317            0 :       END SUBROUTINE cleanup_after_grid
     318              : 
     319              : ! **************************************************************************************************
     320              : !> \brief ...
     321              : ! **************************************************************************************************
     322            0 :       SUBROUTINE cleanup_after_basisset()
     323            0 :          CALL gauxc_destroy_basisset(cache%basisset, status)
     324            0 :          CALL gauxc_check_status(status)
     325            0 :          CALL cleanup_after_molecule()
     326            0 :       END SUBROUTINE cleanup_after_basisset
     327              : 
     328              : ! **************************************************************************************************
     329              : !> \brief ...
     330              : ! **************************************************************************************************
     331            0 :       SUBROUTINE cleanup_after_molecule()
     332            0 :          CALL gauxc_destroy_molecule(cache%molecule, status)
     333            0 :          CALL gauxc_check_status(status)
     334            0 :          CALL cleanup_final()
     335            0 :       END SUBROUTINE cleanup_after_molecule
     336              : 
     337              : ! **************************************************************************************************
     338              : !> \brief ...
     339              : ! **************************************************************************************************
     340            0 :       SUBROUTINE cleanup_final()
     341            0 :          IF (ALLOCATED(cache%last_positions)) DEALLOCATE (cache%last_positions)
     342            0 :          cache%gradient_is_init = .FALSE.
     343            0 :          cache%gradient_notice_printed = .FALSE.
     344            0 :          cache%is_init = .FALSE.
     345            0 :       END SUBROUTINE cleanup_final
     346              : 
     347              :    END SUBROUTINE gauxc_cache_init
     348              : 
     349              : ! **************************************************************************************************
     350              : !> \brief Release all GauXC objects in a cache and deallocate arrays
     351              : !> \param cache ...
     352              : ! **************************************************************************************************
     353          128 :    SUBROUTINE gauxc_cache_release(cache)
     354              :       TYPE(cp_gauxc_cache_type), INTENT(INOUT)              :: cache
     355              : 
     356              : #ifdef __GAUXC
     357              :       TYPE(cp_gauxc_status_type)                            :: status
     358              : 
     359          128 :       IF (cache%is_init) THEN
     360           74 :          IF (cache%has_gradient_grid()) THEN
     361            6 :             CALL gauxc_destroy_integrator(cache%gradient_integrator, status)
     362            6 :             CALL gauxc_check_status(status)
     363            6 :             CALL gauxc_destroy_grid(cache%gradient_grid, status)
     364            6 :             CALL gauxc_check_status(status)
     365              :          END IF
     366           74 :          CALL gauxc_destroy_integrator(cache%integrator, status)
     367           74 :          CALL gauxc_check_status(status)
     368           74 :          CALL gauxc_destroy_grid(cache%grid, status)
     369           74 :          CALL gauxc_check_status(status)
     370           74 :          CALL gauxc_destroy_basisset(cache%basisset, status)
     371           74 :          CALL gauxc_check_status(status)
     372           74 :          CALL gauxc_destroy_molecule(cache%molecule, status)
     373           74 :          CALL gauxc_check_status(status)
     374              :       END IF
     375          128 :       IF (ALLOCATED(cache%last_positions)) DEALLOCATE (cache%last_positions)
     376          128 :       cache%gradient_is_init = .FALSE.
     377          128 :       cache%gradient_notice_printed = .FALSE.
     378          128 :       cache%is_init = .FALSE.
     379              : #else
     380              :       MARK_USED(cache)
     381              :       IF (ALLOCATED(cache%last_positions)) DEALLOCATE (cache%last_positions)
     382              :       cache%gradient_is_init = .FALSE.
     383              :       cache%gradient_notice_printed = .FALSE.
     384              :       cache%is_init = .FALSE.
     385              : #endif
     386          128 :    END SUBROUTINE gauxc_cache_release
     387              : 
     388              : ! **************************************************************************************************
     389              : !> \brief Build the separate gradient grid/integrator on first use and keep it cached.
     390              : !>
     391              : !> \param cache ...
     392              : !> \param params ...
     393              : !> \param status ...
     394              : ! **************************************************************************************************
     395          670 :    SUBROUTINE gauxc_cache_ensure_gradient(cache, params, status)
     396              :       TYPE(cp_gauxc_cache_type), INTENT(INOUT)           :: cache
     397              :       TYPE(cp_gauxc_cache_params), INTENT(INOUT)         :: params
     398              :       TYPE(cp_gauxc_status_type), INTENT(INOUT)          :: status
     399              : 
     400              : #ifdef __GAUXC
     401              :       INTEGER                                            :: error_code, unit_nr
     402              : 
     403          670 :       IF (.NOT. params%need_xc_gradient) RETURN
     404              : 
     405           56 :       IF (.NOT. cache%gradient_notice_printed) THEN
     406           14 :          IF (params%use_fd_gradient .AND. .NOT. params%force_fd_gradient) THEN
     407              :             CALL cp_warn( &
     408              :                __LOCATION__, &
     409              :                "Using finite-difference GauXC XC gradients for METHOD GAPW/GAPW_XC with "// &
     410              :                "basis functions beyond f shells. Analytical high-l gradients have not been "// &
     411            0 :                "enabled for this GauXC installation and functional path.")
     412              :          END IF
     413           14 :          unit_nr = cp_logger_get_default_io_unit()
     414           14 :          IF (unit_nr > 0) THEN
     415            7 :             WRITE (unit_nr, '(A,A)') " GAUXC| Molecular XC gradient method: ", &
     416           20 :                TRIM(MERGE("FD        ", "ANALYTICAL", params%use_fd_gradient))
     417            7 :             WRITE (unit_nr, '(A,A)') " GAUXC| Molecular XC gradient runtime: ", &
     418           21 :                MERGE("MPI ", "SELF", params%use_gradient_mpi_runtime)
     419              :          END IF
     420           14 :          cache%gradient_notice_printed = .TRUE.
     421              :       END IF
     422              : 
     423           56 :       IF (params%use_fd_gradient) RETURN
     424           54 :       IF (.NOT. params%use_gradient_self_runtime) RETURN
     425           48 :       IF (.NOT. cache%is_init) RETURN
     426           48 :       IF (cache%gradient_is_init) RETURN
     427              : 
     428              :       cache%gradient_grid = gauxc_create_grid( &
     429              :                             cache%molecule, &
     430              :                             cache%basisset, &
     431              :                             params%grid_type, &
     432              :                             params%radial_quadrature, &
     433              :                             params%pruning_scheme, &
     434              :                             params%lb_exec_space, &
     435              :                             params%batch_size, &
     436              :                             params%device_runtime_fill_fraction, &
     437              :                             status, &
     438              :                             mpi_comm=mp_comm_self%get_handle(), &
     439              :                             force_new_runtime=.TRUE., &
     440            6 :                             int_exec_space=params%int_exec_space)
     441            6 :       IF (status%status%code /= 0) THEN
     442            0 :          error_code = status%status%code
     443            0 :          CALL gauxc_destroy_grid(cache%gradient_grid, status)
     444            0 :          status%status%code = error_code
     445            0 :          RETURN
     446              :       END IF
     447              : 
     448              :       cache%gradient_integrator = gauxc_create_integrator( &
     449              :                                   TRIM(params%xc_fun_name), &
     450              :                                   cache%gradient_grid, &
     451              :                                   params%int_exec_space, &
     452              :                                   params%lwd_kernel, &
     453              :                                   params%nspins, &
     454            6 :                                   status)
     455            6 :       IF (status%status%code /= 0) THEN
     456            0 :          error_code = status%status%code
     457            0 :          CALL gauxc_destroy_grid(cache%gradient_grid, status)
     458            0 :          status%status%code = error_code
     459            0 :          RETURN
     460              :       END IF
     461            6 :       cache%gradient_is_init = .TRUE.
     462              : #else
     463              :       MARK_USED(cache)
     464              :       MARK_USED(params)
     465              :       MARK_USED(status)
     466              : #endif
     467              :    END SUBROUTINE gauxc_cache_ensure_gradient
     468              : 
     469              : ! **************************************************************************************************
     470              : !> \brief Check if the GauXC cache is valid for the given parameters
     471              : !> \param cache ...
     472              : !> \param params ...
     473              : !> \param para_env ...
     474              : !> \param particle_set ...
     475              : !> \return ...
     476              : !> \retval cache_valid ...
     477              : ! **************************************************************************************************
     478          670 :    FUNCTION gauxc_cache_is_valid( &
     479              :       cache, &
     480              :       params, &
     481              :       para_env, &
     482              :       particle_set) &
     483              :       RESULT(cache_valid)
     484              : 
     485              :       TYPE(cp_gauxc_cache_type), INTENT(IN)                :: cache
     486              :       TYPE(cp_gauxc_cache_params), INTENT(in)              :: params
     487              :       TYPE(mp_para_env_type), INTENT(in), POINTER          :: para_env
     488              :       TYPE(particle_type), DIMENSION(:), POINTER           :: particle_set
     489              :       LOGICAL                                              :: cache_valid
     490              : 
     491              : #ifdef __GAUXC
     492              :       INTEGER                                              :: iatom
     493              :       REAL(c_double), PARAMETER                            :: pos_tol = 1.0E-8_c_double
     494              : 
     495          670 :       cache_valid = .FALSE.
     496          670 :       IF (.NOT. cache%is_init) RETURN
     497          616 :       IF (cache%natom /= params%natom) RETURN
     498          616 :       IF (cache%nspins /= params%nspins) RETURN
     499          616 :       IF (cache%batch_size /= params%batch_size) RETURN
     500          616 :       IF (ABS(cache%device_runtime_fill_fraction - REAL(params%device_runtime_fill_fraction, c_double)) > &
     501              :           1.0E-10_c_double) RETURN
     502          616 :       IF (TRIM(cache%xc_fun_name) /= TRIM(params%xc_fun_name)) RETURN
     503          616 :       IF (TRIM(cache%grid_type) /= TRIM(params%grid_type)) RETURN
     504          616 :       IF (TRIM(cache%radial_quadrature) /= TRIM(params%radial_quadrature)) RETURN
     505          616 :       IF (TRIM(cache%pruning_scheme) /= TRIM(params%pruning_scheme)) RETURN
     506          616 :       IF (TRIM(cache%lb_exec_space) /= TRIM(params%lb_exec_space)) RETURN
     507          616 :       IF (TRIM(cache%int_exec_space) /= TRIM(params%int_exec_space)) RETURN
     508          616 :       IF (TRIM(cache%model_eval_name) /= TRIM(params%model_eval_name)) RETURN
     509          616 :       IF (TRIM(cache%lwd_kernel) /= TRIM(params%lwd_kernel)) RETURN
     510          616 :       IF (cache%use_self_runtime .NEQV. params%use_self_runtime) RETURN
     511              : 
     512          616 :       IF (cache%gradient_runtime /= params%gradient_runtime) RETURN
     513          616 :       IF (cache%gapw_method .NEQV. params%gapw_method) RETURN
     514          616 :       IF (cache%force_fd_gradient .NEQV. params%force_fd_gradient) RETURN
     515          616 :       IF (cache%use_gauxc_model .NEQV. params%use_gauxc_model) RETURN
     516          616 :       IF (cache%mpi_comm /= para_env%get_handle()) RETURN
     517              : 
     518          616 :       IF (.NOT. ALLOCATED(cache%last_positions)) RETURN
     519          616 :       IF (SIZE(cache%last_positions, 2) /= params%natom) RETURN
     520         2012 :       DO iatom = 1, params%natom
     521         5644 :          IF (ANY(ABS(cache%last_positions(:, iatom) - &
     522          596 :                      REAL(particle_set(iatom)%r(:), c_double)) > pos_tol)) RETURN
     523              :       END DO
     524          670 :       cache_valid = .TRUE.
     525              : #else
     526              :       MARK_USED(cache)
     527              :       MARK_USED(particle_set)
     528              :       MARK_USED(params)
     529              :       MARK_USED(para_env)
     530              :       cache_valid = .FALSE.
     531              : #endif
     532              :    END FUNCTION gauxc_cache_is_valid
     533              : 
     534            0 : END MODULE xc_gauxc_cache
        

Generated by: LCOV version 2.0-1