Commit f0bc5254 authored by Florian Goth's avatar Florian Goth
Browse files

make the version of the Master compile again...

parent 2576d142
......@@ -111,6 +111,7 @@ public:
*/
template <typename T>
inline Letter<T> recvfromanyclient();
inline Letter<char> recvfromspecificClient(const Client&);
inline Client peekNextOriginator();
/**
This function adds a Client that's waiting for a connection to the internal structures
......@@ -141,6 +142,11 @@ public:
* @return true if MPI_Probe finds some message, else false.
*/
inline bool anyMessagefrom(const Client& client);
/** This discards the message of the client c
* @param c the client whose message to discard
* */
inline void discardmessage(const Client& c);
void clearInbox() {} //hopefully MPI takes care of this...
private:
bool juststarted;
bool hasdata;
......@@ -154,11 +160,33 @@ private:
void status_valid();
};
inline void MPIServer::discardmessage(const Client& c)
{
if(status_is_uptodate)
{
int len = peeknextSize(c);
char* dump = new char[len];
MPI_Recv(dump, len, MPI_CHAR, c.id, status.MPI_TAG, MPI_COMM_WORLD, &status);
status_is_uptodate = false;
delete [] dump;
}
else
{
std::cout<<"status not up-to-date in discardmessage !"<<std::endl;
exit(-1);
}
}
uint MPIServer::peeknextSize(const Client& c)
{
int length;
if(status_is_uptodate)
MPI_Get_count(&status, MPI_CHAR, &length);//hopefully this works for all datatypes...
else
{
std::cout<<"status not up-to-date in peeknextsize !"<<std::endl;
exit(-1);
}
return length;
}
......@@ -229,6 +257,12 @@ inline bool MPIServer::send<std::string>(const Client& client, const std::string
return MPI_Send(const_cast<char*>(var.c_str()), var.size(), MPI_CHAR, client.id, 314, MPI_COMM_WORLD) != 0;
}
template <>
inline bool MPIServer::send<std::valarray<char> >(const Client& client, const std::valarray<char>& var)
{
return MPI_Send(const_cast<char*>(&(var[0])), var.size(), MPI_CHAR, client.id, 314, MPI_COMM_WORLD) != 0;
}
template <>
inline Letter<valarray<double> > MPIServer::recvfromanyclient<valarray<double> >()
{
......@@ -347,6 +381,18 @@ inline Letter<T> MPIServer::recvfromanyclient()
return retval;
}
inline Letter<char> MPIServer::recvfromspecificClient(const Client& c)
{
status_valid();
Letter<char> retval;
int length;
MPI_Get_count(&status, MPI_CHAR, &length);
MPI_Recv(&(retval.msg), length, MPI_CHAR, c.id, status.MPI_TAG, MPI_COMM_WORLD, &status);
retval.sender.id = c.id;
status_is_uptodate = false;
return retval;
}
const Client& MPIServer::addClient()
{
clients.push_back(Client(1 + alreadyaddedclients) );
......
......@@ -71,9 +71,15 @@ public:
*/
template <typename T>
inline bool sendtoallclients(T);
inline void discardmessage(const Client& c);
private:
};
void SDLServer::discardmessage(const Client& c)
{
getNextLetter(c);
}
inline Letter<char> SDLServer::recvfromspecificClient(const Client& c)
{
Letter<char> retval;
......
......@@ -259,7 +259,7 @@ bool Master::wait_for_Init_Ack(const Client& c, ClientContainer& clients, std::o
}
else
{
getNextLetter(c);//can't be an ack. hence we discard that message
discardmessage(c);//can't be an ack. hence we discard that message
}
}
}
......@@ -674,7 +674,7 @@ void Master::wait_for_all_clients_to_stop(std::list<ClientState<SignType> >& cli
}
else
{
getNextLetter(o);//can't be an ack. hence we discard that message
discardmessage(o);//can't be an ack. hence we discard that message
std::cout<<"Discarding a message!"<<std::endl;
}
}
......@@ -804,7 +804,7 @@ void Master::run(std::vector<Parameters>::const_iterator curparams, std::list<Cl
}
else
{
getNextLetter(client->client);//can't be an ack. hence we discard that message
discardmessage(client->client);//can't be an ack. hence we discard that message
}
}
}
......
Supports Markdown
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