File: LoadBalancerAC.hpp

package info (click to toggle)
primecount 7.16%2Bds-1
  • links: PTS, VCS
  • area: main
  • in suites: trixie
  • size: 1,724 kB
  • sloc: cpp: 18,769; ansic: 102; makefile: 89; sh: 86
file content (59 lines) | stat: -rw-r--r-- 1,332 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
///
/// @file  LoadBalancerAC.hpp
/// @brief This load balancer assigns work to the threads in the
///        computation of the A & C formulas (AC.cpp) in
///        Xavier Gourdon's algorithm.
///
///        Load balancing is described in more detail at:
///        https://github.com/kimwalisch/primecount/blob/master/doc/Easy-Special-Leaves.md
///
/// Copyright (C) 2025 Kim Walisch, <kim.walisch@gmail.com>
///
/// This file is distributed under the BSD License. See the COPYING
/// file in the top level directory.
///

#ifndef LOADBALANCERAC_HPP
#define LOADBALANCERAC_HPP

#include <OmpLock.hpp>

#include <stdint.h>
#include <cstddef>

namespace primecount {

struct ThreadDataAC
{
  int64_t low = 0;
  int64_t segments = 0;
  int64_t segment_size = 0;
  double secs = 0;
};

class LoadBalancerAC
{
public:
  LoadBalancerAC(int64_t sqrtx, int64_t y, int threads, bool is_print);
  bool get_work(ThreadDataAC& thread);

private:
  void print_status(double current_time);
  int64_t low_ = 0;
  int64_t sqrtx_ = 0;
  int64_t y_ = 0;
  int64_t segments_ = 0;
  int64_t segment_size_ = 0;
  int64_t segment_nr_ = 0;
  int64_t max_segment_size_ = 0;
  std::size_t prev_status_size_ = 0;
  double start_time_ = 0;
  double print_time_ = 0;
  int threads_ = 0;
  bool is_print_ = false;
  OmpLock lock_;
};

} // namespace

#endif