Skip to content

Commit c2afe2e

Browse files
committed
Use BLAS zgemm for the H operator in the solver comparison benchmark
The previous naive triple loop re-read the H matrix from memory for every column, which penalized block solvers (PPCG/BPCG) that apply H to many columns at once and favored band-by-band CG. A BLAS gemm applies H to a block with proper cache reuse, matching how the H operator is applied efficiently in real PW (FFT) calculations.
1 parent be5fb2e commit c2afe2e

1 file changed

Lines changed: 7 additions & 8 deletions

File tree

source/source_hsolver/test/diago_compare_test.cpp

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -38,16 +38,15 @@
3838
using T = std::complex<double>;
3939
using Real = double;
4040

41+
extern "C" void zgemm_(const char* transa, const char* transb, const int* m, const int* n, const int* k,
42+
const T* alpha, const T* a, const int* lda,
43+
const T* b, const int* ldb, const T* beta, T* c, const int* ldc);
44+
4145
static void dense_h_multiply(const T* H, int n, const T* in, T* out, int ld, int ncol)
4246
{
43-
for (int j = 0; j < ncol; ++j) {
44-
for (int i = 0; i < n; ++i) {
45-
T sum = 0;
46-
for (int k = 0; k < n; ++k)
47-
sum += H[i + k * n] * in[k + j * ld];
48-
out[i + j * ld] = sum;
49-
}
50-
}
47+
const T one(1.0, 0.0);
48+
const T zero(0.0, 0.0);
49+
zgemm_("N", "N", &n, &ncol, &n, &one, H, &n, in, &ld, &zero, out, &ld);
5150
}
5251

5352
static void identity_s(const T* in, T* out, int ld, int ncol)

0 commit comments

Comments
 (0)