@@ -81,34 +81,42 @@ namespace graybat {
8181
8282 template <class T_Functor >
8383 Cage (CPConfig const cpConfig, T_Functor graphFunctor) :
84- comm (cpConfig),
85- graph (GraphPolicy(graphFunctor())){
86-
84+ comm (new CommunicationPolicy( cpConfig) ),
85+ graph (GraphPolicy(graphFunctor())){
86+
8787 }
88-
89- Cage (CPConfig const cpConfig) :
90- comm (cpConfig),
91- graph (GraphPolicy(graybat::pattern::None<GraphPolicy>()())){
9288
93- }
89+ Cage (CPConfig const cpConfig) :
90+ comm (new CommunicationPolicy(cpConfig)),
91+ graph (GraphPolicy(graybat::pattern::None<GraphPolicy>()())){
92+
93+ }
9494
9595 Cage () :
96- comm (CPConfig()),
97- graph (GraphPolicy(graybat::pattern::None<GraphPolicy>()())){
96+ comm (new CommunicationPolicy(CPConfig())),
97+ graph (GraphPolicy(graybat::pattern::None<GraphPolicy>()())){
98+
99+ }
98100
99- }
100101
101- ~Cage (){
102- // std::cout << "Destruct Cage" << std::endl;
103- }
102+ // Copy constructor
103+ Cage (Cage &) = delete ;
104+ // Copy assignment constructor
105+ Cage& operator =(Cage &) = delete ;
106+ // Move constructor
107+ Cage (Cage &&) = default ;
108+ // Move assignment constructor
109+ Cage& operator =(Cage &&) = default ;
110+ // Destructor
111+ ~Cage (){ /* std::cout << "Destruct Cage" << std::endl */ }
104112
105113
106114 /* **************************************************************************
107115 *
108116 * MEMBER
109117 *
110118 ***************************************************************************/
111- CommunicationPolicy comm;
119+ std::unique_ptr< CommunicationPolicy> comm;
112120 GraphPolicy graph;
113121 Context graphContext;
114122 std::vector<Vertex> hostedVertices;
@@ -275,8 +283,8 @@ namespace graybat {
275283 */
276284 template <class T_Functor >
277285 void distribute (T_Functor distFunctor){
278- hostedVertices = distFunctor (comm. getGlobalContext ().getVAddr (),
279- comm. getGlobalContext ().size (),
286+ hostedVertices = distFunctor (comm-> getGlobalContext ().getVAddr (),
287+ comm-> getGlobalContext ().size (),
280288 *this );
281289
282290 announce (hostedVertices);
@@ -312,12 +320,12 @@ namespace graybat {
312320 Context oldContext = graphContext;
313321
314322 if (global){
315- oldContext = comm. getGlobalContext ();
323+ oldContext = comm-> getGlobalContext ();
316324 }
317325
318326 assert (oldContext.valid ());
319327
320- graphContext = comm. splitContext (vertices.size (), oldContext);
328+ graphContext = comm-> splitContext (vertices.size (), oldContext);
321329
322330 // Each peer announces the vertices it hosts
323331 if (graphContext.valid ()){
@@ -329,17 +337,17 @@ namespace graybat {
329337 // Send hostedVertices to all other peers
330338 for (auto const &vAddr : graphContext){
331339 assert (nVertices[0 ] != 0 );
332- comm. asyncSend (vAddr, 0 , graphContext, nVertices);
333- comm. asyncSend (vAddr, 0 , graphContext, vertexIDs);
340+ comm-> asyncSend (vAddr, 0 , graphContext, nVertices);
341+ comm-> asyncSend (vAddr, 0 , graphContext, vertexIDs);
334342 }
335343
336344 // Recv hostedVertices from all other peers
337345 for (auto const &vAddr : graphContext){
338346 std::vector<Vertex> remoteVertices;
339347 std::array<unsigned , 1 > nVertices {{ 0 }};
340- comm. recv (vAddr, 0 , graphContext, nVertices);
348+ comm-> recv (vAddr, 0 , graphContext, nVertices);
341349 std::vector<unsigned > vertexIDs (nVertices[0 ]);
342- comm. recv (vAddr, 0 , graphContext, vertexIDs);
350+ comm-> recv (vAddr, 0 , graphContext, vertexIDs);
343351
344352 for (unsigned u : vertexIDs){
345353 vertexMap[u] = vAddr;
@@ -381,7 +389,7 @@ namespace graybat {
381389 }
382390 else {
383391 std::stringstream errorMsg;
384- errorMsg << " [" << comm. getGlobalContext ().getVAddr () << " ] No host of vertex " << vertex.id << " known." ;
392+ errorMsg << " [" << comm-> getGlobalContext ().getVAddr () << " ] No host of vertex " << vertex.id << " known." ;
385393 throw std::runtime_error (errorMsg.str ());
386394 }
387395
@@ -415,7 +423,7 @@ namespace graybat {
415423 }
416424
417425 std::vector<Peer> getPeers (){
418- unsigned nPeers = comm. getGlobalContext ().size ();
426+ unsigned nPeers = comm-> getGlobalContext ().size ();
419427 return std::vector<Peer>(nPeers);
420428 }
421429
@@ -441,7 +449,7 @@ namespace graybat {
441449 template <typename T>
442450 void send (const Edge edge, const T& data){
443451 VAddr destVAddr = locateVertex (edge.target );
444- comm. send (destVAddr, edge.id , graphContext, data);
452+ comm-> send (destVAddr, edge.id , graphContext, data);
445453
446454 }
447455
@@ -461,7 +469,7 @@ namespace graybat {
461469 void send (const Edge edge, const T& data, std::vector<Event> &events){
462470 // std::cout << "send cage:" << edge.target.id << " " << edge.id << std::endl;
463471 VAddr destVAddr = locateVertex (edge.target );
464- events.push_back (comm. asyncSend (destVAddr, edge.id , graphContext, data));
472+ events.push_back (comm-> asyncSend (destVAddr, edge.id , graphContext, data));
465473
466474 }
467475
@@ -478,13 +486,13 @@ namespace graybat {
478486 void recv (const Edge edge, T& data){
479487 // std::cout << "recv cage:" << edge.source.id << " " << edge.id << std::endl;
480488 VAddr srcVAddr = locateVertex (edge.source );
481- comm. recv (srcVAddr, edge.id , graphContext, data);
489+ comm-> recv (srcVAddr, edge.id , graphContext, data);
482490
483491 }
484492
485493 template <typename T>
486494 Edge recv (T& data){
487- Event event = comm. recv (graphContext, data);
495+ Event event = comm-> recv (graphContext, data);
488496
489497 return Edge (graph.getEdgeProperty (event.getTag ()).first ,
490498 getVertex (graph.getEdgeSource (event.getTag ())),
@@ -506,7 +514,7 @@ namespace graybat {
506514 template <typename T>
507515 void recv (const Edge edge, T& data, std::vector<Event> &events){
508516 VAddr srcVAddr = locateVertex (edge.source );
509- events.push_back (comm. asyncRecv (srcVAddr, edge.id , graphContext, data));
517+ events.push_back (comm-> asyncRecv (srcVAddr, edge.id , graphContext, data));
510518
511519 }
512520
@@ -552,10 +560,10 @@ namespace graybat {
552560 if (vertexCount == vertices.size ()){
553561
554562 if (hasRootVertex){
555- comm. reduce (rootVAddr, context, op, reduce, *rootRecvData);
563+ comm-> reduce (rootVAddr, context, op, reduce, *rootRecvData);
556564 }
557565 else {
558- comm. reduce (rootVAddr, context, op, reduce, recvData);
566+ comm-> reduce (rootVAddr, context, op, reduce, recvData);
559567
560568 }
561569
@@ -591,7 +599,7 @@ namespace graybat {
591599 // Finally start reduction
592600 if (vertexCount == vertices.size ()){
593601
594- comm. allReduce (context, op, reduce, *(recvDatas[0 ]));
602+ comm-> allReduce (context, op, reduce, *(recvDatas[0 ]));
595603
596604 // Distribute Received Data to Hosted Vertices
597605 for (unsigned i = 1 ; i < recvDatas.size (); ++i){
@@ -639,7 +647,7 @@ namespace graybat {
639647 if (nGatherCalls == hostedVertices.size ()){
640648 std::vector<unsigned > recvCount;
641649 if (peerHostsRootVertex){
642- comm. gatherVar (rootVAddr, context, gather, *rootRecvData, recvCount);
650+ comm-> gatherVar (rootVAddr, context, gather, *rootRecvData, recvCount);
643651
644652 // Reorder the received data, so that the data
645653 // is in vertex id order. This operation is no
@@ -653,7 +661,7 @@ namespace graybat {
653661
654662 }
655663 else {
656- comm. gatherVar (rootVAddr, context, gather, recvData, recvCount);
664+ comm-> gatherVar (rootVAddr, context, gather, recvData, recvCount);
657665 }
658666
659667 gather.clear ();
@@ -690,7 +698,7 @@ namespace graybat {
690698 if (nGatherCalls == hostedVertices.size ()){
691699 std::vector<unsigned > recvCount;
692700
693- comm. allGatherVar (context, gather, *(recvDatas[0 ]), recvCount);
701+ comm-> allGatherVar (context, gather, *(recvDatas[0 ]), recvCount);
694702
695703 // Reordering code
696704 if (reorder){
@@ -771,7 +779,7 @@ namespace graybat {
771779
772780
773781 void synchronize (){
774- comm. synchronize (graphContext);
782+ comm-> synchronize (graphContext);
775783
776784 }
777785
0 commit comments