1 /* Copyright (c) 2017. The SimGrid Team. All rights reserved. */
3 /* This program is free software; you can redistribute it and/or modify it
4 * under the terms of the license (GNU LGPL) which comes with this package. */
6 #include "simgrid/s4u.hpp"
7 #include "src/simix/ActorImpl.hpp"
8 #include "src/simix/smx_private.h"
11 /* This example does not much: It just spans over-polite processes that yield a large amount
12 * of time before ending.
14 * This serves as an example for the s4u-actor-yield() function, with which a process can request
15 * to be rescheduled after the other processes that are ready at the current timestamp.
17 * It can also be used to benchmark our context-switching mechanism.
19 XBT_LOG_NEW_DEFAULT_CATEGORY(s4u_actor_yield, "Messages specific for this s4u example");
20 /* Main function of the Yielder process */
22 long number_of_yields;
24 explicit yielder() = default;
25 explicit yielder(std::vector<std::string> args)
27 number_of_yields = std::stod(args[1]);
31 simgrid::s4u::ActorPtr actor;
32 for (int i = 0; i < number_of_yields; i++)
34 XBT_INFO("I yielded %ld times. Goodbye now!", number_of_yields);
38 int main(int argc, char* argv[])
40 simgrid::s4u::Engine e(&argc, argv);
42 xbt_assert(argc > 2, "Usage: %s platform_file deployment_file\n"
43 "\tExample: %s msg_platform.xml msg_deployment.xml\n",
46 e.loadPlatform(argv[1]); /* - Load the platform description */
47 e.registerFunction<yielder>("yielder");
48 std::vector<std::string> args;
50 e.loadDeployment(argv[2]);
52 e.run(); /* - Run the simulation */