Peano 4
Loading...
Searching...
No Matches
StringMessage.cpp
Go to the documentation of this file.
1#include "StringMessage.h"
2
3#include "tarch/logging/Log.h"
5
6#include <sstream>
7#include <algorithm>
8
9
10
12 std::ostringstream out;
13 out << "(";
14 out << "data=" << getData();
15 out << ",rank=" << _senderDestinationRank;
16 out << ")";
17 return out.str();
18}
19
20
22 return _data;
23}
24
25
26void tarch::mpi::StringMessage::setData(const std::string& value) {
27 _data = value;
28}
29
30
31#ifdef Parallel
34 message, destination, tag,
35 [&]() {
38 },
39 [&]() {
40 tarch::mpi::Rank::getInstance().writeTimeOutWarning( "tarch::mpi::StringMessage", "sendAndPollDanglingMessages()",destination, tag );
41 tarch::mpi::Rank::getInstance().triggerDeadlockTimeOut( "tarch::mpi::StringMessage", "sendAndPollDanglingMessages()", destination, tag );
43 },
45 );
46}
47
48
51 message, source, tag,
52 [&]() {
55 },
56 [&]() {
57 tarch::mpi::Rank::getInstance().writeTimeOutWarning( "tarch::mpi::StringMessage", "receiveAndPollDanglingMessages()", source, tag );
58 tarch::mpi::Rank::getInstance().triggerDeadlockTimeOut( "tarch::mpi::StringMessage", "receiveAndPollDanglingMessages()", source, tag );
60 },
62 );
63}
64#endif
65
66#ifdef Parallel
67
69 return _senderDestinationRank;
70}
71
72
73void tarch::mpi::StringMessage::send(const tarch::mpi::StringMessage& buffer, int destination, int tag, MPI_Comm communicator ) {
74 MPI_Send( buffer._data.c_str(), buffer._data.size()+1, MPI_CHAR, destination, tag, communicator);
75}
76
77
78void tarch::mpi::StringMessage::receive(tarch::mpi::StringMessage& buffer, int source, int tag, MPI_Comm communicator ) {
79 MPI_Status status;
80 MPI_Probe( source, tag, communicator, &status );
81 int count;
82 MPI_Get_count( &status, MPI_CHAR, &count );
83 char tmp[count];
84 MPI_Recv( &tmp, count, MPI_CHAR, source, tag, communicator, &status);
85 buffer._senderDestinationRank = status.MPI_SOURCE;
86 buffer._data = tmp;
87}
88
89
91 const tarch::mpi::StringMessage& buffer,
92 int destination,
93 int tag,
94 std::function<void()> startCommunicationFunctor,
95 std::function<void()> waitFunctor,
96 MPI_Comm communicator
97) {
98 MPI_Request sendRequestHandle;
99 int flag = 0;
100 MPI_Isend( buffer._data.c_str(), buffer._data.size()+1, MPI_CHAR, destination, tag, communicator, &sendRequestHandle );
101 MPI_Test( &sendRequestHandle, &flag, MPI_STATUS_IGNORE );
102 startCommunicationFunctor();
103 while (!flag) {
104 waitFunctor();
105 MPI_Test( &sendRequestHandle, &flag, MPI_STATUS_IGNORE );
106 }
107}
108
109
112 int source,
113 int tag,
114 std::function<void()> startCommunicationFunctor,
115 std::function<void()> waitFunctor,
116 MPI_Comm communicator
117) {
118 MPI_Status status;
119 int flag = 0;
120 MPI_Iprobe( source, tag, communicator, &flag, &status );
121 startCommunicationFunctor();
122 while (!flag) {
123 waitFunctor();
124 MPI_Iprobe( source, tag, communicator, &flag, &status );
125 }
126 int count;
127 MPI_Get_count( &status, MPI_CHAR, &count );
128 char tmp[count];
129 MPI_Recv( &tmp, count, MPI_CHAR, source, tag, communicator, &status);
130 buffer._senderDestinationRank = status.MPI_SOURCE;
131 buffer._data = tmp;
132}
133
134
135bool tarch::mpi::StringMessage::isMessageInQueue(int tag, MPI_Comm communicator) {
136 int flag = 0;
137 MPI_Iprobe(
138 MPI_ANY_SOURCE, tag,
139 communicator, &flag, MPI_STATUS_IGNORE
140 );
141 return flag;
142}
143
144#endif
void triggerDeadlockTimeOut(const std::string &className, const std::string &methodName, int communicationPartnerRank, int tag, int numberOfExpectedMessages=1, const std::string &comment="")
Triggers a time out and shuts down the cluster if a timeout is violated.
Definition Rank.cpp:119
void setDeadlockWarningTimeStamp()
Memorise global timeout.
Definition Rank.cpp:188
void writeTimeOutWarning(const std::string &className, const std::string &methodName, int communicationPartnerRank, int tag, int numberOfExpectedMessages=1)
Writes a warning if relevant.
Definition Rank.cpp:143
void setDeadlockTimeOutTimeStamp()
Definition Rank.cpp:193
static Rank & getInstance()
This operation returns the singleton instance.
Definition Rank.cpp:538
MPI_Comm getCommunicator() const
Definition Rank.cpp:544
virtual void receiveDanglingMessages() override
Answer to MPI Messages.
static ServiceRepository & getInstance()
The string message looks like the other messages which I generate through DaStGen 2,...
static bool isMessageInQueue(int tag, MPI_Comm communicator)
In older DaStGen version, I tried to find out whether a particular message type is in the MPI queue.
static void send(const tarch::mpi::StringMessage &buffer, int destination, int tag, MPI_Comm communicator)
In DaStGen (the first version), I had a non-static version of the send as well as the receive.
void setData(const std::string &value)
static void sendAndPollDanglingMessages(const tarch::mpi::StringMessage &message, int destination, int tag)
static void receive(tarch::mpi::StringMessage &buffer, int source, int tag, MPI_Comm communicator)
std::string toString() const
std::string getData() const
static void receiveAndPollDanglingMessages(tarch::mpi::StringMessage &message, int source, int tag)