Skip to content
Snippets Groups Projects
Commit c6cb04e9 authored by Van Herck, Walter's avatar Van Herck, Walter
Browse files

Added batch information to ThreadInfo

parent 9f175a23
No related branches found
No related tags found
No related merge requests found
Showing
with 455 additions and 107 deletions
......@@ -2,7 +2,7 @@
<?fileVersion 4.0.0?><cproject storage_type_id="org.eclipse.cdt.core.XmlProjectDescriptionStorage">
<storageModule moduleId="org.eclipse.cdt.core.settings">
<cconfiguration id="cdt.managedbuild.toolchain.gnu.macosx.base.45089428">
<storageModule buildSystemId="org.eclipse.cdt.managedbuilder.core.configurationDataProvider" id="cdt.managedbuild.toolchain.gnu.macosx.base.45089428" moduleId="org.eclipse.cdt.core.settings" name="Default">
<storageModule buildSystemId="org.eclipse.cdt.managedbuilder.core.configurationDataProvider" id="cdt.managedbuild.toolchain.gnu.macosx.base.45089428" moduleId="org.eclipse.cdt.core.settings" name="Release">
<externalSettings>
<externalSetting/>
</externalSettings>
......@@ -16,7 +16,7 @@
</extensions>
</storageModule>
<storageModule moduleId="cdtBuildSystem" version="4.0.0">
<configuration artifactName="BornAgain" buildProperties="" description="" id="cdt.managedbuild.toolchain.gnu.macosx.base.45089428" name="Default" parent="org.eclipse.cdt.build.core.emptycfg">
<configuration artifactName="BornAgain" buildProperties="" description="Config for release build" id="cdt.managedbuild.toolchain.gnu.macosx.base.45089428" name="Release" parent="org.eclipse.cdt.build.core.emptycfg">
<folderInfo id="cdt.managedbuild.toolchain.gnu.macosx.base.45089428.834509647" name="/" resourcePath="">
<toolChain id="cdt.managedbuild.toolchain.gnu.macosx.base.329208693" name="cdt.managedbuild.toolchain.gnu.macosx.base" superClass="cdt.managedbuild.toolchain.gnu.macosx.base">
<targetPlatform archList="all" binaryParser="org.eclipse.cdt.core.MachO64" id="cdt.managedbuild.target.gnu.platform.macosx.base.35496915" name="Debug Platform" osList="macosx" superClass="cdt.managedbuild.target.gnu.platform.macosx.base"/>
......@@ -68,6 +68,9 @@
</cconfiguration>
<cconfiguration id="cdt.managedbuild.toolchain.gnu.macosx.base.45089428.1343516600">
<storageModule buildSystemId="org.eclipse.cdt.managedbuilder.core.configurationDataProvider" id="cdt.managedbuild.toolchain.gnu.macosx.base.45089428.1343516600" moduleId="org.eclipse.cdt.core.settings" name="Debug">
<macros>
<stringMacro name="BORNAGAIN_DEBUG" type="VALUE_TEXT" value="yes"/>
</macros>
<externalSettings>
<externalSetting>
<entry flags="RESOLVED" kind="macro" name="BornAgain_DEBUG" value="yes"/>
......@@ -87,7 +90,7 @@
<folderInfo id="cdt.managedbuild.toolchain.gnu.macosx.base.45089428.1343516600." name="/" resourcePath="">
<toolChain id="cdt.managedbuild.toolchain.gnu.macosx.base.443634681" name="cdt.managedbuild.toolchain.gnu.macosx.base" superClass="cdt.managedbuild.toolchain.gnu.macosx.base">
<targetPlatform archList="all" binaryParser="org.eclipse.cdt.core.MachO64" id="cdt.managedbuild.target.gnu.platform.macosx.base.966869129" name="Debug Platform" osList="macosx" superClass="cdt.managedbuild.target.gnu.platform.macosx.base"/>
<builder buildPath="${workspace_loc:/BornAgain}" cleanBuildTarget="distclean" id="cdt.managedbuild.target.gnu.builder.macosx.base.957115956" incrementalBuildTarget="" keepEnvironmentInBuildfile="false" managedBuildOn="false" name="Gnu Make Builder" parallelBuildOn="false" superClass="cdt.managedbuild.target.gnu.builder.macosx.base">
<builder arguments="-j3" buildPath="${workspace_loc:/BornAgain}" cleanBuildTarget="distclean" command="make" id="cdt.managedbuild.target.gnu.builder.macosx.base.957115956" incrementalBuildTarget="" keepEnvironmentInBuildfile="false" managedBuildOn="false" name="Gnu Make Builder" parallelBuildOn="true" parallelizationNumber="optimal" superClass="cdt.managedbuild.target.gnu.builder.macosx.base">
<outputEntries>
<entry flags="VALUE_WORKSPACE_PATH|RESOLVED" kind="outputPath" name=""/>
</outputEntries>
......
......@@ -33,7 +33,7 @@ void TestIsGISAXS2::execute()
SampleBuilderFactory factory;
ISample *sample = factory.createSample("isgisaxs02");
Simulation simulation;
Simulation simulation(mp_options);
simulation.setDetectorParameters(100, 0.0*Units::degree, 2.0*Units::degree, 100, 0.0*Units::degree, 2.0*Units::degree, true);
simulation.setBeamParameters(1.0*Units::angstrom, 0.2*Units::degree, 0.0*Units::degree);
simulation.setSample(*sample);
......
......@@ -44,7 +44,7 @@ void TestIsGISAXS3::execute()
SampleBuilderFactory factory;
// building simulation
Simulation simulation;
Simulation simulation(mp_options);
simulation.setDetectorParameters(100, 0.0*Units::degree, 2.0*Units::degree,
100, 0.0*Units::degree, 2.0*Units::degree, true);
simulation.setBeamParameters(1.0*Units::angstrom, 0.2*Units::degree, 0.0*Units::degree);
......
......@@ -38,7 +38,7 @@ void TestIsGISAXS9::execute()
// test.runpyramidZ45();
// OutputDataIOFactory::writeOutputData(*test.getOutputData(FunctionalTests::IsGISAXS09::kTest_Z45), getOutputPath()+"this_pyramid_Z45.ima");
Simulation simulation;
Simulation simulation(mp_options);
simulation.setDetectorParameters(
100, 0.0*Units::degree, 2.0*Units::degree,
100, 0.0*Units::degree, 2.0*Units::degree, true);
......
......@@ -57,16 +57,20 @@ class DWBASimulation : public ISimulation
const_iterator;
//! Returns read/write iterator that points to the first element
iterator begin();
//! The iterator takes the member ThreadInfo object into consideration.
iterator begin() { return m_dwba_intensity.begin(m_thread_info); }
//! Returns read-only iterator that points to the first element
const_iterator begin() const;
//! The iterator takes the member ThreadInfo object into consideration.
const_iterator begin() const { return m_dwba_intensity.begin(m_thread_info); }
//! Returns read/write iterator that points to the one past last element
const iterator end() { return m_dwba_intensity.end(); }
//! The iterator takes the member ThreadInfo object into consideration.
const iterator end() { return m_dwba_intensity.end(m_thread_info); }
//! Returns read-only iterator that points to the one past last element
const const_iterator end() const { return m_dwba_intensity.end(); }
//! The iterator takes the member ThreadInfo object into consideration.
const const_iterator end() const { return m_dwba_intensity.end(m_thread_info); }
protected:
OutputData<double> m_dwba_intensity;
......
......@@ -16,15 +16,92 @@
#ifndef THREADINFO_H_
#define THREADINFO_H_
#include "Exceptions.h"
//! Information for threads
struct ThreadInfo
{
ThreadInfo() : n_threads(1), i_thread(0) {}
size_t n_threads;
size_t i_thread;
ThreadInfo();
int n_threads;
int current_thread;
int n_batches;
int current_batch;
//! Impose consistency of members
void imposeConsistency();
//! Get the start index to use for this batch and thread when the total
//! size of the data is _total_size_
int getBeginIndex(int total_size);
//! Get the end index to use for this batch and thread when the total
//! size of the data is _total_size_
int getEndIndex(int total_size);
};
#endif /* THREADINFO_H_ */
inline ThreadInfo::ThreadInfo()
: n_threads(1)
, current_thread(0)
, n_batches(1)
, current_batch(0)
{
}
inline void ThreadInfo::imposeConsistency()
{
if (n_batches<2) {
n_batches = 1;
current_batch = 0;
}
if (n_threads<2) {
n_threads = 1;
current_thread = 0;
}
if (current_batch>=n_batches) {
throw ClassInitializationException("Batch number must be smaller than "
"number of batches.");
}
if (current_thread>=n_threads) {
throw ClassInitializationException("Thread number must be smaller than "
"number of threads.");
}
}
inline int ThreadInfo::getBeginIndex(int total_size)
{
int size_per_batch = total_size/n_batches;
if (total_size%n_batches) ++size_per_batch;
int size_of_this_batch =
current_batch==n_batches-1
? total_size - (n_batches-1)*size_per_batch
: size_per_batch;
if (size_of_this_batch<=0) return total_size;
int size_per_thread = size_of_this_batch/n_threads;
if (size_of_this_batch%n_threads) ++size_per_thread;
if (current_thread*size_per_thread>=size_of_this_batch) return total_size;
return current_batch*size_per_batch + current_thread*size_per_thread;
}
inline int ThreadInfo::getEndIndex(int total_size)
{
int size_per_batch = total_size/n_batches;
if (total_size%n_batches) ++size_per_batch;
int size_of_this_batch =
current_batch==n_batches-1
? total_size - (n_batches-1)*size_per_batch
: size_per_batch;
if (size_of_this_batch<=0) return total_size;
int size_per_thread = size_of_this_batch/n_threads;
if (size_of_this_batch%n_threads) ++size_per_thread;
if (current_thread*size_per_thread>=size_of_this_batch) return total_size;
int end_of_thread_in_batch =
current_thread==n_threads-1
? size_of_this_batch
: (current_thread+1)*size_per_thread;
if (end_of_thread_in_batch>size_of_this_batch) {
end_of_thread_in_batch = size_of_this_batch;
}
return current_batch*size_per_batch + end_of_thread_in_batch;
}
#endif /* THREADINFO_H_ */
......@@ -50,37 +50,6 @@ DWBASimulation *DWBASimulation::clone() const
return p_result;
}
DWBASimulation::iterator DWBASimulation::begin()
{
if (m_thread_info.n_threads<2) {
m_thread_info.n_threads = 1;
m_thread_info.i_thread = 0;
}
iterator result(m_dwba_intensity.begin());
if (m_thread_info.n_threads>1) {
MaskIndexModulus thread_mask(
m_thread_info.n_threads, m_thread_info.i_thread);
result.addMask(thread_mask);
}
return result;
}
DWBASimulation::const_iterator DWBASimulation::begin() const
{
size_t n_threads = m_thread_info.n_threads;
size_t i_thread = m_thread_info.i_thread;
if (m_thread_info.n_threads<2) {
n_threads = 1;
i_thread = 0;
}
const_iterator result(m_dwba_intensity.begin());
if (n_threads>1) {
MaskIndexModulus thread_mask(n_threads, i_thread);
result.addMask(thread_mask);
}
return result;
}
double DWBASimulation::getWaveLength() const
{
kvector_t real_ki(m_ki.x().real(), m_ki.y().real(), m_ki.z().real());
......
......@@ -80,7 +80,7 @@ void MultiLayerDWBASimulation::setThreadInfo(const ThreadInfo& thread_info)
void MultiLayerDWBASimulation::run()
{
msglog(MSG::DEBUG) << "MultiLayerDWBASimulation::run() -> Running thread "
<< m_thread_info.i_thread;
<< m_thread_info.current_thread;
SpecularMatrix specularCalculator;
kvector_t m_ki_real(m_ki.x().real(), m_ki.y().real(), m_ki.z().real());
......
......@@ -110,52 +110,57 @@ void Simulation::runSimulation()
"Simulation::runSimulation() -> Error! No sample set.");
m_intensity_map.setAllTo(0.);
// retrieve threading information
int n_threads_total=0;
if (mp_options)
n_threads_total = (*mp_options)["threads"].as<int>();
msglog(MSG::DEBUG) << "Simulation::runSimulation(): n_threads=" <<
n_threads_total << ", sample: " << *mp_sample;
// TODO: --threads=1 is ignored
// n_threads_total = -1;
// msglog(MSG::WARNING) << "TEMPORARILY SET n_threads_total = " << n_threads_total;
if(n_threads_total<0) {
ThreadInfo thread_info;
// retrieve batch and threading information
if (mp_options) {
thread_info.n_batches = (*mp_options)["nbatches"].as<int>();
thread_info.current_batch = (*mp_options)["batch"].as<int>();
thread_info.n_threads = (*mp_options)["threads"].as<int>();
// }
// msglog(MSG::DEBUG) << "Simulation::runSimulation(): n_batches = " <<
std::cout << "Simulation::runSimulation(): n_batches = " <<
thread_info.n_batches << ", current batch = " <<
thread_info.current_batch << ", n_threads = " <<
thread_info.n_threads << std::endl;
//", sample: " << *mp_sample;
}
if (thread_info.n_threads<0) thread_info.n_threads = 1;
if(thread_info.n_threads==1) {
// Single thread.
DWBASimulation *p_dwba_simulation = mp_sample->createDWBASimulation();
if (!p_dwba_simulation)
throw NullPointerException(
"Simulation::runSimulation() -> No dwba simulation");
p_dwba_simulation->init(*this);
p_dwba_simulation->setThreadInfo(thread_info);
p_dwba_simulation->run(); // the work is done here
m_intensity_map += p_dwba_simulation->getDWBAIntensity();
delete p_dwba_simulation;
} else {
// Multithreading.
if(n_threads_total == 0 ) {
if(thread_info.n_threads == 0 ) {
// Take optimal number of threads from the hardware.
n_threads_total = (int)boost::thread::hardware_concurrency();
thread_info.n_threads = (int)boost::thread::hardware_concurrency();
msglog(MSG::INFO) <<
"Simulation::runSimulation() -> Info. Number of threads " <<
n_threads_total << " (taken from hardware concurrency)";
thread_info.n_threads << " (taken from hardware concurrency)";
} else {
msglog(MSG::INFO) <<
"Simulation::runSimulation() -> Info. Number of threads " <<
n_threads_total;
thread_info.n_threads;
}
std::vector<boost::thread*> threads;
std::vector<DWBASimulation*> simulations;
// Initialize n simulations.
ThreadInfo thread_info;
thread_info.n_threads = n_threads_total;
for(int i_thread=0; i_thread<n_threads_total; ++i_thread){
for(int i_thread=0; i_thread<thread_info.n_threads; ++i_thread){
DWBASimulation *p_dwba_simulation =
mp_sample->createDWBASimulation();
if (!p_dwba_simulation) throw NullPointerException(
"Simulation::runSimulation() -> No dwba simulation");
p_dwba_simulation->init(*this);
thread_info.i_thread = i_thread;
thread_info.current_thread = i_thread;
p_dwba_simulation->setThreadInfo(thread_info);
simulations.push_back(p_dwba_simulation);
}
......
......@@ -21,6 +21,7 @@
#include "LLData.h"
#include "OutputDataIterator.h"
#include "SafePointerVector.h"
#include "ThreadInfo.h"
#include <sstream>
......@@ -92,7 +93,21 @@ class OutputData
iterator end() { return iterator(this, getAllocatedSize()); }
//! Returns read-only iterator that points to the one past last element
const_iterator end() const { return const_iterator(this, getAllocatedSize()); }
const_iterator end() const {
return const_iterator(this, getAllocatedSize());
}
//! Returns read/write iterator that points to the first element
iterator begin(ThreadInfo thread_info);
//! Returns read-only iterator that points to the first element
const_iterator begin(ThreadInfo thread_info) const;
//! Returns read/write iterator that points to the one past last element
iterator end(ThreadInfo thread_info);
//! Returns read-only iterator that points to the one past last element
const_iterator end(ThreadInfo thread_info) const;
//! Returns mask that will be used by iterators
Mask *getMask() const { return mp_mask; }
......@@ -336,6 +351,60 @@ typename OutputData<T>::const_iterator OutputData<T>::begin() const
return result;
}
template <class T>
typename OutputData<T>::iterator OutputData<T>::begin(ThreadInfo thread_info)
{
size_t total_size = getAllocatedSize();
thread_info.imposeConsistency();
int start_index = thread_info.getBeginIndex(total_size);
typename OutputData<T>::iterator result(this, start_index);
if (mp_mask)
result.setMask(*mp_mask);
return result;
}
template <class T>
typename OutputData<T>::const_iterator
OutputData<T>::begin(ThreadInfo thread_info) const
{
size_t total_size = getAllocatedSize();
thread_info.imposeConsistency();
int start_index = thread_info.getBeginIndex(total_size);
typename OutputData<T>::const_iterator result(this, start_index);
if (mp_mask)
result.setMask(*mp_mask);
return result;
}
template <class T>
typename OutputData<T>::iterator OutputData<T>::end(ThreadInfo thread_info)
{
size_t total_size = getAllocatedSize();
thread_info.imposeConsistency();
int end_index = thread_info.getEndIndex(total_size);
typename OutputData<T>::iterator result(this, end_index);
if (mp_mask)
result.setMask(*mp_mask);
return result;
}
template <class T>
typename OutputData<T>::const_iterator
OutputData<T>::end(ThreadInfo thread_info) const
{
size_t total_size = getAllocatedSize();
thread_info.imposeConsistency();
int end_index = thread_info.getEndIndex(total_size);
typename OutputData<T>::const_iterator result(this, end_index);
if (mp_mask)
result.setMask(*mp_mask);
return result;
}
template <class T>
void OutputData<T>::setMask(const Mask& mask)
{
......
......@@ -39,11 +39,13 @@ template <class TValue, class TContainer> class OutputDataIterator
OutputDataIterator(const OutputDataIterator<TValue, TContainer>& other);
//! templated copy assignment
template<class TValue2, class TContainer2> OutputDataIterator<TValue, TContainer>& operator=(
template<class TValue2, class TContainer2>
OutputDataIterator<TValue, TContainer>& operator=(
const OutputDataIterator<TValue2, TContainer2>& right);
//! non-templated copy asssignment
OutputDataIterator<TValue, TContainer>& operator=(const OutputDataIterator<TValue, TContainer>& right);
OutputDataIterator<TValue, TContainer>& operator=(
const OutputDataIterator<TValue, TContainer>& right);
virtual ~OutputDataIterator();
......@@ -88,27 +90,16 @@ template <class TValue, class TContainer> class OutputDataIterator
Mask *mp_mask;
};
//! comparison
template <class TValue1, class TContainer1, class TValue2, class TContainer2> bool operator==(
const OutputDataIterator<TValue1, TContainer1>& left,
const OutputDataIterator<TValue2, TContainer2>& right) {
return left.getContainer()==right.getContainer() && left.getIndex()==right.getIndex();
}
template <class TValue1, class TContainer1, class TValue2, class TContainer2> bool operator!=(
const OutputDataIterator<TValue1, TContainer1>& left,
const OutputDataIterator<TValue2, TContainer2>& right) {
return !(left == right);
}
template<class TValue, class TContainer> OutputDataIterator<TValue, TContainer>::OutputDataIterator()
template<class TValue, class TContainer>
OutputDataIterator<TValue, TContainer>::OutputDataIterator()
: m_current_index(0)
, mp_output_data(0)
, mp_mask(0)
{
}
template<class TValue, class TContainer> OutputDataIterator<TValue, TContainer>::OutputDataIterator(
template<class TValue, class TContainer>
OutputDataIterator<TValue, TContainer>::OutputDataIterator(
TContainer *p_output_data, size_t start_at_index)
: m_current_index(start_at_index)
, mp_output_data(p_output_data)
......@@ -118,7 +109,8 @@ template<class TValue, class TContainer> OutputDataIterator<TValue, TContainer>:
template<class TValue, class TContainer>
template<class TValue2, class TContainer2>
OutputDataIterator<TValue, TContainer>::OutputDataIterator(const OutputDataIterator<TValue2, TContainer2>& other)
OutputDataIterator<TValue, TContainer>::OutputDataIterator(
const OutputDataIterator<TValue2, TContainer2>& other)
: m_current_index(0)
, mp_output_data(0)
, mp_mask(0)
......@@ -130,7 +122,8 @@ OutputDataIterator<TValue, TContainer>::OutputDataIterator(const OutputDataItera
}
}
template<class TValue, class TContainer> OutputDataIterator<TValue, TContainer>::OutputDataIterator(
template<class TValue, class TContainer>
OutputDataIterator<TValue, TContainer>::OutputDataIterator(
const OutputDataIterator<TValue, TContainer>& other)
: m_current_index(0)
, mp_output_data(0)
......@@ -143,9 +136,28 @@ template<class TValue, class TContainer> OutputDataIterator<TValue, TContainer>:
}
}
//! comparison
template <class TValue1, class TContainer1, class TValue2, class TContainer2>
bool operator==(
const OutputDataIterator<TValue1, TContainer1>& left,
const OutputDataIterator<TValue2, TContainer2>& right)
{
return left.getContainer()==right.getContainer() &&
left.getIndex()==right.getIndex();
}
template <class TValue1, class TContainer1, class TValue2, class TContainer2>
bool operator!=(
const OutputDataIterator<TValue1, TContainer1>& left,
const OutputDataIterator<TValue2, TContainer2>& right)
{
return !(left == right);
}
template<class TValue, class TContainer>
template<class TValue2, class TContainer2>
OutputDataIterator<TValue, TContainer>& OutputDataIterator<TValue, TContainer>::operator=(
OutputDataIterator<TValue, TContainer>&
OutputDataIterator<TValue, TContainer>::operator=(
const OutputDataIterator<TValue2, TContainer2>& right)
{
OutputDataIterator<TValue, TContainer> copy(right);
......@@ -154,7 +166,8 @@ OutputDataIterator<TValue, TContainer>& OutputDataIterator<TValue, TContainer>::
}
template<class TValue, class TContainer>
OutputDataIterator<TValue, TContainer>& OutputDataIterator<TValue, TContainer>::operator=(
OutputDataIterator<TValue, TContainer>&
OutputDataIterator<TValue, TContainer>::operator=(
const OutputDataIterator<TValue, TContainer>& right)
{
OutputDataIterator<TValue, TContainer> copy(right);
......@@ -162,12 +175,15 @@ OutputDataIterator<TValue, TContainer>& OutputDataIterator<TValue, TContainer>::
return *this;
}
template<class TValue, class TContainer> OutputDataIterator<TValue, TContainer>::~OutputDataIterator()
template<class TValue, class TContainer>
OutputDataIterator<TValue, TContainer>::~OutputDataIterator()
{
if (mp_mask) delete mp_mask;
}
template<class TValue, class TContainer> OutputDataIterator<TValue, TContainer>& OutputDataIterator<TValue, TContainer>::operator++()
template<class TValue, class TContainer>
OutputDataIterator<TValue, TContainer>&
OutputDataIterator<TValue, TContainer>::operator++()
{
if (mp_mask) {
m_current_index = mp_mask->getNextIndex(m_current_index);
......@@ -180,7 +196,9 @@ template<class TValue, class TContainer> OutputDataIterator<TValue, TContainer>&
return *this;
}
template<class TValue, class TContainer> OutputDataIterator<TValue, TContainer> OutputDataIterator<TValue, TContainer>::operator++(int dummy)
template<class TValue, class TContainer>
OutputDataIterator<TValue, TContainer>
OutputDataIterator<TValue, TContainer>::operator++(int dummy)
{
(void)dummy;
OutputDataIterator<TValue, TContainer> result(*this);
......@@ -188,17 +206,20 @@ template<class TValue, class TContainer> OutputDataIterator<TValue, TContainer>
return result;
}
template<class TValue, class TContainer> TValue& OutputDataIterator<TValue, TContainer>::operator*() const
template<class TValue, class TContainer> TValue&
OutputDataIterator<TValue, TContainer>::operator*() const
{
return (*mp_output_data)[m_current_index];
}
template<class TValue, class TContainer> TValue* OutputDataIterator<TValue, TContainer>::operator->() const
template<class TValue, class TContainer> TValue*
OutputDataIterator<TValue, TContainer>::operator->() const
{
return& ((*mp_output_data)[m_current_index]);
}
template<class TValue, class TContainer> void OutputDataIterator<TValue, TContainer>::setMask(const Mask& mask)
template<class TValue, class TContainer>
void OutputDataIterator<TValue, TContainer>::setMask(const Mask& mask)
{
if (mp_mask !=& mask) {
delete mp_mask;
......@@ -208,10 +229,13 @@ template<class TValue, class TContainer> void OutputDataIterator<TValue, TContai
m_current_index = mp_mask->getFirstValidIndex();
}
template<class TValue, class TContainer> void OutputDataIterator<TValue, TContainer>::addMask(const Mask& mask)
template<class TValue, class TContainer>
void OutputDataIterator<TValue, TContainer>::addMask(const Mask& mask)
{
if (mask.mp_submask) {
throw RuntimeErrorException("OutputDataIterator<>::addMask() -> Error! One can only add single masks to OutputDataIterator at a time");
throw RuntimeErrorException("OutputDataIterator<>::addMask()"
" -> Error! One can only add single masks to OutputDataIterator"
" at a time");
}
Mask *p_old_mask = getMask();
mp_mask = mask.clone();
......@@ -220,7 +244,9 @@ template<class TValue, class TContainer> void OutputDataIterator<TValue, TContai
m_current_index = mp_mask->getFirstValidIndex();
}
template<class TValue, class TContainer> void OutputDataIterator<TValue, TContainer>::swapContents(OutputDataIterator<TValue, TContainer>& other)
template<class TValue, class TContainer>
void OutputDataIterator<TValue, TContainer>::swapContents(
OutputDataIterator<TValue, TContainer>& other)
{
std::swap(this->m_current_index, other.m_current_index);
std::swap(this->mp_output_data, other.mp_output_data);
......
......@@ -27,11 +27,18 @@ void AddCoreOptions(ProgramOptions *p_options)
// general options
bpo::options_description core_options("Core options");
core_options.add_options()
("threads", bpo::value<int>()->default_value(-1), "number of threads\n"
"arg<0 - no threads, arg=0 - system optimal, otherwise specified number of threads.")
("msglog", bpo::value<std::string>()->default_value("ERROR"), "Logging at one of the levels "
"VERBOSE, DEBUG, INFO, WARNING, ERROR, FATAL"
);
("threads", bpo::value<int>()->default_value(-1),
"number of threads\n"
"arg<0 - no threads, arg=0 - system optimal, otherwise"
" specified number of threads.")
("nbatches", bpo::value<int>()->default_value(1),
"number of batches\n")
("batch", bpo::value<int>()->default_value(0),
"current batch number (must be smaller than \"nbatches\")")
("msglog", bpo::value<std::string>()->default_value("ERROR"),
"Logging at one of the levels "
"VERBOSE, DEBUG, INFO, WARNING, ERROR, FATAL"
);
// adding options into main options holder
p_options->add(core_options);
}
......
......@@ -31,8 +31,9 @@ ProgramOptions::ProgramOptions() : m_options_is_consistent(false)
const bpo::variable_value& ProgramOptions::operator[] (const std::string& s) const
{
if( !m_options_is_consistent ) {
// no consistent options, there reason might be that no call to parseConfigFile
// has been made (for example due to the absence of main())
// no consistent options, the reason might be that no call to
// parseConfigFile has been made (for example due to the absence of
// main())
//parseConfigFile();
//throw LogicErrorException("ProgramOptions::operator[] -> FixMe! No config file parsed yet.");
}
......@@ -48,12 +49,13 @@ void ProgramOptions::parseCommandLine(int argc, char **argv)
// parsing command line arguments
try {
// if positional option description is empty, no command line arguments without '--' or '-' will be accepted
// if positional option description is empty, no command line arguments
// without '--' or '-' will be accepted
// 'store' populates the variable map
bpo::store( bpo::command_line_parser( argc, argv).options( m_options ).positional( m_positional_options ).run(), m_variables_map);
//bpo::store(bpo::parse_command_line(argc, argv, m_options), m_variables_map);
// 'notify' raises any erros encountered
// 'notify' raises any errors encountered
bpo::notify(m_variables_map);
if (m_variables_map.count("help") || argc == 1) {
......
// ************************************************************************** //
//
// BornAgain: simulate and fit scattering at grazing incidence
//
//! @file ThreadInfoTest.h
//! @brief Defines unit test for AxisDouble class.
//!
//! @homepage http://apps.jcns.fz-juelich.de/BornAgain
//! @license GNU General Public License v3 or higher (see COPYING)
//! @copyright Forschungszentrum Jülich GmbH 2013
//! @authors Scientific Computing Group at MLZ Garching
//! @authors C. Durniak, G. Pospelov, W. Van Herck, J. Wuttke
//
// ************************************************************************** //
#ifndef AXISDOUBLETEST_H
#define AXISDOUBLETEST_H
......
......@@ -28,6 +28,7 @@ HEADERS += \
ParameterPoolTest.h \
RealParameterWrapperTest.h \
SimulationTest.h \
ThreadInfoTest.h \
#OBJECTS_DIR = obj
......
// ************************************************************************** //
//
// BornAgain: simulate and fit scattering at grazing incidence
//
//! @file ThreadInfoTest.h
//! @brief Defines unit test for ThreadInfo class.
//!
//! @homepage http://apps.jcns.fz-juelich.de/BornAgain
//! @license GNU General Public License v3 or higher (see COPYING)
//! @copyright Forschungszentrum Jülich GmbH 2013
//! @authors Scientific Computing Group at MLZ Garching
//! @authors C. Durniak, G. Pospelov, W. Van Herck, J. Wuttke
//
// ************************************************************************** //
#ifndef THREADINFOTEST_H_
#define THREADINFOTEST_H_
#include "ThreadInfo.h"
#include "gtest/gtest.h"
class ThreadInfoTest : public ::testing::Test
{
protected:
ThreadInfoTest()
: thread_info() {}
ThreadInfo thread_info;
};
TEST_F(ThreadInfoTest, DefaultIsSingleBatchAndThread)
{
EXPECT_EQ(1, thread_info.n_batches);
EXPECT_EQ(0, thread_info.current_batch);
EXPECT_EQ(1, thread_info.n_threads);
EXPECT_EQ(0, thread_info.current_thread);
}
TEST_F(ThreadInfoTest, MakeValuesConsistent)
{
thread_info.n_batches = 0;
thread_info.n_threads = -1;
thread_info.current_batch = -5;
thread_info.current_thread = 10;
EXPECT_EQ(0, thread_info.n_batches);
EXPECT_EQ(-5, thread_info.current_batch);
EXPECT_EQ(-1, thread_info.n_threads);
EXPECT_EQ(10, thread_info.current_thread);
thread_info.imposeConsistency();
EXPECT_EQ(1, thread_info.n_batches);
EXPECT_EQ(0, thread_info.current_batch);
EXPECT_EQ(1, thread_info.n_threads);
EXPECT_EQ(0, thread_info.current_thread);
}
TEST_F(ThreadInfoTest, BeginIndex)
{
thread_info.n_batches = 4;
thread_info.n_threads = 3;
thread_info.current_batch = 0;
thread_info.current_thread = 0;
EXPECT_EQ(0, thread_info.getBeginIndex(20));
thread_info.current_batch = 0;
thread_info.current_thread = 1;
EXPECT_EQ(2, thread_info.getBeginIndex(20));
thread_info.current_batch = 0;
thread_info.current_thread = 2;
EXPECT_EQ(4, thread_info.getBeginIndex(20));
thread_info.current_batch = 1;
thread_info.current_thread = 0;
EXPECT_EQ(5, thread_info.getBeginIndex(20));
thread_info.current_batch = 2;
thread_info.current_thread = 0;
EXPECT_EQ(10, thread_info.getBeginIndex(20));
thread_info.current_batch = 3;
thread_info.current_thread = 0;
EXPECT_EQ(15, thread_info.getBeginIndex(18));
thread_info.current_batch = 3;
thread_info.current_thread = 2;
EXPECT_EQ(17, thread_info.getBeginIndex(18));
}
TEST_F(ThreadInfoTest, EndIndex)
{
thread_info.n_batches = 4;
thread_info.n_threads = 3;
thread_info.current_batch = 0;
thread_info.current_thread = 0;
EXPECT_EQ(2, thread_info.getEndIndex(20));
thread_info.current_batch = 0;
thread_info.current_thread = 1;
EXPECT_EQ(4, thread_info.getEndIndex(20));
thread_info.current_batch = 0;
thread_info.current_thread = 2;
EXPECT_EQ(5, thread_info.getEndIndex(20));
thread_info.current_batch = 1;
thread_info.current_thread = 0;
EXPECT_EQ(7, thread_info.getEndIndex(20));
thread_info.current_batch = 2;
thread_info.current_thread = 0;
EXPECT_EQ(12, thread_info.getEndIndex(20));
thread_info.current_batch = 3;
thread_info.current_thread = 2;
EXPECT_EQ(18, thread_info.getEndIndex(18));
thread_info.current_batch = 3;
thread_info.current_thread = 2;
EXPECT_EQ(20, thread_info.getEndIndex(20));
}
TEST_F(ThreadInfoTest, ZeroSizeBatchesThreads)
{
thread_info.n_batches = 4;
thread_info.n_threads = 4;
thread_info.current_batch = 0;
thread_info.current_thread = 0;
EXPECT_EQ(0, thread_info.getBeginIndex(10));
EXPECT_EQ(1, thread_info.getEndIndex(10));
thread_info.current_batch = 0;
thread_info.current_thread = 1;
EXPECT_EQ(1, thread_info.getBeginIndex(10));
EXPECT_EQ(2, thread_info.getEndIndex(10));
thread_info.current_batch = 0;
thread_info.current_thread = 2;
EXPECT_EQ(2, thread_info.getBeginIndex(10));
EXPECT_EQ(3, thread_info.getEndIndex(10));
thread_info.current_batch = 0;
thread_info.current_thread = 3;
EXPECT_EQ(10, thread_info.getBeginIndex(10));
EXPECT_EQ(10, thread_info.getEndIndex(10));
thread_info.current_batch = 3;
thread_info.current_thread = 1;
EXPECT_EQ(10, thread_info.getBeginIndex(10));
EXPECT_EQ(10, thread_info.getEndIndex(10));
thread_info.current_batch = 3;
thread_info.current_thread = 2;
EXPECT_EQ(10, thread_info.getBeginIndex(10));
EXPECT_EQ(10, thread_info.getEndIndex(10));
}
#endif /* THREADINFOTEST_H_ */
......@@ -14,6 +14,7 @@
#include "OutputDataTest.h"
#include "ParameterPoolTest.h"
#include "RealParameterWrapperTest.h"
#include "ThreadInfoTest.h"
struct ErrorStreamRedirect {
ErrorStreamRedirect( std::streambuf * new_buffer )
......
......@@ -71580,6 +71580,7 @@
GCC_WARN_UNUSED_VARIABLE = YES;
HEADER_SEARCH_PATHS = (
/opt/local/include,
/opt/local/include/eigen3,
"${ROOT_INCLUDE}",
"${SRCROOT}/App",
);
......@@ -71616,6 +71617,7 @@
GCC_WARN_UNUSED_VARIABLE = YES;
HEADER_SEARCH_PATHS = (
/opt/local/include,
/opt/local/include/eigen3,
"${ROOT_INCLUDE}",
"${SRCROOT}/App",
);
......@@ -71655,6 +71657,7 @@
HEADER_SEARCH_PATHS = (
/opt/local/include,
/opt/local/include/boost,
/opt/local/include/eigen3,
"${PYTHON_INCLUDE}",
"${PYTHON_NUMPY_INCLUDE}",
);
......@@ -71697,6 +71700,7 @@
HEADER_SEARCH_PATHS = (
/opt/local/include,
/opt/local/include/boost,
/opt/local/include/eigen3,
"${PYTHON_INCLUDE}",
"${PYTHON_NUMPY_INCLUDE}",
);
......@@ -72064,8 +72068,9 @@
GCC_WARN_UNUSED_VARIABLE = YES;
HEADER_SEARCH_PATHS = (
/opt/local/include,
/opt/local/include/root,
/opt/local/include/boost,
/opt/local/include/eigen3,
/opt/local/include/root,
"${PYTHON_INCLUDE}",
"${PYTHON_NUMPY_INCLUDE}",
);
......@@ -72109,8 +72114,9 @@
GCC_WARN_UNUSED_VARIABLE = YES;
HEADER_SEARCH_PATHS = (
/opt/local/include,
/opt/local/include/root,
/opt/local/include/boost,
/opt/local/include/eigen3,
/opt/local/include/root,
"${PYTHON_INCLUDE}",
"${PYTHON_NUMPY_INCLUDE}",
);
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment