BornAgain  1.19.79
Open-source research software to simulate and fit neutron and x-ray reflectometry and grazing-incidence small-angle scattering
SimulationOptions.cpp
Go to the documentation of this file.
1 // ************************************************************************************************
2 //
3 // BornAgain: simulate and fit reflection and scattering
4 //
5 //! @file Resample/Options/SimulationOptions.cpp
6 //! @brief Implements class SimulationOptions
7 //!
8 //! @homepage http://www.bornagainproject.org
9 //! @license GNU General Public License v3 or higher (see COPYING)
10 //! @copyright Forschungszentrum Jülich GmbH 2018
11 //! @authors Scientific Computing Group at MLZ (see CITATION, AUTHORS)
12 //
13 // ************************************************************************************************
14 
16 #include "Base/Util/Assert.h"
17 #include <cstdlib>
18 #include <iostream>
19 #include <string>
20 #include <thread>
21 
23  : m_mc_integration(false)
24  , m_include_specular(false)
25  , m_use_avg_materials(false)
26  , m_mc_points(1)
27 {
28  if (const char* env_p = std::getenv("BA_NTHREADS")) {
29  m_thread_info.n_threads = std::stoi(env_p);
30  if (m_thread_info.n_threads > 0)
31  return;
32  }
34 }
35 
37 {
38  return m_mc_integration && m_mc_points > 1;
39 }
40 
41 void SimulationOptions::setMonteCarloIntegration(bool flag, size_t mc_points)
42 {
43  m_mc_integration = flag;
44  m_mc_points = mc_points;
45 }
46 
48 {
49  ASSERT(nthreads >= 0);
50  if (nthreads == 0)
52  else
53  m_thread_info.n_threads = nthreads;
55 }
56 
58 {
60  return m_thread_info.n_threads;
61 }
62 
64 {
65  ASSERT(nbatches > 0);
66  m_thread_info.n_batches = nbatches;
67 }
68 
70 {
72  return m_thread_info.n_batches;
73 }
74 
76 {
77  unsigned result = m_thread_info.current_batch;
78  ASSERT(result < m_thread_info.n_batches);
79  return result;
80 }
81 
83 {
84  return std::thread::hardware_concurrency();
85 }
Defines the macro ASSERT.
#define ASSERT(condition)
Definition: Assert.h:45
Defines class SimulationOptions.
ThreadInfo m_thread_info
void setNumberOfBatches(int nbatches)
Sets number of batches to split.
unsigned getNumberOfBatches() const
unsigned getCurrentBatch() const
unsigned getHardwareConcurrency() const
unsigned getNumberOfThreads() const
bool isIntegrate() const
void setNumberOfThreads(int nthreads)
Sets number of threads to use during the simulation (0 - take the default value from the hardware)
void setMonteCarloIntegration(bool flag=true, size_t mc_points=50)
Enables/disables MonetCarlo integration.
std::string getenv(const std::string &name)
Returns environment variable.
Definition: SysUtils.cpp:32
unsigned current_batch
Definition: ThreadInfo.h:25
unsigned n_batches
Definition: ThreadInfo.h:24
unsigned n_threads
Definition: ThreadInfo.h:23