An error occurred while loading the file. Please try again.
-
Paul Heinzlreiter authored64a76f62
MpiSimulation.cpp 2.10 KiB
#include <iostream>
#include "../datastructures/Body.hpp"
#include "MpiSimulation.hpp"
#include "../datastructures/Tree.hpp"
namespace nbody {
using namespace std;
MpiSimulation::MpiSimulation(int& argc, char**& argv) {
Body b[2];
int blocklengths[7] = {1, 3, 3, 3, 1, 1, 1};
MPI::Datatype datatypes[7] = {MPI::LB, MPI::DOUBLE, MPI::DOUBLE, MPI::DOUBLE, MPI::DOUBLE, MPI::BOOL, MPI::UB};
MPI::Aint displacements[7];
MPI::Init(argc, argv);
this->mpiSize = MPI::COMM_WORLD.Get_size();
this->mpiRank = MPI::COMM_WORLD.Get_rank();
this->correctState = true;
this->bodyType = MPI::DATATYPE_NULL;
displacements[0] = MPI::Get_address(&(b[0])) - MPI::Get_address(&(b[0]));
displacements[1] = MPI::Get_address(&(b[0].position[0])) - MPI::Get_address(&(b[0]));
displacements[2] = MPI::Get_address(&(b[0].velocity[0])) - MPI::Get_address(&(b[0]));
displacements[3] = MPI::Get_address(&(b[0].acceleration[0])) - MPI::Get_address(&(b[0]));
displacements[4] = MPI::Get_address(&(b[0].mass)) - MPI::Get_address(&(b[0]));
displacements[5] = MPI::Get_address(&(b[0].refinement)) - MPI::Get_address(&(b[0]));
displacements[6] = MPI::Get_address(&(b[1])) - MPI::Get_address(&(b[0]));
this->bodyType = this->bodyType.Create_struct(7, blocklengths, displacements, datatypes);
this->bodyType.Commit();
if (this->mpiRank == 0) {
if (argc != 2) {
this->correctState = false;
} else {
this->bodies = Tree::dubinskiParse(string(argv[1]));
if (this->bodies.empty()) {
this->correctState = false;
}
}
}
MPI::COMM_WORLD.Bcast(&this->correctState, 1, MPI::BOOL, 0);
MpiBodyComm comm(&this->bodyType);
comm.testing(this->bodies, this->mpiRank);
/*
if (this->mpiRank == 0) {
comm.sendBlocking(1, this->bodies);
} else if (this->mpiRank == 0) {
comm.recvBlocking(0, this->bodies);
}
*/
}
bool MpiSimulation::stateCorrect() {
return this->correctState;
}
MpiSimulation::~MpiSimulation() {
this->bodyType.Free();
MPI::Finalize();
}
int MpiSimulation::getNumberOfProcesses() {
return this->mpiSize;
}
int MpiSimulation::getProcessId() {
return this->mpiRank;
}
}