Commit d583ce09 authored by Pavel Moravec's avatar Pavel Moravec
Browse files

Remove extra spaces

parent a7891194
......@@ -7,25 +7,25 @@
void Director::respond_getNextAvailAgentID()
{
communicator->sendNextID(getNextAvailAgentID());
communicator->sendNextID(getNextAvailAgentID());
}
void Director::respond_startNewAgent()
{
communicator->sendACKtoLastFO(); //send requested ACK back, maybe unneccessary?
communicator->sendACKtoLastFO(); //send requested ACK back, maybe unneccessary?
}
void Director::respond_closeAgent()
{
communicator->sendACKtoLastFO(); //send requested ACK back, maybe unneccessary?
communicator->sendACKtoLastFO(); //send requested ACK back, maybe unneccessary?
}
void Director::respond_updateParentalLink()
{
communicator->sendACKtoLastFO(); //send requested ACK back, maybe unneccessary?
communicator->sendACKtoLastFO(); //send requested ACK back, maybe unneccessary?
}
......@@ -82,7 +82,7 @@ void Director::waitHereUntilEveryoneIsHereToo(/*int stage?*/) //Will this work w
{
char buffer[DIRECTOR_RECV_MAX] = {0};
int ibuffer[DIRECTOR_RECV_MAX] = {0};
int items;
e_comm_tags tag;
fprintf(stderr, "Running detection loop in Director\n");
......@@ -116,18 +116,18 @@ void Director::waitHereUntilEveryoneIsHereToo(/*int stage?*/) //Will this work w
assert(items == 2);
closeAgent(ibuffer[0], ibuffer[1]);
respond_closeAgent();
break;
break;
case e_comm_tags::next_stage:
communicator->receiveFOMessage(buffer, items, instance, tag);
break;
default:
fprintf(stderr,"Unprocessed communication tag %i on Director\n", tag);
communicator->receiveFOMessage(buffer, items, instance, tag);
//PM: Mark client as done and if all are done leave the cycle
//PM: Mark client as done and if all are done leave the cycle
break;
}
} while(tag != e_comm_tags::next_stage);
fprintf(stderr, "Ending detection loop in Director, will send sync\n");
//communicator->sendSync()
......
......@@ -18,7 +18,7 @@ int MPI_Communicator::init(int *argc, char ***argv) {
MPI_Comm_size(MPI_COMM_WORLD, &instances);
MPI_Comm_rank(MPI_COMM_WORLD, &instance_ID);
const int v3d_count = 3;
int v3d_blocks[] = {1,1,1};
MPI_Aint v3d_displ[] = {offsetof(Vector3d<float>, x), offsetof(Vector3d<float>, y), offsetof(Vector3d<float>, z) };
......@@ -55,7 +55,7 @@ int MPI_Communicator::init(int *argc, char ***argv) {
}
shift = sizeof(int)*8 - cshift;
DEBUG_REPORT("Shift agent ID by " << shift << " bits\n");
MPI_Get_processor_name(processor_name, &name_len);
return state;
}
......@@ -68,20 +68,20 @@ bool MPI_Communicator::detectMPIMessage(MPI_Comm comm, int peer, e_comm_tags & t
int state = MPI_Iprobe(peer, MPI_tag, comm, &flag, &status);
if (state != MPI_SUCCESS) { return false; }
if (flag) {
if (flag) {
//debugMPIComm("Poll", comm, flag, peer, tag);
tag = (e_comm_tags) status.MPI_TAG;
}
return flag; // Message available
tag = (e_comm_tags) status.MPI_TAG;
}
return flag; // Message available
}
bool MPI_Communicator::receiveAndProcessDirectorMessage(void * buffer, int &recv_size, e_comm_tags &tag) {
MPI_Status status;
bool result;
int state;
// do { --
// do { --
result = detectMPIMessage(director_comm, DIRECTOR_ID, tag);
if (result) {
return receiveDirectorMessage(buffer, recv_size, tag);
......@@ -119,7 +119,7 @@ bool MPI_Communicator::receiveFOMessage(void * buffer, int &recv_size, int & ins
int state;
if (instance_ID == 0) { instance_ID = MPI_ANY_SOURCE;}
state = receiveMPIMessage(director_comm, buffer, recv_size, MPI_CHAR, &status, instance_ID, tag);
if (state == MPI_SUCCESS) {
tag = (e_comm_tags) status.MPI_TAG;
......@@ -167,43 +167,43 @@ void MPI_Communicator::startNewDaughterAgent(const int childID, const int parent
//fprintf(stderr, "MPI_SEND to %i startNewDaughterAgent %i of agent %i\n", childID, parentID);
}
void MPI_Communicator::setAgentsDetailedDrawingMode(int FO, int agentID, bool state)
void MPI_Communicator::setAgentsDetailedDrawingMode(int FO, int agentID, bool state)
{
int buffer [] = {agentID, state};
sendFO(buffer, sizeof(buffer)/sizeof(int), FO, e_comm_tags::set_detailed_drawing);
receiveFOACK(FO);
receiveFOACK(FO);
}
void MPI_Communicator::setAgentsDetailedReportingMode(int FO, int agentID, bool state)
void MPI_Communicator::setAgentsDetailedReportingMode(int FO, int agentID, bool state)
{
int buffer [] = {agentID, state};
sendFO(buffer, sizeof(buffer)/sizeof(int), FO, e_comm_tags::set_detailed_reporting);
receiveFOACK(FO);
receiveFOACK(FO);
}
void MPI_Communicator::publishAgentsAABBs(int FO)
void MPI_Communicator::publishAgentsAABBs(int FO)
{
int buffer [] = {0};
sendFO(buffer, 0, FO, e_comm_tags::send_AABB);
receiveFOACK(FO);
receiveFOACK(FO);
}
void MPI_Communicator::renderNextFrame(int FO)
void MPI_Communicator::renderNextFrame(int FO)
{
int buffer [] = {0};
sendFO(buffer, 0, FO, e_comm_tags::render_frame);
receiveFOACK(FO);
receiveFOACK(FO);
}
size_t MPI_Communicator::cntOfAABBs(int FO)
size_t MPI_Communicator::cntOfAABBs(int FO)
{
e_comm_tags tag = e_comm_tags::count_AABB;
int buffer [] = {0};
int id_cnt = 1;
sendFO(buffer, 0, FO, e_comm_tags::count_AABB);
receiveFOMessage(buffer, id_cnt, FO, tag);
return buffer[0];
return buffer[0];
}
void MPI_Communicator::sendCntOfAABBs(size_t count_AABBs)
......
......@@ -12,7 +12,7 @@ typedef struct {
int atype; // Agent Type ID, from agent
} t_aabb;
#define StringsImprintSize 256 //This should be moved to some common header file with strings
#define StringsImprintSize 256 //This should be moved to some common header file with strings
typedef struct {
size_t hash;
......@@ -67,7 +67,7 @@ public:
virtual int sendDirector(void *data, int count, e_comm_tags tag) = 0;
virtual bool receiveAndProcessDirectorMessage(void * buffer, int &recv_size, e_comm_tags &tag) = 0;
virtual bool receiveDirectorMessage(void * buffer, int &recv_size, e_comm_tags &tag) = 0;
virtual bool receiveDirectorMessage(void * buffer, int &recv_size, e_comm_tags &tag) = 0;
inline int sendACKtoDirector() {
char id = 0;
......@@ -76,9 +76,9 @@ public:
inline void receiveDirectorACK() {
e_comm_tags tag = e_comm_tags::ACK; //Should we use ::unspecified instead?
receiveDirectorMessage(director_buffer, director_buffer_size, tag);
receiveDirectorMessage(director_buffer, director_buffer_size, tag);
}
inline void waitSync() {
e_comm_tags tag = e_comm_tags::next_stage;
//fprintf(stderr, "waitSync called\n");
......@@ -91,17 +91,17 @@ public:
sendNextFO(NULL, 0, e_comm_tags::next_stage);
}
}
/*** Front officer communication channels */
virtual e_comm_tags detectFOMessage() = 0;
virtual bool receiveFOMessage(void * buffer, int &recv_size, int & instance_ID, e_comm_tags &tag) = 0; //Single reception step, for response messages
virtual bool receiveFOMessage(void * buffer, int &recv_size, int & instance_ID, e_comm_tags &tag) = 0; //Single reception step, for response messages
virtual int sendFO(void *data, int count, int instance_ID, e_comm_tags tag) = 0;
inline int sendLastFO(void *data, int count, e_comm_tags tag) {
return sendFO(data, count, lastFOID, tag);
}
inline int sendACKtoLastFO() {
char id = 0;
return sendLastFO(&id, 0, e_comm_tags::ACK); // We could also store last tag and send it back instead of ACK
......@@ -109,26 +109,26 @@ public:
inline void receiveFOACK(int FO) {
e_comm_tags tag = e_comm_tags::ACK; //Should we use ::unspecified instead?
receiveFOMessage(director_buffer, director_buffer_size, FO, tag);
receiveFOMessage(director_buffer, director_buffer_size, FO, tag);
}
inline int sendNextFO(void *data, int count, e_comm_tags tag) {
inline int sendNextFO(void *data, int count, e_comm_tags tag) {
return sendFO(data, count, (instance_ID+1) % instances, tag);
}
inline virtual int sendPrevFO(void *data, int count, e_comm_tags tag) { // Is this method needed at all?
return sendFO(data, count, (instance_ID+instances-1) % instances, tag);
}
}
inline int receiveAndProcessNextFOMessages(e_comm_tags tag = e_comm_tags::unspecified) {
int toFO = (instance_ID + 1) % instances;
return receiveFOMessage(director_buffer, director_buffer_size, toFO, tag);
return receiveFOMessage(director_buffer, director_buffer_size, toFO, tag);
}
inline int receiveAndProcessPrevFOMessages(e_comm_tags tag = e_comm_tags::unspecified) {
int toFO = (instance_ID + instances - 1) % instances;
return receiveFOMessage(director_buffer, director_buffer_size, toFO, tag);
return receiveFOMessage(director_buffer, director_buffer_size, toFO, tag);
}
/*** Specific communication methods ***/
......@@ -137,25 +137,25 @@ public:
/*{
return (instance_ID << shift) | (++internal_agent_ID); //Recalculate better to take into account milions of cells!!!
}*/
virtual void startNewAgent(const int newAgentID, const int associatedFO, const bool wantsToAppearInCTCtracksTXTfile = true) = 0;
virtual void closeAgent(const int agentID, const int associatedFO) = 0;
virtual void startNewDaughterAgent(const int childID, const int parentID) = 0;
virtual void publishAgentsAABBs(int FO) = 0;
virtual void waitFor_publishAgentsAABBs() = 0;
virtual void waitFor_renderNextFrame() = 0;
virtual void sendNextID(int id) = 0;
virtual void setAgentsDetailedDrawingMode(int FO, int agentID, bool state) = 0;
virtual void setAgentsDetailedReportingMode(int FO, int agentID, bool state) = 0;
virtual size_t cntOfAABBs(int FO) = 0;
virtual void sendCntOfAABBs(size_t count_AABBs) = 0;
virtual void renderNextFrame(int FO) = 0;
protected:
int instance_ID;
int instances;
......@@ -163,7 +163,7 @@ protected:
int internal_agent_ID;
int lastFOID;
int hasSent;
int shift; // Shift ID by given number of bits, to reduce communication for getNextAvailAgentID, maybe rework later
static e_comm_tags messageType; // Message type enum for sending/receiving individual distributed messages
......@@ -192,13 +192,13 @@ public:
virtual void startNewAgent(const int newAgentID, const int associatedFO, const bool wantsToAppearInCTCtracksTXTfile = true);
virtual void closeAgent(const int agentID, const int associatedFO);
virtual void startNewDaughterAgent(const int childID, const int parentID);
virtual void publishAgentsAABBs(int FO);
virtual void waitFor_publishAgentsAABBs();
virtual void waitFor_renderNextFrame();
virtual void sendNextID(int id);
virtual void setAgentsDetailedDrawingMode(int FO, int agentID, bool state);
virtual void setAgentsDetailedReportingMode(int FO, int agentID, bool state);
virtual size_t cntOfAABBs(int FO);
......@@ -211,25 +211,25 @@ public:
return sendMPIMessage(director_comm, data, count, tagMap(tag), 0, tag);
}
virtual e_comm_tags detectFOMessage();
virtual e_comm_tags detectFOMessage();
virtual int sendFO(void *data, int count, int instance_ID, e_comm_tags tag) {
return sendMPIMessage(director_comm, data, count, tagMap(tag), instance_ID, tag);
}
//boot receiveAndProcessDirectorMessagesForDirector(Director & director....
virtual bool receiveAndProcessDirectorMessage(void * buffer, int &recv_size, e_comm_tags &tag); //Probably not needed to run in cycle if notifications separate, only director needs cycle
virtual bool receiveDirectorMessage(void * buffer, int &recv_size, e_comm_tags &tag); //Single reception step, for request-response messages
virtual bool receiveDirectorMessage(void * buffer, int &recv_size, e_comm_tags &tag); //Single reception step, for request-response messages
/*** Front officer communication channels */
virtual bool receiveFOMessage(void * buffer, int &recv_size, int & instance_ID, e_comm_tags &tag); //Single reception step, for response messages
virtual bool receiveFOMessage(void * buffer, int &recv_size, int & instance_ID, e_comm_tags &tag); //Single reception step, for response messages
virtual void close();
protected:
char processor_name[MPI_MAX_PROCESSOR_NAME];
int name_len;
int init(int *argc, char ***argv);
inline void debugMPIComm(const char* what, MPI_Comm comm, int items, int peer=MPI_ANY_SOURCE, e_comm_tags tag = e_comm_tags::unspecified) {
......@@ -240,7 +240,7 @@ protected:
REPORT(what << " MPI message at " << instance_ID << " via " << cname << " P" << peer << "/I" << items << "/T" << tag);
#endif
}
inline int sendMPIMessage(MPI_Comm comm, void *data, int items, MPI_Datatype datatype, int peer=0, e_comm_tags tag = e_comm_tags::unspecified) {
int tag2 = (tag == e_comm_tags::unspecified)?MPI_ANY_TAG:tag;
debugMPIComm("Send", comm, items, peer, tag);
......@@ -252,23 +252,23 @@ protected:
debugMPIComm("Receive", comm, items, peer, tag);
int state = MPI_Recv(data, items, datatype, peer, tag, comm, status);
if (state == MPI_SUCCESS) {
if (state == MPI_SUCCESS) {
state = MPI_Get_count(status, datatype, &items);
}
return state;
}
inline MPI_Datatype tagMap(e_comm_tags tag) {
switch (tag) {
case e_comm_tags::next_ID:
case e_comm_tags::new_agent: //int, int, bool - special datype?
case e_comm_tags::new_agent: //int, int, bool - special datype?
case e_comm_tags::update_parent:
case e_comm_tags::close_agent:
return MPI_INT64_T; //Really? Or MPI_INT64_T or MPI_UINT64_T?
case e_comm_tags::count_AABB:
return MPI_UINT64_T;
return MPI_UINT64_T;
case e_comm_tags::send_AABB:
return MPI_AABB; //Broadcast First Types, then AABBs
return MPI_AABB; //Broadcast First Types, then AABBs
case e_comm_tags::next_stage:
case e_comm_tags::noop:
case e_comm_tags::ACK:
......@@ -277,19 +277,19 @@ protected:
//case e_comm_tags::set_detailed_drawing: case e_comm_tags::set_debug: //could be also MPI_C_BOOL
//case e_comm_tags::new_type // byte array or a special MPI structure? - UINT64 + 256*Char !!!
default: // shadow_copy, render frame, // Conversions would be slow?
return MPI_BYTE;
return MPI_BYTE;
}
}
bool detectMPIMessage(MPI_Comm comm, int peer, e_comm_tags & tag);
int sendMPIBroadcast(void *data, int count, MPI_Datatype datatype, e_comm_tags tag); //AABB from each FO to all as an example
int receiveAndProcessMPIBroadcasts(e_comm_tags tag = e_comm_tags::unspecified);
// Frame rendering not necessary to wait for token
// for with ID to distunguish send/receive for AABB? Token passing better (scene with more independent part)
MPI_Datatype MPI_AABB;
MPI_Datatype MPI_VECTOR3D;
MPI_Datatype MPI_AGENTTYPE;
......
......@@ -38,13 +38,13 @@ void FrontOfficer::waitFor_publishAgentsAABBs()
e_comm_tags tag = e_comm_tags::unspecified;
for (int i = 1 ; i < communicator->getInstanceID() ; i++) {
//communicator->appendAABBs(/*AABBs list*/);
}
}
}
void FrontOfficer::notify_publishAgentsAABBs(const int FOsID)
{
//send the broadcasts here with broadcast_AABBofAgent ???
//HOW to get N? -> vzít z std::map<int,AbstractAgent*> agents
//HOW to get N? -> vzít z std::map<int,AbstractAgent*> agents
char data[] = {0}; // Use NULL instead? Would it be OK for MPI to work with?
communicator->sendNextFO(data,0, e_comm_tags::send_AABB);
......@@ -221,7 +221,7 @@ void FrontOfficer::respond_setDetailedReportingMode()
void FrontOfficer::waitHereUntilEveryoneIsHereToo() //Will this work without specification of stage as an argument?
{
// For cycle like in the Director to process D->FO messages?
// For cycle like in the Director to process D->FO messages?
int ibuffer[DIRECTOR_RECV_MAX] = {0};
char buffer[DIRECTOR_RECV_MAX] = {0};
int items;
......@@ -268,7 +268,7 @@ void FrontOfficer::waitHereUntilEveryoneIsHereToo() //Will this work without spe
communicator->receiveFOMessage(buffer, items, instance, tag);
break;
}
} while (tag != e_comm_tags::next_stage);
fprintf(stderr, "Ending detection loop in FO %i and waiting for sync\n", ID);
communicator->waitSync(); //waitFor_publishAgentsAABBs();
......
Markdown is supported
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