Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Update copyright lines.
[simgrid.git] / examples / s4u / io-dependent / s4u-io-dependent.cpp
1 /* Copyright (c) 2007-2021. The SimGrid Team. All rights reserved.          */
2
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. */
5
6 #include "simgrid/s4u.hpp"
7 #include <simgrid/plugins/file_system.h>
8 #include <vector>
9
10 XBT_LOG_NEW_DEFAULT_CATEGORY(s4u_test, "Messages specific for this s4u example");
11
12 static void test()
13 {
14   simgrid::s4u::ExecPtr bob_compute = simgrid::s4u::this_actor::exec_init(1e9);
15   simgrid::s4u::IoPtr bob_write =
16       simgrid::s4u::Host::current()->get_disks().front()->io_init(4000000, simgrid::s4u::Io::OpType::WRITE);
17   simgrid::s4u::IoPtr carl_read =
18       simgrid::s4u::Host::by_name("carl")->get_disks().front()->io_init(4000000, simgrid::s4u::Io::OpType::READ);
19   simgrid::s4u::ExecPtr carl_compute = simgrid::s4u::Host::by_name("carl")->exec_async(1e9);
20
21   // Name the activities (for logging purposes only)
22   bob_compute->set_name("bob compute");
23   bob_write->set_name("bob write");
24   carl_read->set_name("carl read");
25   carl_compute->set_name("carl compute");
26
27   // Create the dependencies:
28   // 'bob_write' is a successor of 'bob_compute'
29   // 'carl_read' is a successor of 'bob_write'
30   // 'carl_compute' is a successor of 'carl_read'
31   bob_compute->add_successor(bob_write);
32   bob_write->add_successor(carl_read);
33   carl_read->add_successor(carl_compute);
34
35   // Start the activities.
36   bob_compute->start();
37   bob_write->vetoable_start();
38   carl_read->vetoable_start();
39   carl_compute->vetoable_start();
40
41   // Wait for their completion (should be replaced by a wait_any_for at some point)
42   bob_compute->wait();
43   bob_write->wait();
44   carl_read->wait();
45   carl_compute->wait();
46 }
47
48 int main(int argc, char* argv[])
49 {
50   simgrid::s4u::Engine e(&argc, argv);
51   sg_storage_file_system_init();
52   e.load_platform(argv[1]);
53
54   simgrid::s4u::Actor::create("bob", simgrid::s4u::Host::by_name("bob"), test);
55
56   e.run();
57
58   XBT_INFO("Simulation time %g", e.get_clock());
59
60   return 0;
61 }