About
A job is a threaded, reusable, independent work item (task). It can be queued to be executed with other jobs in a (parallel) pipeline.
Job
A custom job is based on maxon::JobInterfaceTemplate, maxon::JobResultInterface and maxon::JobInterface. The custom class contains data and implements the function call operator with the actual workload. A job instance is based on maxon::JobRef.
- Warning
- Make sure that a job has no additional, hidden dependencies like for example executing parallelized code internally.
{
public:
FactorialJob() { };
{
}
{
{
factorial = _n;
while (_n > 1)
{
--_n;
factorial *= _n;
}
}
}
private:
};
Template for jobs which inherit from JobInterface (and are not created using a lambda).
Definition: job.h:1120
const Py_UNICODE size_t n
Definition: unicodeobject.h:1184
#define MAXON_IMPLICIT
Definition: apibase.h:186
UInt64 UInt
unsigned 32/64 bit int, size depends on the platform
Definition: apibase.h:203
#define MAXON_LIKELY(...)
Definition: compilerdetection.h:426
ResultOk< void > SetResult()
Definition: job.h:1080
A job can also implement:
A job has to be enqueued in a queue to be executed (see job queue below):
job.Enqueue();
static auto Create(ARGS &&... args)
Definition: apibase.h:2818
#define DiagnosticOutput(formatString,...)
Definition: debugdiagnostics.h:170
#define iferr_return
Definition: resultbase.h:1524
A running job can be cancelled:
These observers can be used to react to certain events:
Further utility function are:
Static utility functions are:
Job Group
Jobs can be organized in job groups. These groups are used to execute and wait for multiple jobs simultaneously. The jobs of a group typically belong together. The jobs are executed as efficiently as possible.
The maxon::JobGroupRef members are:
{
{
}
Reference to a group (JobGroupInterface).
Definition: jobgroup.h:428
Result< void > Add(ARGS &&... args) const
Adds a job, a lambda, a BaseArray of jobs or a whole subgroup. The group takes exclusive ownership of...
Definition: jobgroup.h:548
Bool Wait(TimeValue timeout=TIMEVALUE_INFINITE, WAITMODE mode=WAITMODE::DEFAULT) const
Waits until all jobs of the group have been executed.
Definition: jobgroup.h:499
const JobGroupRef & Enqueue(JobQueueInterface *queue=JOBQUEUE_CURRENT) const
Enqueues all jobs of the group including subgroups. This will add a reference and remove it when the ...
Definition: jobgroup.h:452
static ResultMemT< JobGroupRef > Create(JOBGROUPFLAGS flags=JOBGROUPFLAGS::DEFAULT)
Creates a JobGroup.
Definition: jobgroup.h:439
for(i=0;i< length;i++)
Definition: unicodeobject.h:61
The maxon namespace contains all declarations of the MAXON API.
Definition: autoweight.h:14
#define iferr_ignore(...)
Definition: resultbase.h:1489
const char const char const char * file
Definition: object.h:439
{
{
return CreateFileHash(
file);
}
Reference to a job (JobInterface).
Definition: job.h:1241
static auto Create(FN &&src, ARGS &&... args) -> ResultMemT< JobResultRef< decltype(src(std::forward< ARGS >(args)...))>>
Creates a reference to a job with n arguments.
Definition: job.h:1264
maxon::BaseArray<FileHashJob> jobs;
{
}
Int GetCount(const ITERABLE &iterable)
Definition: collection.h:37
Jobs that do belong to a job group can handle sub-jobs:
Queue
Jobs are added to a queue which executes these jobs. A queue provides worker threads and distributes the jobs.
- Note
- Typically it is not needed to create a custom queue. maxon::JOBQUEUE_CURRENT should be used.
Default job queues are:
It is possible to manually create queues in order to organize job execution.
- Note
- Functions like maxon::JobInterface::Enqueue() or maxon::JobGroupRef::Enqueue() add the job or jobs to the current job queue if no argument is given.
Further Reading