Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Update copyright lines.
[simgrid.git] / examples / c / actor-yield / actor-yield.c
1 /* Copyright (c) 2017-2021. 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/actor.h"
7 #include "simgrid/engine.h"
8
9 #include "xbt/asserts.h"
10 #include "xbt/log.h"
11 #include "xbt/str.h"
12
13 /* This example does not much: It just spans over-polite actors that yield a large amount
14  * of time before ending.
15  *
16  * This serves as an example for the sg_actor_yield() function, with which an actor can request
17  * to be rescheduled after the other actors that are ready at the current timestamp.
18  *
19  * It can also be used to benchmark our context-switching mechanism.
20  */
21
22 XBT_LOG_NEW_DEFAULT_CATEGORY(actor_yield, "Messages specific for this example");
23
24 /* Main function of the Yielder actor */
25 static void yielder(int argc, char* argv[])
26 {
27   xbt_assert(argc == 2, "The sender function expects 1 arguments from the XML deployment file");
28   long number_of_yields = xbt_str_parse_int(argv[1], "Invalid amount of yields: %s"); /* - number of yields */
29
30   for (int i = 0; i < number_of_yields; i++)
31     sg_actor_yield();
32   XBT_INFO("I yielded %ld times. Goodbye now!", number_of_yields);
33 }
34
35 int main(int argc, char* argv[])
36 {
37   simgrid_init(&argc, argv);
38   xbt_assert(argc > 2,
39              "Usage: %s platform_file deployment_file\n"
40              "\tExample: %s msg_platform.xml msg_deployment.xml\n",
41              argv[0], argv[0]);
42
43   simgrid_load_platform(argv[1]); /* - Load the platform description */
44
45   simgrid_register_function("yielder", yielder);
46   simgrid_load_deployment(argv[2]); /* - Deploy the sender and receiver actors */
47
48   simgrid_run();
49   return 0;
50 }