1 /* Copyright (c) 2007-2017. 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/s4u.hpp"
7 #include "simgrid/s4u/VirtualMachine.hpp"
8 XBT_LOG_NEW_DEFAULT_CATEGORY(s4u_test, "Messages specific for this s4u example");
10 static void computation_fun()
12 double clock_sta = simgrid::s4u::Engine::getClock();
13 simgrid::s4u::this_actor::execute(1000000);
14 double clock_end = simgrid::s4u::Engine::getClock();
16 XBT_INFO("%s:%s task executed %g", simgrid::s4u::this_actor::getHost()->getCname(),
17 simgrid::s4u::this_actor::getCname(), clock_end - clock_sta);
20 static void launch_computation_worker(s4u_Host* host)
22 simgrid::s4u::Actor::createActor("compute", host, computation_fun);
27 const char* tx_actor_name;
31 static void communication_tx_fun(std::vector<std::string> args)
33 simgrid::s4u::MailboxPtr mbox = simgrid::s4u::Mailbox::byName(args.at(0));
34 struct s_payload* payload = xbt_new(struct s_payload, 1);
35 payload->tx_actor_name = simgrid::s4u::Actor::self()->getCname();
36 payload->tx_host = simgrid::s4u::this_actor::getHost();
37 payload->clock_sta = simgrid::s4u::Engine::getClock();
39 mbox->put(payload, 1000000);
42 static void communication_rx_fun(std::vector<std::string> args)
44 const char* actor_name = simgrid::s4u::Actor::self()->getCname();
45 const char* host_name = simgrid::s4u::this_actor::getHost()->getCname();
46 simgrid::s4u::MailboxPtr mbox = simgrid::s4u::Mailbox::byName(args.at(0));
48 struct s_payload* payload = static_cast<struct s_payload*>(mbox->get());
49 double clock_end = simgrid::s4u::Engine::getClock();
51 XBT_INFO("%s:%s to %s:%s => %g sec", payload->tx_host->getCname(), payload->tx_actor_name, host_name, actor_name,
52 clock_end - payload->clock_sta);
57 static void launch_communication_worker(s4u_Host* tx_host, s4u_Host* rx_host)
59 std::string mbox_name = std::string("MBOX:") + tx_host->getCname() + "-" + rx_host->getCname();
60 std::vector<std::string> args;
61 args.push_back(mbox_name);
63 simgrid::s4u::Actor::createActor("comm_tx", tx_host, communication_tx_fun, args);
65 simgrid::s4u::Actor::createActor("comm_rx", rx_host, communication_rx_fun, args);
68 static void master_main()
70 s4u_Host* pm0 = simgrid::s4u::Host::by_name("Fafard");
71 s4u_Host* pm1 = simgrid::s4u::Host::by_name("Tremblay");
73 XBT_INFO("## Test 1 (started): check computation on normal PMs");
75 XBT_INFO("### Put a task on a PM");
76 launch_computation_worker(pm0);
77 simgrid::s4u::this_actor::sleep_for(2);
79 XBT_INFO("### Put two tasks on a PM");
80 launch_computation_worker(pm0);
81 launch_computation_worker(pm0);
82 simgrid::s4u::this_actor::sleep_for(2);
84 XBT_INFO("### Put a task on each PM");
85 launch_computation_worker(pm0);
86 launch_computation_worker(pm1);
87 simgrid::s4u::this_actor::sleep_for(2);
89 XBT_INFO("## Test 1 (ended)");
91 XBT_INFO("## Test 2 (started): check impact of running a task inside a VM (there is no degradation for the moment)");
93 XBT_INFO("### Put a VM on a PM, and put a task to the VM");
94 simgrid::s4u::VirtualMachine* vm0 = new simgrid::s4u::VirtualMachine("VM0", pm0, 1);
96 launch_computation_worker(vm0);
97 simgrid::s4u::this_actor::sleep_for(2);
100 XBT_INFO("## Test 2 (ended)");
103 "## Test 3 (started): check impact of running a task collocated with a VM (there is no VM noise for the moment)");
105 XBT_INFO("### Put a VM on a PM, and put a task to the PM");
106 vm0 = new simgrid::s4u::VirtualMachine("VM0", pm0, 1);
108 launch_computation_worker(pm0);
109 simgrid::s4u::this_actor::sleep_for(2);
111 XBT_INFO("## Test 3 (ended)");
113 XBT_INFO("## Test 4 (started): compare the cost of running two tasks inside two different VMs collocated or not (for"
114 " the moment, there is no degradation for the VMs. Hence, the time should be equals to the time of test 1");
116 XBT_INFO("### Put two VMs on a PM, and put a task to each VM");
117 vm0 = new simgrid::s4u::VirtualMachine("VM0", pm0, 1);
119 simgrid::s4u::VirtualMachine* vm1 = new simgrid::s4u::VirtualMachine("VM1", pm0, 1);
120 launch_computation_worker(vm0);
121 launch_computation_worker(vm1);
122 simgrid::s4u::this_actor::sleep_for(2);
126 XBT_INFO("### Put a VM on each PM, and put a task to each VM");
127 vm0 = new simgrid::s4u::VirtualMachine("VM0", pm0, 1);
128 vm1 = new simgrid::s4u::VirtualMachine("VM1", pm1, 1);
131 launch_computation_worker(vm0);
132 launch_computation_worker(vm1);
133 simgrid::s4u::this_actor::sleep_for(2);
136 XBT_INFO("## Test 4 (ended)");
138 XBT_INFO("## Test 5 (started): Analyse network impact");
139 XBT_INFO("### Make a connection between PM0 and PM1");
140 launch_communication_worker(pm0, pm1);
141 simgrid::s4u::this_actor::sleep_for(5);
143 XBT_INFO("### Make two connection between PM0 and PM1");
144 launch_communication_worker(pm0, pm1);
145 launch_communication_worker(pm0, pm1);
146 simgrid::s4u::this_actor::sleep_for(5);
148 XBT_INFO("### Make a connection between PM0 and VM0@PM0");
149 vm0 = new simgrid::s4u::VirtualMachine("VM0", pm0, 1);
151 launch_communication_worker(pm0, vm0);
152 simgrid::s4u::this_actor::sleep_for(5);
155 XBT_INFO("### Make a connection between PM0 and VM0@PM1");
156 vm0 = new simgrid::s4u::VirtualMachine("VM0", pm1, 1);
157 launch_communication_worker(pm0, vm0);
158 simgrid::s4u::this_actor::sleep_for(5);
161 XBT_INFO("### Make two connections between PM0 and VM0@PM1");
162 vm0 = new simgrid::s4u::VirtualMachine("VM0", pm1, 1);
164 launch_communication_worker(pm0, vm0);
165 launch_communication_worker(pm0, vm0);
166 simgrid::s4u::this_actor::sleep_for(5);
169 XBT_INFO("### Make a connection between PM0 and VM0@PM1, and also make a connection between PM0 and PM1");
170 vm0 = new simgrid::s4u::VirtualMachine("VM0", pm1, 1);
172 launch_communication_worker(pm0, vm0);
173 launch_communication_worker(pm0, pm1);
174 simgrid::s4u::this_actor::sleep_for(5);
177 XBT_INFO("### Make a connection between VM0@PM0 and PM1@PM1, and also make a connection between VM0@PM0 and VM1@PM1");
178 vm0 = new simgrid::s4u::VirtualMachine("VM0", pm0, 1);
179 vm1 = new simgrid::s4u::VirtualMachine("VM1", pm1, 1);
182 launch_communication_worker(vm0, vm1);
183 launch_communication_worker(vm0, vm1);
184 simgrid::s4u::this_actor::sleep_for(5);
188 XBT_INFO("## Test 5 (ended)");
191 int main(int argc, char* argv[])
193 simgrid::s4u::Engine e(&argc, argv);
194 e.loadPlatform(argv[1]); /* - Load the platform description */
196 simgrid::s4u::Actor::createActor("master_", simgrid::s4u::Host::by_name("Fafard"), master_main);
200 XBT_INFO("Simulation time %g", e.getClock());