Go to the documentation of this file.
11 #ifndef DIST_OBJECT_HPP
12 #define DIST_OBJECT_HPP
28 template<
typename T1,
typename T2>
39 template <
typename vvGraphT>
46 typedef typename vvGraphT::vertex_t
Vertex;
50 typedef typename vvGraphT::edge_t
Edge;
58 thrust::device_vector<uint> *_data;
59 std::unordered_map<Vertex, uint> _vNum;
63 DistNhbd(vvGraphT &S) : _n(S.size()), _S(S), _data(0) {}
75 thrust::device_vector<uint> *
data()
81 vvGraphT &
graph() {
return _S; };
94 if(_S.valence(v) > _nbs)
99 thrust::host_vector<uint> hData(_n * _nbs);
105 hData[d++] = _vNum[w];
108 for(
uint k = _S.valence(v); k < _nbs; k++)
109 hData[d++] = _vNum[v];
114 }
catch (
const std::exception &e) {
115 throw(QString(
"Unable to allocate distributed neighborhood object of sizes %1 %2 %3, err:%4")
116 .arg(_n).arg(_nbs).arg(
sizeof(
uint)).arg(e.what()));
118 throw(QString(
"Unable to allocate distributed neighborhood object of sizes %1 %2 %3")
119 .arg(_n).arg(_nbs).arg(
sizeof(
uint)));
132 template <
typename DistNhbdT,
typename DataT>
136 thrust::device_vector<DataT> *_data;
151 virtual DataT *
vData(
const typename DistNhbdT::Vertex &) {
return 0; }
157 thrust::device_vector<DataT> *
data()
168 }
catch (
const std::exception &e) {
169 throw(QString(
"Unable to allocate distributed vertex object of sizes %1 %2, err:%3")
170 .arg(_nhbd.n()).arg(
sizeof(DataT)).arg(e.what()));
172 throw(QString(
"Unable to allocate distributed vertex object of sizes %1 %2")
173 .arg(_nhbd.n()).arg(
sizeof(DataT)));
181 throw(QString(
"Error: Distributed vector has no host storage"));
185 thrust::host_vector<DataT> hData(_nhbd.n());
186 forall(
const typename DistNhbdT::Vertex &v, _nhbd.graph())
187 hData[_nhbd.vNum(v)] = *
vData(v);
198 throw(QString(
"Error: Distributed vector has no host storage"));
201 if(_data->size() != _nhbd.n())
202 throw(QString(
"Error: Distributed vector size mismatch on device buffer"));
205 thrust::host_vector<DataT> hData(_nhbd.n());
207 forall(
const typename DistNhbdT::Vertex &v, _nhbd.graph())
208 *
vData(v) = hData[_nhbd.vNum(v)];
217 template <
typename DistNhbdT,
typename DataT>
220 DataT DistNhbdT::VertexContent::*_off;
228 DataT *
vData(
const typename DistNhbdT::Vertex &v)
230 return &((*v).*_off);
239 template <
typename DistNhbdT,
typename ContentT,
typename DataT>
244 DataT ContentT::*_off;
249 DataT ContentT::*off)
253 DataT *
vData(
const typename DistNhbdT::Vertex &v)
255 return &((v->*_map).*_off);
272 template <
typename DistNhbdT,
typename DataT>
278 thrust::device_vector<DataT> *
_data;
296 virtual DataT *
eData(
const typename DistNhbdT::Vertex &v1,
const typename DistNhbdT::Vertex &v2) {
return 0; }
299 thrust::device_vector<DataT> *
data()
310 }
catch (
const std::exception &e) {
311 throw(QString(
"Unable to allocate distributed neighborhood object of sizes %1 %2 %3, err:%4")
312 .arg(
_nhbd.n()).arg(
_nhbd.nbs()).arg(
sizeof(DataT)).arg(e.what()));
314 throw(QString(
"Unable to allocate distributed edge object of sizes %1 %2 %3")
315 .arg(
_nhbd.n()).arg(
_nhbd.nbs()).arg(
sizeof(DataT)));
323 throw(QString(
"Error: DistEdge is temp (no graph storage)"));
328 thrust::host_vector<DataT> hData(
_nhbd.n() *
_nhbd.nbs());
331 forall(
const typename DistNhbdT::Vertex &v,
_nhbd.graph()) {
332 forall(
const typename DistNhbdT::Vertex &w,
_nhbd.graph().neighbors(v))
333 hData[d++] = *
eData(v,w);
337 hData[d++] = DataT();
348 throw(QString(
"Warning DistEdge is temp (no graph storage)"));
354 thrust::host_vector<DataT> hData(
_nhbd.n() *
_nhbd.nbs());
359 forall(
const typename DistNhbdT::Vertex &v,
_nhbd.graph()) {
360 forall(
const typename DistNhbdT::Vertex &w,
_nhbd.graph().neighbors(v))
361 *
eData(v,w) = hData[s++];
375 template <
typename DistNhbdT,
typename DataT>
378 DataT DistNhbdT::EdgeContent::*_off;
386 DataT *
eData(
const typename DistNhbdT::Vertex &v1,
const typename DistNhbdT::Vertex &v2)
397 template <
typename DistNhbdT,
typename ContentT,
typename DataT>
401 typedef std::pair<typename DistNhbdT::Vertex, typename DistNhbdT::Vertex>
EdgePair;
411 DataT *
eData(
const typename DistNhbdT::Vertex &v1,
const typename DistNhbdT::Vertex &v2)
Vertex::content_t VertexContent
VertexContent content_t
Type of the content of the vertex.
EdgeContent content_t
Type of the content of the edge.
int mgx_EXPORT copyGPU(T1 *src, T2 *dst)
Edge::content_t EdgeContent
DistEdgeAttr(DistNhbdT &nhbd, AttrMap< EdgePair, ContentT > *map, DataT ContentT::*off)
Distributed matrix library.
DataT * eData(const typename DistNhbdT::Vertex &v1, const typename DistNhbdT::Vertex &v2)
DistVertex(DistNhbdT &nhbd, bool hasData)
int mgx_EXPORT allocGPU(T **vec, size_t n)
thrust::device_vector< uint > * data()
virtual DataT * vData(const typename DistNhbdT::Vertex &)
thrust::device_vector< DataT > * _data
DistEdge(DistNhbdT &nhbd)
void setAttrMap(AttrMap< typename DistNhbdT::Vertex, ContentT > *map)
AttrMap< EdgePair, ContentT > * _map
DistEdge(DistNhbdT &nhbd, bool hasData)
vvGraphT::vertex_t Vertex
void setAttrMap(AttrMap< EdgePair, ContentT > *map)
uint vNum(const Vertex &v)
DistVertexAttr(DistNhbdT &nhbd, AttrMap< typename DistNhbdT::Vertex, ContentT > *map, DataT ContentT::*off)
thrust::device_vector< DataT > * data()
virtual DataT * eData(const typename DistNhbdT::Vertex &v1, const typename DistNhbdT::Vertex &v2)
DistVertex(DistNhbdT &nhbd)
std::pair< typename DistNhbdT::Vertex, typename DistNhbdT::Vertex > EdgePair
DataT * eData(const typename DistNhbdT::Vertex &v1, const typename DistNhbdT::Vertex &v2)
DataT * vData(const typename DistNhbdT::Vertex &v)
DistVertexGraph(DistNhbdT &nhbd, DataT DistNhbdT::VertexContent::*off)
thrust::device_vector< DataT > * data()
DataT * vData(const typename DistNhbdT::Vertex &v)
DistEdgeGraph(DistNhbdT &nhbd, DataT DistNhbdT::EdgeContent::*off)
CU_HOST_DEVICE Vector< dim, T > map(const T &(*fct)(const T1 &), const Vector< dim, T1 > &v)