diff --git a/opm/simulators/linalg/cuistl/detail/vector_operations.cu b/opm/simulators/linalg/cuistl/detail/vector_operations.cu index 5c7223870..c557c9b7a 100644 --- a/opm/simulators/linalg/cuistl/detail/vector_operations.cu +++ b/opm/simulators/linalg/cuistl/detail/vector_operations.cu @@ -54,7 +54,7 @@ namespace // TODO: [perf] Is it faster to just use a mask? Probably does not matter either way // This is hopefully not where we will spend most of our time. if (globalIndex < numberOfElements) { - buffer[indices[globalIndex]] = a[indices[globalIndex]] * b[indices[globalIndex]]; + buffer[globalIndex] = a[indices[globalIndex]] * b[indices[globalIndex]]; } } diff --git a/tests/cuistl/test_cuvector.cpp b/tests/cuistl/test_cuvector.cpp index be516de2b..dc41cc47e 100644 --- a/tests/cuistl/test_cuvector.cpp +++ b/tests/cuistl/test_cuvector.cpp @@ -280,5 +280,16 @@ BOOST_AUTO_TEST_CASE(RandomVectors) BOOST_CHECK_EQUAL(projectedA[i], a[i]); } } + + aGPU = GVector(a); + auto twoNormAtIndices = aGPU.two_norm(indexSetGPU); + + double correctTwoNormAtIndices = 0.0; + for (size_t i = 0; i < indexSet.size(); ++i) { + correctTwoNormAtIndices += a[indexSet[i]] * a[indexSet[i]]; + } + correctTwoNormAtIndices = std::sqrt(correctTwoNormAtIndices); + + BOOST_CHECK_CLOSE(correctTwoNormAtIndices, twoNormAtIndices, 1e-7); } }