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

* unblocking send

parent e8515bf5
Branches
No related merge requests found
......@@ -5,6 +5,7 @@ namespace nbody {
using namespace std;
MpiBodyComm::MpiBodyComm(MPI::Datatype* bodyDatatype) {
//keep pointer to datatype for send/recv
this->datatype = bodyDatatype;
this->request = MPI::REQUEST_NULL;
}
......@@ -13,7 +14,8 @@ namespace nbody {
if (this->request != MPI::REQUEST_NULL) {
//wait for termination of possibly open request
this->request.Wait();
this->request.Free();
//TODO: check why request cannot be freed
//this->request.Free();
}
}
......@@ -27,17 +29,17 @@ namespace nbody {
int currentSource;
int currentSize;
//check for message beforehand to get number of bodies transmitted
//check for actual source because input parameter could be MPI::ANY_SOURCE
MPI::COMM_WORLD.Probe(source, 0, status);
currentSource = status.Get_source();
currentSize = status.Get_count(*this->datatype);
//allocate correct vector size for incoming data
bodies.resize(currentSize);
MPI::COMM_WORLD.Recv(&bodies[0], currentSize, *this->datatype, currentSource, 0);
}
/*
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;
......@@ -45,20 +47,11 @@ namespace nbody {
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);
this->buffer.resize(bodies.size());
std::copy(bodies.begin(), bodies.end(), this->buffer.begin());
this->request = MPI::COMM_WORLD.Isend(&this->buffer[0], this->buffer.size(), *this->datatype, target, 0);
return true;
}
*/
/*
void MpiBodyComm::setupDatatype(vector<Body> bodies) {
......
......@@ -18,7 +18,7 @@ namespace nbody {
virtual ~MpiBodyComm();
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 sendUnblocking(int target, vector<Body> bodies);
/*
virtual bool sendBlocking(int target, vector<Body> bodies);
virtual bool sendUnblocking(int target, vector<Body> bodies);
......
......@@ -41,7 +41,7 @@ namespace nbody {
MpiBodyComm comm(&this->bodyType);
if (this->mpiRank == 0) {
comm.sendBlocking(1, this->bodies);
comm.sendUnblocking(1, this->bodies);
} else if (this->mpiRank == 1) {
comm.recvBlocking(0, this->bodies);
cout << "SIZE: " << 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