Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
cosmetics
[simgrid.git] / examples / s4u / actor-yield / s4u-actor-yield.cpp
1 /* Copyright (c) 2017. The SimGrid Team. All rights reserved.               */
2
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. */
5
6 #include "simgrid/s4u.hpp"
7
8 /* This example does not much: It just spans over-polite actor that yield a large amount
9 * of time before ending.
10 *
11 * This serves as an example for the simgrid::s4u::this_actor::yield() function, with which an actor can request
12 * to be rescheduled after the other actor that are ready at the current timestamp.
13 *
14 * It can also be used to benchmark our context-switching mechanism.
15 */
16 XBT_LOG_NEW_DEFAULT_CATEGORY(s4u_actor_yield, "Messages specific for this s4u example");
17 /* Main function of the Yielder process */
18 class yielder {
19  long number_of_yields;
20 public: 
21  explicit yielder() = default;
22  explicit yielder(std::vector<std::string> args)
23
24  number_of_yields = std::stod(args[1]);
25 }
26 void operator()()
27 {
28  for (int i = 0; i < number_of_yields; i++)
29  simgrid::s4u::this_actor::yield();
30  XBT_INFO("I yielded %ld times. Goodbye now!", number_of_yields);
31 }
32 };
33
34 int main(int argc, char* argv[])
35 {
36  simgrid::s4u::Engine e(&argc, argv);
37  
38  xbt_assert(argc > 2, "Usage: %s platform_file deployment_file\n"
39  "\tExample: %s platform.xml deployment.xml\n",
40  argv[0], argv[0]);
41  
42  e.loadPlatform(argv[1]);  /* - Load the platform description */
43  e.registerFunction<yielder>("yielder");
44  std::vector<std::string> args; 
45
46  e.loadDeployment(argv[2]);
47
48  e.run();  /* - Run the simulation */
49
50  return 0;
51 }