TCPSPSuite
parallelizer.hpp
1 //
2 // Created by lukas on 14.12.17.
3 //
4 
5 #ifndef TCPSPSUITE_PARALLELIZER_HPP
6 #define TCPSPSUITE_PARALLELIZER_HPP
7 
8 #include "../datastructures/maybe.hpp" // for Maybe
9 #include "../util/log.hpp" // for Log
10 #include "timer.hpp"
11 #include <mutex> // for mutex
12 #include <stddef.h> // for size_t
13 #include <string> // for string
14 #include <thread> // for thread
15 #include <utility> // for pair
16 #include <vector> // for vector
17 class Randomizer;
18 class SolverConfig;
19 class Storage;
20 
21 class Parallelizer {
22 public:
23  Parallelizer(Storage & storage, std::string run_id, Randomizer & randomizer);
24  void run_in_parallel(const std::vector<std::string> & filenames,
25  const std::vector<SolverConfig> & configurations,
26  unsigned int thread_count);
27 
28 private:
29  Storage & storage;
30  std::string run_id;
31  Randomizer & randomizer;
32  size_t totalTasks;
33 
34  void run_thread(int thread_id);
35  Maybe<std::pair<std::string, SolverConfig>> get_next_task();
36 
37  std::mutex queue_mutex;
38  std::vector<std::pair<std::string, SolverConfig>> remaining_tasks;
39 
40  std::vector<std::thread> threads;
41 
42  Log l;
43 };
44 
45 #endif // TCPSPSUITE_PARALLELIZER_HPP