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 ({bob_compute, bob_write, carl_read, carl_compute});
22 // Name the activities (for logging purposes only)
23 bob_compute->set_name("bob compute");
24 bob_write->set_name("bob write");
25 carl_read->set_name("carl read");
26 carl_compute->set_name("carl compute");
28 // Create the dependencies:
29 // 'bob_write' is a successor of 'bob_compute'
30 // 'carl_read' is a successor of 'bob_write'
31 // 'carl_compute' is a successor of 'carl_read'
32 bob_compute->add_successor(bob_write);
33 bob_write->add_successor(carl_read);
34 carl_read->add_successor(carl_compute);
36 // Start the activities.
40 carl_compute->start();
42 // wait for the completion of all activities
43 while (not pending_activities.empty()) {
44 auto completed_one = pending_activities.wait_any();
45 if (completed_one != nullptr)
46 XBT_INFO("Activity '%s' is complete", completed_one->get_cname());
50 int main(int argc, char* argv[])
52 sg4::Engine e(&argc, argv);
53 e.load_platform(argv[1]);
55 sg4::Actor::create("bob", e.host_by_name("bob"), test);
59 XBT_INFO("Simulation time %g", sg4::Engine::get_clock());