6 #ifndef MYRAMATH_JOBGRAPH_USERJOBGRAPH_H 7 #define MYRAMATH_JOBGRAPH_USERJOBGRAPH_H 14 #include <myramath/MYRAMATH_EXPORT.h> 16 #include <myramath/utility/detail/ssize.h> 51 {
return JobID(job); }
56 for (
int p = 0; p < pids.size(); ++p)
57 output.push_back(
JobID(pids[p]) );
63 for (
int c = 0; c < cids.size(); ++c)
64 output.push_back(
JobID(cids[c]) );
68 virtual std::string
name()
const {
return n; }
72 { pids.push_back(p); }
76 { cids.push_back(c); }
91 std::vector<uint64_t> pids;
94 std::vector<uint64_t> cids;
104 UserJob(uint64_t j,
const Functor& f,
const std::string& s)
110 this->pids = that.pids;
111 this->cids = that.cids;
120 { functor();
return 1; }
139 template<
class Functor> uint64_t
insert(
const Functor& f)
141 uint64_t
id = jobs.size();
149 template<
class Functor> uint64_t
insert(
const Functor& f,
const std::string& n)
151 uint64_t
id = jobs.size();
161 uint64_t J = ssize(jobs);
162 if (j0 < 0)
throw eprintf(
"UserJobGraph::add_edge(), underflow j0 < 0", j0);
163 if (j1 < 0)
throw eprintf(
"UserJobGraph::add_edge(), underflow j1 < 0", j1);
164 if (j0 >= J)
throw eprintf(
"UserJobGraph::add_edge(), overflow j0 >= J", j0, J);
165 if (j1 >= J)
throw eprintf(
"UserJobGraph::add_edge(), overflow j1 >= J", j1, J);
167 jobs[j0]->add_child(j1);
168 jobs[j1]->add_parent(j0);
181 for (uint64_t j = 0; j < this->jobs.size(); ++j)
182 that->jobs.push_back( this->jobs[j]->clone() );
183 that->bids = this->bids;
184 that->eids = this->eids;
190 {
return jobs.size(); }
193 virtual std::string
name()
const 194 {
return "UserJobGraph"; }
199 typedef std::set<uint64_t>::const_iterator Iterator;
200 for (Iterator b = bids.begin(); b != bids.end(); ++b)
201 output.push_back(
JobID(*b) );
207 typedef std::set<uint64_t>::const_iterator Iterator;
208 for (Iterator e = eids.begin(); e != eids.end(); ++e)
209 output.push_back(
JobID(*e) );
214 {
return jobs[
id.unpack()]->clone(); }
218 {
return jobs.size(); }
223 for (uint64_t j = 0; j < jobs.size(); ++j)
230 std::vector<UserJobBase*> jobs;
233 std::set<uint64_t> bids;
236 std::set<uint64_t> eids;
UserJob(const UserJob &that)
Copy constructor.
Definition: UserJobGraph.h:108
Abstraction to represent one node of a JobGraph.
Definition: Job.h:25
Abstraction to represent one node of a JobGraph.
uint64_t insert(const Functor &f)
Inserts a Job (in the form of a C++11 lambda) to this JobGraph, returns its unique JobID...
Definition: UserJobGraph.h:139
Returns a std::runtime_error() whose message has been populated using printf()-style formatting...
virtual uint64_t execute()
Executes the underlying Functor.
Definition: UserJobGraph.h:119
virtual std::string name() const
Returns a printable name for this Job, for debugging.
Definition: UserJobGraph.h:68
virtual UserJobBase * clone() const =0
Implementation detail of FunctorJobGraph::clone()
~UserJobBase()
Frees internal resources.
Definition: UserJobGraph.h:79
Implementation detail of UserJobGraph Job's, structural aspects.
Definition: UserJobGraph.h:38
virtual Job * create(JobID id)
Constructs the Job corresponding to the given JobID.
Definition: UserJobGraph.h:213
uint64_t size() const
Returns maximum JobID.
Definition: UserJobGraph.h:217
virtual JobID id() const
Returns the JobID of this Job.
Definition: UserJobGraph.h:50
virtual UserJobBase * clone() const
Implementation detail of UserJobGraph::clone()
Definition: UserJobGraph.h:115
Base/contract class for all other JobGraph's.
Definition: JobGraph.h:30
void add_child(uint64_t c)
Adds a child dependency.
Definition: UserJobGraph.h:75
virtual ~UserJobGraph()
Virtual destructor, so subtypes can release resources.
Definition: UserJobGraph.h:221
virtual void children(JobIDs &output) const
Returns the JobID's of children.
Definition: UserJobGraph.h:61
Abstraction for representing a directed acyclic graph of Job's.
UserJobBase(uint64_t j, const std::string &s)
Constructor, requires ID and name.
Definition: UserJobGraph.h:43
void add_parent(uint64_t p)
Adds a parent dependency.
Definition: UserJobGraph.h:71
virtual void ends(JobIDs &output) const
Enumerates the JobIDs of Job's that have no children (where execution ends)
Definition: UserJobGraph.h:205
virtual JobGraphBase * clone() const
Virtual copy-constructor.
Definition: UserJobGraph.h:178
virtual void begins(JobIDs &output) const
Enumerates the JobIDs of Job's that have no parents (where execution begins)
Definition: UserJobGraph.h:197
virtual void parents(JobIDs &output) const
Returns the JobID's of parents.
Definition: UserJobGraph.h:54
void add_edge(uint64_t j0, uint64_t j1)
Adds a dependency, that Job j0 must execute before Job j1.
Definition: UserJobGraph.h:159
virtual ~UserJob()
Frees internal resources.
Definition: UserJobGraph.h:123
UserJob(uint64_t j, const Functor &f, const std::string &s)
Constructor, requires ID and Functor payload.
Definition: UserJobGraph.h:104
UserJobGraph()
Default constructor, empty Graph.
Definition: UserJobGraph.h:135
Key type used to identify the Job's of a JobGraph.
Implementation detail of UserJobGraph Job's, calculational aspects.
Definition: UserJobGraph.h:99
virtual uint64_t n_work() const
Total "work" over all Job's of this JobGraph.
Definition: UserJobGraph.h:189
virtual std::string name() const
Returns a printable name for this JobGraph, for debugging.
Definition: UserJobGraph.h:193
Key type used to identify the Job's of a JobGraph.
Definition: JobID.h:60
std::vector< JobID > JobIDs
Useful typedef.
Definition: JobID.h:118
uint64_t insert(const Functor &f, const std::string &n)
Like insert(f), but can also give a name to the Job (useful for debugging).
Definition: UserJobGraph.h:149
Container-like JobGraph class, can be manually populated with user-defined Job's and dependencies...
Definition: UserJobGraph.h:31