Skip to content

Commit 0c54095

Browse files
committed
Merge pull request ComputationalRadiationPhysics#844 from Heikman/feature-Gather2D
2D support for cuSTL::algorithm::mpi::Gather
2 parents 1f2ffd2 + bd76ea0 commit 0c54095

File tree

2 files changed

+59
-24
lines changed

2 files changed

+59
-24
lines changed

src/libPMacc/include/cuSTL/algorithm/mpi/Gather.hpp

Lines changed: 7 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/**
2-
* Copyright 2013 Heiko Burau
2+
* Copyright 2013, 2015 Heiko Burau
33
*
44
* This file is part of libPMacc.
55
*
@@ -20,8 +20,7 @@
2020
* If not, see <http://www.gnu.org/licenses/>.
2121
*/
2222

23-
#ifndef ALGORITHM_MPI_GATHER_HPP
24-
#define ALGORITHM_MPI_GATHER_HPP
23+
#pragma once
2524

2625
#include "mpi.h"
2726
#include "math/vector/Int.hpp"
@@ -46,19 +45,16 @@ class Gather
4645
std::vector<math::Int<dim> > positions;
4746
bool m_participate;
4847

49-
template<typename Type, int T_dim, int memDim>
50-
struct CopyToDest;
51-
52-
template<typename Type>
53-
struct CopyToDest<Type, 3, 2>
48+
template<typename Type, int memDim>
49+
struct CopyToDest
5450
{
5551
void operator()(const Gather<dim>& gather,
56-
container::HostBuffer<Type, 2>& dest,
52+
container::HostBuffer<Type, memDim>& dest,
5753
std::vector<Type>& tmpDest,
58-
container::HostBuffer<Type, 2>& source, int dir) const;
54+
container::HostBuffer<Type, memDim>& source, int dir) const;
5955
};
6056

61-
template<typename Type, int T_dim, int memDim>
57+
template<typename Type, int memDim>
6258
friend class CopyToDest;
6359
public:
6460
Gather(const zone::SphericZone<dim>& p_zone);
@@ -79,5 +75,3 @@ class Gather
7975
} // PMacc
8076

8177
#include "Gather.tpp"
82-
83-
#endif // ALGORITHM_MPI_GATHER_HPP

src/libPMacc/include/cuSTL/algorithm/mpi/Gather.tpp

Lines changed: 52 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/**
2-
* Copyright 2013 Heiko Burau
2+
* Copyright 2013, 2015 Heiko Burau
33
*
44
* This file is part of libPMacc.
55
*
@@ -31,6 +31,47 @@ namespace algorithm
3131
{
3232
namespace mpi
3333
{
34+
35+
namespace GatherHelper
36+
{
37+
38+
/** @tparam dim dimension of mpi cluster
39+
* @tparam memDim dimension of memory to be gathered
40+
*
41+
* if memDim == dim - 1 then ``dir`` indicates the direction (orientation)
42+
* of the (meta)plane.
43+
*/
44+
template<int dim, int memDim>
45+
struct posInMem;
46+
47+
template<int dim>
48+
struct posInMem<dim, dim>
49+
{
50+
math::Int<dim> operator()(const math::Int<dim>& pos, int) const
51+
{
52+
return pos;
53+
}
54+
};
55+
56+
template<>
57+
struct posInMem<DIM3, DIM2>
58+
{
59+
math::Int<DIM2> operator()(const math::Int<DIM3>& pos, int dir) const
60+
{
61+
return math::Int<DIM2>(pos[(dir+1)%3], pos[(dir+2)%3]);
62+
}
63+
};
64+
65+
template<>
66+
struct posInMem<DIM2, DIM1>
67+
{
68+
math::Int<DIM1> operator()(const math::Int<DIM2>& pos, int dir) const
69+
{
70+
return math::Int<DIM1>(pos[(dir+1)%2]);
71+
}
72+
};
73+
74+
}
3475

3576
template<int dim>
3677
Gather<dim>::Gather(const zone::SphericZone<dim>& p_zone) : comm(MPI_COMM_NULL)
@@ -102,29 +143,29 @@ int Gather<dim>::rank() const
102143
}
103144

104145
template<int dim>
105-
template<typename Type>
106-
void Gather<dim>::CopyToDest<Type, 3, 2>::operator()(
146+
template<typename Type, int memDim>
147+
void Gather<dim>::CopyToDest<Type, memDim>::operator()(
107148
const Gather<dim>& gather,
108-
container::HostBuffer<Type, 2>& dest,
149+
container::HostBuffer<Type, memDim>& dest,
109150
std::vector<Type>& tmpDest,
110-
container::HostBuffer<Type, 2>& source, int dir) const
151+
container::HostBuffer<Type, memDim>& source, int dir) const
111152
{
112153
using namespace math;
113154

114155
for(int i = 0; i < (int)gather.positions.size(); i++)
115156
{
116-
Int<3> pos = gather.positions[i];
117-
Int<2> pos2D(pos[(dir+1)%3], pos[(dir+2)%3]);
157+
Int<dim> pos = gather.positions[i];
158+
Int<memDim> posInMem = GatherHelper::posInMem<dim, memDim>()(pos, dir);
118159

119-
cudaWrapper::Memcopy<2>()(&(*dest.origin()(pos2D * (Int<2>)source.size())), dest.getPitch(),
160+
cudaWrapper::Memcopy<memDim>()(&(*dest.origin()(posInMem * (Int<memDim>)source.size())), dest.getPitch(),
120161
tmpDest.data() + i * source.size().productOfComponents(), source.getPitch(),
121162
source.size(), cudaWrapper::flags::Memcopy::hostToHost);
122163
}
123164
}
124165

125-
template<>
166+
template<int dim>
126167
template<typename Type, int memDim>
127-
void Gather<3>::operator()(container::HostBuffer<Type, memDim>& dest,
168+
void Gather<dim>::operator()(container::HostBuffer<Type, memDim>& dest,
128169
container::HostBuffer<Type, memDim>& source, int dir) const
129170
{
130171
if(!this->m_participate) return;
@@ -137,7 +178,7 @@ void Gather<3>::operator()(container::HostBuffer<Type, memDim>& dest,
137178
0, this->comm));
138179
if(!root()) return;
139180

140-
CopyToDest<Type, 3, memDim>()(*this, dest, tmpDest, source, dir);
181+
CopyToDest<Type, memDim>()(*this, dest, tmpDest, source, dir);
141182
}
142183

143184
} // mpi

0 commit comments

Comments
 (0)