Reduce MITC4 Jet product scratch stack storage
This commit is contained in:
@@ -594,17 +594,17 @@ Jet operator*(const Jet& left, const Jet& right) {
|
||||
const bool masked_exceptions =
|
||||
(_mm_getcsr() & _MM_MASK_MASK) == _MM_MASK_MASK;
|
||||
const bool outer_accepted = Outer(left.first, right.first, result_second);
|
||||
std::array<double, kHessianSize> scratch;
|
||||
if (masked_exceptions && outer_accepted) {
|
||||
// Retain earlier upper entries for later lower entries before overwriting
|
||||
// them. Reuse the MKL k=1 transpose while preserving the original row-major
|
||||
// arithmetic order as well as each entry's four-term association.
|
||||
std::array<double, kGlobalDofCount * (kGlobalDofCount - 1U) / 2U> upper;
|
||||
std::size_t saved = 0U;
|
||||
for (std::size_t row = 0U; row < kGlobalDofCount; ++row) {
|
||||
for (std::size_t column = 0U; column < row; ++column) {
|
||||
const std::size_t index = row * kGlobalDofCount + column;
|
||||
result_second[index] = left_second[index] * right.value +
|
||||
result_second[index] + upper[saved++] +
|
||||
result_second[index] + scratch[saved++] +
|
||||
left.value * right_second[index];
|
||||
}
|
||||
const std::size_t diagonal = row * kGlobalDofCount + row;
|
||||
@@ -616,7 +616,7 @@ Jet operator*(const Jet& left, const Jet& right) {
|
||||
const std::size_t transpose = column * kGlobalDofCount + row;
|
||||
const double forward = result_second[index];
|
||||
const double reverse = result_second[transpose];
|
||||
upper[column * (column - 1U) / 2U + row] = forward;
|
||||
scratch[column * (column - 1U) / 2U + row] = forward;
|
||||
result_second[index] = left_second[index] * right.value +
|
||||
forward + reverse + left.value * right_second[index];
|
||||
}
|
||||
@@ -624,13 +624,12 @@ Jet operator*(const Jet& left, const Jet& right) {
|
||||
return result;
|
||||
}
|
||||
// Preserve the reverse input-validation order after a rejected first outer.
|
||||
std::array<double, kHessianSize> reverse;
|
||||
Outer(right.first, left.first, reverse.data());
|
||||
Outer(right.first, left.first, scratch.data());
|
||||
for (std::size_t row = 0U; row < kGlobalDofCount; ++row) {
|
||||
for (std::size_t column = 0U; column < kGlobalDofCount; ++column) {
|
||||
const std::size_t index = row * kGlobalDofCount + column;
|
||||
result_second[index] = left_second[index] * right.value +
|
||||
result_second[index] + reverse[index] +
|
||||
result_second[index] + scratch[index] +
|
||||
left.value * right_second[index];
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user