1 /* Copyright (c) 2007-2022. The SimGrid Team.
2 * All rights reserved. */
4 /* This program is free software; you can redistribute it and/or modify it
5 * under the terms of the license (GNU LGPL) which comes with this package. */
7 #include "simgrid/plugins/energy.h"
8 #include "simgrid/plugins/live_migration.h"
9 #include "simgrid/s4u.hpp"
12 XBT_LOG_NEW_DEFAULT_CATEGORY(example, "Messages specific for this example");
14 static void task_executor()
16 simgrid::s4u::ExecPtr ptr = simgrid::s4u::this_actor::exec_init(3000000000.0)->start();
18 // ptr->test(); // Harmless
19 simgrid::s4u::this_actor::sleep_for(3); // Breaks everything
22 const auto* vm = dynamic_cast<simgrid::s4u::VirtualMachine*>(ptr->get_host());
23 xbt_assert(vm != nullptr, "Hey, I expected to run on a VM");
24 XBT_INFO("Task done. It's running on %s@%s that runs at %.0ef/s. host2 runs at %.0ef/s", vm->get_cname(),
25 vm->get_pm()->get_cname(), vm->get_speed(), simgrid::s4u::Host::by_name("host2")->get_speed());
28 int main(int argc, char* argv[])
30 simgrid::s4u::Engine e(&argc, argv);
31 simgrid::s4u::Engine::set_config("network/model:CM02"); // Much less realistic, but easier to compute manually
33 sg_vm_live_migration_plugin_init();
34 sg_host_energy_plugin_init();
36 xbt_assert(argc == 2, "Usage: %s platform.xml\n", argv[0]);
38 e.load_platform(argv[1]);
39 auto* pm = e.host_by_name("host1");
40 auto* vm = pm->create_vm("VM0", 1 /*nCores*/);
41 vm->set_ramsize(1250000000)->start();
42 simgrid::s4u::Actor::create("executor", vm, task_executor);
44 simgrid::s4u::Actor::create("migration", pm, [vm]() {
45 XBT_INFO("%s migration started", vm->get_cname());
46 const auto* old = vm->get_pm();
48 sg_vm_migrate(vm, simgrid::s4u::Host::by_name("host2"));
50 XBT_INFO("VM '%s' migrated from '%s' to '%s'", vm->get_cname(), old->get_cname(), vm->get_pm()->get_cname());