From d117138066c37a0da006ff32114575367fdaa9bf Mon Sep 17 00:00:00 2001 From: Frederic Suter Date: Sat, 7 Mar 2020 15:46:44 +0100 Subject: [PATCH] convert platform-failures --- MANIFEST.in | 4 +- examples/c/CMakeLists.txt | 2 + .../c/platform-failures/platform-failures.c | 139 +++++++++++++++++ .../platform-failures/platform-failures.tesh | 6 +- examples/deprecated/msg/CMakeLists.txt | 4 +- .../msg/platform-failures/platform-failures.c | 143 ------------------ 6 files changed, 148 insertions(+), 150 deletions(-) create mode 100644 examples/c/platform-failures/platform-failures.c rename examples/{deprecated/msg => c}/platform-failures/platform-failures.tesh (94%) delete mode 100644 examples/deprecated/msg/platform-failures/platform-failures.c diff --git a/MANIFEST.in b/MANIFEST.in index 36e80cca32..227d242079 100644 --- a/MANIFEST.in +++ b/MANIFEST.in @@ -89,6 +89,8 @@ include examples/c/io-disk-raw/io-disk-raw.tesh include examples/c/io-file-remote/io-file-remote.c include examples/c/io-file-remote/io-file-remote.tesh include examples/c/io-file-remote/io-file-remote_d.xml +include examples/c/platform-failures/platform-failures.c +include examples/c/platform-failures/platform-failures.tesh include examples/c/plugin-hostload/plugin-hostload.c include examples/c/plugin-hostload/plugin-hostload.tesh include examples/deprecated/java/app/bittorrent/Common.java @@ -271,8 +273,6 @@ include examples/deprecated/msg/network-ns3/network-ns3.c include examples/deprecated/msg/network-ns3/network-ns3.tesh include examples/deprecated/msg/network-ns3/one_cluster_d.xml include examples/deprecated/msg/network-ns3/onelink_d.xml -include examples/deprecated/msg/platform-failures/platform-failures.c -include examples/deprecated/msg/platform-failures/platform-failures.tesh include examples/deprecated/msg/synchro-semaphore/synchro-semaphore.c include examples/deprecated/msg/synchro-semaphore/synchro-semaphore.tesh include examples/deprecated/msg/trace-categories/trace-categories.c diff --git a/examples/c/CMakeLists.txt b/examples/c/CMakeLists.txt index 11d445be30..dcf5c24975 100644 --- a/examples/c/CMakeLists.txt +++ b/examples/c/CMakeLists.txt @@ -10,6 +10,7 @@ foreach(x exec-async exec-basic exec-dvfs exec-remote exec-waitany energy-exec energy-exec-ptask energy-vm io-disk-raw io-file-remote + platform-failures plugin-hostload) add_executable (${x}-c EXCLUDE_FROM_ALL ${x}/${x}.c) target_link_libraries(${x}-c simgrid) @@ -65,6 +66,7 @@ foreach(x exec-async exec-basic exec-dvfs exec-remote exec-waitany energy-exec energy-exec-ptask energy-vm io-disk-raw io-file-remote + platform-failures plugin-hostload) ADD_TESH(c-${x} --setenv platfdir=${CMAKE_HOME_DIRECTORY}/examples/platforms --setenv bindir=${CMAKE_BINARY_DIR}/examples/c/${x} diff --git a/examples/c/platform-failures/platform-failures.c b/examples/c/platform-failures/platform-failures.c new file mode 100644 index 0000000000..725e31f06d --- /dev/null +++ b/examples/c/platform-failures/platform-failures.c @@ -0,0 +1,139 @@ +/* Copyright (c) 2007-2020. The SimGrid Team. All rights reserved. */ + +/* 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. */ + +#include "simgrid/actor.h" +#include "simgrid/comm.h" +#include "simgrid/engine.h" +#include "simgrid/exec.h" +#include "simgrid/host.h" +#include "simgrid/mailbox.h" + +#include "xbt/asserts.h" +#include "xbt/log.h" +#include "xbt/str.h" + +#include /* snprintf */ + +#define FINALIZE 221297 /* a magic number to tell people to stop working */ + +XBT_LOG_NEW_DEFAULT_CATEGORY(platform_failures, "Messages specific for this example"); + +static void master(int argc, char* argv[]) +{ + xbt_assert(argc == 5); + long number_of_tasks = xbt_str_parse_int(argv[1], "Invalid amount of tasks: %s"); + double task_comp_size = xbt_str_parse_double(argv[2], "Invalid computational size: %s"); + double task_comm_size = xbt_str_parse_double(argv[3], "Invalid communication size: %s"); + long workers_count = xbt_str_parse_int(argv[4], "Invalid amount of workers: %s"); + + XBT_INFO("Got %ld workers and %ld tasks to process", workers_count, number_of_tasks); + + for (int i = 0; i < number_of_tasks; i++) { + char mailbox_name[256]; + snprintf(mailbox_name, 255, "worker-%ld", i % workers_count); + sg_mailbox_t mailbox = sg_mailbox_by_name(mailbox_name); + + XBT_INFO("Send a message to %s", mailbox_name); + double* payload = (double*)xbt_malloc(sizeof(double)); + *payload = task_comp_size; + sg_comm_t comm = sg_mailbox_put_async(mailbox, payload, task_comm_size); + + switch (sg_comm_wait_for(comm, 10.0)) { + case SG_OK: + XBT_INFO("Send to %s completed", mailbox_name); + break; + case SG_ERROR_NETWORK: + XBT_INFO("Mmh. The communication with '%s' failed. Nevermind. Let's keep going!", mailbox_name); + free(payload); + break; + case SG_ERROR_TIMEOUT: + XBT_INFO("Mmh. Got timeouted while speaking to '%s'. Nevermind. Let's keep going!", mailbox_name); + free(payload); + break; + default: + xbt_die("Unexpected behavior"); + } + } + + XBT_INFO("All tasks have been dispatched. Let's tell everybody the computation is over."); + for (int i = 0; i < workers_count; i++) { + char mailbox_name[256]; + snprintf(mailbox_name, 255, "worker-%ld", i % workers_count); + sg_mailbox_t mailbox = sg_mailbox_by_name(mailbox_name); + double* payload = (double*)xbt_malloc(sizeof(double)); + *payload = FINALIZE; + sg_comm_t comm = sg_mailbox_put_async(mailbox, payload, 0); + + switch (sg_comm_wait_for(comm, 1.0)) { + case SG_ERROR_NETWORK: + XBT_INFO("Mmh. Can't reach '%s'! Nevermind. Let's keep going!", mailbox_name); + free(payload); + break; + case SG_ERROR_TIMEOUT: + XBT_INFO("Mmh. Got timeouted while speaking to '%s'. Nevermind. Let's keep going!", mailbox_name); + free(payload); + break; + case SG_OK: + /* nothing */ + break; + default: + xbt_die("Unexpected behavior with '%s'", mailbox_name); + } + } + + XBT_INFO("Goodbye now!"); +} + +static void worker(int argc, char* argv[]) +{ + xbt_assert(argc == 2); + char mailbox_name[80]; + double* payload; + long id = xbt_str_parse_int(argv[1], "Invalid argument %s"); + + snprintf(mailbox_name, 79, "worker-%ld", id); + sg_mailbox_t mailbox = sg_mailbox_by_name(mailbox_name); + + while (1) { + XBT_INFO("Waiting a message on %s", mailbox_name); + sg_comm_t comm = sg_mailbox_get_async(mailbox, (void**)&payload); + sg_error_t retcode = sg_comm_wait(comm); + if (retcode == SG_OK) { + if (*payload == FINALIZE) { + free(payload); + break; + } else { + XBT_INFO("Start execution..."); + sg_actor_execute(*payload); + XBT_INFO("Execution complete."); + free(payload); + } + } else if (retcode == SG_ERROR_NETWORK) { + XBT_INFO("Mmh. Something went wrong. Nevermind. Let's keep going!"); + } + } + XBT_INFO("I'm done. See you!"); +} + +int main(int argc, char* argv[]) +{ + simgrid_init(&argc, argv); + xbt_assert(argc > 2, + "Usage: %s platform_file deployment_file\n" + "\tExample: %s msg_platform.xml msg_deployment.xml\n", + argv[0], argv[0]); + + simgrid_load_platform(argv[1]); + + simgrid_register_function("master", master); + simgrid_register_function("worker", worker); + simgrid_load_deployment(argv[2]); + + simgrid_run(); + + XBT_INFO("Simulation time %g", simgrid_get_clock()); + + return 0; +} diff --git a/examples/deprecated/msg/platform-failures/platform-failures.tesh b/examples/c/platform-failures/platform-failures.tesh similarity index 94% rename from examples/deprecated/msg/platform-failures/platform-failures.tesh rename to examples/c/platform-failures/platform-failures.tesh index 79947c51cb..e258993ced 100644 --- a/examples/deprecated/msg/platform-failures/platform-failures.tesh +++ b/examples/c/platform-failures/platform-failures.tesh @@ -3,7 +3,7 @@ p Testing a simple master/worker example application handling failures TCP crosstraffic DISABLED ! output sort 19 -$ ${bindir:=.}/platform-failures --log=xbt_cfg.thres:critical --log=no_loc ${platfdir}/small_platform_failures.xml ${srcdir}/../app-masterworker/app-masterworker_d.xml --cfg=path:${srcdir} --cfg=network/crosstraffic:0 "--log=root.fmt:[%10.6r]%e(%i:%P@%h)%e%m%n" --log=surf_cpu.t:verbose +$ ${bindir:=.}/platform-failures-c --log=xbt_cfg.thres:critical --log=no_loc ${platfdir}/small_platform_failures.xml ${srcdir:=.}/../../s4u/platform-failures/s4u-platform-failures_d.xml --cfg=path:${srcdir} --cfg=network/crosstraffic:0 "--log=root.fmt:[%10.6r]%e(%i:%P@%h)%e%m%n" --log=surf_cpu.t:verbose > [ 0.000000] (0:maestro@) Cannot launch actor 'worker' on failed host 'Fafard' > [ 0.000000] (0:maestro@) Deployment includes some initially turned off Hosts ... nevermind. > [ 0.000000] (1:master@Tremblay) Got 5 workers and 20 tasks to process @@ -108,7 +108,7 @@ $ ${bindir:=.}/platform-failures --log=xbt_cfg.thres:critical --log=no_loc ${pla p Testing a simple master/worker example application handling failures. TCP crosstraffic ENABLED ! output sort 19 -$ ${bindir:=.}/platform-failures --log=xbt_cfg.thres:critical --log=no_loc ${platfdir}/small_platform_failures.xml ${srcdir}/../app-masterworker/app-masterworker_d.xml --cfg=path:${srcdir} "--log=root.fmt:[%10.6r]%e(%i:%P@%h)%e%m%n" --log=surf_cpu.t:verbose +$ ${bindir:=.}/platform-failures-c --log=xbt_cfg.thres:critical --log=no_loc ${platfdir}/small_platform_failures.xml ${srcdir:=.}/../../s4u/platform-failures/s4u-platform-failures_d.xml --cfg=path:${srcdir} "--log=root.fmt:[%10.6r]%e(%i:%P@%h)%e%m%n" --log=surf_cpu.t:verbose > [ 0.000000] (0:maestro@) Cannot launch actor 'worker' on failed host 'Fafard' > [ 0.000000] (0:maestro@) Deployment includes some initially turned off Hosts ... nevermind. > [ 0.000000] (1:master@Tremblay) Got 5 workers and 20 tasks to process @@ -217,4 +217,4 @@ p complex with such an integration test. One day, we will setup a set of p unit tests for the surf solver, and such issues will be addressable again. p For the time being, I just give up, sorry. -p $ ${bindir:=.}/platform-failures --log=xbt_cfg.thres:critical --log=no_loc ${platfdir}/small_platform_failures.xml ${srcdir}/../app-masterworker/app-masterworker_d.xml --cfg=path:${srcdir} --cfg=cpu/optim:TI "--log=root.fmt:[%10.6r]%e(%i:%P@%h)%e%m%n" --log=surf_cpu.t:verbose +p $ ${bindir:=.}/platform-failures-c --log=xbt_cfg.thres:critical --log=no_loc ${platfdir}/small_platform_failures.xml ${srcdir:=.}/../../s4u/platform-failures/s4u-platform-failures_d.xml --cfg=path:${srcdir} --cfg=cpu/optim:TI "--log=root.fmt:[%10.6r]%e(%i:%P@%h)%e%m%n" --log=surf_cpu.t:verbose diff --git a/examples/deprecated/msg/CMakeLists.txt b/examples/deprecated/msg/CMakeLists.txt index 402f82c7b3..cbbc1d58b0 100644 --- a/examples/deprecated/msg/CMakeLists.txt +++ b/examples/deprecated/msg/CMakeLists.txt @@ -1,6 +1,6 @@ # C examples foreach(x app-masterworker cloud-masterworker - dht-pastry platform-failures + dht-pastry synchro-semaphore trace-categories trace-route-user-variables trace-link-user-variables trace-masterworker trace-process-migration trace-host-user-variables) @@ -56,7 +56,7 @@ set(xml_files ${xml_files} ${CMAKE_CURRENT_SOURCE_DIR}/app-masterworker/a if(enable_msg) foreach(x app-masterworker cloud-masterworker - dht-pastry dht-kademlia platform-failures + dht-pastry dht-kademlia synchro-semaphore) ADD_TESH_FACTORIES(msg-${x} "thread;ucontext;raw;boost" --setenv bindir=${CMAKE_BINARY_DIR}/examples/deprecated/msg/${x} diff --git a/examples/deprecated/msg/platform-failures/platform-failures.c b/examples/deprecated/msg/platform-failures/platform-failures.c deleted file mode 100644 index 542f03473e..0000000000 --- a/examples/deprecated/msg/platform-failures/platform-failures.c +++ /dev/null @@ -1,143 +0,0 @@ -/* Copyright (c) 2007-2020. The SimGrid Team. All rights reserved. */ - -/* 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. */ - -#include "simgrid/msg.h" - -#include /* snprintf */ - -XBT_LOG_NEW_DEFAULT_CATEGORY(msg_test, "Messages specific for this msg example"); - -#define FINALIZE ((void*)221297) /* a magic number to tell people to stop working */ - -static void task_cleanup_handler(void* task) -{ - MSG_task_destroy(task); -} - -static int master(int argc, char *argv[]) -{ - xbt_assert(argc == 5); - long number_of_tasks = xbt_str_parse_int(argv[1], "Invalid amount of tasks: %s"); - double task_comp_size = xbt_str_parse_double(argv[2], "Invalid computational size: %s"); - double task_comm_size = xbt_str_parse_double(argv[3], "Invalid communication size: %s"); - long workers_count = xbt_str_parse_int(argv[4], "Invalid amount of workers: %s"); - - XBT_INFO("Got %ld workers and %ld tasks to process", workers_count, number_of_tasks); - - for (int i = 0; i < number_of_tasks; i++) { - char mailbox[256]; - snprintf(mailbox, 255, "worker-%ld", i % workers_count); - XBT_INFO("Send a message to %s", mailbox); - msg_task_t task = MSG_task_create("Task", task_comp_size, task_comm_size, NULL); - - switch ( MSG_task_send_with_timeout(task,mailbox,10.0) ) { - case MSG_OK: - XBT_INFO("Send to %s completed", mailbox); - break; - - case MSG_TRANSFER_FAILURE: - XBT_INFO("Mmh. The communication with '%s' failed. Nevermind. Let's keep going!", mailbox); - MSG_task_destroy(task); - break; - - case MSG_TIMEOUT: - XBT_INFO ("Mmh. Got timeouted while speaking to '%s'. Nevermind. Let's keep going!", mailbox); - MSG_task_destroy(task); - break; - - default: - xbt_die( "Unexpected behavior"); - } - } - - XBT_INFO("All tasks have been dispatched. Let's tell everybody the computation is over."); - for (int i = 0; i < workers_count; i++) { - char mailbox[256]; - snprintf(mailbox, 255, "worker-%ld", i % workers_count); - msg_task_t task = MSG_task_create("finalize", 0, 0, FINALIZE); - - switch (MSG_task_send_with_timeout(task,mailbox,1.0)) { - - case MSG_TRANSFER_FAILURE: - XBT_INFO("Mmh. Can't reach '%s'! Nevermind. Let's keep going!", mailbox); - MSG_task_destroy(task); - break; - - case MSG_TIMEOUT: - XBT_INFO("Mmh. Got timeouted while speaking to '%s'. Nevermind. Let's keep going!", mailbox); - MSG_task_destroy(task); - break; - - case MSG_OK: - /* nothing */ - break; - - default: - xbt_die("Unexpected behavior with '%s'", mailbox); - } - } - - XBT_INFO("Goodbye now!"); - return 0; -} - -static int worker(int argc, char *argv[]) -{ - xbt_assert(argc == 2); - char mailbox[80]; - - long id= xbt_str_parse_int(argv[1], "Invalid argument %s"); - - snprintf(mailbox, 79,"worker-%ld", id); - - while (1) { - msg_task_t task = NULL; - XBT_INFO("Waiting a message on %s", mailbox); - int retcode = MSG_task_receive( &(task), mailbox); - if (retcode == MSG_OK) { - if (MSG_task_get_data(task) == FINALIZE) { - MSG_task_destroy(task); - break; - } - XBT_INFO("Start execution..."); - MSG_process_set_data(MSG_process_self(), task); - retcode = MSG_task_execute(task); - MSG_process_set_data(MSG_process_self(), NULL); - if (retcode == MSG_OK) { - XBT_INFO("Execution complete."); - MSG_task_destroy(task); - } else { - XBT_INFO("Hey ?! What's up ? "); - xbt_die("Unexpected behavior"); - } - } else if (retcode == MSG_TRANSFER_FAILURE) { - XBT_INFO("Mmh. Something went wrong. Nevermind. Let's keep going!"); - } else { - xbt_die("Unexpected behavior"); - } - } - XBT_INFO("I'm done. See you!"); - return 0; -} - -int main(int argc, char *argv[]) -{ - MSG_init(&argc, argv); - xbt_assert(argc > 2, "Usage: %s platform_file deployment_file\n" - "\tExample: %s msg_platform.xml msg_deployment.xml\n", argv[0], argv[0]); - - MSG_create_environment(argv[1]); - - MSG_function_register("master", master); - MSG_function_register("worker", worker); - MSG_process_set_data_cleanup(task_cleanup_handler); - MSG_launch_application(argv[2]); - - msg_error_t res = MSG_main(); - - XBT_INFO("Simulation time %g", MSG_get_clock()); - - return res != MSG_OK; -} -- 2.20.1