LCOV - code coverage report
Current view: top level - src - qs_matrix_pools.F (source / functions) Coverage Total Hit
Test: CP2K Regtests (git:123285f) Lines: 60.5 % 185 112
Test Date: 2026-11-04 00:58:17 Functions: 80.0 % 5 4

            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              : ! **************************************************************************************************
       9              : !> \brief wrapper for the pools of matrixes
      10              : !> \par History
      11              : !>      05.2003 created [fawzi]
      12              : !> \author fawzi
      13              : ! **************************************************************************************************
      14              : MODULE qs_matrix_pools
      15              :    USE cp_blacs_env,                    ONLY: cp_blacs_env_type
      16              :    USE cp_fm_pool_types,                ONLY: cp_fm_pool_p_type,&
      17              :                                               cp_fm_pool_type,&
      18              :                                               fm_pool_create,&
      19              :                                               fm_pool_get_el_struct,&
      20              :                                               fm_pool_release,&
      21              :                                               fm_pools_dealloc
      22              :    USE cp_fm_struct,                    ONLY: cp_fm_struct_create,&
      23              :                                               cp_fm_struct_get,&
      24              :                                               cp_fm_struct_release,&
      25              :                                               cp_fm_struct_type
      26              :    USE message_passing,                 ONLY: mp_para_env_type
      27              :    USE qs_mo_types,                     ONLY: get_mo_set,&
      28              :                                               mo_set_type
      29              : #include "./base/base_uses.f90"
      30              : 
      31              :    IMPLICIT NONE
      32              :    PRIVATE
      33              : 
      34              :    LOGICAL, PRIVATE, PARAMETER :: debug_this_module = .TRUE.
      35              :    CHARACTER(len=*), PARAMETER, PRIVATE :: moduleN = 'qs_matrix_pools'
      36              : 
      37              :    PUBLIC :: qs_matrix_pools_type
      38              :    PUBLIC :: mpools_release, mpools_get, &
      39              :              mpools_create, mpools_rebuild_fm_pools
      40              : 
      41              : ! **************************************************************************************************
      42              : !> \brief container for the pools of matrixes used by qs
      43              : !> \param ao_mo_fm_pools pools with (ao x mo) full matrixes (same order as
      44              : !>        c).
      45              : !> \param ao_ao_fm_pool pools with (ao x ao) full matrixes (same order as
      46              : !>        c).
      47              : !> \param mo_mo_fm_pools pools with (mo x mo) full matrixes (same
      48              : !>        order as c).
      49              : !> \param ao_mosub_fm_pools pools with (ao x mosub) full matrixes, where mosub
      50              : !>        are a subset of the mos
      51              : !> \param mosub_mosub_fm_pools pools with (mosub x mosub) full matrixes, where mosub
      52              : !>        are a subset of the mos
      53              : !>
      54              : !> \param maxao_maxao_fm_pools pool of matrixes big enough to accommodate any
      55              : !>        aoxao matrix (useful for temp matrixes)
      56              : !> \param maxao_maxmo_fm_pools pool of matrixes big enough to accommodate any
      57              : !>        aoxmo matrix (useful for temp matrixes)
      58              : !> \param maxmo_maxmo_fm_pools pool of matrixes big enough to accommodate any
      59              : !>        moxmo matrix (useful for temp matrixes)
      60              : !> \par History
      61              : !>      04.2003 created [fawzi]
      62              : !> \author fawzi
      63              : ! **************************************************************************************************
      64              :    TYPE qs_matrix_pools_type
      65              :       TYPE(cp_fm_pool_p_type), DIMENSION(:), POINTER        :: ao_mo_fm_pools => NULL(), &
      66              :                                                                mo_mo_fm_pools => NULL()
      67              :       TYPE(cp_fm_pool_type), POINTER                      :: ao_ao_fm_pool => NULL()
      68              :       TYPE(cp_fm_pool_p_type), DIMENSION(:), POINTER        :: ao_mosub_fm_pools => NULL(), &
      69              :                                                                mosub_mosub_fm_pools => NULL()
      70              :    END TYPE qs_matrix_pools_type
      71              : 
      72              : CONTAINS
      73              : 
      74              : ! **************************************************************************************************
      75              : !> \brief releases the given mpools
      76              : !> \param mpools the matrix pools type to release
      77              : !> \par History
      78              : !>      04.2003 created [fawzi]
      79              : !> \author fawzi
      80              : ! **************************************************************************************************
      81        34532 :    SUBROUTINE mpools_release(mpools)
      82              :       TYPE(qs_matrix_pools_type), POINTER                :: mpools
      83              : 
      84        34532 :       IF (ASSOCIATED(mpools)) THEN
      85        12332 :          CALL fm_pools_dealloc(mpools%ao_mo_fm_pools)
      86        12332 :          CALL fm_pool_release(mpools%ao_ao_fm_pool)
      87        12332 :          CALL fm_pools_dealloc(mpools%mo_mo_fm_pools)
      88        12332 :          IF (ASSOCIATED(mpools%ao_mosub_fm_pools)) THEN
      89            0 :             CALL fm_pools_dealloc(mpools%ao_mosub_fm_pools)
      90              :          END IF
      91        12332 :          IF (ASSOCIATED(mpools%mosub_mosub_fm_pools)) THEN
      92            0 :             CALL fm_pools_dealloc(mpools%mosub_mosub_fm_pools)
      93              :          END IF
      94        12332 :          DEALLOCATE (mpools)
      95              :       END IF
      96        34532 :       NULLIFY (mpools)
      97        34532 :    END SUBROUTINE mpools_release
      98              : 
      99              : ! **************************************************************************************************
     100              : !> \brief returns various attributes of the mpools (notably the pools
     101              : !>      contained in it)
     102              : !> \param mpools the matrix pools object you want info about
     103              : !> \param ao_mo_fm_pools ...
     104              : !> \param ao_ao_fm_pool ...
     105              : !> \param mo_mo_fm_pools ...
     106              : !> \param ao_mosub_fm_pools ...
     107              : !> \param mosub_mosub_fm_pools ...
     108              : !> \param maxao_maxmo_fm_pool ...
     109              : !> \param maxao_maxao_fm_pool ...
     110              : !> \param maxmo_maxmo_fm_pool ...
     111              : !> \par History
     112              : !>      04.2003 created [fawzi]
     113              : !> \author fawzi
     114              : ! **************************************************************************************************
     115       225261 :    SUBROUTINE mpools_get(mpools, ao_mo_fm_pools, ao_ao_fm_pool, &
     116              :                          mo_mo_fm_pools, ao_mosub_fm_pools, mosub_mosub_fm_pools, &
     117              :                          maxao_maxmo_fm_pool, maxao_maxao_fm_pool, maxmo_maxmo_fm_pool)
     118              :       TYPE(qs_matrix_pools_type), INTENT(IN)             :: mpools
     119              :       TYPE(cp_fm_pool_p_type), DIMENSION(:), OPTIONAL, &
     120              :          POINTER                                         :: ao_mo_fm_pools
     121              :       TYPE(cp_fm_pool_type), OPTIONAL, POINTER           :: ao_ao_fm_pool
     122              :       TYPE(cp_fm_pool_p_type), DIMENSION(:), OPTIONAL, &
     123              :          POINTER                                         :: mo_mo_fm_pools, ao_mosub_fm_pools, &
     124              :                                                             mosub_mosub_fm_pools
     125              :       TYPE(cp_fm_pool_type), OPTIONAL, POINTER           :: maxao_maxmo_fm_pool, &
     126              :                                                             maxao_maxao_fm_pool, &
     127              :                                                             maxmo_maxmo_fm_pool
     128              : 
     129       225261 :       IF (PRESENT(ao_mo_fm_pools)) ao_mo_fm_pools => mpools%ao_mo_fm_pools
     130       225261 :       IF (PRESENT(maxao_maxmo_fm_pool)) THEN
     131        17293 :          IF (ASSOCIATED(mpools%ao_mo_fm_pools)) THEN
     132        17293 :             maxao_maxmo_fm_pool => mpools%ao_mo_fm_pools(1)%pool
     133              :          ELSE
     134            0 :             NULLIFY (maxao_maxmo_fm_pool) ! raise an error?
     135              :          END IF
     136              :       END IF
     137       225261 :       IF (PRESENT(ao_ao_fm_pool)) ao_ao_fm_pool => mpools%ao_ao_fm_pool
     138       225261 :       IF (PRESENT(maxao_maxao_fm_pool)) THEN
     139            0 :          IF (ASSOCIATED(mpools%ao_ao_fm_pool)) THEN
     140            0 :             maxao_maxao_fm_pool => mpools%ao_ao_fm_pool
     141              :          ELSE
     142            0 :             NULLIFY (maxao_maxao_fm_pool) ! raise an error?
     143              :          END IF
     144              :       END IF
     145       225261 :       IF (PRESENT(mo_mo_fm_pools)) mo_mo_fm_pools => mpools%mo_mo_fm_pools
     146       225261 :       IF (PRESENT(maxmo_maxmo_fm_pool)) THEN
     147            0 :          IF (ASSOCIATED(mpools%mo_mo_fm_pools)) THEN
     148            0 :             maxmo_maxmo_fm_pool => mpools%mo_mo_fm_pools(1)%pool
     149              :          ELSE
     150            0 :             NULLIFY (maxmo_maxmo_fm_pool) ! raise an error?
     151              :          END IF
     152              :       END IF
     153       225261 :       IF (PRESENT(ao_mosub_fm_pools)) ao_mosub_fm_pools => mpools%ao_mosub_fm_pools
     154       225261 :       IF (PRESENT(mosub_mosub_fm_pools)) mosub_mosub_fm_pools => mpools%mosub_mosub_fm_pools
     155       225261 :    END SUBROUTINE mpools_get
     156              : 
     157              : ! **************************************************************************************************
     158              : !> \brief creates a mpools
     159              : !> \param mpools the mpools to create
     160              : !> \par History
     161              : !>      04.2003 created [fawzi]
     162              : !> \author fawzi
     163              : ! **************************************************************************************************
     164        12332 :    SUBROUTINE mpools_create(mpools)
     165              :       TYPE(qs_matrix_pools_type), POINTER                :: mpools
     166              : 
     167        12332 :       ALLOCATE (mpools)
     168              :       NULLIFY (mpools%ao_ao_fm_pool, mpools%ao_mo_fm_pools, &
     169              :                mpools%mo_mo_fm_pools, mpools%ao_mosub_fm_pools, &
     170              :                mpools%mosub_mosub_fm_pools)
     171        12332 :    END SUBROUTINE mpools_create
     172              : 
     173              : ! **************************************************************************************************
     174              : !> \brief rebuilds the pools of the (ao x mo, ao x ao , mo x mo) full matrixes
     175              : !> \param mpools the environment where the pools should be rebuilt
     176              : !> \param mos the molecular orbitals (qs_env%c), must contain up to
     177              : !>        date nmo and nao
     178              : !> \param blacs_env the blacs environment of the full matrixes
     179              : !> \param para_env the parallel environment of the matrixes
     180              : !> \param nmosub number of the orbitals for the creation
     181              : !>        of the pools containing only a subset of mos (OPTIONAL)
     182              : !> \par History
     183              : !>      08.2002 created [fawzi]
     184              : !>      04.2005 added pools for a subset of mos [MI]
     185              : !> \author Fawzi Mohamed
     186              : ! **************************************************************************************************
     187        12350 :    SUBROUTINE mpools_rebuild_fm_pools(mpools, mos, blacs_env, para_env, &
     188              :                                       nmosub)
     189              :       TYPE(qs_matrix_pools_type), POINTER                :: mpools
     190              :       TYPE(mo_set_type), DIMENSION(:), INTENT(IN)        :: mos
     191              :       TYPE(cp_blacs_env_type), POINTER                   :: blacs_env
     192              :       TYPE(mp_para_env_type), POINTER                    :: para_env
     193              :       INTEGER, DIMENSION(2), INTENT(IN), OPTIONAL        :: nmosub
     194              : 
     195              :       CHARACTER(len=*), PARAMETER :: routineN = 'mpools_rebuild_fm_pools'
     196              : 
     197              :       INTEGER                                            :: handle, ispin, max_nmo, min_nmo, nao, &
     198              :                                                             ncg, nmo, nrg, nspins
     199              :       LOGICAL                                            :: prepare_subset, should_rebuild
     200              :       TYPE(cp_fm_pool_type), POINTER                     :: p_att
     201              :       TYPE(cp_fm_struct_type), POINTER                   :: fmstruct
     202              : 
     203        12350 :       CALL timeset(routineN, handle)
     204              : 
     205        12350 :       NULLIFY (fmstruct, p_att)
     206        12350 :       prepare_subset = .FALSE.
     207        12350 :       IF (PRESENT(nmosub)) THEN
     208            0 :          IF (nmosub(1) > 0) prepare_subset = .TRUE.
     209              :       END IF
     210              : 
     211        12350 :       IF (.NOT. ASSOCIATED(mpools)) THEN
     212         8978 :          CALL mpools_create(mpools)
     213              :       END IF
     214        12350 :       nspins = SIZE(mos)
     215              : 
     216        12350 :       IF (ASSOCIATED(mpools%ao_mo_fm_pools)) THEN
     217           18 :          IF (nspins /= SIZE(mpools%ao_mo_fm_pools)) THEN
     218            0 :             CALL fm_pools_dealloc(mpools%ao_mo_fm_pools)
     219              :          END IF
     220              :       END IF
     221        12350 :       IF (.NOT. ASSOCIATED(mpools%ao_mo_fm_pools)) THEN
     222        51507 :          ALLOCATE (mpools%ao_mo_fm_pools(nspins))
     223        26843 :          DO ispin = 1, nspins
     224        26843 :             NULLIFY (mpools%ao_mo_fm_pools(ispin)%pool)
     225              :          END DO
     226              :       END IF
     227              : 
     228        12350 :       IF (ASSOCIATED(mpools%ao_ao_fm_pool)) THEN
     229           18 :          CALL fm_pool_release(mpools%ao_ao_fm_pool)
     230              :       END IF
     231        12350 :       IF (.NOT. ASSOCIATED(mpools%ao_ao_fm_pool)) THEN
     232        12350 :          NULLIFY (mpools%ao_ao_fm_pool)
     233              :       END IF
     234              : 
     235        12350 :       IF (ASSOCIATED(mpools%mo_mo_fm_pools)) THEN
     236           18 :          IF (nspins /= SIZE(mpools%mo_mo_fm_pools)) THEN
     237            0 :             CALL fm_pools_dealloc(mpools%mo_mo_fm_pools)
     238              :          END IF
     239              :       END IF
     240        12350 :       IF (.NOT. ASSOCIATED(mpools%mo_mo_fm_pools)) THEN
     241        51507 :          ALLOCATE (mpools%mo_mo_fm_pools(nspins))
     242        26843 :          DO ispin = 1, nspins
     243        26843 :             NULLIFY (mpools%mo_mo_fm_pools(ispin)%pool)
     244              :          END DO
     245              :       END IF
     246              : 
     247        12350 :       IF (prepare_subset) THEN
     248              : 
     249            0 :          IF (ASSOCIATED(mpools%ao_mosub_fm_pools)) THEN
     250            0 :             IF (nspins /= SIZE(mpools%ao_mosub_fm_pools)) THEN
     251            0 :                CALL fm_pools_dealloc(mpools%ao_mosub_fm_pools)
     252              :             END IF
     253              :          END IF
     254            0 :          IF (.NOT. ASSOCIATED(mpools%ao_mosub_fm_pools)) THEN
     255            0 :             ALLOCATE (mpools%ao_mosub_fm_pools(nspins))
     256            0 :             DO ispin = 1, nspins
     257            0 :                NULLIFY (mpools%ao_mosub_fm_pools(ispin)%pool)
     258              :             END DO
     259              :          END IF
     260              : 
     261            0 :          IF (ASSOCIATED(mpools%mosub_mosub_fm_pools)) THEN
     262            0 :             IF (nspins /= SIZE(mpools%mosub_mosub_fm_pools)) THEN
     263            0 :                CALL fm_pools_dealloc(mpools%mosub_mosub_fm_pools)
     264              :             END IF
     265              :          END IF
     266            0 :          IF (.NOT. ASSOCIATED(mpools%mosub_mosub_fm_pools)) THEN
     267            0 :             ALLOCATE (mpools%mosub_mosub_fm_pools(nspins))
     268            0 :             DO ispin = 1, nspins
     269            0 :                NULLIFY (mpools%mosub_mosub_fm_pools(ispin)%pool)
     270              :             END DO
     271              :          END IF
     272              : 
     273              :       END IF ! prepare_subset
     274              : 
     275        12350 :       CALL get_mo_set(mos(1), nao=nao, nmo=min_nmo)
     276        12350 :       max_nmo = min_nmo
     277        14533 :       DO ispin = 2, SIZE(mos)
     278         2183 :          CALL get_mo_set(mos(ispin), nmo=nmo)
     279         2183 :          IF (max_nmo < nmo) THEN
     280            0 :             CPABORT("the mo with the most orbitals must be the first ")
     281              :          END IF
     282        16716 :          min_nmo = MIN(min_nmo, nmo)
     283              :       END DO
     284              : 
     285              :       ! aoao pools
     286        26883 :       should_rebuild = .FALSE.
     287        26883 :       DO ispin = 1, nspins
     288        14533 :          p_att => mpools%ao_ao_fm_pool
     289        14533 :          should_rebuild = (should_rebuild .OR. (.NOT. ASSOCIATED(p_att)))
     290        26883 :          IF (.NOT. should_rebuild) THEN
     291            0 :             fmstruct => fm_pool_get_el_struct(mpools%ao_ao_fm_pool)
     292            0 :             CALL cp_fm_struct_get(fmstruct, nrow_global=nrg, ncol_global=ncg)
     293            0 :             CALL get_mo_set(mos(1), nao=nao, nmo=nmo)
     294            0 :             should_rebuild = nao /= nrg .OR. nao /= ncg
     295              :          END IF
     296              :       END DO
     297        12350 :       IF (should_rebuild) THEN
     298        12350 :          CALL fm_pool_release(mpools%ao_ao_fm_pool)
     299              : 
     300              :          CALL cp_fm_struct_create(fmstruct, nrow_global=nao, &
     301              :                                   ncol_global=nao, para_env=para_env, &
     302        12350 :                                   context=blacs_env)
     303        12350 :          CALL fm_pool_create(mpools%ao_ao_fm_pool, fmstruct)
     304        12350 :          CALL cp_fm_struct_release(fmstruct)
     305              :       END IF
     306              : 
     307              :       ! aomo pools
     308              :       should_rebuild = .FALSE.
     309        26883 :       DO ispin = 1, nspins
     310        14533 :          p_att => mpools%ao_mo_fm_pools(ispin)%pool
     311        14533 :          should_rebuild = (should_rebuild .OR. (.NOT. ASSOCIATED(p_att)))
     312        26883 :          IF (.NOT. should_rebuild) THEN
     313              :             fmstruct => fm_pool_get_el_struct(mpools%ao_mo_fm_pools(ispin) &
     314           18 :                                               %pool)
     315           18 :             CALL cp_fm_struct_get(fmstruct, nrow_global=nrg, ncol_global=ncg)
     316           18 :             CALL get_mo_set(mos(1), nao=nao, nmo=nmo)
     317           18 :             should_rebuild = nao /= nrg .OR. nmo /= ncg
     318              :          END IF
     319              :       END DO
     320        12350 :       IF (should_rebuild) THEN
     321        26875 :          DO ispin = 1, nspins
     322        26875 :             CALL fm_pool_release(mpools%ao_mo_fm_pools(ispin)%pool)
     323              :          END DO
     324              : 
     325        12346 :          IF (max_nmo == min_nmo) THEN
     326              :             CALL cp_fm_struct_create(fmstruct, nrow_global=nao, &
     327              :                                      ncol_global=max_nmo, para_env=para_env, &
     328        11355 :                                      context=blacs_env)
     329        23902 :             DO ispin = 1, SIZE(mos)
     330        23902 :                CALL fm_pool_create(mpools%ao_mo_fm_pools(ispin)%pool, fmstruct)
     331              :             END DO
     332        11355 :             CALL cp_fm_struct_release(fmstruct)
     333              :          ELSE
     334         2973 :             DO ispin = 1, SIZE(mos)
     335         1982 :                CALL get_mo_set(mos(ispin), nmo=nmo, nao=nao)
     336              :                CALL cp_fm_struct_create(fmstruct, nrow_global=nao, &
     337              :                                         ncol_global=nmo, para_env=para_env, &
     338         1982 :                                         context=blacs_env)
     339              :                CALL fm_pool_create(mpools%ao_mo_fm_pools(ispin)%pool, &
     340         1982 :                                    fmstruct)
     341         4955 :                CALL cp_fm_struct_release(fmstruct)
     342              :             END DO
     343              :          END IF
     344              :       END IF
     345              : 
     346              :       ! momo pools
     347              :       should_rebuild = .FALSE.
     348        26883 :       DO ispin = 1, nspins
     349        14533 :          p_att => mpools%mo_mo_fm_pools(ispin)%pool
     350        14533 :          should_rebuild = (should_rebuild .OR. (.NOT. ASSOCIATED(p_att)))
     351        26883 :          IF (.NOT. should_rebuild) THEN
     352           18 :             fmstruct => fm_pool_get_el_struct(p_att)
     353              :             CALL cp_fm_struct_get(fmstruct, nrow_global=nrg, &
     354           18 :                                   ncol_global=ncg)
     355           18 :             CALL get_mo_set(mos(1), nao=nao, nmo=nmo)
     356           18 :             should_rebuild = nmo /= nrg .OR. nmo /= ncg
     357              :          END IF
     358              :       END DO
     359        12350 :       IF (should_rebuild) THEN
     360        26875 :          DO ispin = 1, nspins
     361        26875 :             CALL fm_pool_release(mpools%mo_mo_fm_pools(ispin)%pool)
     362              :          END DO
     363              : 
     364        12346 :          IF (max_nmo == min_nmo) THEN
     365              :             CALL cp_fm_struct_create(fmstruct, nrow_global=max_nmo, &
     366              :                                      ncol_global=max_nmo, para_env=para_env, &
     367        11355 :                                      context=blacs_env)
     368        23902 :             DO ispin = 1, SIZE(mos)
     369              :                CALL fm_pool_create(mpools%mo_mo_fm_pools(ispin)%pool, &
     370        23902 :                                    fmstruct)
     371              :             END DO
     372        11355 :             CALL cp_fm_struct_release(fmstruct)
     373              :          ELSE
     374         2973 :             DO ispin = 1, SIZE(mos)
     375         1982 :                NULLIFY (mpools%mo_mo_fm_pools(ispin)%pool)
     376         1982 :                CALL get_mo_set(mos(ispin), nmo=nmo, nao=nao)
     377              :                CALL cp_fm_struct_create(fmstruct, nrow_global=nmo, &
     378              :                                         ncol_global=nmo, para_env=para_env, &
     379         1982 :                                         context=blacs_env)
     380              :                CALL fm_pool_create(mpools%mo_mo_fm_pools(ispin)%pool, &
     381         1982 :                                    fmstruct)
     382         4955 :                CALL cp_fm_struct_release(fmstruct)
     383              :             END DO
     384              :          END IF
     385              :       END IF
     386              : 
     387        12350 :       IF (prepare_subset) THEN
     388              :          ! aomosub pools
     389              :          should_rebuild = .FALSE.
     390            0 :          DO ispin = 1, nspins
     391            0 :             p_att => mpools%ao_mosub_fm_pools(ispin)%pool
     392            0 :             should_rebuild = (should_rebuild .OR. (.NOT. ASSOCIATED(p_att)))
     393            0 :             IF (.NOT. should_rebuild) THEN
     394              :                fmstruct => fm_pool_get_el_struct(mpools%ao_mosub_fm_pools(ispin) &
     395            0 :                                                  %pool)
     396              :                CALL cp_fm_struct_get(fmstruct, nrow_global=nrg, &
     397            0 :                                      ncol_global=ncg)
     398            0 :                CALL get_mo_set(mos(1), nao=nao)
     399            0 :                should_rebuild = nao /= nrg .OR. nmosub(ispin) /= ncg
     400              :             END IF
     401              :          END DO
     402            0 :          IF (should_rebuild) THEN
     403            0 :             DO ispin = 1, nspins
     404            0 :                CALL fm_pool_release(mpools%ao_mosub_fm_pools(ispin)%pool)
     405              :             END DO
     406              : 
     407            0 :             IF (nspins == 1 .OR. nmosub(1) == nmosub(2)) THEN
     408              :                CALL cp_fm_struct_create(fmstruct, nrow_global=nao, &
     409              :                                         ncol_global=nmosub(1), para_env=para_env, &
     410            0 :                                         context=blacs_env)
     411            0 :                DO ispin = 1, SIZE(mos)
     412            0 :                   CALL fm_pool_create(mpools%ao_mosub_fm_pools(ispin)%pool, fmstruct)
     413              :                END DO
     414            0 :                CALL cp_fm_struct_release(fmstruct)
     415              :             ELSE
     416            0 :                DO ispin = 1, SIZE(mos)
     417            0 :                   CALL get_mo_set(mos(ispin), nao=nao)
     418              :                   CALL cp_fm_struct_create(fmstruct, nrow_global=nao, &
     419              :                                            ncol_global=nmosub(1), para_env=para_env, &
     420            0 :                                            context=blacs_env)
     421              :                   CALL fm_pool_create(mpools%ao_mosub_fm_pools(ispin)%pool, &
     422            0 :                                       fmstruct)
     423            0 :                   CALL cp_fm_struct_release(fmstruct)
     424              :                END DO
     425              :             END IF
     426              :          END IF ! should_rebuild
     427              : 
     428              :          ! mosubmosub pools
     429              :          should_rebuild = .FALSE.
     430            0 :          DO ispin = 1, nspins
     431            0 :             p_att => mpools%mosub_mosub_fm_pools(ispin)%pool
     432            0 :             should_rebuild = (should_rebuild .OR. (.NOT. ASSOCIATED(p_att)))
     433            0 :             IF (.NOT. should_rebuild) THEN
     434            0 :                fmstruct => fm_pool_get_el_struct(p_att)
     435              :                CALL cp_fm_struct_get(fmstruct, nrow_global=nrg, &
     436            0 :                                      ncol_global=ncg)
     437            0 :                should_rebuild = nmosub(ispin) /= nrg .OR. nmosub(ispin) /= ncg
     438              :             END IF
     439              :          END DO
     440            0 :          IF (should_rebuild) THEN
     441            0 :             DO ispin = 1, nspins
     442            0 :                CALL fm_pool_release(mpools%mosub_mosub_fm_pools(ispin)%pool)
     443              :             END DO
     444              : 
     445            0 :             IF (nspins == 1 .OR. nmosub(1) == nmosub(2)) THEN
     446              :                CALL cp_fm_struct_create(fmstruct, nrow_global=nmosub(1), &
     447              :                                         ncol_global=nmosub(1), para_env=para_env, &
     448            0 :                                         context=blacs_env)
     449            0 :                DO ispin = 1, SIZE(mos)
     450              :                   CALL fm_pool_create(mpools%mosub_mosub_fm_pools(ispin)%pool, &
     451            0 :                                       fmstruct)
     452              :                END DO
     453            0 :                CALL cp_fm_struct_release(fmstruct)
     454              :             ELSE
     455            0 :                DO ispin = 1, SIZE(mos)
     456            0 :                   NULLIFY (mpools%mosub_mosub_fm_pools(ispin)%pool)
     457              :                   CALL cp_fm_struct_create(fmstruct, nrow_global=nmosub(ispin), &
     458              :                                            ncol_global=nmosub(ispin), para_env=para_env, &
     459            0 :                                            context=blacs_env)
     460              :                   CALL fm_pool_create(mpools%mosub_mosub_fm_pools(ispin)%pool, &
     461            0 :                                       fmstruct)
     462            0 :                   CALL cp_fm_struct_release(fmstruct)
     463              :                END DO
     464              :             END IF
     465              :          END IF ! should_rebuild
     466              :       END IF ! prepare_subset
     467              : 
     468        12350 :       CALL timestop(handle)
     469        12350 :    END SUBROUTINE mpools_rebuild_fm_pools
     470              : 
     471              : ! **************************************************************************************************
     472              : 
     473            0 : END MODULE qs_matrix_pools
        

Generated by: LCOV version 2.0-1