DiSMEC++
task.h
Go to the documentation of this file.
1 // Copyright (c) 2021, Aalto University, developed by Erik Schultheis
2 // All rights reserved.
3 //
4 // SPDX-License-Identifier: MIT
5 
6 #ifndef DISMEC_TASK_H
7 #define DISMEC_TASK_H
8 
9 #include "thread_id.h"
10 
11 namespace dismec::parallel {
21  class TaskGenerator {
22  public:
24 
25  virtual ~TaskGenerator() = default;
26  [[nodiscard]] virtual long num_tasks() const = 0;
27 
28  virtual void run_tasks(long begin, long end, thread_id_t thread_id) = 0;
29 
45  virtual void prepare(long num_threads, long chunk_size) {};
46 
51  virtual void init_thread(thread_id_t thread_id) {};
52 
59  virtual void finalize() {}
60  };
61 }
62 
63 #endif //DISMEC_TASK_H
Base class for all parallelized operations.
Definition: task.h:21
virtual void finalize()
Called after all threads have finished their tasks.
Definition: task.h:59
virtual ~TaskGenerator()=default
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.
Definition: task.h:45
virtual long num_tasks() const =0
virtual void init_thread(thread_id_t thread_id)
Called once a thread has spun up, but before it runs its first task.
Definition: task.h:51
Strong typedef for an int to signify a thread id.
Definition: thread_id.h:20