Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
suggested solution tu use simix through a function
[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 #include "src/simix/ActorImpl.hpp"
8 #include "src/simix/smx_private.h"
9 #include <string>
10
11 /* This example does not much: It just spans over-polite processes that yield a large amount
12 * of time before ending.
13 *
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.
16 *
17 * It can also be used to benchmark our context-switching mechanism.
18 */
19 XBT_LOG_NEW_DEFAULT_CATEGORY(s4u_actor_yield, "Messages specific for this s4u example");
20 /* Main function of the Yielder process */
21 class yielder {
22  long number_of_yields;
23 public: 
24  explicit yielder() = default;
25  explicit yielder(std::vector<std::string> args)
26
27  number_of_yields = std::stod(args[1]);
28 }
29 void operator()()
30 {
31  simgrid::s4u::ActorPtr actor;
32  for (int i = 0; i < number_of_yields; i++)
33  actor->yield();
34  XBT_INFO("I yielded %ld times. Goodbye now!", number_of_yields);
35 }
36 };
37
38 int main(int argc, char* argv[])
39 {
40  simgrid::s4u::Engine e(&argc, argv);
41  
42  xbt_assert(argc > 2, "Usage: %s platform_file deployment_file\n"
43  "\tExample: %s msg_platform.xml msg_deployment.xml\n",
44  argv[0], argv[0]);
45  
46  e.loadPlatform(argv[1]);  /* - Load the platform description */
47  e.registerFunction<yielder>("yielder");
48  std::vector<std::string> args; 
49
50  e.loadDeployment(argv[2]);
51
52  e.run();  /* - Run the simulation */
53
54  return 0;
55 }