1 /* Copyright (c) 2007-2023. 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/plugins/file_system.h>
10 XBT_LOG_NEW_DEFAULT_CATEGORY(s4u_test, "Messages specific for this s4u example");
11 namespace sg4 = simgrid::s4u;
15 sg4::ExecPtr bob_compute = sg4::this_actor::exec_init(1e9);
16 sg4::IoPtr bob_write = sg4::Host::current()->get_disks().front()->io_init(4000000, sg4::Io::OpType::WRITE);
17 sg4::IoPtr carl_read = sg4::Host::by_name("carl")->get_disks().front()->io_init(4000000, sg4::Io::OpType::READ);
18 sg4::ExecPtr carl_compute = sg4::Host::by_name("carl")->exec_init(1e9);
20 sg4::ActivitySet pending_activities ({boost::dynamic_pointer_cast<sg4::Activity>(bob_compute),
21 boost::dynamic_pointer_cast<sg4::Activity>(bob_write),
22 boost::dynamic_pointer_cast<sg4::Activity>(carl_read),
23 boost::dynamic_pointer_cast<sg4::Activity>(carl_compute)});
25 // Name the activities (for logging purposes only)
26 bob_compute->set_name("bob compute");
27 bob_write->set_name("bob write");
28 carl_read->set_name("carl read");
29 carl_compute->set_name("carl compute");
31 // Create the dependencies:
32 // 'bob_write' is a successor of 'bob_compute'
33 // 'carl_read' is a successor of 'bob_write'
34 // 'carl_compute' is a successor of 'carl_read'
35 bob_compute->add_successor(bob_write);
36 bob_write->add_successor(carl_read);
37 carl_read->add_successor(carl_compute);
39 // Start the activities.
43 carl_compute->start();
45 // wait for the completion of all activities
46 while (not pending_activities.empty()) {
47 auto completed_one = pending_activities.wait_any();
48 if (completed_one != nullptr)
49 XBT_INFO("Activity '%s' is complete", completed_one->get_cname());
53 int main(int argc, char* argv[])
55 sg4::Engine e(&argc, argv);
56 e.load_platform(argv[1]);
58 sg4::Actor::create("bob", e.host_by_name("bob"), test);
62 XBT_INFO("Simulation time %g", sg4::Engine::get_clock());