DiSMEC++
dismec::parallel::TaskGenerator Class Referenceabstract

Base class for all parallelized operations. More...

#include <task.h>

Inheritance diagram for dismec::parallel::TaskGenerator:
anonymous_namespace{runner.cpp}::DummyTask dismec::TrainingTaskGenerator dismec::prediction::EvaluateMetrics dismec::prediction::PredictionBase dismec::prediction::FullPredictionTaskGenerator dismec::prediction::TopKPredictionTaskGenerator

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...
 

Detailed Description

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.

Definition at line 21 of file task.h.

Member Typedef Documentation

◆ thread_id_t

Constructor & Destructor Documentation

◆ ~TaskGenerator()

virtual dismec::parallel::TaskGenerator::~TaskGenerator ( )
virtualdefault

Member Function Documentation

◆ finalize()

virtual void dismec::parallel::TaskGenerator::finalize ( )
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().

◆ init_thread()

virtual void dismec::parallel::TaskGenerator::init_thread ( thread_id_t  thread_id)
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().

◆ num_tasks()

◆ prepare()

virtual void dismec::parallel::TaskGenerator::prepare ( long  num_threads,
long  chunk_size 
)
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().

Note
For memory that is used inside the computations done by each thread, the 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().
Parameters
num_threadsNumber of threads that will be used.
chunk_sizeA 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().

◆ run_tasks()


The documentation for this class was generated from the following file: