MyraMath
ParallelJobGraph.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_PARALLELJOBGRAPH_H
7 #define MYRAMATH_JOBGRAPH_PARALLELJOBGRAPH_H
8 
14 #include <myramath/MYRAMATH_EXPORT.h>
15 
16 #include <myramath/jobgraph/Job.h>
19 #include <myramath/jobgraph/Options.h>
20 
21 #include <string>
22 #include <stdint.h>
23 
24 namespace myra {
25 
27 class MYRAMATH_EXPORT ParallelJobGraph : public JobGraphBase
28  {
29  public:
30 
31  // --------------------------- Container API.
32 
35 
37  int insert(const JobGraph& g);
38 
40  const JobGraph& at(int g) const;
41 
42  // --------------------------- Base JobGraph overrides.
43 
45  virtual uint64_t n_work() const;
46 
48  virtual std::string name() const;
49 
51  virtual void begins(JobIDs& output) const;
52 
54  virtual void ends(JobIDs& output) const;
55 
57  virtual ::myra::Job* create(JobID j);
58 
60  virtual std::vector<Job*> create();
61 
63  uint64_t size() const;
64 
66  virtual ::myra::JobGraphBase* clone() const;
67 
69  virtual ~ParallelJobGraph();
70 
71  private:
72 
73  // Internal contents.
74  typedef std::vector<JobGraph> Subgraphs;
75  Subgraphs subgraphs;
76 
77  // Implementation detail, a Job that delegates everything to an underlying Job from one of the contained subgraphs[]
78  class ParallelJob : public ::myra::Job
79  {
80  private:
81 
82  // Underlying Job.
83  ::myra::Job* job;
84 
85  // Which subgraph it came from.
86  int g;
87 
88  // Host graph.
89  ParallelJobGraph* host;
90 
91  public:
92 
93  // Constructor, requires underlying Job* and host ParallelJobGraph*.
94  ParallelJob(::myra::Job* in_job, int in_g, ParallelJobGraph* in_host);
95 
96  // Delegates to job->id(), adds offset.
97  virtual JobID id() const;
98 
99  // Delegates to job->parents(), adds offsets to each.
100  virtual void parents(JobIDs& output) const;
101 
102  // Delegates to job->children(), adds offsets to each.
103  virtual void children(JobIDs& output) const;
104 
105  // Returns job->execute()
106  virtual uint64_t execute();
107 
108  // Returns job->name()
109  virtual std::string name() const;
110 
111  // Deletes job.
112  virtual ~ParallelJob();
113 
114  };
115 
116  // This implementation detail is a friend.
117  friend class ParallelJob;
118 
119  };
120 
122 MYRAMATH_EXPORT JobGraph parallelize(const JobGraph& g0, const JobGraph& g1);
124 MYRAMATH_EXPORT JobGraph parallelize(const JobGraph& g0, const JobGraph& g1, const JobGraph& g2);
125 MYRAMATH_EXPORT JobGraph parallelize(const JobGraph& g0, const JobGraph& g1, const JobGraph& g2, const JobGraph& g3);
126 MYRAMATH_EXPORT JobGraph parallelize(const JobGraph& g0, const JobGraph& g1, const JobGraph& g2, const JobGraph& g3, const JobGraph& g4);
128 
129 } // namespace myra
130 
131 #endif
Abstraction to represent one node of a JobGraph.
Definition: Job.h:25
Abstraction to represent one node of a JobGraph.
Contains multiple JobGraph&#39;s, can execute() them all in parallel.
Definition: ParallelJobGraph.h:27
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