1
1
/* *
2
- * Copyright 2013 Heiko Burau
2
+ * Copyright 2013, 2015 Heiko Burau
3
3
*
4
4
* This file is part of libPMacc.
5
5
*
@@ -31,6 +31,47 @@ namespace algorithm
31
31
{
32
32
namespace mpi
33
33
{
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
+ }
34
75
35
76
template <int dim>
36
77
Gather<dim>::Gather(const zone::SphericZone<dim>& p_zone) : comm(MPI_COMM_NULL)
@@ -102,29 +143,29 @@ int Gather<dim>::rank() const
102
143
}
103
144
104
145
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 ()(
107
148
const Gather<dim>& gather,
108
- container::HostBuffer<Type, 2 >& dest,
149
+ container::HostBuffer<Type, memDim >& dest,
109
150
std::vector<Type>& tmpDest,
110
- container::HostBuffer<Type, 2 >& source, int dir) const
151
+ container::HostBuffer<Type, memDim >& source, int dir) const
111
152
{
112
153
using namespace math ;
113
154
114
155
for (int i = 0 ; i < (int )gather.positions .size (); i++)
115
156
{
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);
118
159
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 (),
120
161
tmpDest.data () + i * source.size ().productOfComponents (), source.getPitch (),
121
162
source.size (), cudaWrapper::flags::Memcopy::hostToHost);
122
163
}
123
164
}
124
165
125
- template <>
166
+ template <int dim >
126
167
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,
128
169
container::HostBuffer<Type, memDim>& source, int dir) const
129
170
{
130
171
if (!this ->m_participate ) return ;
@@ -137,7 +178,7 @@ void Gather<3>::operator()(container::HostBuffer<Type, memDim>& dest,
137
178
0 , this ->comm ));
138
179
if (!root ()) return ;
139
180
140
- CopyToDest<Type, 3 , memDim>()(*this , dest, tmpDest, source, dir);
181
+ CopyToDest<Type, memDim>()(*this , dest, tmpDest, source, dir);
141
182
}
142
183
143
184
} // mpi
0 commit comments