MyraMath
FusedJobGraph.h
Go to the documentation of this file.
1 // ========================================================================= //
2 // This file is part of MyraMath, copyright (c) 2014-2019 by Ryan A Chilton //
3 // and distributed by MyraCore, LLC. See LICENSE.txt for license terms. //
4 // ========================================================================= //
5 
6 #ifndef MYRAMATH_JOBGRAPH_FUSEDJOBGRAPH_H
7 #define MYRAMATH_JOBGRAPH_FUSEDJOBGRAPH_H
8 
14 #include <myramath/MYRAMATH_EXPORT.h>
15 
16 #include <myramath/jobgraph/Job.h>
19 #include <myramath/jobgraph/Options.h>
20 
21 #include <map>
22 #include <vector>
23 #include <string>
24 #include <stdint.h>
25 
26 namespace myra {
27 
28 class FusedJobGraph;
29 
31 class MYRAMATH_EXPORT FusedJobGraph : public JobGraphBase
32  {
33  public:
34 
35  // --------------------------- Graph/container API.
36 
38  FusedJobGraph();
39 
41  int insert(const JobGraph& g);
42 
44  const JobGraph& at(int g) const;
45 
47  void add_edge(int g0, JobID j0, int g1, JobID j1);
48 
49  // --------------------------- JobGraphBase obligations.
50 
52  virtual JobGraphBase* clone() const;
53 
55  virtual uint64_t n_work() const;
56 
58  virtual std::string name() const;
59 
61  virtual void begins(JobIDs& output) const;
62 
64  virtual void ends(JobIDs& output) const;
65 
67  virtual ::myra::Job* create(JobID j);
68 
70  virtual std::vector<Job*> create();
71 
73  uint64_t size() const;
74 
76  virtual ~FusedJobGraph();
77 
78  private:
79 
80  // Internal contents.
81  typedef std::vector<JobGraph> Subgraphs;
82  Subgraphs subgraphs;
83 
84  // Useful typedef.
85  typedef std::map<JobID,JobIDs> Map;
86 
87  // Dependencies, forward view of underlying bimap.
88  Map forward;
89 
90  // Dependencies, reverse view of underlying bimap.
91  Map reverse;
92 
93  // Implementation detail, a Job that delegates everything to an underlying Job from one of the contained subgraphs[]
94  class FusedJob : public ::myra::Job
95  {
96  private:
97 
98  // Underlying Job.
99  ::myra::Job* job;
100 
101  // Which subgraph it came from.
102  int g;
103 
104  // Host graph.
105  FusedJobGraph* host;
106 
107  public:
108 
109  // Constructor, requires underlying Job* j and host graph g.
110  FusedJob(::myra::Job* in_j, int in_g, FusedJobGraph* in_host);
111 
112  // Delegates to job->id(), adds offset.
113  virtual JobID id() const override;
114 
115  // Delegates to job->parents(), adds offsets to each. Appends any inter-subgraph parents.
116  virtual void parents(JobIDs& output) const;
117 
118  // Delegates to job->children(), adds offsets to each. Appends any inter-subgraph children.
119  virtual void children(JobIDs& output) const;
120 
121  // Returns job->execute()
122  virtual uint64_t execute();
123 
124  // Returns job->name()
125  virtual std::string name() const;
126 
127  // Deletes job.
128  virtual ~FusedJob();
129 
130  };
131 
132  // This implementation detail is a friend.
133  friend class FusedJob;
134 
135  };
136 
137 } // namespace myra
138 
139 #endif
Abstraction to represent one node of a JobGraph.
Definition: Job.h:25
Abstraction to represent one node of a JobGraph.
Type erasure class that wraps JobGraphBase, gives it value semantics.
Definition: JobGraph.h:64
Definition: syntax.dox:1
Base/contract class for all other JobGraph&#39;s.
Definition: JobGraph.h:30
Abstraction for representing a directed acyclic graph of Job&#39;s.
Key type used to identify the Job&#39;s of a JobGraph.
Key type used to identify the Job&#39;s of a JobGraph.
Definition: JobID.h:60
std::vector< JobID > JobIDs
Useful typedef.
Definition: JobID.h:118
Contains multiple JobGraph&#39;s, fuses them together.
Definition: FusedJobGraph.h:31