Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 12 additions & 6 deletions src/QMCWaveFunctions/TWFFastDerivWrapper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -336,8 +336,9 @@ void TWFFastDerivWrapper::computeMDDerivatives_Obs(const std::vector<ValueMatrix

// s[h,v] = -Minv_B[h,o].Minv_Mv[o,v]
ValueMatrix s_hv(nocc, nvirt);
BLAS::gemm('n', 'n', nvirt, nocc, nocc, -1.0, Minv_Mv[sid].data(), Minv_Mv[sid].cols(), Minv_B[sid].data(),
Minv_B[sid].cols(), 0.0, s_hv.data(), s_hv.cols());
if (nvirt > 0)
BLAS::gemm('n', 'n', nvirt, nocc, nocc, -1.0, Minv_Mv[sid].data(), Minv_Mv[sid].cols(), Minv_B[sid].data(),
Minv_B[sid].cols(), 0.0, s_hv.data(), s_hv.cols());

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

When nvirt = 0, is max_exc_level defined at line 360 always zero? if so, prefer an early return before s_hv is defined.


// s[h,v] = Minv_B[h,v] - Minv_B[h,o].Minv_Mv[o,v]
for (size_t i = 0; i < s_hv.rows(); i++)
Expand Down Expand Up @@ -428,6 +429,9 @@ void TWFFastDerivWrapper::computeMDDerivatives_Obs(const std::vector<ValueMatrix

void TWFFastDerivWrapper::transform_Av_AoBv(const ValueMatrix& A, const ValueMatrix& B, ValueMatrix& X) const
{
// if nvirt == 0, no work to do
if (X.cols() == 0) return;

// A [h,o+v]
// B [o,v]

Expand Down Expand Up @@ -530,8 +534,9 @@ void TWFFastDerivWrapper::computeMDDerivatives_dmu(const std::vector<ValueMatrix
transform_Av_AoBv(Minv_B[sid], Minv_Mv[sid], X3b_ov);

// X432b[h,v] -= Minv_dM[h,o].X3b[o,v]
BLAS::gemm('n', 'n', nvirt, nocc, nocc, -1.0, X3b_ov.data(), X3b_ov.cols(), Minv_dM[sid].data(),
Minv_dM[sid].cols(), 1.0, X432b_hv.data(), X432b_hv.cols());
if (nvirt > 0)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can it cover a larger scope? All the ValueMatrix above with nvirt should be in the scope and hence their consumption.

BLAS::gemm('n', 'n', nvirt, nocc, nocc, -1.0, X3b_ov.data(), X3b_ov.cols(), Minv_dM[sid].data(),
Minv_dM[sid].cols(), 1.0, X432b_hv.data(), X432b_hv.cols());


// compute difference from ref here and add that term back later
Expand Down Expand Up @@ -830,8 +835,9 @@ void TWFFastDerivWrapper::buildIntermediates(const std::vector<ValueMatrix>& Min
// n: all orbs (o+v)

// Minv_Mv = Minv[o,e].M[e,v]
BLAS::gemm('n', 'n', nvirt, ptclnum, ptclnum, 1.0, M[id].data() + ptclnum, M[id].cols(), Minv[id].data(),
Minv[id].cols(), 0.0, Minv_Mv[id].data(), Minv_Mv[id].cols());
if (nvirt > 0) // avoid gemm call with LDC == 0

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If you move the definition of nvirt here like if (int nvirt = norb - ptclnum; nvirt > 0).
The code will be more compact and readable.

BLAS::gemm('n', 'n', nvirt, ptclnum, ptclnum, 1.0, M[id].data() + ptclnum, M[id].cols(), Minv[id].data(),
Minv[id].cols(), 0.0, Minv_Mv[id].data(), Minv_Mv[id].cols());

// Minv_B = Minv[o,e].B[e,n]
BLAS::gemm('n', 'n', norb, ptclnum, ptclnum, 1.0, B[id].data(), B[id].cols(), Minv[id].data(), Minv[id].cols(), 0.0,
Expand Down
Loading