(git:6344619)
Loading...
Searching...
No Matches
cp_fm_diag_utils_unittest.F
Go to the documentation of this file.
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
9 USE cp_fm_diag_utils, ONLY: cp_fm_max_ncpu_non_zero_column
12
13 IMPLICIT NONE
14
15 INTEGER, PARAMETER :: orders(2) = [509, 536]
16 INTEGER :: i, itest, n
17 INTEGER, EXTERNAL :: numroc
18 TYPE(cp_fm_struct_type) :: matrix_struct
19 TYPE(mp_para_env_type), TARGET :: para_env
20
21 ! Layout metadata only: exercise large process grids even in two-rank CI.
22 para_env%num_pe = 32
23 matrix_struct%para_env => para_env
24 matrix_struct%nrow_block = 64
25 matrix_struct%ncol_block = 64
26 ALLOCATE (matrix_struct%nrow_locals(0:3), matrix_struct%ncol_locals(0:7))
27
28 DO itest = 1, SIZE(orders)
29 n = orders(itest)
30 matrix_struct%nrow_global = n
31 matrix_struct%ncol_global = n
32 DO i = 0, 3
33 matrix_struct%nrow_locals(i) = numroc(n, 64, i, 0, 4)
34 END DO
35 DO i = 0, 7
36 matrix_struct%ncol_locals(i) = numroc(n, 64, i, 0, 8)
37 END DO
38
39 IF (cp_fm_max_ncpu_non_zero_column(matrix_struct, 32, 64) /= 32) THEN
40 error stop "Valid original redistribution layout changed"
41 END IF
42 ! 20 ranks use a 2x10 grid with empty columns; 18 ranks use a safe 3x6 grid.
43 IF (cp_fm_max_ncpu_non_zero_column(matrix_struct, 20, 64) /= 18) THEN
44 error stop "Unsafe forced redistribution layout accepted"
45 END IF
46 IF (cp_fm_max_ncpu_non_zero_column(matrix_struct, 12, 64) /= 12) THEN
47 error stop "Safe redistribution heuristic target changed"
48 END IF
49 IF (cp_fm_max_ncpu_non_zero_column(matrix_struct, 8, 64) /= 8) THEN
50 error stop "Safe smaller redistribution target changed"
51 END IF
52 IF (cp_fm_max_ncpu_non_zero_column(matrix_struct, 20, 32) /= 20) THEN
53 error stop "Redistribution check ignored the final block size"
54 END IF
55 END DO
56
57 ! Mandatory redistribution must still work when forced redistribution is off.
58 matrix_struct%nrow_global = 1
59 matrix_struct%ncol_global = 1
60 matrix_struct%nrow_locals = 0
61 matrix_struct%ncol_locals = 0
62 matrix_struct%nrow_locals(0) = 1
63 matrix_struct%ncol_locals(0) = 1
64 IF (cp_fm_max_ncpu_non_zero_column(matrix_struct, 32, 64) /= 1) THEN
65 error stop "Empty original redistribution layout was retained"
66 END IF
67
68 DEALLOCATE (matrix_struct%nrow_locals, matrix_struct%ncol_locals)
69
70 ! Changing blocks also recreates the grid, even when the rank count is unchanged.
71 para_env%num_pe = 20
72 matrix_struct%nrow_global = 509
73 matrix_struct%ncol_global = 509
74 matrix_struct%nrow_block = 96
75 matrix_struct%ncol_block = 96
76 ALLOCATE (matrix_struct%nrow_locals(0:3), matrix_struct%ncol_locals(0:4))
77 DO i = 0, 3
78 matrix_struct%nrow_locals(i) = numroc(509, 96, i, 0, 4)
79 END DO
80 DO i = 0, 4
81 matrix_struct%ncol_locals(i) = numroc(509, 96, i, 0, 5)
82 END DO
83 IF (cp_fm_max_ncpu_non_zero_column(matrix_struct, 20, 64) /= 18) THEN
84 error stop "Block-size change skipped the target grid check"
85 END IF
86 DEALLOCATE (matrix_struct%nrow_locals, matrix_struct%ncol_locals)
87
88 ! A safe default grid must not hide an invalid original custom grid.
89 para_env%num_pe = 32
90 matrix_struct%nrow_block = 64
91 matrix_struct%ncol_block = 64
92 ALLOCATE (matrix_struct%nrow_locals(0:1), matrix_struct%ncol_locals(0:15))
93 DO i = 0, 1
94 matrix_struct%nrow_locals(i) = numroc(509, 64, i, 0, 2)
95 END DO
96 DO i = 0, 15
97 matrix_struct%ncol_locals(i) = numroc(509, 64, i, 0, 16)
98 END DO
99 IF (cp_fm_max_ncpu_non_zero_column(matrix_struct, 32, 64) /= 24) THEN
100 error stop "Invalid original grid skipped mandatory redistribution"
101 END IF
102 DEALLOCATE (matrix_struct%nrow_locals, matrix_struct%ncol_locals)
program cp_fm_diag_utils_unittest
Auxiliary tools to redistribute cp_fm_type and cp_cfm_type matrices before and after diagonalization....
represent the structure of a full matrix
Interface to the message passing library MPI.
keeps the information about the structure of a full matrix
stores all the informations relevant to an mpi environment