From b1da02856184658f322d82e15ddce7f415b213a8 Mon Sep 17 00:00:00 2001 From: Joseph Schuchart Date: Thu, 3 Aug 2017 14:24:41 +0200 Subject: [PATCH 1/4] Fix compiler error in MatrixRef::lbegin() --- build.nasty.sh | 5 +++-- dash/include/dash/matrix/LocalMatrixRef.h | 10 ++++++++++ .../dash/matrix/internal/LocalMatrixRef-inl.h | 15 +++++++++++++++ dash/include/dash/matrix/internal/MatrixRef-inl.h | 6 +++--- 4 files changed, 31 insertions(+), 5 deletions(-) diff --git a/build.nasty.sh b/build.nasty.sh index 753ffb2a1..219e81e5b 100755 --- a/build.nasty.sh +++ b/build.nasty.sh @@ -61,11 +61,11 @@ fi # Configure with default release build settings: mkdir -p $BUILD_DIR rm -Rf $BUILD_DIR/* -(cd $BUILD_DIR && cmake -DCMAKE_BUILD_TYPE=Release \ +(cd $BUILD_DIR && cmake -DCMAKE_BUILD_TYPE=Debug \ -DENVIRONMENT_TYPE=default \ -DINSTALL_PREFIX=$HOME/opt/dash-0.3.0-nasty \ -DDART_IMPLEMENTATIONS=mpi \ - -DENABLE_THREADSUPPORT=ON \ + -DENABLE_THREADSUPPORT=OFF \ -DENABLE_DEV_COMPILER_WARNINGS=OFF \ -DENABLE_EXT_COMPILER_WARNINGS=OFF \ -DENABLE_LT_OPTIMIZATION=OFF \ @@ -91,6 +91,7 @@ rm -Rf $BUILD_DIR/* -DENABLE_HDF5=ON \ \ -DENABLE_NASTYMPI=ON \ + -DNASTYMPI_LIBRARY_PATH=/home/joseph/src/nasty-MPI/ \ \ -DBUILD_EXAMPLES=OFF \ -DBUILD_TESTS=ON \ diff --git a/dash/include/dash/matrix/LocalMatrixRef.h b/dash/include/dash/matrix/LocalMatrixRef.h index 11dab1a19..f21006a79 100644 --- a/dash/include/dash/matrix/LocalMatrixRef.h +++ b/dash/include/dash/matrix/LocalMatrixRef.h @@ -159,6 +159,16 @@ class LocalMatrixRef Matrix * mat ); + /** + * Constructor, creates a local view reference to a Matrix view at the + * specified global coordinates. + */ + template + LocalMatrixRef( + Matrix * mat, + std::array global_coords + ); + /** * View at local block at given local block coordinates. */ diff --git a/dash/include/dash/matrix/internal/LocalMatrixRef-inl.h b/dash/include/dash/matrix/internal/LocalMatrixRef-inl.h index e48d6f060..250b5f9ab 100644 --- a/dash/include/dash/matrix/internal/LocalMatrixRef-inl.h +++ b/dash/include/dash/matrix/internal/LocalMatrixRef-inl.h @@ -40,6 +40,21 @@ ::LocalMatrixRef( DASH_LOG_TRACE_VAR("LocalMatrixRef(mat) >", _refview._viewspec); } +template +template +LocalMatrixRef +::LocalMatrixRef( + Matrix * mat, + std::array global_coords) + : _refview(mat->_ref._refview) +{ + auto local_extents = mat->_pattern.local_extents(); + DASH_LOG_TRACE_VAR("LocalMatrixRef(mat, gcoords)", local_extents); + auto local_offsets = mat->_pattern.global(global_coords); + _refview._viewspec = ViewSpec_t(local_offsets, local_extents); + DASH_LOG_TRACE_VAR("LocalMatrixRef(mat, gcoords) >", _refview._viewspec); +} + #if 0 template LocalMatrixRef diff --git a/dash/include/dash/matrix/internal/MatrixRef-inl.h b/dash/include/dash/matrix/internal/MatrixRef-inl.h index 8641835ac..4d9fb2282 100644 --- a/dash/include/dash/matrix/internal/MatrixRef-inl.h +++ b/dash/include/dash/matrix/internal/MatrixRef-inl.h @@ -251,7 +251,7 @@ typename MatrixRef::local_type MatrixRef ::sub_local() noexcept { - return local_type(this); + return local_type(this->_refview._mat, _refview._coord); } template @@ -266,7 +266,7 @@ ::lbegin() noexcept // _mat->local.view(_refview) // // ... as order of projections (slice + local vs. local + slice) matters. - return sub_local().begin(); + return sub_local().lbegin(); } template @@ -281,7 +281,7 @@ ::lend() noexcept // _mat->local.view(_refview) // // ... as order of projections (slice + local vs. local + slice) matters. - return sub_local().end(); + return sub_local().lend(); } template From 49fd93bf5bc3c7482182ced851e18b8515d4e894 Mon Sep 17 00:00:00 2001 From: Joseph Schuchart Date: Thu, 3 Aug 2017 14:25:27 +0200 Subject: [PATCH 2/4] Fix LocalMatrixRef::lend() (previously handed out a nullptr) --- dash/include/dash/matrix/internal/LocalMatrixRef-inl.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/dash/include/dash/matrix/internal/LocalMatrixRef-inl.h b/dash/include/dash/matrix/internal/LocalMatrixRef-inl.h index 250b5f9ab..f2d591fd1 100644 --- a/dash/include/dash/matrix/internal/LocalMatrixRef-inl.h +++ b/dash/include/dash/matrix/internal/LocalMatrixRef-inl.h @@ -289,7 +289,7 @@ inline T * LocalMatrixRef ::lend() noexcept { - return end().local(); + return begin().local() + size(); } template @@ -297,7 +297,7 @@ constexpr const T * LocalMatrixRef ::lend() const noexcept { - return end().local(); + return begin().local() + size(); } template From f23831266062e9be357c58ce5b863fe0001a6372 Mon Sep 17 00:00:00 2001 From: Joseph Schuchart Date: Thu, 3 Aug 2017 14:25:48 +0200 Subject: [PATCH 3/4] Add test case for MatrixRef::lbegin() --- dash/test/container/MatrixTest.cc | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/dash/test/container/MatrixTest.cc b/dash/test/container/MatrixTest.cc index ab04385bd..70f5c9092 100644 --- a/dash/test/container/MatrixTest.cc +++ b/dash/test/container/MatrixTest.cc @@ -1616,3 +1616,29 @@ TEST_F(MatrixTest, MoveSemantics){ ASSERT_EQ_U(*(matrix_b.lbegin()), 1); } } + + +TEST_F(MatrixTest, MatrixRefLbegin){ + using matrix_t = dash::Matrix; + size_t nelem = dash::size() * 10; + size_t tilesize = 5; + matrix_t matrix(nelem, nelem, dash::TILE(tilesize), dash::TILE(tilesize)); + auto& pattern = matrix.pattern(); + dash::fill(matrix.begin(), matrix.end(), -1); + + auto lbs = pattern.local_blockspec(); + + // fill our blocks with our ID + for (size_t i = 0; i < lbs.size(); ++i) { + auto coords = lbs.coords(i); + auto block = matrix.block(coords); + for (auto bliter = block.lbegin(); bliter != block.lend(); ++bliter) { + *bliter = dash::myid(); + } + } + + // check that all our elements are correctly set + for (auto iter = matrix.lbegin(); iter != matrix.lend(); ++iter) { + ASSERT_EQ_U(*iter, dash::myid()); + } +} From dcc9fa1780d886a50da410d346768dfda990ae13 Mon Sep 17 00:00:00 2001 From: Joseph Schuchart Date: Thu, 3 Aug 2017 16:55:07 +0200 Subject: [PATCH 4/4] Use viewspec offsets in sub_local() --- dash/include/dash/matrix/internal/MatrixRef-inl.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/dash/include/dash/matrix/internal/MatrixRef-inl.h b/dash/include/dash/matrix/internal/MatrixRef-inl.h index 4d9fb2282..6db0575ae 100644 --- a/dash/include/dash/matrix/internal/MatrixRef-inl.h +++ b/dash/include/dash/matrix/internal/MatrixRef-inl.h @@ -251,7 +251,7 @@ typename MatrixRef::local_type MatrixRef ::sub_local() noexcept { - return local_type(this->_refview._mat, _refview._coord); + return local_type(this->_refview._mat, _refview._viewspec.offsets()); } template