Skip to content
Snippets Groups Projects
Commit e8806b8d authored by Paul Heinzlreiter's avatar Paul Heinzlreiter
Browse files

* debugging

parent a84f75c9
Branches
No related merge requests found
#include <mpi.h>
#include <vector>
#include <iostream>
#include "datastructures/Body.hpp"
int main(int argc, char** argv) {
......@@ -11,27 +12,54 @@ int main(int argc, char** argv) {
MPI::Datatype type[3] = {MPI::DOUBLE, MPI::DOUBLE, MPI::DOUBLE};
int blocks[3] = {3, 3, 1};
MPI::Aint disp[3];
vector<Body> data;
Body data[16];
if (MPI::COMM_WORLD.Get_rank() == 0) {
for (int i = 0; i < 16; i++) {
Body b;
Body b((double) i, (double) i, (double) i);
data.push_back(b);
data[i] = b;
}
if (MPI::COMM_WORLD.Get_rank() == 0) {
for (int i = 0; i < 16; i++) {
cout << MPI::COMM_WORLD.Get_rank() << " " << data[i].position[0] << endl;
}
}
} else {
data.reserve(16);
for (int i = 0; i < 16; i++) {
Body b((double) 0, (double) 0, (double) 0);
data[i] = b;
}
if (MPI::COMM_WORLD.Get_rank() != 0) {
for (int i = 0; i < 16; i++) {
cout << MPI::COMM_WORLD.Get_rank() << " " << data[i].position[0] << endl;
}
}
}
/*
disp[0] = MPI::Get_address(data[0].position);
disp[1] = MPI::Get_address(data[0].velocity);
disp[2] = MPI::Get_address(&data[0].mass);
*/
disp[0] = MPI::Get_address(data[0].position) - MPI::Get_address(&data[0]);
disp[1] = MPI::Get_address(data[0].velocity) - MPI::Get_address(&data[0]);
disp[2] = MPI::Get_address(&data[0].mass) - MPI::Get_address(&data[0]);
Btype = Btype.Create_struct(3, blocks, disp, type);
Btype.Commit();
MPI::COMM_WORLD.Bcast(MPI::BOTTOM, 16, Btype, 0);
cout << "------" << endl;
Btype.Free();
if (MPI::COMM_WORLD.Get_rank() != 0) {
for (int i = 0; i < 16; i++) {
cout << MPI::COMM_WORLD.Get_rank() << " " << data[i].position[0] << endl;
}
}
MPI::Finalize();
/*
MPI::Datatype Btype;
......
......@@ -11,36 +11,27 @@ namespace nbody {
this->blocklengths[0] = 3;
this->blocklengths[1] = 3;
this->blocklengths[2] = 1;
//setup initial data type and initialize request for tracking status of unblocking send
/*
this->datatypes[0] = MPI::DOUBLE;
this->datatypes[1] = MPI::DOUBLE;
this->datatypes[2] = MPI::DOUBLE;
this->blocklengths[0] = 3;
this->blocklengths[1] = 3;
this->blocklengths[2] = 1;
this->request = MPI::REQUEST_NULL;
this->commBodyType = MPI::DATATYPE_NULL;
*/
this->sendBodyType = MPI::DATATYPE_NULL;
this->recvBodyType = MPI::DATATYPE_NULL;
}
MpiBodyComm::~MpiBodyComm() {
/*
if (this->request != MPI::REQUEST_NULL) {
//wait for termination of possibly open request
this->request.Wait();
this->request.Free();
//this->request.Free();
}
if (this->commBodyType != MPI::DATATYPE_NULL) {
this->commBodyType.Free();
if (this->sendBodyType != MPI::DATATYPE_NULL) {
this->sendBodyType.Free();
}
if (this->recvBodyType != MPI::DATATYPE_NULL) {
this->recvBodyType.Free();
}
*/
}
bool MpiBodyComm::sendBlocking(int target, vector<Body> bodies) {
//TODO: check for unfinished send
void MpiBodyComm::sendBlocking(int target, vector<Body> bodies) {
MPI::Datatype btype = MPI::DATATYPE_NULL;
MPI::Aint displ[3];
......@@ -49,10 +40,8 @@ namespace nbody {
displ[2] = MPI::Get_address(&(bodies[0].mass));
btype = btype.Create_struct(3, this->blocklengths, displ, this->datatypes);
btype.Commit();
MPI::COMM_WORLD.Send(MPI::BOTTOM, bodies.size(), btype, target, 0);
btype.Free();
return false;
}
void MpiBodyComm::recvBlocking(int source, vector<Body>& bodies) {
......@@ -60,31 +49,52 @@ namespace nbody {
Body templateBody;
MPI::Datatype btype = MPI::DATATYPE_NULL;
MPI::Aint displ[3];
int currentSource;
displ[0] = MPI::Get_address(templateBody.position);
displ[1] = MPI::Get_address(templateBody.velocity);
displ[2] = MPI::Get_address(&(templateBody.mass));
btype = btype.Create_struct(3, this->blocklengths, displ, this->datatypes);
btype.Commit();
while (!MPI::COMM_WORLD.Iprobe(source, 0, status));
cout << "RECVED " << status.Get_count(btype) << endl;
currentSource = status.Get_source();
bodies.clear();
bodies.reserve(status.Get_count(btype));
cout << "BRG " << status.Get_count(btype) << endl;
bodies.reserve(status.Get_count(btype));
btype.Free();
displ[0] = MPI::Get_address(bodies[0].position);
displ[1] = MPI::Get_address(bodies[0].velocity);
displ[2] = MPI::Get_address(&(bodies[0].mass));
btype = btype.Create_struct(3, this->blocklengths, displ, this->datatypes);
btype.Commit();
MPI::COMM_WORLD.Recv(MPI::BOTTOM, status.Get_count(btype), btype, source, 0);
MPI::COMM_WORLD.Recv(MPI::BOTTOM, status.Get_count(btype), btype, currentSource, 0);
btype.Free();
//MPI::COMM_WORLD.Recv(MPI::BOTTOM, bodySize, btype, 0, 0);
//cout << "RECVED " << bodySize << " " << status.Get_count(btype) << endl;
}
bool MpiBodyComm::sendUnblocking(int target, vector<Body> bodies) {
MPI::Aint displ[3];
if (this->request != MPI::REQUEST_NULL && !this->request.Test()) {
//unblocking send still not finished
return false;
}
if (this->request != MPI::REQUEST_NULL) {
this->request.Free();
}
this->buffer.clear();
this->buffer = bodies;
if (this->sendBodyType != MPI::DATATYPE_NULL) {
this->sendBodyType.Free();
}
displ[0] = MPI::Get_address(bodies[0].position);
displ[1] = MPI::Get_address(bodies[0].velocity);
displ[2] = MPI::Get_address(&(bodies[0].mass));
this->sendBodyType = this->sendBodyType.Create_struct(3, this->blocklengths, displ, this->datatypes);
this->sendBodyType.Commit();
this->request = MPI::COMM_WORLD.Isend(MPI::BOTTOM, this->buffer.size(), this->sendBodyType, target, 0);
return true;
}
/*
......
......@@ -12,6 +12,10 @@ namespace nbody {
protected:
int blocklengths[3];
MPI::Datatype datatypes[3];
MPI::Request request;
vector<Body> buffer;
MPI::Datatype sendBodyType;
MPI::Datatype recvBodyType;
/*
MPI::Datatype commBodyType;
MPI::Datatype datatypes[3];
......@@ -29,8 +33,9 @@ namespace nbody {
MpiBodyComm();
virtual ~MpiBodyComm();
virtual void testing(vector<Body>& data, int myRank);
virtual bool sendBlocking(int target, vector<Body> bodies);
virtual void sendBlocking(int target, vector<Body> bodies);
virtual void recvBlocking(int source, vector<Body>& bodies);
virtual bool sendUnblocking(int target, vector<Body> bodies);
/*
virtual bool sendBlocking(int target, vector<Body> bodies);
virtual bool sendUnblocking(int target, vector<Body> bodies);
......
#include <iostream>
#include "../datastructures/Body.hpp"
#include "MpiSimulation.hpp"
#include "../datastructures/Tree.hpp"
namespace nbody {
using namespace std;
MpiSimulation::MpiSimulation(int& argc, char**& argv) {
MPI::Init(argc, argv);
this->mpiSize = MPI::COMM_WORLD.Get_size();
......@@ -28,6 +31,7 @@ namespace nbody {
comm.sendBlocking(1, this->bodies);
} else if (this->mpiRank == 1) {
comm.recvBlocking(0, this->bodies);
cout << "recveded " << this->bodies.size() << endl;
}
}
......
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment