Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
d844f6c901f055311d5fb40b308943674a4435ba
[simgrid.git] / examples / c / exec-remote / exec-remote.c
1 /* Copyright (c) 2007-2020. 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/exec.h"
9 #include "simgrid/host.h"
10
11 #include "xbt/log.h"
12
13 XBT_LOG_NEW_DEFAULT_CATEGORY(exec_remote, "Messages specific for this example");
14
15 static void wizard(int argc, char* argv[])
16 {
17   const_sg_host_t fafard = sg_host_by_name("Fafard");
18   sg_host_t ginette      = sg_host_by_name("Ginette");
19   sg_host_t boivin       = sg_host_by_name("Boivin");
20
21   XBT_INFO("I'm a wizard! I can run a task on the Ginette host from the Fafard one! Look!");
22   sg_exec_t exec = sg_actor_exec_init(48.492e6);
23   sg_exec_set_host(exec, ginette);
24   sg_exec_start(exec);
25   XBT_INFO("It started. Running 48.492Mf takes exactly one second on Ginette (but not on Fafard).");
26
27   sg_actor_sleep_for(0.1);
28   XBT_INFO("Loads in flops/s: Boivin=%.0f; Fafard=%.0f; Ginette=%.0f", sg_host_get_load(boivin),
29            sg_host_get_load(fafard), sg_host_get_load(ginette));
30
31   sg_exec_wait(exec);
32
33   XBT_INFO("Done!");
34   XBT_INFO("And now, harder. Start a remote task on Ginette and move it to Boivin after 0.5 sec");
35   exec = sg_actor_exec_init(73293500);
36   sg_exec_set_host(exec, ginette);
37   sg_exec_start(exec);
38
39   sg_actor_sleep_for(0.5);
40   XBT_INFO("Loads before the move: Boivin=%.0f; Fafard=%.0f; Ginette=%.0f", sg_host_get_load(boivin),
41            sg_host_get_load(fafard), sg_host_get_load(ginette));
42
43   sg_exec_set_host(exec, boivin);
44
45   sg_actor_sleep_for(0.1);
46   XBT_INFO("Loads after the move: Boivin=%.0f; Fafard=%.0f; Ginette=%.0f", sg_host_get_load(boivin),
47            sg_host_get_load(fafard), sg_host_get_load(ginette));
48
49   sg_exec_wait(exec);
50   XBT_INFO("Done!");
51 }
52
53 int main(int argc, char* argv[])
54 {
55   simgrid_init(&argc, argv);
56   simgrid_load_platform(argv[1]);
57   sg_actor_create("test", sg_host_by_name("Fafard"), wizard, 0, NULL);
58
59   simgrid_run();
60
61   return 0;
62 }