A
lgorithmique
N
umérique
D
istribuée
Public GIT Repository
projects
/
simgrid.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
| inline |
side by side
Use Mailbox::get_unique<>(), and save a few delete.
[simgrid.git]
/
examples
/
s4u
/
comm-waituntil
/
s4u-comm-waituntil.cpp
diff --git
a/examples/s4u/comm-waituntil/s4u-comm-waituntil.cpp
b/examples/s4u/comm-waituntil/s4u-comm-waituntil.cpp
index
cfccd31
..
30532c6
100644
(file)
--- a/
examples/s4u/comm-waituntil/s4u-comm-waituntil.cpp
+++ b/
examples/s4u/comm-waituntil/s4u-comm-waituntil.cpp
@@
-21,7
+21,7
@@
static void sender(int argc, char** argv)
{
xbt_assert(argc == 4, "Expecting 3 parameters from the XML deployment file but got %d", argc);
long messages_count = std::stol(argv[1]); /* - number of messages */
-
double msg_size = std::stod
(argv[2]); /* - message size in bytes */
+
long msg_size = std::stol
(argv[2]); /* - message size in bytes */
long receivers_count = std::stol(argv[3]); /* - number of receivers */
std::vector<simgrid::s4u::CommPtr> pending_comms;
@@
-31,7
+31,7
@@
static void sender(int argc, char** argv)
std::string mboxName = std::string("receiver-") + std::to_string(i % receivers_count);
simgrid::s4u::Mailbox* mbox = simgrid::s4u::Mailbox::by_name(mboxName);
std::string msgName = std::string("Message ") + std::to_string(i);
-
std::string* payload
= new std::string(msgName); // copy the data we send:
+
auto* payload
= new std::string(msgName); // copy the data we send:
// 'msgName' is not a stable storage location
XBT_INFO("Send '%s' to '%s'", msgName.c_str(), mboxName.c_str());
@@
-45,7
+45,7
@@
static void sender(int argc, char** argv)
for (int i = 0; i < receivers_count; i++) {
std::string mboxName = std::string("receiver-") + std::to_string(i % receivers_count);
simgrid::s4u::Mailbox* mbox = simgrid::s4u::Mailbox::by_name(mboxName);
-
std::string* payload
= new std::string("finalize"); // Make a copy of the data we will send
+
auto* payload
= new std::string("finalize"); // Make a copy of the data we will send
simgrid::s4u::CommPtr comm = mbox->put_async(payload, 0);
pending_comms.push_back(comm);
@@
-71,11
+71,10
@@
static void receiver(int argc, char** argv)
XBT_INFO("Wait for my first message");
for (bool cont = true; cont;) {
-
const std::string* received = static_cast<std::string*>(mbox->get()
);
+
auto received = mbox->get_unique<std::string>(
);
XBT_INFO("I got a '%s'.", received->c_str());
if (*received == "finalize")
cont = false; // If it's a finalize message, we're done.
- delete received;
}
}