Skip to content

Commit d0781c8

Browse files
committed
Made cage move constructable
1 parent 8fa1b46 commit d0781c8

File tree

5 files changed

+127
-76
lines changed

5 files changed

+127
-76
lines changed

include/graybat/Cage.hpp

Lines changed: 45 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -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

include/graybat/communicationPolicy/BMPI.hpp

Lines changed: 16 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -103,21 +103,27 @@ namespace graybat {
103103
using Uri = int;
104104

105105
BMPI(Config const) :contextCount(0),
106-
uriMap(0),
107-
initialContext(contextCount, mpi::communicator()){
106+
uriMap(0),
107+
initialContext(contextCount, mpi::communicator()){
108108

109-
uriMap.push_back(std::vector<Uri>());
109+
uriMap.push_back(std::vector<Uri>());
110110

111-
for(auto const &vAddr : initialContext){
112-
uriMap.back().push_back(vAddr);
113-
}
111+
for(auto const &vAddr : initialContext){
112+
uriMap.back().push_back(vAddr);
113+
}
114114

115115
}
116116

117-
// Destructor
118-
~BMPI(){
119-
120-
}
117+
// Copy constructor
118+
BMPI(BMPI&) = delete;
119+
// Copy assignment constructor
120+
BMPI& operator=(BMPI&) = delete;
121+
// Move constructor
122+
BMPI(BMPI&&) = delete;
123+
// Move assignment constructor
124+
BMPI& operator=(BMPI&&) = delete;
125+
// Destructor
126+
~BMPI(){}
121127
/***********************************************************************//**
122128
*
123129
* @name Point to Point Communication Interface

include/graybat/communicationPolicy/ZMQ.hpp

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -151,14 +151,19 @@ namespace graybat {
151151

152152
}
153153

154-
// Destructor
155-
~ZMQ(){
156-
SocketBase::deinit();
157-
}
158-
154+
// Copy constructor
155+
ZMQ(ZMQ &) = delete;
156+
// Copy assignment constructor
157+
ZMQ& operator=(ZMQ &) = delete;
158+
// Move constructor
159159
ZMQ(ZMQ &&other) = delete;
160-
ZMQ(ZMQ &other) = delete;
160+
// Move assignment constructor
161+
ZMQ& operator=(ZMQ &&) = delete;
161162

163+
// Destructor
164+
~ZMQ(){
165+
SocketBase::deinit();
166+
}
162167

163168
/***********************************************************************//**
164169
*

include/graybat/communicationPolicy/socket/Base.hpp

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -89,9 +89,17 @@ namespace graybat {
8989
std::thread recvHandler;
9090
std::thread ctrlHandler;
9191

92-
// Construct/Destruct Methods
92+
// Constructor
9393
Base(Config const config);
94-
94+
// Copy constructor
95+
Base(Base&) = delete;
96+
// Copy assignment constructor
97+
Base& operator=(Base&) = delete;
98+
// Move constructor
99+
Base(Base&&) = delete;
100+
// Move assigment constructor
101+
Base& operator=(Base&&) = delete;
102+
// Destructor
95103
~Base();
96104

97105
void init();

test/CageUT.cpp

Lines changed: 45 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -81,43 +81,67 @@ struct Progress {
8181

8282
};
8383

84+
85+
86+
8487
/*******************************************************************************
8588
* Test Suites
8689
******************************************************************************/
90+
91+
92+
/***************************************************************************
93+
* Test Cases
94+
****************************************************************************/
8795
BOOST_AUTO_TEST_SUITE( graybat_cage_point_to_point_test )
8896

8997

9098
/*******************************************************************************
9199
* Communication Policies to Test
92100
******************************************************************************/
93-
namespace hana = boost::hana;
101+
namespace hana = boost::hana;
94102

95-
size_t const nRuns = 1000;
103+
size_t const nRuns = 1000;
96104

97-
using ZMQ = graybat::communicationPolicy::ZMQ;
98-
using BMPI = graybat::communicationPolicy::BMPI;
99-
using GP = graybat::graphPolicy::BGL<>;
100-
using ZMQCage = graybat::Cage<ZMQ, GP>;
101-
using BMPICage = graybat::Cage<BMPI, GP>;
102-
using ZMQConfig = ZMQ::Config;
103-
using BMPIConfig = BMPI::Config;
105+
using ZMQ = graybat::communicationPolicy::ZMQ;
106+
using BMPI = graybat::communicationPolicy::BMPI;
107+
using GP = graybat::graphPolicy::BGL<>;
108+
using ZMQCage = graybat::Cage<ZMQ, GP>;
109+
using BMPICage = graybat::Cage<BMPI, GP>;
110+
using ZMQConfig = ZMQ::Config;
111+
using BMPIConfig = BMPI::Config;
104112

105-
ZMQConfig zmqConfig = {"tcp://127.0.0.1:5000",
106-
"tcp://127.0.0.1:5001",
107-
static_cast<size_t>(std::stoi(std::getenv("OMPI_COMM_WORLD_SIZE"))),
108-
"context_cage_test"};
113+
ZMQConfig zmqConfig = {"tcp://127.0.0.1:5000",
114+
"tcp://127.0.0.1:5001",
115+
static_cast<size_t>(std::stoi(std::getenv("OMPI_COMM_WORLD_SIZE"))),
116+
"context_cage_test"};
109117

110-
BMPIConfig bmpiConfig;
118+
BMPIConfig bmpiConfig;
111119

112-
ZMQCage zmqCage(zmqConfig);
113-
BMPICage bmpiCage(bmpiConfig);
120+
ZMQCage zmqCage(zmqConfig);
121+
BMPICage bmpiCage(bmpiConfig);
114122

115-
auto cages = hana::make_tuple(std::ref(zmqCage),
116-
std::ref(bmpiCage) );
123+
auto cages = hana::make_tuple(std::ref(zmqCage),
124+
std::ref(bmpiCage) );
125+
126+
// auto cages = hana::make_tuple(std::ref(zmqCage));
127+
128+
129+
130+
BOOST_AUTO_TEST_CASE( move_construct ){
131+
hana::for_each(cages, [](auto cageRef) {
132+
// Test setup
133+
using Cage = typename decltype(cageRef)::type;
134+
135+
// Test run
136+
{
137+
auto &cage = cageRef.get();
138+
auto cage2 = std::move(cage);
139+
std::cout << cage2.getPeers().size() << std::endl;
140+
cage = std::move(cage2);
141+
}
142+
});
143+
}
117144

118-
/***************************************************************************
119-
* Test Cases
120-
****************************************************************************/
121145
BOOST_AUTO_TEST_CASE( send_recv ){
122146
hana::for_each(cages, [](auto cageRef){
123147
// Test setup

0 commit comments

Comments
 (0)