6 This tutorial presents the basics to understand how DAG are represented in Simgrid and how to simulate their workflow.
11 Directed Acyclic Graph:
15 \mathcal{G} = (\mathcal{V},\mathcal{E})
17 Set of vertices representing :ref:`Activities <API_s4u_Activity>`:
21 \mathcal{V} = {v_i | i = 1, ..., V}
23 Set of edges representing precedence constraints between :ref:`Activities <API_s4u_Activity>`:
27 \mathcal{E} = {e_i,j | (i,j) \in {1, ..., V} x {1, ..., V}}
29 .. image:: /img/dag.svg
32 Representing Vertices/Activities
33 ................................
35 There is two types of :ref:`Activities <API_s4u_Activity>` that can represent Vertices: :ref:`Exec <API_s4u_Exec>` and :ref:`Comm <API_s4u_Comm>`.
36 Thoses activities must be initiated and configured to properly describe your worflow.
38 An Exec represents the execution of an amount of flop on a :ref:`Host <API_s4u_Host>` of your platform.
42 ExecPtr exec = Exec::init();
43 exec->set_flops_amount(int);
44 exec->set_host(Host*);
47 A Comm represents a data transfer between two :ref:`Hosts <API_s4u_Host>` of your platform.
51 CommPtr comm = Comm::sendto_init();
52 comm->set_source(Host*);
53 comm->set_destination(Host*);
56 Representing Edges/Dependencies
57 ...............................
59 An activity will not start until all of its dependencies have been completed.
60 Activities may have any number of successors.
61 Dependencies between Activities are created using :cpp:func:`simgrid::s4u::Activity::add_successor`.
65 exec->add_successor(comm);
67 The Activity ``comm`` will not start until ``exec`` has been completed.
72 The goal of this lab is to describe the following DAG:
74 .. image:: /img/dag1.svg
77 In this DAG we want ``c1`` to compute 1e9 flops, ``c2`` to compute 5e9 flops and ``c3`` to compute 2e9 flops.
78 There is also a data transfer of 5e8 bytes between ``c1`` and ``c3``.
80 First of all, include the Simgrid library and define the log category.
82 .. literalinclude:: ../../examples/cpp/dag-tuto/s4u-dag-tuto.cpp
86 Inside the ``main`` function create an instance of :ref:`Engine <API_s4u_Engine>` and load the platform.
88 .. literalinclude:: ../../examples/cpp/dag-tuto/s4u-dag-tuto.cpp
92 Retrieve pointers to some hosts.
94 .. literalinclude:: ../../examples/cpp/dag-tuto/s4u-dag-tuto.cpp
98 Initiate the activities.
100 .. literalinclude:: ../../examples/cpp/dag-tuto/s4u-dag-tuto.cpp
104 Give names to thoses activities.
106 .. literalinclude:: ../../examples/cpp/dag-tuto/s4u-dag-tuto.cpp
110 Set the amount of work for each activity.
112 .. literalinclude:: ../../examples/cpp/dag-tuto/s4u-dag-tuto.cpp
116 Define the dependencies between the activities.
118 .. literalinclude:: ../../examples/cpp/dag-tuto/s4u-dag-tuto.cpp
122 Set the location of each Exec activity and source and destination for the Comm activity.
124 .. literalinclude:: ../../examples/cpp/dag-tuto/s4u-dag-tuto.cpp
128 Start the executions of Activities without dependencies.
130 .. literalinclude:: ../../examples/cpp/dag-tuto/s4u-dag-tuto.cpp
134 Add a callback to monitor the activities.
136 .. literalinclude:: ../../examples/cpp/dag-tuto/s4u-dag-tuto.cpp
140 Finally, run the simulation.
142 .. literalinclude:: ../../examples/cpp/dag-tuto/s4u-dag-tuto.cpp
146 The execution of this code should give you the following output:
148 .. literalinclude:: ../../examples/cpp/dag-tuto/s4u-dag-tuto.tesh
151 Lab 2: Import a DAG from a file
152 -------------------------------
154 In this lab we present how to import a DAG into you Simgrid simulation, either using a DOT file, a JSON file, or a DAX file.
156 The files presented in this lab describe the following DAG:
158 .. image:: /img/dag2.svg
164 A DOT file describes a workflow in accordance with the graphviz format.
166 The following DOT file describes the workflow presented at the beginning of this lab:
168 .. literalinclude:: ../../examples/cpp/dag-from-dot-simple/dag.dot
171 It can be imported as a vector of Activities into Simgrid using :cpp:func:`simgrid::s4u::create_DAG_from_DOT`. Then, you have to assign hosts to your Activities.
173 .. literalinclude:: ../../examples/cpp/dag-from-dot-simple/s4u-dag-from-dot-simple.cpp
176 The execution of this code should give you the following output:
178 .. literalinclude:: ../../examples/cpp/dag-from-dot-simple/s4u-dag-from-dot-simple.tesh
185 A JSON file describes a workflow in accordance with the `wfformat <https://github.com/wfcommons/wfformat>`_ .
187 The following JSON file describes the workflow presented at the beginning of this lab:
189 .. literalinclude:: ../../examples/cpp/dag-from-json-simple/dag.json
192 It can be imported as a vector of Activities into Simgrid using :cpp:func:`simgrid::s4u::create_DAG_from_json`.
194 .. literalinclude:: ../../examples/cpp/dag-from-json-simple/s4u-dag-from-json-simple.cpp
197 The execution of this code should give you the following output:
199 .. literalinclude:: ../../examples/cpp/dag-from-json-simple/s4u-dag-from-json-simple.tesh
203 From a DAX file [deprecated]
204 ............................
206 A DAX file describes a workflow in accordance with the `Pegasus <http://pegasus.isi.edu/>`_ format.
208 The following DAX file describes the workflow presented at the beginning of this lab:
210 .. literalinclude:: ../../examples/cpp/dag-from-dax-simple/dag.xml
213 It can be imported as a vector of Activities into Simgrid using :cpp:func:`simgrid::s4u::create_DAG_from_DAX`.
215 .. literalinclude:: ../../examples/cpp/dag-from-dax-simple/s4u-dag-from-dax-simple.cpp