Skip to content

Commit fa0c360

Browse files
committed
test reuse sparsity pattern
Signed-off-by: Steven Hahn <[email protected]>
1 parent adcc3b8 commit fa0c360

File tree

3 files changed

+16
-5
lines changed

3 files changed

+16
-5
lines changed

resolve/workspace/LinAlgWorkspaceCpu.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,7 @@ namespace ReSolve
108108
{
109109
assert(scaleaddi_buffer_ == nullptr);
110110
scaleaddi_buffer_ = buffer;
111+
scaleAddISetupDone();
111112
}
112113

113114
} // namespace ReSolve

tests/unit/matrix/MatrixHandlerTests.hpp

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -214,7 +214,17 @@ namespace ReSolve
214214
{
215215
A->syncData(memory::HOST);
216216
}
217-
status *= verifyScaleAddICsrMatrix(A, val);
217+
// expected sum is 2*30+1
218+
status *= verifyScaleAddICsrMatrix(A, 61);
219+
220+
// run again to reuse sparsity pattern.
221+
handler_.scaleAddI(A, val, memspace_);
222+
if (memspace_ == memory::DEVICE)
223+
{
224+
A->syncData(memory::HOST);
225+
}
226+
// expected sum is 2*61+1
227+
status *= verifyScaleAddICsrMatrix(A, 123);
218228

219229
delete A;
220230
return status.report(testname.c_str());
@@ -705,10 +715,10 @@ namespace ReSolve
705715
* @pre A is a valid, allocated CSR matrix
706716
* @invariant A
707717
* @param[in] A matrix::Csr* pointer to the matrix to be verified
708-
* @param[in] alpha matrix scale factor
718+
* @param[in] expected sum of row elements
709719
* @return bool true if the matrix is valid, false otherwise
710720
*/
711-
bool verifyScaleAddICsrMatrix(matrix::Csr* A, real_type alpha)
721+
bool verifyScaleAddICsrMatrix(matrix::Csr* A, real_type expected)
712722
{
713723
// Check if the matrix is valid
714724
if (A == nullptr)
@@ -728,8 +738,6 @@ namespace ReSolve
728738
index_type* scaled_row_ptr = A->getRowData(memory::HOST);
729739
real_type* scaled_value = A->getValues(memory::HOST);
730740

731-
const real_type expected = 30. * alpha + 1.;
732-
733741
// Verify values - each element scaled by scale. Diagonal elements should be 1.
734742
for (index_type i = 0; i < n; ++i)
735743
{

tests/unit/matrix/runMatrixHandlerTests.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,8 +76,10 @@ void runTests(const std::string& backend, ReSolve::tests::TestingResults& result
7676
result += test.rightScale(1024, 2048);
7777
workspace.resetLinAlgWorkspace();
7878
result += test.rightScale(2048, 1024);
79+
#if !defined(RESOLVE_USE_CUDA) && !defined(RESOLVE_USE_HIP)
7980
workspace.resetLinAlgWorkspace();
8081
result += test.scaleAddI(100);
82+
#endif
8183
std::cout << "\n";
8284
}
8385

0 commit comments

Comments
 (0)