Jpp  18.3.1
the software that should make you happy
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
Public Types | Public Member Functions | Static Public Attributes | Private Attributes | List of all members
JACOUSTICS::JFremantle Class Reference

Thread pool for global fits. More...

#include <JFremantle_t.hh>

Public Types

typedef std::vector< JHitinput_type
 
typedef JLANG::JObjectOutput
< JSuperEvt
output_type
 

Public Member Functions

 JFremantle (const JGeometry &geometry, const JSoundVelocity &velocity, const JFitParameters &parameters, const size_t ns, const size_t backlog=std::numeric_limits< size_t >::max())
 Constructor. More...
 
 ~JFremantle ()
 Destructor. More...
 
void enqueue (input_type &data)
 Queue data. More...
 

Static Public Attributes

static std::string oid = ""
 detector identifier More...
 
static JQuantile Q
 chi2/NDF More...
 
static bool squash = false
 squash transmissions in output More...
 
static output_typeoutput = NULL
 optional output More...
 

Private Attributes

std::vector< std::thread > workers
 
std::queue< input_typeinput
 
std::mutex in
 
std::mutex out
 
std::condition_variable cv
 
std::condition_variable cw
 
bool stop
 
size_t backlog
 

Detailed Description

Thread pool for global fits.

Definition at line 31 of file JFremantle_t.hh.

Member Typedef Documentation

Definition at line 34 of file JFremantle_t.hh.

Definition at line 35 of file JFremantle_t.hh.

Constructor & Destructor Documentation

JACOUSTICS::JFremantle::JFremantle ( const JGeometry geometry,
const JSoundVelocity velocity,
const JFitParameters parameters,
const size_t  ns,
const size_t  backlog = std::numeric_limits<size_t>::max() 
)
inline

Constructor.

Parameters
geometrydetector geometry
velocitysound velocity
parametersparameters
nsnumber of threads
backlogbacklog

Definition at line 47 of file JFremantle_t.hh.

51  :
52  stop(false),
54  {
55  using namespace std;
56  using namespace JPP;
57 
58  Q.reset();
59 
60  for (size_t i = 0; i < ns; ++i) {
61 
62  thread worker([this, geometry, velocity, parameters]() {
63 
65 
66  for (JGlobalfit katoomba(geometry, velocity, parameters); ; ) {
67 
68  {
69  unique_lock<mutex> lock(in);
70 
71  cv.wait(lock, [this]() { return stop || !input.empty(); });
72 
73  if (stop && input.empty()) {
74  return;
75  }
76 
77  data.swap(input.front());
78 
79  input.pop();
80  }
81 
82  cw.notify_one();
83 
84  const auto result = katoomba(data.begin(), data.end());
85 
86  if (result.chi2 / result.ndf <= katoomba.parameters.chi2perNDF) {
87 
88  {
89  unique_lock<mutex> lock(out);
90 
91  Q.put(result.chi2 / result.ndf);
92 
93  if (JFremantle::output != NULL) {
95  result.getTimeRange(),
96  data .size(),
97  result.size(),
98  result.value.getN(),
99  result.ndf,
100  result.chi2),
101  result.value,
102  result.begin,
103  JFremantle::squash ? result.begin : result.end));
104  }
105  }
106  }
107  }
108  });
109 
110  workers.emplace_back(std::move(worker));
111  }
112  }
void reset()
Reset.
Definition: JKatoomba_t.hh:89
std::vector< size_t > ns
std::condition_variable cv
Global fit of prameterised detector geometry to acoustics data.
Definition: JGlobalfit.hh:29
static std::string oid
detector identifier
Monte Carlo run header.
Definition: JHead.hh:1234
std::queue< input_type > input
static JQuantile Q
chi2/NDF
static output_type * output
optional output
void put(const double x)
Put value.
Definition: JKatoomba_t.hh:101
virtual bool put(const T &object)=0
Object output.
static bool squash
squash transmissions in output
Auxiliary data structure to convert model to super event.
std::vector< std::thread > workers
std::condition_variable cw
JACOUSTICS::JFremantle::~JFremantle ( )
inline

Destructor.

Definition at line 118 of file JFremantle_t.hh.

119  {
120  using namespace std;
121 
122  {
123  unique_lock<mutex> lock(in);
124 
125  stop = true;
126  }
127 
128  cv.notify_all();
129 
130  for (auto& worker : workers) {
131  worker.join();
132  }
133  }
std::condition_variable cv
std::vector< std::thread > workers

Member Function Documentation

void JACOUSTICS::JFremantle::enqueue ( input_type data)
inline

Queue data.

Parameters
datadata

Definition at line 141 of file JFremantle_t.hh.

142  {
143  using namespace std;
144 
145  {
146  unique_lock<mutex> lock(in);
147 
148  cw.wait(lock, [this]() { return stop || input.size() <= backlog; });
149 
150  if (stop) {
151  throw runtime_error("The thread pool has been stopped.");
152  }
153 
154  input.emplace(std::move(data));
155  }
156 
157  cv.notify_one();
158  }
std::condition_variable cv
std::queue< input_type > input
std::condition_variable cw

Member Data Documentation

std::string JACOUSTICS::JFremantle::oid = ""
static

detector identifier

Definition at line 160 of file JFremantle_t.hh.

JQuantile JACOUSTICS::JFremantle::Q
static

chi2/NDF

Definition at line 161 of file JFremantle_t.hh.

bool JACOUSTICS::JFremantle::squash = false
static

squash transmissions in output

Definition at line 162 of file JFremantle_t.hh.

JFremantle::output_type * JACOUSTICS::JFremantle::output = NULL
static

optional output

Definition at line 163 of file JFremantle_t.hh.

std::vector<std::thread> JACOUSTICS::JFremantle::workers
private

Definition at line 166 of file JFremantle_t.hh.

std::queue<input_type> JACOUSTICS::JFremantle::input
private

Definition at line 167 of file JFremantle_t.hh.

std::mutex JACOUSTICS::JFremantle::in
private

Definition at line 168 of file JFremantle_t.hh.

std::mutex JACOUSTICS::JFremantle::out
private

Definition at line 169 of file JFremantle_t.hh.

std::condition_variable JACOUSTICS::JFremantle::cv
private

Definition at line 170 of file JFremantle_t.hh.

std::condition_variable JACOUSTICS::JFremantle::cw
private

Definition at line 171 of file JFremantle_t.hh.

bool JACOUSTICS::JFremantle::stop
private

Definition at line 172 of file JFremantle_t.hh.

size_t JACOUSTICS::JFremantle::backlog
private

Definition at line 173 of file JFremantle_t.hh.


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