1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61
|
#include <config.h>
#include <fstream>
#define BOOST_TEST_MODULE CsrToCscOffsetMap
#include <boost/test/unit_test.hpp>
#include <boost/version.hpp>
#include <dune/common/fvector.hh>
#include <dune/istl/bcrsmatrix.hh>
#include <dune/istl/matrixmarket.hh>
#include <opm/simulators/linalg/gpubridge/opencl/openclBISAI.hpp>
BOOST_AUTO_TEST_CASE(testcsrtocscoffsetmap){
using Matrix = Dune::BCRSMatrix<double>;
Matrix matrix;
{
std::ifstream mfile("offset_map_matrix.txt");
if (!mfile) {
throw std::runtime_error("Could not read matrix file");
}
readMatrixMarket(matrix, mfile);
}
// a transposed version of the matrix is read because the transposed
// of a CSR representation is equivalente to CSC
Matrix matrix_transposed;
{
std::ifstream mfile("offset_map_matrix_transposed.txt");
if (!mfile) {
throw std::runtime_error("Could not read matrix file");
}
readMatrixMarket(matrix_transposed, mfile);
}
// has to make copy because the output of readMatrixMarket does not
// have contiguous non-zero values
Matrix matrix_copy(matrix);
Matrix matrix_transposed_copy(matrix_transposed);
std::vector<int> rowPointers, colIndices, map;
auto* nnzValues = &matrix_copy[0][0];
auto* nnzValues_transposed = &matrix_transposed_copy[0][0];
rowPointers.emplace_back(0);
for (Matrix::Iterator r = matrix.begin(); r != matrix.end(); ++r) {
for (auto c = r->begin(); c != r->end(); ++c) {
colIndices.emplace_back(c.index());
}
rowPointers.emplace_back(colIndices.size());
}
map = Opm::Accelerator::buildCsrToCscOffsetMap(rowPointers, colIndices);
for (unsigned int i = 0; i < colIndices.size(); i++){
BOOST_CHECK_EQUAL(nnzValues[i], nnzValues_transposed[map[i]]);
}
}
|