#include "../datastructures/Body.hpp" #include "MpiSimulation.hpp" namespace nbody { MpiSimulation::MpiSimulation(int& argc, char**& argv) { MPI::Datatype types[5] = {MPI::LB, MPI::DOUBLE, MPI::DOUBLE, MPI::DOUBLE, MPI::UB}; int blocklengths[5] = {1, 3, 3, 1, 1}; MPI::Aint displacements[5]; CommBody example; MPI::Init(argc, argv); example.mass = 0.0; example.position[0] = 0.0; example.position[1] = 0.0; example.position[2] = 0.0; example.velocity[0] = 0.0; example.velocity[1] = 0.0; example.velocity[2] = 0.0; displacements[0] = MPI::Get_address(&example); displacements[1] = MPI::Get_address(&example.position[0]); displacements[2] = MPI::Get_address(&example.velocity[0]); displacements[3] = MPI::Get_address(&example.mass); displacements[4] = MPI::Get_address(&example + sizeof(CommBody)); this->mpiBody = this->mpiBody.Create_struct(5, blocklengths, displacements, types); this->mpiBody.Commit(); this->mpiSize = MPI::COMM_WORLD.Get_size(); this->mpiRank = MPI::COMM_WORLD.Get_rank(); MPI::COMM_WORLD.Bcast(&example, 1, this->mpiBody, 0); } MpiSimulation::~MpiSimulation() { this->mpiBody.Free(); MPI::Finalize(); } }