DiSMEC++
|
Base class for all parallelized operations. More...
#include <task.h>
Public Types | |
using | thread_id_t = dismec::parallel::thread_id_t |
Public Member Functions | |
virtual | ~TaskGenerator ()=default |
virtual long | num_tasks () const =0 |
virtual void | run_tasks (long begin, long end, thread_id_t thread_id)=0 |
virtual void | prepare (long num_threads, long chunk_size) |
Called to notify the TaskGenerator about the number of threads. More... | |
virtual void | init_thread (thread_id_t thread_id) |
Called once a thread has spun up, but before it runs its first task. More... | |
virtual void | finalize () |
Called after all threads have finished their tasks. More... | |
Base class for all parallelized operations.
Any computation that should be parallelized using the ParallelRunner
has to be implemented as a subclass of TaskGenerator
. This requires implementing two functions num_tasks()
which returns the number of tasks the generator provides, and run_tasks()
, which shall execute the actual computation for a given task. The run_tasks()
function has to be re-entrant when called with different non-overlapping [begin, end)
intervals.
|
virtualdefault |
|
inlinevirtual |
Called after all threads have finished their tasks.
This function is called from the main thread after all worker threads have finished their work. It can be used to perform single threaded reductions or clean up per-thread buffers.
Reimplemented in dismec::TrainingTaskGenerator, dismec::prediction::TopKPredictionTaskGenerator, and dismec::prediction::EvaluateMetrics.
Definition at line 59 of file task.h.
Referenced by dismec::parallel::ParallelRunner::run().
|
inlinevirtual |
Called once a thread has spun up, but before it runs its first task.
This function is called from inside the thread that also will run the tasks.
Reimplemented in dismec::TrainingTaskGenerator, dismec::prediction::EvaluateMetrics, and dismec::prediction::PredictionBase.
Definition at line 51 of file task.h.
Referenced by dismec::parallel::ParallelRunner::run().
|
pure virtual |
|
inlinevirtual |
Called to notify the TaskGenerator
about the number of threads.
This function is called from the main thread, before distributed work is started. It gives the TaskGenerator
a chance to allocate working memory for each thread, so these allocations don't need to be done and repeated in run_task()
.
init_thread()
should be used. This will be called from inside the thread that will do the actual computations, so that when using this on a NUMA
system, first-touch policy has a chance to place the allocation in the correct RAM. In that case, this function should only allocate an array of pointers that will be filled in by init_thread()
. num_threads | Number of threads that will be used. |
chunk_size | A hint for the size of chunks used when running this task. Note that if the total number of tasks is not a multiple of the chunk_size , there may be some calls to run_tasks() with less than chunk_size tasks. |
Reimplemented in dismec::TrainingTaskGenerator, dismec::prediction::TopKPredictionTaskGenerator, dismec::prediction::FullPredictionTaskGenerator, and dismec::prediction::EvaluateMetrics.
Definition at line 45 of file task.h.
Referenced by dismec::parallel::ParallelRunner::run().
|
pure virtual |