Skip to content

Commit

Permalink
running on cluster, lab, and boost
Browse files Browse the repository at this point in the history
  • Loading branch information
JossWhittle committed Aug 23, 2016
1 parent 8b92189 commit 50db6bf
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 31 deletions.
33 changes: 19 additions & 14 deletions MEL/Graph.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,6 @@ SOFTWARE.
#include <stack>
#include <unordered_set>

static size_t count = 0;

template<typename T>
struct DiGraphNode {
T value;
Expand All @@ -45,9 +43,8 @@ struct DiGraphNode {

template<typename MSG>
inline void DeepCopy(MSG &msg) {
count++;
msg & edges;
for (auto e : edges) msg.packSharedPtr(e);
for (auto &e : edges) msg.packSharedPtr(e);
};
};

Expand All @@ -56,13 +53,13 @@ inline DiGraphNode<int>* MakeBTreeGraph(const int numNodes) {
std::vector<DiGraphNode<int>*> nodes(numNodes);
for (int i = 0; i < numNodes; ++i) {
nodes[i] = MEL::MemConstruct<DiGraphNode<int>>(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]);
}
Expand All @@ -71,12 +68,13 @@ inline DiGraphNode<int>* MakeBTreeGraph(const int numNodes) {

inline DiGraphNode<int>* MakeRingGraph(const int numNodes) {
/// Ring Graph
std::vector<DiGraphNode<int>*> nodes;
std::vector<DiGraphNode<int>*> nodes(numNodes);
for (int i = 0; i < numNodes; ++i) {
nodes.push_back(MEL::MemConstruct<DiGraphNode<int>>(i));
nodes[i] = MEL::MemConstruct<DiGraphNode<int>>(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];
Expand All @@ -86,13 +84,14 @@ inline DiGraphNode<int>* MakeRandomGraph(const int numNodes) {
srand(1234567);

/// Random Graph
std::vector<DiGraphNode<int>*> nodes;
std::vector<DiGraphNode<int>*> nodes(numNodes);
for (int i = 0; i < numNodes; ++i) {
nodes.push_back(MEL::MemConstruct<DiGraphNode<int>>(i));
nodes[i] = MEL::MemConstruct<DiGraphNode<int>>(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]);
}
Expand All @@ -102,12 +101,13 @@ inline DiGraphNode<int>* MakeRandomGraph(const int numNodes) {

inline DiGraphNode<int>* MakeFullyConnectedGraph(const int numNodes) {
/// Fully Connected Graph
std::vector<DiGraphNode<int>*> nodes;
std::vector<DiGraphNode<int>*> nodes(numNodes);
for (int i = 0; i < numNodes; ++i) {
nodes.push_back(MEL::MemConstruct<DiGraphNode<int>>(i));
nodes[i] = MEL::MemConstruct<DiGraphNode<int>>(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]);
}
Expand All @@ -134,7 +134,6 @@ inline void DestructGraph(DiGraphNode<int> *&root) {
}
};


int main(int argc, char *argv[]) {
MEL::Init(argc, argv);

Expand All @@ -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<int> *graph = nullptr;
if (rank == 0) {
switch (graphType) {
Expand Down Expand Up @@ -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";
Expand All @@ -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;
Expand Down
33 changes: 17 additions & 16 deletions MEL_deepcopy_experimental.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -52,14 +52,13 @@ namespace MEL {
template<typename T>
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;
Expand Down Expand Up @@ -377,7 +376,7 @@ namespace MEL {

/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

template<typename TRANSPORT_METHOD, typename HASH_MAP = MEL::Deep::PointerHashMap>
template<typename TRANSPORT_METHOD, typename HASH_MAP>
class Message {
private:
/// Members
Expand All @@ -387,7 +386,9 @@ namespace MEL {

template<typename P>
inline enable_if_pointer<P> transport(P &ptr, const int len) {
offset += len * sizeof(std::remove_pointer<P>::type); // where P == T*, find T
typedef typename std::remove_pointer<P>::type T; // where P == T*, find T

offset += len * sizeof(T);
transporter.transport(ptr, len);
};

Expand All @@ -400,8 +401,8 @@ namespace MEL {
template<typename P>
inline enable_if_pointer<P> transportAlloc(P &ptr, const int len) {
if (!TRANSPORT_METHOD::SOURCE) {
typedef std::remove_pointer<P>::type T; // where P == T*, find T
ptr = (len > 0 && ptr != nullptr) ? MEL::MemAlloc<T>(len, T()) : nullptr;
typedef typename std::remove_pointer<P>::type T; // where P == T*, find T
ptr = (len > 0 && ptr != nullptr) ? MEL::MemAlloc<T>(len) : nullptr;
}
transport(ptr, len);
};
Expand Down Expand Up @@ -1104,7 +1105,7 @@ namespace MEL {
Message<TransportBufferWrite, HASH_MAP> msg(buffer, bufferSize);
msg.packVarFootprint(obj);

MEL::Deep::FileWrite(buffer, bufferSize, dst, tag, comm);
MEL::Deep::FileWrite(buffer, bufferSize, file);

MEL::MemFree(buffer);
};
Expand All @@ -1120,7 +1121,7 @@ namespace MEL {
Message<TransportBufferWrite, HASH_MAP> msg(buffer, bufferSize);
msg.packRootPtr(ptr);

MEL::Deep::FileWrite(buffer, bufferSize, dst, tag, comm);
MEL::Deep::FileWrite(buffer, bufferSize, file);

MEL::MemFree(buffer);
};
Expand All @@ -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);
};
Expand Down Expand Up @@ -1184,7 +1185,7 @@ namespace MEL {
inline enable_if_deep_not_pointer<T> 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<TransportBufferRead, HASH_MAP> msg(buffer, bufferSize);
msg.packVarFootprint(obj);
Expand All @@ -1196,7 +1197,7 @@ namespace MEL {
inline enable_if_pointer<P> 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<TransportBufferRead, HASH_MAP> msg(buffer, bufferSize);
ptr = (P) 0x1;
Expand Down Expand Up @@ -1262,7 +1263,7 @@ namespace MEL {
Message<TransportBufferWrite, HASH_MAP> msg(buffer, bufferSize);
msg.packVarFootprint(obj);

MEL::Deep::FileWrite(buffer, bufferSize, dst, tag, comm);
MEL::Deep::FileWrite(buffer, bufferSize, file);

MEL::MemFree(buffer);
};
Expand All @@ -1278,7 +1279,7 @@ namespace MEL {
Message<TransportBufferWrite, HASH_MAP> msg(buffer, bufferSize);
msg.packRootPtr(ptr);

MEL::Deep::FileWrite(buffer, bufferSize, dst, tag, comm);
MEL::Deep::FileWrite(buffer, bufferSize, file);

MEL::MemFree(buffer);
};
Expand All @@ -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);
};
Expand Down Expand Up @@ -1342,7 +1343,7 @@ namespace MEL {
inline enable_if_deep_not_pointer<T> 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<TransportBufferRead, HASH_MAP> msg(buffer, bufferSize);
msg.packVarFootprint(obj);
Expand All @@ -1354,7 +1355,7 @@ namespace MEL {
inline enable_if_pointer<P> 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<TransportBufferRead, HASH_MAP> msg(buffer, bufferSize);
ptr = (P) 0x1;
Expand Down
2 changes: 1 addition & 1 deletion MEL_stream.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -273,7 +273,7 @@ namespace MEL {
write(&val);
}
else {
read(&val));
read(&val);
}
return *this;
};
Expand Down

0 comments on commit 50db6bf

Please sign in to comment.