1 /* Copyright (c) 2007-2021. 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");
14 std::vector<simgrid::s4u::IoPtr> pending_ios;
16 simgrid::s4u::ExecPtr bob_compute = simgrid::s4u::this_actor::exec_init(1e9);
17 simgrid::s4u::IoPtr bob_write =
18 simgrid::s4u::Host::current()->get_disks().front()->io_init(4000000, simgrid::s4u::Io::OpType::WRITE);
19 pending_ios.push_back(bob_write);
20 simgrid::s4u::IoPtr carl_read =
21 simgrid::s4u::Host::by_name("carl")->get_disks().front()->io_init(4000000, simgrid::s4u::Io::OpType::READ);
22 pending_ios.push_back(carl_read);
23 simgrid::s4u::ExecPtr carl_compute = simgrid::s4u::Host::by_name("carl")->exec_init(1e9);
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.
41 bob_write->vetoable_start();
42 carl_read->vetoable_start();
43 carl_compute->vetoable_start();
45 // wait for the completion of all activities
47 while (not pending_ios.empty()) {
48 int changed_pos = simgrid::s4u::Io::wait_any(pending_ios);
49 XBT_INFO("Io '%s' is complete", pending_ios[changed_pos]->get_cname());
50 pending_ios.erase(pending_ios.begin() + changed_pos);
55 int main(int argc, char* argv[])
57 simgrid::s4u::Engine e(&argc, argv);
58 sg_storage_file_system_init();
59 e.load_platform(argv[1]);
61 simgrid::s4u::Actor::create("bob", simgrid::s4u::Host::by_name("bob"), test);
65 XBT_INFO("Simulation time %g", simgrid::s4u::Engine::get_clock());