Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 11 additions & 4 deletions Core/ComponentBaseClasses/elxMetricBase.hxx
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
#define elxMetricBase_hxx

#include "elxMetricBase.h"
#include "elxConversion.h"

namespace elastix
{
Expand Down Expand Up @@ -155,11 +156,17 @@ MetricBase<TElastix>::BeforeEachResolutionBase()
thisAsAdvanced->SetUseMultiThread(useMultiThreading);
if (useMultiThreading)
{
std::string tmp = configuration.GetCommandLineArgument("-threads");
if (!tmp.empty())
if (const std::string commandLineArgument = configuration.GetCommandLineArgument("-threads");
!commandLineArgument.empty())
{
const unsigned int nrOfThreads = atoi(tmp.c_str());
thisAsAdvanced->SetNumberOfWorkUnits(nrOfThreads);
if (itk::ThreadIdType numberOfThreads{}; Conversion::StringToValue(commandLineArgument, numberOfThreads))
{
thisAsAdvanced->SetNumberOfWorkUnits(numberOfThreads);
}
else
{
assert(!"This command-line argument should be checked already, by MainBase::SetMaximumNumberOfThreads()!");
}
}
}

Expand Down
31 changes: 21 additions & 10 deletions Core/Kernel/elxMainBase.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@

#include "elxMainBase.h"
#include "elxComponentLoader.h"
#include "elxConversion.h"

#include "elxMacro.h"
#include "itkMultiThreaderBase.h"
Expand All @@ -38,6 +39,7 @@
#endif

#include <cstdlib>
#include <limits>
#include <sstream>

namespace elastix
Expand Down Expand Up @@ -409,19 +411,28 @@ MainBase::SetProcessPriority() const
void
MainBase::SetMaximumNumberOfThreads() const
{
/** Get the number of threads from the command line. */
std::string maximumNumberOfThreadsString = m_Configuration->GetCommandLineArgument("-threads");
// Get the number of threads from the command line. If supplied, set the maximum number of threads.
const auto commandLineKey = "-threads";

/** If supplied, set the maximum number of threads. */
if (!maximumNumberOfThreadsString.empty())
if (const std::string commandLineArgument = m_Configuration->GetCommandLineArgument(commandLineKey);
!commandLineArgument.empty())
{
const int maximumNumberOfThreads = atoi(maximumNumberOfThreadsString.c_str());
itk::MultiThreaderBase::SetGlobalMaximumNumberOfThreads(maximumNumberOfThreads);
if (itk::ThreadIdType numberOfThreads{}; Conversion::StringToValue(commandLineArgument, numberOfThreads))
{
itk::MultiThreaderBase::SetGlobalMaximumNumberOfThreads(numberOfThreads);

// The following statement (getting and setting GlobalDefaultNumberOfThreads) may look redundant, but it's not
// (using ITK 5.4.0)! The Set function ensures that GlobalDefaultNumberOfThreads <= GlobalMaximumNumberOfThreads.
// (GlobalDefaultNumberOfThreads is important, as ITK uses this number when constructing the ThreadPool.)
itk::MultiThreaderBase::SetGlobalDefaultNumberOfThreads(itk::MultiThreaderBase::GetGlobalDefaultNumberOfThreads());
// The following statement (getting and setting GlobalDefaultNumberOfThreads) may look redundant, but it's not
// (using ITK 5.4.0)! The Set function ensures that GlobalDefaultNumberOfThreads <= GlobalMaximumNumberOfThreads.
// (GlobalDefaultNumberOfThreads is important, as ITK uses this number when constructing the ThreadPool.)
itk::MultiThreaderBase::SetGlobalDefaultNumberOfThreads(
itk::MultiThreaderBase::GetGlobalDefaultNumberOfThreads());
}
else
{
itkExceptionMacro("\"" << commandLineKey << "\" command-line argument \"" << commandLineArgument
<< "\" must be a positive " << std::numeric_limits<itk::ThreadIdType>::digits
<< "-bits number.");
}
}
} // end SetMaximumNumberOfThreads()

Expand Down
3 changes: 0 additions & 3 deletions Core/Main/elastix.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -201,9 +201,6 @@ main(int argc, char ** argv)
} // end else (so, if key does not equal "-p")
} // end for loop

/** The argv0 argument, required for finding the component.dll/so's. */
argMap.insert(ArgumentMapEntryType("-argv0", argv[0]));

int returndummy{};

/** Check if at least once the option "-p" is given. */
Expand Down
5 changes: 1 addition & 4 deletions Core/Main/elastixlib.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -162,10 +162,7 @@ ELASTIX::RegisterImages(ImagePointer fixedImage,
/** Save this information. */
const auto outFolder = value;

const ArgumentMapType argMap{ /** The argv0 argument, required for finding the component.dll/so's. */
ArgumentMapEntryType("-argv0", "elastix"),
ArgumentMapEntryType("-out", outFolder)
};
const ArgumentMapType argMap{ ArgumentMapEntryType("-out", outFolder) };

/** Check if the output directory exists. */
if (performLogging && !itksys::SystemTools::FileIsDirectory(outFolder))
Expand Down
3 changes: 0 additions & 3 deletions Core/Main/transformix.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -187,9 +187,6 @@ main(int argc, char ** argv)

} // end for loop

/** The argv0 argument, required for finding the component.dll/so's. */
argMap.insert(ArgumentMapEntryType("-argv0", argv[0]));

/** Check that the option "-tp" is given. */
if (argMap.count("-tp") == 0)
{
Expand Down
3 changes: 0 additions & 3 deletions Core/Main/transformixlib.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -169,9 +169,6 @@ TRANSFORMIX::TransformImage(ImagePointer inputImage,
}
}

/** The argv0 argument, required for finding the component.dll/so's. */
argMap.insert(ArgumentMapEntryType("-argv0", "transformix"));

/** Setup the log system. */
const elx::log::guard logGuard{};
int returndummy2 = elx::log::setup(logFileName, performLogging, performCout) ? 0 : 1;
Expand Down
Loading