Skip to content

[WIP]Fix MatrixRef::lbegin/lend #428

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 4 commits into
base: development
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions build.nasty.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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 \
Expand All @@ -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 \
Expand Down
10 changes: 10 additions & 0 deletions dash/include/dash/matrix/LocalMatrixRef.h
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,16 @@ class LocalMatrixRef
Matrix<T_, NumDimensions, index_type, PatternT> * mat
);

/**
* Constructor, creates a local view reference to a Matrix view at the
* specified global coordinates.
*/
template <class T_>
LocalMatrixRef<T, NumDimensions, CUR, PatternT>(
Matrix<T_, NumDimensions, index_type, PatternT> * mat,
std::array<index_type, NumDimensions> global_coords
);

/**
* View at local block at given local block coordinates.
*/
Expand Down
19 changes: 17 additions & 2 deletions dash/include/dash/matrix/internal/LocalMatrixRef-inl.h
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,21 @@ ::LocalMatrixRef(
DASH_LOG_TRACE_VAR("LocalMatrixRef(mat) >", _refview._viewspec);
}

template <typename T, dim_t NumDim, dim_t CUR, class PatternT>
template <class T_>
LocalMatrixRef<T, NumDim, CUR, PatternT>
::LocalMatrixRef(
Matrix<T_, NumDim, index_type, PatternT> * mat,
std::array<index_type, NumDim> 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<typename T, dim_t NumDim, dim_t CUR, class PatternT>
LocalMatrixRef<T, NumDim, CUR, PatternT>
Expand Down Expand Up @@ -274,15 +289,15 @@ inline T *
LocalMatrixRef<T, NumDim, CUR, PatternT>
::lend() noexcept
{
return end().local();
return begin().local() + size();
}

template<typename T, dim_t NumDim, dim_t CUR, class PatternT>
constexpr const T *
LocalMatrixRef<T, NumDim, CUR, PatternT>
::lend() const noexcept
{
return end().local();
return begin().local() + size();
}

template<typename T, dim_t NumDim, dim_t CUR, class PatternT>
Expand Down
6 changes: 3 additions & 3 deletions dash/include/dash/matrix/internal/MatrixRef-inl.h
Original file line number Diff line number Diff line change
Expand Up @@ -251,7 +251,7 @@ typename MatrixRef<T, NumDim, CUR, PatternT>::local_type
MatrixRef<T, NumDim, CUR, PatternT>
::sub_local() noexcept
{
return local_type(this);
return local_type(this->_refview._mat, _refview._viewspec.offsets());
}

template <typename T, dim_t NumDim, dim_t CUR, class PatternT>
Expand All @@ -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 <typename T, dim_t NumDim, dim_t CUR, class PatternT>
Expand All @@ -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 <typename T, dim_t NumDim, dim_t CUR, class PatternT>
Expand Down
26 changes: 26 additions & 0 deletions dash/test/container/MatrixTest.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1616,3 +1616,29 @@ TEST_F(MatrixTest, MoveSemantics){
ASSERT_EQ_U(*(matrix_b.lbegin()), 1);
}
}


TEST_F(MatrixTest, MatrixRefLbegin){
using matrix_t = dash::Matrix<int, 2>;
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());
}
}