From 0df48f496c6d97082a56fc68b7960bff9113a996 Mon Sep 17 00:00:00 2001 From: Martin Quinson Date: Tue, 4 Feb 2020 10:34:22 +0100 Subject: [PATCH] move this first C example to the example directory + cosmetics in outputs --- {teshsuite => examples}/c/CMakeLists.txt | 8 ++++---- .../c/async-waitany/async-waitany.c | 11 +++++------ .../c/async-waitany/async-waitany.tesh | 0 .../c/async-waitany/async-waitany_d.xml | 0 examples/s4u/async-wait/s4u-async-wait.cpp | 4 ++-- examples/s4u/async-wait/s4u-async-wait.tesh | 2 +- examples/s4u/async-waitall/s4u-async-waitall.cpp | 2 +- examples/s4u/async-waitany/s4u-async-waitany.cpp | 2 +- tools/cmake/DefinePackages.cmake | 2 +- 9 files changed, 15 insertions(+), 16 deletions(-) rename {teshsuite => examples}/c/CMakeLists.txt (67%) rename {teshsuite => examples}/c/async-waitany/async-waitany.c (92%) rename {teshsuite => examples}/c/async-waitany/async-waitany.tesh (100%) rename {teshsuite => examples}/c/async-waitany/async-waitany_d.xml (100%) diff --git a/teshsuite/c/CMakeLists.txt b/examples/c/CMakeLists.txt similarity index 67% rename from teshsuite/c/CMakeLists.txt rename to examples/c/CMakeLists.txt index 29e6483c40..0b073d17bf 100644 --- a/teshsuite/c/CMakeLists.txt +++ b/examples/c/CMakeLists.txt @@ -12,8 +12,8 @@ set(teshsuite_src ${teshsuite_src} PARENT_SCOPE) set(xml_files ${xml_files} ${CMAKE_CURRENT_SOURCE_DIR}/async-waitany/async-waitany_d.xml PARENT_SCOPE) foreach(x async-waitany) - ADD_TESH(tesh-c-${x} --setenv platfdir=${CMAKE_HOME_DIRECTORY}/examples/platforms - --setenv bindir=${CMAKE_BINARY_DIR}/teshsuite/c/${x} - --cd ${CMAKE_HOME_DIRECTORY}/teshsuite/c/${x} - ${CMAKE_HOME_DIRECTORY}/teshsuite/c/${x}/${x}.tesh) + ADD_TESH(c-${x} --setenv platfdir=${CMAKE_HOME_DIRECTORY}/examples/platforms + --setenv bindir=${CMAKE_BINARY_DIR}/examples/c/${x} + --cd ${CMAKE_HOME_DIRECTORY}/examples/c/${x} + ${CMAKE_HOME_DIRECTORY}/examples/c/${x}/${x}.tesh) endforeach() diff --git a/teshsuite/c/async-waitany/async-waitany.c b/examples/c/async-waitany/async-waitany.c similarity index 92% rename from teshsuite/c/async-waitany/async-waitany.c rename to examples/c/async-waitany/async-waitany.c index d1b2d2188b..cff2764f4b 100644 --- a/teshsuite/c/async-waitany/async-waitany.c +++ b/examples/c/async-waitany/async-waitany.c @@ -31,7 +31,7 @@ static int sender(int argc, char* argv[]) sg_mailbox_t* mboxes = malloc(sizeof(sg_mailbox_t) * receivers_count); for (long i = 0; i < receivers_count; i++) { char mailbox_name[80]; - snprintf(mailbox_name, 79, "receiver-%ld", (i)); + snprintf(mailbox_name, 79, "receiver-%ld", i); sg_mailbox_t mbox = sg_mailbox_by_name(mailbox_name); mboxes[i] = mbox; } @@ -39,20 +39,19 @@ static int sender(int argc, char* argv[]) /* Start dispatching all messages to receivers, in a round robin fashion */ for (int i = 0; i < messages_count; i++) { char msg_content[80]; - snprintf(msg_content, 79, "Message_%d", i); + snprintf(msg_content, 79, "Message %d", i); sg_mailbox_t mbox = mboxes[i % receivers_count]; XBT_INFO("Send '%s' to '%s'", msg_content, sg_mailbox_get_name(mbox)); - sg_comm_t comm = sg_mailbox_put_async(mbox, xbt_strdup(msg_content), msg_size); - pending_comms[pending_comms_count++] = comm; + /* Create a communication representing the ongoing communication, and store it in pending_comms */ + pending_comms[pending_comms_count++] = sg_mailbox_put_async(mbox, xbt_strdup(msg_content), msg_size); } /* Start sending messages to let the workers know that they should stop */ for (int i = 0; i < receivers_count; i++) { XBT_INFO("Send 'finalize' to 'receiver-%d'", i); char* end_msg = xbt_strdup("finalize"); sg_mailbox_t mbox = mboxes[i % receivers_count]; - sg_comm_t comm = sg_mailbox_put_async(mbox, end_msg, 0); - pending_comms[pending_comms_count++] = comm; + pending_comms[pending_comms_count++] = sg_mailbox_put_async(mbox, end_msg, 0); } XBT_INFO("Done dispatching all messages"); diff --git a/teshsuite/c/async-waitany/async-waitany.tesh b/examples/c/async-waitany/async-waitany.tesh similarity index 100% rename from teshsuite/c/async-waitany/async-waitany.tesh rename to examples/c/async-waitany/async-waitany.tesh diff --git a/teshsuite/c/async-waitany/async-waitany_d.xml b/examples/c/async-waitany/async-waitany_d.xml similarity index 100% rename from teshsuite/c/async-waitany/async-waitany_d.xml rename to examples/c/async-waitany/async-waitany_d.xml diff --git a/examples/s4u/async-wait/s4u-async-wait.cpp b/examples/s4u/async-wait/s4u-async-wait.cpp index 24a3e2b1b2..8dec9667cb 100644 --- a/examples/s4u/async-wait/s4u-async-wait.cpp +++ b/examples/s4u/async-wait/s4u-async-wait.cpp @@ -36,8 +36,8 @@ static int sender(int argc, char** argv) /* Start dispatching all messages to receivers, in a round robin fashion */ for (int i = 0; i < messages_count; i++) { std::string msg_content = std::string("Message ") + std::to_string(i); - // Copy the data we send: 'msg_content' is not a stable storage location. - // It will be destroyed when this actor leaves the loop, ie before the receiver gets it + // Copy the data we send: the 'msg_content' variable is not a stable storage location. + // It will be destroyed when this actor leaves the loop, ie before the receiver gets the data std::string* payload = new std::string(msg_content); XBT_INFO("Send '%s' to '%s'", msg_content.c_str(), mboxes[i % receivers_count]->get_cname()); diff --git a/examples/s4u/async-wait/s4u-async-wait.tesh b/examples/s4u/async-wait/s4u-async-wait.tesh index dcdaac0b28..93edebfcfe 100644 --- a/examples/s4u/async-wait/s4u-async-wait.tesh +++ b/examples/s4u/async-wait/s4u-async-wait.tesh @@ -13,4 +13,4 @@ $ ${bindir:=.}/s4u-async-wait ${platfdir}/small_platform_fatpipe.xml s4u-async-w > [ 0.210917] (2:receiver@Ruby) I got a 'Message 1'. > [ 0.316375] (2:receiver@Ruby) I got a 'Message 2'. > [ 0.318326] (2:receiver@Ruby) I got a 'finalize'. -> [ 0.318326] (1:sender@Tremblay) Goodbye now! \ No newline at end of file +> [ 0.318326] (1:sender@Tremblay) Goodbye now! diff --git a/examples/s4u/async-waitall/s4u-async-waitall.cpp b/examples/s4u/async-waitall/s4u-async-waitall.cpp index 14d53cc5bb..da09d449a5 100644 --- a/examples/s4u/async-waitall/s4u-async-waitall.cpp +++ b/examples/s4u/async-waitall/s4u-async-waitall.cpp @@ -47,7 +47,7 @@ public: /* Start dispatching all messages to receivers, in a round robin fashion */ for (int i = 0; i < messages_count; i++) { std::string msg_content = std::string("Message ") + std::to_string(i); - // Copy the data we send: 'msg_content' is not a stable storage location. + // Copy the data we send: the 'msg_content' variable is not a stable storage location. // It will be destroyed when this actor leaves the loop, ie before the receiver gets it std::string* payload = new std::string(msg_content); diff --git a/examples/s4u/async-waitany/s4u-async-waitany.cpp b/examples/s4u/async-waitany/s4u-async-waitany.cpp index dba580ed5f..293deec65b 100644 --- a/examples/s4u/async-waitany/s4u-async-waitany.cpp +++ b/examples/s4u/async-waitany/s4u-async-waitany.cpp @@ -50,7 +50,7 @@ public: /* Start dispatching all messages to receivers, in a round robin fashion */ for (int i = 0; i < messages_count; i++) { std::string msg_content = std::string("Message ") + std::to_string(i); - // Copy the data we send: 'msg_content' is not a stable storage location. + // Copy the data we send: the 'msg_content' variable is not a stable storage location. // It will be destroyed when this actor leaves the loop, ie before the receiver gets it std::string* payload = new std::string(msg_content); diff --git a/tools/cmake/DefinePackages.cmake b/tools/cmake/DefinePackages.cmake index 0a1c3b4d2a..b5f5345436 100644 --- a/tools/cmake/DefinePackages.cmake +++ b/tools/cmake/DefinePackages.cmake @@ -1003,6 +1003,7 @@ set(txt_files # The list of cmake build directories is constructed from the following list. # Add your CMakeLists file here to see your subdir built. set(CMAKEFILES_TXT + examples/c/CMakeLists.txt examples/s4u/CMakeLists.txt examples/smpi/CMakeLists.txt examples/smpi/NAS/CMakeLists.txt @@ -1015,7 +1016,6 @@ set(CMAKEFILES_TXT examples/deprecated/msg/mc/CMakeLists.txt examples/deprecated/simdag/CMakeLists.txt - teshsuite/c/CMakeLists.txt teshsuite/java/CMakeLists.txt teshsuite/lua/CMakeLists.txt teshsuite/mc/CMakeLists.txt -- 2.20.1