1 /* Copyright (c) 2007-2020. The SimGrid Team. All rights reserved. */
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. */
6 #include "simgrid/actor.h"
7 #include "simgrid/engine.h"
8 #include "simgrid/exec.h"
9 #include "simgrid/host.h"
10 #include "simgrid/plugins/energy.h"
11 #include "xbt/asserts.h"
12 #include "xbt/config.h"
15 XBT_LOG_NEW_DEFAULT_CATEGORY(energy_exec_ptask, "Messages specific for this example");
17 static void runner(int argc, char* argv[])
19 /* Retrieve the list of all hosts as an array of hosts */
20 int host_count = (int)sg_host_count();
21 sg_host_t* hosts = sg_host_list();
23 XBT_INFO("First, build a classical parallel task, with 1 Gflop to execute on each node, "
24 "and 10MB to exchange between each pair");
25 double* computation_amounts = xbt_new0(double, host_count);
26 double* communication_amounts = xbt_new0(double, host_count * host_count);
28 for (int i = 0; i < host_count; i++)
29 computation_amounts[i] = 1e9; // 1 Gflop
31 for (int i = 0; i < host_count; i++)
32 for (int j = i + 1; j < host_count; j++)
33 communication_amounts[i * host_count + j] = 1e7; // 10 MB
35 sg_actor_parallel_execute(host_count, hosts, computation_amounts, communication_amounts);
37 xbt_free(communication_amounts);
38 xbt_free(computation_amounts);
40 XBT_INFO("We can do the same with a timeout of one second enabled.");
41 computation_amounts = xbt_new0(double, host_count);
42 communication_amounts = xbt_new0(double, host_count * host_count);
43 for (int i = 0; i < host_count; i++)
44 computation_amounts[i] = 1e9; // 1 Gflop
45 for (int i = 0; i < host_count; i++)
46 for (int j = i + 1; j < host_count; j++)
47 communication_amounts[i * host_count + j] = 1e7; // 10 MB
49 sg_exec_t exec = sg_actor_parallel_exec_init(host_count, hosts, computation_amounts, communication_amounts);
50 sg_exec_wait_for(exec, 1 /* timeout (in seconds)*/);
51 xbt_free(communication_amounts);
52 xbt_free(computation_amounts);
54 XBT_INFO("Then, build a parallel task involving only computations and no communication (1 Gflop per node)");
55 computation_amounts = xbt_new0(double, host_count);
56 for (int i = 0; i < host_count; i++)
57 computation_amounts[i] = 1e9; // 1 Gflop
58 sg_actor_parallel_execute(host_count, hosts, computation_amounts, NULL);
59 xbt_free(computation_amounts);
61 XBT_INFO("Then, build a parallel task with no computation nor communication (synchro only)");
62 computation_amounts = xbt_new0(double, host_count);
63 communication_amounts = xbt_new0(double, host_count * host_count);
64 sg_actor_parallel_execute(host_count, hosts, computation_amounts, communication_amounts);
65 xbt_free(communication_amounts);
66 xbt_free(computation_amounts);
68 XBT_INFO("Finally, trick the ptask to do a 'remote execution', on host %s", sg_host_get_name(hosts[1]));
69 computation_amounts = xbt_new0(double, 1);
70 computation_amounts[0] = 1e9; // 1 Gflop
73 sg_actor_parallel_execute(1, remote, computation_amounts, NULL /* no comm */);
74 xbt_free(computation_amounts);
76 XBT_INFO("Goodbye now!");
80 int main(int argc, char* argv[])
82 simgrid_init(&argc, argv);
83 sg_cfg_set_string("host/model", "ptask_L07");
85 xbt_assert(argc <= 3, "1Usage: %s <platform file> [--energy]", argv[0]);
86 xbt_assert(argc >= 2, "2Usage: %s <platform file> [--energy]", argv[0]);
88 if (argc == 3 && argv[2][2] == 'e')
89 sg_host_energy_plugin_init();
91 simgrid_load_platform(argv[1]);
93 /* Pick the first host from the platform file */
94 sg_host_t* all_hosts = sg_host_list();
95 sg_host_t first_host = all_hosts[0];
98 sg_actor_create("test", first_host, runner, 0, NULL);
101 XBT_INFO("Simulation done.");