Permalink
Browse files

made Grid::loadMember()/saveMember() reusable, delegate there from Di…

…splacedGrid
  • Loading branch information...
gentryx committed Jun 29, 2018
1 parent 5bce237 commit c4a3e2f7499ee04e2511a3416f5a11a0a7be7029
Showing with 50 additions and 20 deletions.
  1. +16 −18 src/libgeodecomp/storage/displacedgrid.h
  2. +34 −2 src/libgeodecomp/storage/grid.h
@@ -329,15 +329,14 @@ class DisplacedGrid : public GridBase<CELL_TYPE, TOPOLOGY::DIM>
const typename Region<DIM>::StreakIterator& begin,
const typename Region<DIM>::StreakIterator& end) const
{
for (typename Region<DIM>::StreakIterator i = begin; i != end; ++i) {
selector.copyMemberOut(
&(*this)[i->origin],
MemoryLocation::HOST,
target,
targetLocation,
std::size_t(i->length()));
target += selector.sizeOfExternal() * i->length();
}
typedef DisplacedGridHelpers::NormalizingIterator<TOPOLOGY, TOPOLOGICALLY_CORRECT> NormalizingIterator;
delegate.saveMemberImplementationTemplated(
target,
targetLocation,
selector,
NormalizingIterator(begin, origin, topoDimensions),
end);
}
void loadMemberImplementation(
@@ -347,15 +346,14 @@ class DisplacedGrid : public GridBase<CELL_TYPE, TOPOLOGY::DIM>
const typename Region<DIM>::StreakIterator& begin,
const typename Region<DIM>::StreakIterator& end)
{
for (typename Region<DIM>::StreakIterator i = begin; i != end; ++i) {
selector.copyMemberIn(
source,
sourceLocation,
&(*this)[i->origin],
MemoryLocation::HOST,
std::size_t(i->length()));
source += selector.sizeOfExternal() * i->length();
}
typedef DisplacedGridHelpers::NormalizingIterator<TOPOLOGY, TOPOLOGICALLY_CORRECT> NormalizingIterator;
delegate.loadMemberImplementationTemplated(
source,
sourceLocation,
selector,
NormalizingIterator(begin, origin, topoDimensions),
end);
}
private:
@@ -421,7 +421,23 @@ class Grid : public GridBase<CELL_TYPE, TOPOLOGY::DIM>
const typename Region<DIM>::StreakIterator& begin,
const typename Region<DIM>::StreakIterator& end) const
{
for (typename Region<DIM>::StreakIterator i = begin; i != end; ++i) {
saveMemberImplementationTemplated(
target,
targetLocation,
selector,
begin,
end);
}
template<typename ITERATOR_TYPE1, typename ITERATOR_TYPE2>
void saveMemberImplementationTemplated(
char *target,
MemoryLocation::Location targetLocation,
const Selector<CELL_TYPE>& selector,
const ITERATOR_TYPE1& begin,
const ITERATOR_TYPE2& end) const
{
for (ITERATOR_TYPE1 i = begin; i != end; ++i) {
selector.copyMemberOut(
&(*this)[i->origin],
MemoryLocation::HOST,
@@ -439,7 +455,23 @@ class Grid : public GridBase<CELL_TYPE, TOPOLOGY::DIM>
const typename Region<DIM>::StreakIterator& begin,
const typename Region<DIM>::StreakIterator& end)
{
for (typename Region<DIM>::StreakIterator i = begin; i != end; ++i) {
loadMemberImplementationTemplated(
source,
sourceLocation,
selector,
begin,
end);
}
template<typename ITERATOR_TYPE1, typename ITERATOR_TYPE2>
void loadMemberImplementationTemplated(
const char *source,
MemoryLocation::Location sourceLocation,
const Selector<CELL_TYPE>& selector,
const ITERATOR_TYPE1& begin,
const ITERATOR_TYPE2& end)
{
for (ITERATOR_TYPE1 i = begin; i != end; ++i) {
selector.copyMemberIn(
source,
sourceLocation,

0 comments on commit c4a3e2f

Please sign in to comment.