diff --git a/MEL/Graph.cpp b/MEL/Graph.cpp index 0f61f8b..3f88387 100644 --- a/MEL/Graph.cpp +++ b/MEL/Graph.cpp @@ -33,8 +33,6 @@ SOFTWARE. #include #include -static size_t count = 0; - template struct DiGraphNode { T value; @@ -45,9 +43,8 @@ struct DiGraphNode { template inline void DeepCopy(MSG &msg) { - count++; msg & edges; - for (auto e : edges) msg.packSharedPtr(e); + for (auto &e : edges) msg.packSharedPtr(e); }; }; @@ -56,13 +53,13 @@ inline DiGraphNode* MakeBTreeGraph(const int numNodes) { std::vector*> nodes(numNodes); for (int i = 0; i < numNodes; ++i) { nodes[i] = MEL::MemConstruct>(i); - nodes[i]->edges.reserve(2); } if (numNodes > 1) nodes[0]->edges.push_back(nodes[1]); for (int i = 1; i < numNodes; ++i) { const int j = ((i - 1) * 2) + 2; + nodes[i]->edges.reserve(2); if (j < numNodes) nodes[i]->edges.push_back(nodes[j]); if ((j + 1) < numNodes) nodes[i]->edges.push_back(nodes[j + 1]); } @@ -71,12 +68,13 @@ inline DiGraphNode* MakeBTreeGraph(const int numNodes) { inline DiGraphNode* MakeRingGraph(const int numNodes) { /// Ring Graph - std::vector*> nodes; + std::vector*> nodes(numNodes); for (int i = 0; i < numNodes; ++i) { - nodes.push_back(MEL::MemConstruct>(i)); + nodes[i] = MEL::MemConstruct>(i); } for (int i = 0; i < numNodes; ++i) { + nodes[i]->edges.reserve(1); nodes[i]->edges.push_back(nodes[(i + 1) % numNodes]); } return nodes[0]; @@ -86,13 +84,14 @@ inline DiGraphNode* MakeRandomGraph(const int numNodes) { srand(1234567); /// Random Graph - std::vector*> nodes; + std::vector*> nodes(numNodes); for (int i = 0; i < numNodes; ++i) { - nodes.push_back(MEL::MemConstruct>(i)); + nodes[i] = MEL::MemConstruct>(i); } for (int i = 0; i < numNodes; ++i) { const int numEdges = rand() % numNodes; + nodes[i]->edges.reserve(numEdges); for (int j = 0; j < numEdges; ++j) { nodes[i]->edges.push_back(nodes[rand() % numNodes]); } @@ -102,12 +101,13 @@ inline DiGraphNode* MakeRandomGraph(const int numNodes) { inline DiGraphNode* MakeFullyConnectedGraph(const int numNodes) { /// Fully Connected Graph - std::vector*> nodes; + std::vector*> nodes(numNodes); for (int i = 0; i < numNodes; ++i) { - nodes.push_back(MEL::MemConstruct>(i)); + nodes[i] = MEL::MemConstruct>(i); } for (int i = 0; i < numNodes; ++i) { + nodes[i]->edges.reserve(numNodes); for (int j = 0; j < numNodes; ++j) { nodes[i]->edges.push_back(nodes[j]); } @@ -134,7 +134,6 @@ inline void DestructGraph(DiGraphNode *&root) { } }; - int main(int argc, char *argv[]) { MEL::Init(argc, argv); @@ -148,9 +147,10 @@ int main(int argc, char *argv[]) { MEL::Exit(-1); } - const int numNodes = 1 << std::stoi(argv[1]), // 2^n nodes + const int numNodes = 1 << std::stoi(argv[1]), // 2^n nodes graphType = std::stoi(argv[2]); + DiGraphNode *graph = nullptr; if (rank == 0) { switch (graphType) { @@ -184,6 +184,8 @@ int main(int argc, char *argv[]) { std::cout << "Broadcast Graph in " << (endTime - startTime) << " seconds..." << std::endl; } + MEL::Barrier(comm); + // File name for output std::stringstream sstr; sstr << "rank=" << rank << " type=" << graphType << " nodes=" << numNodes << ".graph"; @@ -195,8 +197,11 @@ int main(int argc, char *argv[]) { graphFile.close(); } + MEL::Barrier(comm); + DestructGraph(graph); - std::cout << "Done." << std::endl; + + if (rank == 0) std::cout << "Done." << std::endl; MEL::Finalize(); return 0; diff --git a/MEL_deepcopy_experimental.hpp b/MEL_deepcopy_experimental.hpp index 08042ca..4f78b00 100644 --- a/MEL_deepcopy_experimental.hpp +++ b/MEL_deepcopy_experimental.hpp @@ -52,14 +52,13 @@ namespace MEL { template inline void transport(T *&ptr, const int len) { stream.write(ptr, len); - offset += len * sizeof(T); }; }; class TransportRecvStream { private: /// Members - MEL::Send_stream stream; + MEL::Recv_stream stream; public: static constexpr bool SOURCE = false; @@ -377,7 +376,7 @@ namespace MEL { ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// - template + template class Message { private: /// Members @@ -387,7 +386,9 @@ namespace MEL { template inline enable_if_pointer

transport(P &ptr, const int len) { - offset += len * sizeof(std::remove_pointer

::type); // where P == T*, find T + typedef typename std::remove_pointer

::type T; // where P == T*, find T + + offset += len * sizeof(T); transporter.transport(ptr, len); }; @@ -400,8 +401,8 @@ namespace MEL { template inline enable_if_pointer

transportAlloc(P &ptr, const int len) { if (!TRANSPORT_METHOD::SOURCE) { - typedef std::remove_pointer

::type T; // where P == T*, find T - ptr = (len > 0 && ptr != nullptr) ? MEL::MemAlloc(len, T()) : nullptr; + typedef typename std::remove_pointer

::type T; // where P == T*, find T + ptr = (len > 0 && ptr != nullptr) ? MEL::MemAlloc(len) : nullptr; } transport(ptr, len); }; @@ -1104,7 +1105,7 @@ namespace MEL { Message msg(buffer, bufferSize); msg.packVarFootprint(obj); - MEL::Deep::FileWrite(buffer, bufferSize, dst, tag, comm); + MEL::Deep::FileWrite(buffer, bufferSize, file); MEL::MemFree(buffer); }; @@ -1120,7 +1121,7 @@ namespace MEL { Message msg(buffer, bufferSize); msg.packRootPtr(ptr); - MEL::Deep::FileWrite(buffer, bufferSize, dst, tag, comm); + MEL::Deep::FileWrite(buffer, bufferSize, file); MEL::MemFree(buffer); }; @@ -1137,7 +1138,7 @@ namespace MEL { msg.packVarFootprint(len); msg.packRootPtr(ptr, len); - MEL::Deep::FileWrite(buffer, bufferSize, dst, tag, comm); + MEL::Deep::FileWrite(buffer, bufferSize, file); MEL::MemFree(buffer); }; @@ -1184,7 +1185,7 @@ namespace MEL { inline enable_if_deep_not_pointer BufferedFileRead(T &obj, MEL::File &file) { int bufferSize; char *buffer = nullptr; - MEL::Deep::FileRead(buffer, bufferSize, src, tag, comm); + MEL::Deep::FileRead(buffer, bufferSize, file); Message msg(buffer, bufferSize); msg.packVarFootprint(obj); @@ -1196,7 +1197,7 @@ namespace MEL { inline enable_if_pointer

BufferedFileRead(P &ptr, MEL::File &file) { int bufferSize; char *buffer = nullptr; - MEL::Deep::FileRead(buffer, bufferSize, src, tag, comm); + MEL::Deep::FileRead(buffer, bufferSize, file); Message msg(buffer, bufferSize); ptr = (P) 0x1; @@ -1262,7 +1263,7 @@ namespace MEL { Message msg(buffer, bufferSize); msg.packVarFootprint(obj); - MEL::Deep::FileWrite(buffer, bufferSize, dst, tag, comm); + MEL::Deep::FileWrite(buffer, bufferSize, file); MEL::MemFree(buffer); }; @@ -1278,7 +1279,7 @@ namespace MEL { Message msg(buffer, bufferSize); msg.packRootPtr(ptr); - MEL::Deep::FileWrite(buffer, bufferSize, dst, tag, comm); + MEL::Deep::FileWrite(buffer, bufferSize, file); MEL::MemFree(buffer); }; @@ -1295,7 +1296,7 @@ namespace MEL { msg.packVarFootprint(len); msg.packRootPtr(ptr, len); - MEL::Deep::FileWrite(buffer, bufferSize, dst, tag, comm); + MEL::Deep::FileWrite(buffer, bufferSize, file); MEL::MemFree(buffer); }; @@ -1342,7 +1343,7 @@ namespace MEL { inline enable_if_deep_not_pointer BufferedFileRead(T &obj, std::ifstream &file) { int bufferSize; char *buffer = nullptr; - MEL::Deep::FileRead(buffer, bufferSize, src, tag, comm); + MEL::Deep::FileRead(buffer, bufferSize, file); Message msg(buffer, bufferSize); msg.packVarFootprint(obj); @@ -1354,7 +1355,7 @@ namespace MEL { inline enable_if_pointer

BufferedFileRead(P &ptr, std::ifstream &file) { int bufferSize; char *buffer = nullptr; - MEL::Deep::FileRead(buffer, bufferSize, src, tag, comm); + MEL::Deep::FileRead(buffer, bufferSize, file); Message msg(buffer, bufferSize); ptr = (P) 0x1; diff --git a/MEL_stream.hpp b/MEL_stream.hpp index b1b3296..1e01b04 100644 --- a/MEL_stream.hpp +++ b/MEL_stream.hpp @@ -273,7 +273,7 @@ namespace MEL { write(&val); } else { - read(&val)); + read(&val); } return *this; };