File: SimulationOptions.cpp

package info (click to toggle)
bornagain 23.0-4
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 103,936 kB
  • sloc: cpp: 423,131; python: 40,997; javascript: 11,167; awk: 630; sh: 318; ruby: 173; xml: 130; makefile: 51; ansic: 24
file content (91 lines) | stat: -rw-r--r-- 2,379 bytes parent folder | download | duplicates (2)
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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
//  ************************************************************************************************
//
//  BornAgain: simulate and fit reflection and scattering
//
//! @file      Resample/Option/SimulationOptions.cpp
//! @brief     Implements class SimulationOptions.
//!
//! @homepage  http://www.bornagainproject.org
//! @license   GNU General Public License v3 or higher (see COPYING)
//! @copyright Forschungszentrum Jülich GmbH 2018
//! @authors   Scientific Computing Group at MLZ (see CITATION, AUTHORS)
//
//  ************************************************************************************************

#include "Resample/Option/SimulationOptions.h"
#include "Base/Util/Assert.h"
#include <cstdlib>
#include <iostream>
#include <string>
#include <thread>

SimulationOptions::SimulationOptions()
    : m_mc_integration(false)
    , m_include_specular(false)
    , m_use_avg_materials(false)
    , m_mc_points(1)
{
    if (const char* env_p = std::getenv("BA_NTHREADS")) {
        m_n_threads = std::stoi(env_p);
        if (m_n_threads > 0)
            return;
    }
    m_n_threads = getHardwareConcurrency();
}

bool SimulationOptions::isIntegrate() const
{
    return m_mc_integration && m_mc_points > 1;
}

void SimulationOptions::setMonteCarloIntegration(bool flag, size_t mc_points)
{
    m_mc_integration = flag;
    m_mc_points = mc_points;
}

void SimulationOptions::setNumberOfThreads(int nthreads)
{
    ASSERT(nthreads >= 0);
    if (nthreads == 0)
        m_n_threads = getHardwareConcurrency();
    else
        m_n_threads = nthreads;
    ASSERT(m_n_threads > 0);
}

unsigned SimulationOptions::getNumberOfThreads() const
{
    ASSERT(m_n_threads > 0);
    return m_n_threads;
}

void SimulationOptions::setNumberOfBatches(int nbatches)
{
    ASSERT(nbatches > 0);
    m_n_batches = nbatches;
}

void SimulationOptions::setMesoOptions(bool use_rec_sum, double rad_factor)
{
    m_meso_options.use_reciprocal_sum = use_rec_sum;
    m_meso_options.radius_factor = rad_factor;
}

unsigned SimulationOptions::getNumberOfBatches() const
{
    ASSERT(m_n_batches > 0);
    return m_n_batches;
}

unsigned SimulationOptions::getCurrentBatch() const
{
    unsigned result = m_current_batch;
    ASSERT(result < m_n_batches);
    return result;
}

unsigned SimulationOptions::getHardwareConcurrency() const
{
    return std::thread::hardware_concurrency();
}