Newer
Older
#include "datastructures/BarnesHutTree.hpp"
int main(int argc, char* argv[]) {
MpiSimulation simulation(argc, argv);
MpiBodyComm comm;
vector<Body> bodies;
if (simulation.getProcessId() == 0) {
bodies = Tree::dubinskiParse(argv[1]);
comm.sendBlocking(1, bodies);
} else {
comm.recvBlocking(0, bodies);
}
MPI::Datatype Btype;
MPI::Datatype type[3] = {MPI::DOUBLE, MPI::DOUBLE, MPI::DOUBLE};
int blocks[3] = {3, 3, 1};
MPI::Aint disp[3];
if (simulation.getProcessId() == 0) {
bodies = Tree::dubinskiParse(argv[1]);
} else {
bodies.reserve(128);
}
disp[0] = MPI::Get_address(&(tb.position[0]));
disp[1] = MPI::Get_address(&(tb.velocity[0]));
disp[2] = MPI::Get_address(&(tb.mass));
Btype = Btype.Create_struct(3, blocks, disp, type);
Btype.Commit();
Btype.Free();
disp[0] = MPI::Get_address(bodies[0].position);
disp[1] = MPI::Get_address(bodies[0].velocity);
disp[2] = MPI::Get_address(&bodies[0].mass);
Btype = Btype.Create_struct(3, blocks, disp, type);
Btype.Commit();
//MPI::COMM_WORLD.Bcast(MPI::BOTTOM, 128, Btype, 0);
if (simulation.getProcessId() == 0) {
MPI::COMM_WORLD.Send(MPI::BOTTOM, 128, Btype, 1, 0);
} else if (simulation.getProcessId() == 1) {
MPI::COMM_WORLD.Recv(MPI::BOTTOM, 128, Btype, 0, 0);
/*
if (simulation.getProcessId() == 0) {
BarnesHutTree tree;
vector<Body> bodies = Tree::dubinskiParse(argv[1]);
cout << bodies.size() << endl;
tree.build(bodies);
if (!tree.isCorrect()) {
cout << "Tree not correct" << endl;
return -1;
}
tree.print();
tree.computeForces();
tree.moveBodies();
tree.rebuildTree();
if (!tree.isCorrect()) {
cout << "Tree not correct" << endl;
return -1;
}
tree.print();
comm.sendBlocking(1, bodies);
} else if (simulation.getProcessId() == 1) {
vector<Body> recved;
comm.recvBlocking(0, recved);
} else {
std::cout << "You need to specify the body input file." << endl;
}