From d6b4c74778b2ffd4fcc9d00726b3f4f06dcf6a01 Mon Sep 17 00:00:00 2001 From: Frederic Suter Date: Fri, 22 Feb 2019 19:13:15 +0100 Subject: [PATCH] convert maestro-set to S4U --- .gitignore | 2 +- examples/deprecated/msg/CMakeLists.txt | 16 ------ examples/s4u/CMakeLists.txt | 20 +++++++ .../maestro-set/s4u-maestro-set.cpp} | 54 +++++++++---------- .../maestro-set/s4u-maestro-set.tesh} | 2 +- 5 files changed, 47 insertions(+), 47 deletions(-) rename examples/{deprecated/msg/maestro-set/maestro-set.cpp => s4u/maestro-set/s4u-maestro-set.cpp} (62%) rename examples/{deprecated/msg/maestro-set/maestro-set.tesh => s4u/maestro-set/s4u-maestro-set.tesh} (76%) diff --git a/.gitignore b/.gitignore index 3009272ddc..59e3d9a515 100644 --- a/.gitignore +++ b/.gitignore @@ -123,7 +123,6 @@ examples/deprecated/msg/cloud-masterworker/cloud-masterworker examples/deprecated/msg/dht-kademlia/dht-kademlia examples/deprecated/msg/dht-pastry/dht-pastry examples/deprecated/msg/energy-vm/energy-vm -examples/deprecated/msg/maestro-set/maestro-set examples/deprecated/msg/mc/bugged1 examples/deprecated/msg/mc/bugged1_liveness examples/deprecated/msg/mc/bugged2 @@ -184,6 +183,7 @@ examples/s4u/io-async/s4u-io-async examples/s4u/io-file-remote/s4u-io-file-remote examples/s4u/io-file-system/s4u-io-file-system examples/s4u/io-storage-raw/s4u-io-storage-raw +examples/s4u/maestro-set/s4u-maestro-set examples/s4u/platform-failures/s4u-platform-failures examples/s4u/platform-properties/s4u-platform-properties examples/s4u/plugin-hostload/s4u-plugin-hostload diff --git a/examples/deprecated/msg/CMakeLists.txt b/examples/deprecated/msg/CMakeLists.txt index b8b6bef89d..0e62567023 100644 --- a/examples/deprecated/msg/CMakeLists.txt +++ b/examples/deprecated/msg/CMakeLists.txt @@ -13,16 +13,6 @@ foreach(x app-masterworker cloud-masterworker set(tesh_files ${tesh_files} ${CMAKE_CURRENT_SOURCE_DIR}/${x}/${x}.tesh) endforeach() -# CPP examples -foreach(x maestro-set) - add_executable (${x} EXCLUDE_FROM_ALL ${x}/${x}.cpp) - target_link_libraries(${x} simgrid) - set_target_properties(${x} PROPERTIES RUNTIME_OUTPUT_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/${x}) - add_dependencies(tests ${x}) - set(examples_src ${examples_src} ${CMAKE_CURRENT_SOURCE_DIR}/${x}/${x}.cpp) - set(tesh_files ${tesh_files} ${CMAKE_CURRENT_SOURCE_DIR}/${x}/${x}.tesh) -endforeach() - if(SIMGRID_HAVE_NS3) add_executable (network-ns3 EXCLUDE_FROM_ALL network-ns3/network-ns3.c) target_link_libraries(network-ns3 simgrid) @@ -87,12 +77,6 @@ ADD_TESH_FACTORIES(msg-dht-kademlia-parallel "thread;ucontext;raw;boost" --cfg c --setenv platfdir=${CMAKE_HOME_DIRECTORY}/examples/platforms ${CMAKE_HOME_DIRECTORY}/examples/deprecated/msg/dht-kademlia/dht-kademlia.tesh) -if(NOT WIN32) - ADD_TESH_FACTORIES(msg-maestro-set "thread" --setenv srcdir=${CMAKE_HOME_DIRECTORY}/examples/deprecated/msg --cd ${CMAKE_BINARY_DIR}/examples/deprecated/msg ${CMAKE_HOME_DIRECTORY}/examples/deprecated/msg/maestro-set/maestro-set.tesh) -else() - message("Test maestro-set disabled on windows: this feature is not working") -endif() - ADD_TESH_FACTORIES(app-masterworker-multicore "thread;ucontext;raw;boost" --setenv srcdir=${CMAKE_HOME_DIRECTORY}/examples/deprecated/msg/app-masterworker --setenv bindir=${CMAKE_BINARY_DIR}/examples/deprecated/msg/app-masterworker diff --git a/examples/s4u/CMakeLists.txt b/examples/s4u/CMakeLists.txt index 6327f60579..3942d21af6 100644 --- a/examples/s4u/CMakeLists.txt +++ b/examples/s4u/CMakeLists.txt @@ -110,6 +110,26 @@ if (NOT enable_memcheck AND NOT WIN32) ${CMAKE_CURRENT_SOURCE_DIR}/app-pingpong/simix-breakpoint.tesh) endif() +# Examples accepting only thread factories +################################## +foreach (example maestro-set) + add_executable (s4u-${example} EXCLUDE_FROM_ALL ${example}/s4u-${example}.cpp) + target_link_libraries(s4u-${example} simgrid) + set_target_properties(s4u-${example} PROPERTIES RUNTIME_OUTPUT_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/${example}) + add_dependencies(tests s4u-${example}) + + set(tesh_files ${tesh_files} ${CMAKE_CURRENT_SOURCE_DIR}/${example}/s4u-${example}.tesh) + set(examples_src ${examples_src} ${CMAKE_CURRENT_SOURCE_DIR}/${example}/s4u-${example}.cpp) + + if(NOT WIN32) + ADD_TESH_FACTORIES(s4u-${example} "thread" --setenv bindir=${CMAKE_CURRENT_BINARY_DIR}/${example} + --setenv platfdir=${CMAKE_HOME_DIRECTORY}/examples/platforms + ${CMAKE_HOME_DIRECTORY}/examples/s4u/${example}/s4u-${example}.tesh) + else() + message("Test maestro-set disabled on windows: this feature is not working") + endif() +endforeach() + # Add all extra files to the archive #################################### diff --git a/examples/deprecated/msg/maestro-set/maestro-set.cpp b/examples/s4u/maestro-set/s4u-maestro-set.cpp similarity index 62% rename from examples/deprecated/msg/maestro-set/maestro-set.cpp rename to examples/s4u/maestro-set/s4u-maestro-set.cpp index 5663d7870d..bd0802eb48 100644 --- a/examples/deprecated/msg/maestro-set/maestro-set.cpp +++ b/examples/s4u/maestro-set/s4u-maestro-set.cpp @@ -3,7 +3,7 @@ /* This program is free software; you can redistribute it and/or modify it * under the terms of the license (GNU LGPL) which comes with this package. */ -/** @addtogroup MSG_examples +/** @addtogroup S4U_examples * * - maestro-set/maestro-set.cpp: Switch the system thread hosting our maestro. * That's a very advanced example in which we move the maestro thread to another process. @@ -13,82 +13,78 @@ * expected. You can still use that feature from a C code. */ -#include "simgrid/msg.h" +#include "simgrid/Exception.hpp" +#include "simgrid/actor.h" +#include "simgrid/s4u.hpp" +#include #include -XBT_LOG_NEW_DEFAULT_CATEGORY(msg_test, "Messages specific for this msg example"); +XBT_LOG_NEW_DEFAULT_CATEGORY(s4u_test, "Messages specific for this s4u example"); std::thread::id root_id; -static void ensure_root_tid() { +static void ensure_root_tid() +{ std::thread::id this_id = std::this_thread::get_id(); xbt_assert(root_id == this_id, "I was supposed to be the main thread"); XBT_INFO("I am the main thread, as expected"); } -static void ensure_other_tid() { +static void ensure_other_tid() +{ std::thread::id this_id = std::this_thread::get_id(); xbt_assert(this_id != root_id, "I was NOT supposed to be the main thread"); XBT_INFO("I am not the main thread, as expected"); } - - -static int sender(int argc, char *argv[]) +static void sender() { ensure_root_tid(); - - msg_task_t task_la = MSG_task_create("Some task", 0.0, 10e8, NULL); - MSG_task_send(task_la, "some mailbox"); - - return 0; + std::string* payload = new std::string("some message"); + simgrid::s4u::Mailbox::by_name("some mailbox")->put((void*)payload, 10e8); } -static int receiver(int argc, char *argv[]) +static void receiver() { ensure_other_tid(); - msg_task_t task_la = NULL; - xbt_assert(MSG_task_receive(&task_la,"some mailbox") == MSG_OK); + std::string* payload = static_cast(simgrid::s4u::Mailbox::by_name("some mailbox")->get()); XBT_INFO("Task received"); - MSG_task_destroy(task_la); - - return 0; + delete payload; } static void maestro(void* data) { ensure_other_tid(); - MSG_process_create("receiver",&receiver,NULL,MSG_host_by_name("Jupiter")); - MSG_main(); + simgrid::s4u::Actor::create("receiver", simgrid::s4u::Host::by_name("Jupiter"), receiver); + simgrid::s4u::Engine::get_instance()->run(); } /** Main function */ -int main(int argc, char *argv[]) +int main(int argc, char* argv[]) { root_id = std::this_thread::get_id(); SIMIX_set_maestro(maestro, NULL); - MSG_init(&argc, argv); + simgrid::s4u::Engine e(&argc, argv); if (argc != 2) { XBT_CRITICAL("Usage: %s platform_file\n", argv[0]); - xbt_die("example: %s msg_platform.xml\n",argv[0]); + xbt_die("example: %s msg_platform.xml\n", argv[0]); } - MSG_create_environment(argv[1]); + e.load_platform(argv[1]); /* Become one of the simulated process. * * This must be done after the creation of the platform because we are depending attaching to a host.*/ - MSG_process_attach("sender", NULL, MSG_host_by_name("Tremblay"), NULL); + sg_actor_attach("sender", nullptr, simgrid::s4u::Host::by_name("Tremblay"), nullptr); ensure_root_tid(); // Execute the sender code: - const char* subargv[3] = { "sender", "Jupiter", NULL }; - sender(2, (char**) subargv); + sender(); - MSG_process_detach(); // Become root thread again + sg_actor_detach(); // Become root thread again XBT_INFO("Detached"); ensure_root_tid(); diff --git a/examples/deprecated/msg/maestro-set/maestro-set.tesh b/examples/s4u/maestro-set/s4u-maestro-set.tesh similarity index 76% rename from examples/deprecated/msg/maestro-set/maestro-set.tesh rename to examples/s4u/maestro-set/s4u-maestro-set.tesh index b3f69dd8d6..cf21b21b14 100644 --- a/examples/deprecated/msg/maestro-set/maestro-set.tesh +++ b/examples/s4u/maestro-set/s4u-maestro-set.tesh @@ -1,6 +1,6 @@ #!/usr/bin/env tesh -$ $SG_TEST_EXENV maestro-set/maestro-set$EXEEXT ${srcdir:=.}/../../platforms/small_platform.xml "--log=root.fmt:[%10.6r]%e(%i:%P@%h)%e%m%n" +$ $SG_TEST_EXENV ${bindir:=.}/s4u-maestro-set$EXEEXT ${platfdir:=.}/small_platform.xml "--log=root.fmt:[%10.6r]%e(%i:%P@%h)%e%m%n" > [ 0.000000] (0:maestro@) I am not the main thread, as expected > [ 0.000000] (2:receiver@Jupiter) I am not the main thread, as expected > [ 0.000000] (1:sender@Tremblay) I am the main thread, as expected -- 2.20.1