Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Update copyright lines for 2022.
[simgrid.git] / examples / c / exec-basic / exec-basic.c
1 /* Copyright (c) 2010-2022. 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 #include "simgrid/host.h"
9
10 #include "xbt/asserts.h"
11 #include "xbt/log.h"
12
13 XBT_LOG_NEW_DEFAULT_CATEGORY(exec_basic, "Messages specific for this example");
14
15 static void executor(int argc, char* argv[])
16 {
17   /* sg_actor_execute() tells SimGrid to pause the calling actor
18    * until its host has computed the amount of flops passed as a parameter */
19   sg_actor_execute(98095);
20   XBT_INFO("Done.");
21
22   /* This simple example does not do anything beyond that */
23 }
24
25 static void privileged(int argc, char* argv[])
26 {
27   /* sg_actor_execute_with_priority() specifies that this execution gets a larger share of the resource.
28    *
29    * Since the priority is 2, it computes twice as fast as a regular one.
30    *
31    * So instead of a half/half sharing between the two executions,
32    * we get a 1/3 vs 2/3 sharing. */
33   sg_actor_execute_with_priority(98095, 2);
34   XBT_INFO("Done.");
35
36   /* Note that the timings printed when executing this example are a bit misleading,
37    * because the uneven sharing only last until the privileged actor ends.
38    * After this point, the unprivileged one gets 100% of the CPU and finishes
39    * quite quickly. */
40 }
41
42 int main(int argc, char* argv[])
43 {
44   simgrid_init(&argc, argv);
45   xbt_assert(argc > 1, "Usage: %s platform_file\n\tExample: %s ../platforms/small_platform.xml\n", argv[0], argv[0]);
46
47   simgrid_load_platform(argv[1]);
48
49   sg_actor_create("executor", sg_host_by_name("Tremblay"), executor, 0, NULL);
50   sg_actor_create("privileged", sg_host_by_name("Tremblay"), privileged, 0, NULL);
51
52   simgrid_run();
53
54   return 0;
55 }