From: Martin Quinson Date: Thu, 26 Jan 2017 21:41:36 +0000 (+0100) Subject: New example for MSG_process_yield() X-Git-Tag: v3_15~514 X-Git-Url: http://info.iut-bm.univ-fcomte.fr/pub/gitweb/simgrid.git/commitdiff_plain/8a6c72d1a413ad73f93d5e13768ca57b435130aa New example for MSG_process_yield() --- diff --git a/.gitignore b/.gitignore index d353406e6a..9b56f91afa 100644 --- a/.gitignore +++ b/.gitignore @@ -121,6 +121,7 @@ doc/msg-tuto-src/masterworker3 doc/msg-tuto-src/masterworker4 examples/msg/actions-comm/actions-comm examples/msg/actions-storage/actions-storage +examples/msg/async-yield/async-yield examples/msg/async-wait/async-wait examples/msg/async-waitall/async-waitall examples/msg/async-waitany/async-waitany diff --git a/examples/msg/CMakeLists.txt b/examples/msg/CMakeLists.txt index 5fa4f26e42..a427f2dbe5 100644 --- a/examples/msg/CMakeLists.txt +++ b/examples/msg/CMakeLists.txt @@ -1,5 +1,5 @@ # C examples -foreach(x actions-comm actions-storage app-masterworker app-pingpong app-pmm app-token-ring async-wait async-waitall +foreach(x actions-comm actions-storage app-masterworker app-pingpong app-pmm app-token-ring async-yield async-wait async-waitall async-waitany cloud-capping cloud-masterworker cloud-migration cloud-simple cloud-two-tasks dht-chord dht-pastry energy-consumption energy-onoff energy-pstate energy-ptask energy-vm platform-failures io-file io-remote io-storage task-priority process-create process-kill process-migration process-suspend @@ -49,7 +49,7 @@ foreach (file answer dht-kademlia node routing_table task) set(examples_src ${examples_src} ${CMAKE_CURRENT_SOURCE_DIR}/dht-kademlia/${file}.c ${CMAKE_CURRENT_SOURCE_DIR}/dht-kademlia/${file}.h) endforeach() -foreach (file actions-comm actions-storage app-bittorrent app-chainsend app-masterworker app-pingpong async-wait +foreach (file actions-comm actions-storage app-bittorrent app-chainsend app-masterworker app-pingpong async-yield async-wait async-waitall async-waitany dht-chord dht-kademlia io-remote platform-properties task-priority) set(xml_files ${xml_files} ${CMAKE_CURRENT_SOURCE_DIR}/${file}/${file}_d.xml) @@ -94,7 +94,7 @@ set(xml_files ${xml_files} ${CMAKE_CURRENT_SOURCE_DIR}/actions-comm/actio ${CMAKE_CURRENT_SOURCE_DIR}/process-startkilltime/start_kill_d.xml PARENT_SCOPE) foreach(x actions-comm actions-storage app-bittorrent app-chainsend app-masterworker app-pingpong app-token-ring - async-wait async-waitall async-waitany cloud-capping cloud-masterworker cloud-migration cloud-simple + async-yield async-wait async-waitall async-waitany cloud-capping cloud-masterworker cloud-migration cloud-simple cloud-two-tasks dht-chord dht-pastry dht-kademlia platform-failures io-file io-remote io-storage task-priority process-create process-kill process-migration process-suspend platform-properties synchro-semaphore process-startkilltime) diff --git a/examples/msg/async-yield/async-yield.c b/examples/msg/async-yield/async-yield.c new file mode 100644 index 0000000000..ada22e374d --- /dev/null +++ b/examples/msg/async-yield/async-yield.c @@ -0,0 +1,46 @@ +/* Copyright (c) 2017. 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" + +/* This example does not much: It just spans over-polite processes that yield a large amount + * of time before ending. + * + * This serves as an example for the MSG_process_yield() function, with which a process can request + * to be rescheduled after the other processes that are ready at the current timestamp. + * + * It can also be used to benchmark our context-switching mechanism. + */ + +XBT_LOG_NEW_DEFAULT_CATEGORY(msg_async_yield, "Messages specific for this msg example"); + +/* Main function of the Yielder process */ +static int yielder(int argc, char* argv[]) +{ + xbt_assert(argc == 2, "The sender function expects 1 arguments from the XML deployment file"); + long number_of_yields = xbt_str_parse_int(argv[1], "Invalid amount of yields: %s"); /* - number of yields */ + + for (int i = 0; i < number_of_yields; i++) + MSG_process_yield(); + XBT_INFO("I yielded %ld times. Goodbye now!", number_of_yields); + 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]); /* - Load the platform description */ + + MSG_function_register("yielder", yielder); + MSG_launch_application(argv[2]); /* - Deploy the sender and receiver processes */ + + msg_error_t res = MSG_main(); /* - Run the simulation */ + + return res != MSG_OK; +} diff --git a/examples/msg/async-yield/async-yield.tesh b/examples/msg/async-yield/async-yield.tesh new file mode 100644 index 0000000000..e5aef16db5 --- /dev/null +++ b/examples/msg/async-yield/async-yield.tesh @@ -0,0 +1,5 @@ +#! ./tesh + +$ $SG_TEST_EXENV ${bindir:=.}/async-yield ${srcdir:=.}/small_platform_fatpipe.xml ${srcdir:=.}/../msg/async-yield/async-yield_d.xml "--log=root.fmt:[%10.6r]%e(%i:%P@%h)%e%m%n" +> [ 0.000000] (1:yielder@Tremblay) I yielded 10 times. Goodbye now! +> [ 0.000000] (2:yielder@Ruby) I yielded 15 times. Goodbye now! diff --git a/examples/msg/async-yield/async-yield_d.xml b/examples/msg/async-yield/async-yield_d.xml new file mode 100644 index 0000000000..0b1b17a4f4 --- /dev/null +++ b/examples/msg/async-yield/async-yield_d.xml @@ -0,0 +1,10 @@ + + + + + + + + + +