From: Martin Quinson Date: Wed, 14 Jun 2017 20:44:14 +0000 (+0200) Subject: simple test on waitany X-Git-Tag: v3.16~97 X-Git-Url: http://bilbo.iut-bm.univ-fcomte.fr/pub/gitweb/simgrid.git/commitdiff_plain/8169282cca06266967c585e8619feed5a3905117 simple test on waitany This is the MWE of #170. Thanks, Henri. --- diff --git a/teshsuite/s4u/CMakeLists.txt b/teshsuite/s4u/CMakeLists.txt index 785df31fbe..56b32611c3 100644 --- a/teshsuite/s4u/CMakeLists.txt +++ b/teshsuite/s4u/CMakeLists.txt @@ -1,4 +1,4 @@ -foreach(x actor comm-pt2pt concurrent_rw host_on_off_wait listen_async pid storage_client_server) +foreach(x actor comm-pt2pt comm-waitany concurrent_rw host_on_off_wait listen_async pid storage_client_server) add_executable (${x} ${x}/${x}.cpp) target_link_libraries(${x} simgrid) set_target_properties(${x} PROPERTIES RUNTIME_OUTPUT_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/${x}) @@ -19,7 +19,8 @@ foreach(x host_on_off_wait listen_async pid storage_client_server) endforeach() # The output is not relevant -ADD_TEST(tesh-s4u-comm-pt2pt ${CMAKE_BINARY_DIR}/teshsuite/s4u/comm-pt2pt/comm-pt2pt ${CMAKE_HOME_DIRECTORY}/examples/platforms/cluster.xml) +ADD_TEST(tesh-s4u-comm-pt2pt ${CMAKE_BINARY_DIR}/teshsuite/s4u/comm-pt2pt/comm-pt2pt ${CMAKE_HOME_DIRECTORY}/examples/platforms/cluster.xml) +ADD_TEST(tesh-s4u-comm-waitany ${CMAKE_BINARY_DIR}/teshsuite/s4u/comm-pt2pt/comm-waitany ${CMAKE_HOME_DIRECTORY}/examples/platforms/cluster.xml) diff --git a/teshsuite/s4u/comm-waitany/comm-waitany.cpp b/teshsuite/s4u/comm-waitany/comm-waitany.cpp new file mode 100644 index 0000000000..1f67aa0941 --- /dev/null +++ b/teshsuite/s4u/comm-waitany/comm-waitany.cpp @@ -0,0 +1,72 @@ +#include +#include +#include +#include + +#define NUM_COMMS 10 + +XBT_LOG_NEW_DEFAULT_CATEGORY(mwe, "Minimum Working Example"); + +static void receiver() +{ + simgrid::s4u::MailboxPtr mymailbox = simgrid::s4u::Mailbox::byName("receiver_mailbox"); + simgrid::s4u::MailboxPtr theirmailbox = simgrid::s4u::Mailbox::byName("sender_mailbox"); + + std::vector pending_comms; + + XBT_INFO("Placing %d asynchronous recv requests", NUM_COMMS); + void* data = calloc(1, sizeof(int)); + for (int i = 0; i < NUM_COMMS; i++) { + simgrid::s4u::CommPtr comm = simgrid::s4u::Comm::recv_async(mymailbox, &data); + pending_comms.push_back(comm); + } + + XBT_INFO("Sleeping for 100 seconds..."); + simgrid::s4u::this_actor::sleep_for(100.0); + XBT_INFO("Calling wait_any() for %ld pending comms", pending_comms.size()); + std::vector::iterator ret_it = + simgrid::s4u::Comm::wait_any(pending_comms.begin(), pending_comms.end()); + XBT_INFO("Counting the number of completed comms..."); + + int count = 0; + for (; ret_it != pending_comms.end(); count++, ret_it++) + ; + + xbt_assert(count == 1, "wait_any() replied that %d comms have completed, which is broken!", count); +} + +static void sender() +{ + simgrid::s4u::MailboxPtr mymailbox = simgrid::s4u::Mailbox::byName("sender_mailbox"); + simgrid::s4u::MailboxPtr theirmailbox = simgrid::s4u::Mailbox::byName("receiver_mailbox"); + + void* data = calloc(1, sizeof(int)); + + for (int i = 0; i < NUM_COMMS; i++) { + XBT_INFO("Sending a message to the receiver"); + simgrid::s4u::this_actor::send(theirmailbox, &data, 4); + XBT_INFO("Sleeping for 1000 seconds"); + simgrid::s4u::this_actor::sleep_for(1000.0); + } +} + +int main(int argc, char** argv) +{ + + simgrid::s4u::Engine* engine = new simgrid::s4u::Engine(&argc, argv); + + if (argc < 2) { + std::cerr << "Usage: " << argv[0] << " " << std::endl; + exit(1); + } + + engine->loadPlatform(argv[1]); + simgrid::s4u::Host* host = simgrid::s4u::Host::by_name("Tremblay"); + + simgrid::s4u::Actor::createActor("Receiver", host, receiver); + simgrid::s4u::Actor::createActor("Sender", host, sender); + + simgrid::s4u::Engine::instance()->run(); + + return 0; +}