Skip to content

Commit

Permalink
STYLE: Remove unused OpenMP based code
Browse files Browse the repository at this point in the history
Removed unreachable `if` clauses of the form `if (x && false)`, `else` clauses of `if (true)` or `if (x || true)`, and `#else` parts of `#if 1`.

Removed unused `#include <omp.h>` directives.

Removed unreachable code that was specifically for either a single-threaded or a multi-threaded implementation.
  • Loading branch information
N-Dekker committed Jul 5, 2024
1 parent da21f9d commit 0eef0e6
Show file tree
Hide file tree
Showing 8 changed files with 36 additions and 410 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -555,42 +555,12 @@ ParzenWindowMutualInformationImageToImageMetric<TFixedImage, TMovingImage>::Afte
const ThreadIdType numberOfThreads = Self::GetNumberOfWorkUnits();

/** Accumulate derivatives. */
// compute single-threadedly
if (!Superclass::m_UseMultiThread && false) // force multi-threaded
{
derivative = Superclass::m_GetValueAndDerivativePerThreadVariables[0].st_Derivative;
for (ThreadIdType i = 1; i < numberOfThreads; ++i)
{
derivative += Superclass::m_GetValueAndDerivativePerThreadVariables[i].st_Derivative;
}
}
#ifdef ELASTIX_USE_OPENMP
// compute multi-threadedly with openmp
else if (false) // Superclass::m_UseOpenMP )
{
const int spaceDimension = static_cast<int>(this->GetNumberOfParameters());

# pragma omp parallel for
for (int j = 0; j < spaceDimension; ++j)
{
DerivativeValueType sum = Superclass::m_GetValueAndDerivativePerThreadVariables[0].st_Derivative[j];
for (ThreadIdType i = 1; i < numberOfThreads; ++i)
{
sum += Superclass::m_GetValueAndDerivativePerThreadVariables[i].st_Derivative[j];
}
derivative[j] = sum;
}
}
#endif
// compute multi-threadedly with itk threads
else
{
Superclass::m_ThreaderMetricParameters.st_DerivativePointer = derivative.begin();
Superclass::m_ThreaderMetricParameters.st_NormalizationFactor = 1.0;
Superclass::m_ThreaderMetricParameters.st_DerivativePointer = derivative.begin();
Superclass::m_ThreaderMetricParameters.st_NormalizationFactor = 1.0;

this->m_Threader->SetSingleMethodAndExecute(this->AccumulateDerivativesThreaderCallback,
&(Superclass::m_ThreaderMetricParameters));
}
this->m_Threader->SetSingleMethodAndExecute(this->AccumulateDerivativesThreaderCallback,
&(Superclass::m_ThreaderMetricParameters));

} // end AfterThreadedComputeDerivativeLowMemory()

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,6 @@
#include "itkMersenneTwisterRandomVariateGenerator.h"
#include "itkComputeImageExtremaFilter.h"

#ifdef ELASTIX_USE_OPENMP
# include <omp.h>
#endif

namespace itk
{

Expand Down Expand Up @@ -671,42 +667,12 @@ AdvancedMeanSquaresImageToImageMetric<TFixedImage, TMovingImage>::AfterThreadedG
value *= normal_sum;

/** Accumulate derivatives. */
// compute single-threadedly
if (!Superclass::m_UseMultiThread && false) // force multi-threaded
{
derivative = Superclass::m_GetValueAndDerivativePerThreadVariables[0].st_Derivative * normal_sum;
for (ThreadIdType i = 1; i < numberOfThreads; ++i)
{
derivative += Superclass::m_GetValueAndDerivativePerThreadVariables[i].st_Derivative * normal_sum;
}
}
// compute multi-threadedly with itk threads
else if (true) // force ITK threads !Superclass::m_UseOpenMP )
{
Superclass::m_ThreaderMetricParameters.st_DerivativePointer = derivative.begin();
Superclass::m_ThreaderMetricParameters.st_NormalizationFactor = 1.0 / normal_sum;
Superclass::m_ThreaderMetricParameters.st_DerivativePointer = derivative.begin();
Superclass::m_ThreaderMetricParameters.st_NormalizationFactor = 1.0 / normal_sum;

this->m_Threader->SetSingleMethodAndExecute(this->AccumulateDerivativesThreaderCallback,
&(Superclass::m_ThreaderMetricParameters));
}
#ifdef ELASTIX_USE_OPENMP
// compute multi-threadedly with openmp
else
{
const int spaceDimension = static_cast<int>(this->GetNumberOfParameters());

# pragma omp parallel for
for (int j = 0; j < spaceDimension; ++j)
{
DerivativeValueType sum{};
for (ThreadIdType i = 0; i < numberOfThreads; ++i)
{
sum += Superclass::m_GetValueAndDerivativePerThreadVariables[i].st_Derivative[j];
}
derivative[j] = sum * normal_sum;
}
}
#endif
this->m_Threader->SetSingleMethodAndExecute(this->AccumulateDerivativesThreaderCallback,
&(Superclass::m_ThreaderMetricParameters));

} // end AfterThreadedGetValueAndDerivative()

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,6 @@

#include "itkAdvancedNormalizedCorrelationImageToImageMetric.h"

#ifdef ELASTIX_USE_OPENMP
# include <omp.h>
#endif

#include <algorithm> // For min.
#include <cassert>

Expand Down Expand Up @@ -642,76 +638,18 @@ AdvancedNormalizedCorrelationImageToImageMetric<TFixedImage, TMovingImage>::Afte
value = sfm / denom;

/** Calculate the metric derivative. */
// single-threaded
if (!Superclass::m_UseMultiThread && false) // force multi-threaded
{
DerivativeType & derivativeF = this->m_CorrelationGetValueAndDerivativePerThreadVariables[0].st_DerivativeF;
DerivativeType & derivativeM = this->m_CorrelationGetValueAndDerivativePerThreadVariables[0].st_DerivativeM;
DerivativeType & differential = this->m_CorrelationGetValueAndDerivativePerThreadVariables[0].st_Differential;
// force multi-threaded

for (ThreadIdType i = 1; i < numberOfThreads; ++i)
{
derivativeF += this->m_CorrelationGetValueAndDerivativePerThreadVariables[i].st_DerivativeF;
derivativeM += this->m_CorrelationGetValueAndDerivativePerThreadVariables[i].st_DerivativeM;
differential += this->m_CorrelationGetValueAndDerivativePerThreadVariables[i].st_Differential;
}
MultiThreaderAccumulateDerivativeType userData;

const auto numberOfParameters = this->GetNumberOfParameters();
userData.st_Metric = const_cast<Self *>(this);
userData.st_sf_N = sf / N;
userData.st_sm_N = sm / N;
userData.st_sfm_smm = sfm / smm;
userData.st_InvertedDenominator = 1.0 / denom;
userData.st_DerivativePointer = derivative.begin();

/** Subtract things from derivativeF and derivativeM. */
double diff, derF, derM;
for (unsigned int i = 0; i < numberOfParameters; ++i)
{
diff = differential[i];
derF = derivativeF[i] - (sf / N) * diff;
derM = derivativeM[i] - (sm / N) * diff;
derivative[i] = (derF - (sfm / smm) * derM) / denom;
}
}
else if (true) // force !Superclass::m_UseOpenMP ) // multi-threaded using ITK threads
{
MultiThreaderAccumulateDerivativeType userData;

userData.st_Metric = const_cast<Self *>(this);
userData.st_sf_N = sf / N;
userData.st_sm_N = sm / N;
userData.st_sfm_smm = sfm / smm;
userData.st_InvertedDenominator = 1.0 / denom;
userData.st_DerivativePointer = derivative.begin();

this->m_Threader->SetSingleMethodAndExecute(AccumulateDerivativesThreaderCallback, &userData);
}
#ifdef ELASTIX_USE_OPENMP
// compute multi-threadedly with openmp
else
{
const int spaceDimension = static_cast<int>(this->GetNumberOfParameters());
const AccumulateType sf_N = sf / N;
const AccumulateType sm_N = sm / N;
const AccumulateType sfm_smm = sfm / smm;

# pragma omp parallel for
for (int j = 0; j < spaceDimension; ++j)
{
DerivativeValueType derivativeF = this->m_CorrelationGetValueAndDerivativePerThreadVariables[0].st_DerivativeF[j];
DerivativeValueType derivativeM = this->m_CorrelationGetValueAndDerivativePerThreadVariables[0].st_DerivativeM[j];
DerivativeValueType differential =
this->m_CorrelationGetValueAndDerivativePerThreadVariables[0].st_Differential[j];

for (ThreadIdType i = 1; i < numberOfThreads; ++i)
{
derivativeF += this->m_CorrelationGetValueAndDerivativePerThreadVariables[i].st_DerivativeF[j];
derivativeM += this->m_CorrelationGetValueAndDerivativePerThreadVariables[i].st_DerivativeM[j];
differential += this->m_CorrelationGetValueAndDerivativePerThreadVariables[i].st_Differential[j];
}

derivativeF -= sf_N * differential;
derivativeM -= sm_N * differential;

derivative[j] = (derivativeF - sfm_smm * derivativeM) / denom;
}
} // end OpenMP
#endif
this->m_Threader->SetSingleMethodAndExecute(AccumulateDerivativesThreaderCallback, &userData);

} // end AfterThreadedGetValueAndDerivative()

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,6 @@

#include "itkTransformBendingEnergyPenaltyTerm.h"

#ifdef ELASTIX_USE_OPENMP
# include <omp.h>
#endif

namespace itk
{

Expand Down Expand Up @@ -582,7 +578,7 @@ TransformBendingEnergyPenaltyTerm<TFixedImage, TScalarType>::AfterThreadedGetVal
derivative /= static_cast<DerivativeValueType>(Superclass::m_NumberOfPixelsCounted);
}
// compute multi-threadedly with itk threads
else if (!Superclass::m_UseOpenMP || true) // force
else
{
Superclass::m_ThreaderMetricParameters.st_DerivativePointer = derivative.begin();
Superclass::m_ThreaderMetricParameters.st_NormalizationFactor =
Expand All @@ -591,26 +587,6 @@ TransformBendingEnergyPenaltyTerm<TFixedImage, TScalarType>::AfterThreadedGetVal
this->m_Threader->SetSingleMethodAndExecute(this->AccumulateDerivativesThreaderCallback,
&(Superclass::m_ThreaderMetricParameters));
}
#ifdef ELASTIX_USE_OPENMP
// compute multi-threadedly with openmp
else
{
const DerivativeValueType numPix = static_cast<DerivativeValueType>(Superclass::m_NumberOfPixelsCounted);
const int nthreads = static_cast<int>(numberOfThreads);
omp_set_num_threads(nthreads);
const int spaceDimension = static_cast<int>(this->GetNumberOfParameters());
# pragma omp parallel for
for (int j = 0; j < spaceDimension; ++j)
{
DerivativeValueType sum{};
for (ThreadIdType i = 0; i < numberOfThreads; ++i)
{
sum += Superclass::m_GetValueAndDerivativePerThreadVariables[i].st_Derivative[j];
}
derivative[j] = sum / numPix;
}
}
#endif

} // end AfterThreadedGetValueAndDerivative()

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,6 @@
#include "itkSumSquaredTissueVolumeDifferenceImageToImageMetric.h"
#include <vnl/algo/vnl_matrix_update.h>

#ifdef ELASTIX_USE_OPENMP
# include <omp.h>
#endif

namespace itk
{

Expand Down Expand Up @@ -637,46 +633,12 @@ SumSquaredTissueVolumeDifferenceImageToImageMetric<TFixedImage, TMovingImage>::A
value /= static_cast<RealType>(Superclass::m_NumberOfPixelsCounted);

/** Accumulate derivatives. */
/** compute single-threadedly */
if (!Superclass::m_UseMultiThread && false) // force multi-threaded as in AdvancedMeanSquares
{
derivative = Superclass::m_GetValueAndDerivativePerThreadVariables[0].st_Derivative;
for (ThreadIdType i = 1; i < numberOfThreads; ++i)
{
derivative += Superclass::m_GetValueAndDerivativePerThreadVariables[i].st_Derivative;
}

derivative /= static_cast<DerivativeValueType>(Superclass::m_NumberOfPixelsCounted);
}
// compute multi-threadedly with itk threads
else if (true) // force ITK threads !Superclass::m_UseOpenMP )
{
Superclass::m_ThreaderMetricParameters.st_DerivativePointer = derivative.begin();
Superclass::m_ThreaderMetricParameters.st_NormalizationFactor =
static_cast<DerivativeValueType>(Superclass::m_NumberOfPixelsCounted);

this->m_Threader->SetSingleMethodAndExecute(this->AccumulateDerivativesThreaderCallback,
&(Superclass::m_ThreaderMetricParameters));
}
Superclass::m_ThreaderMetricParameters.st_DerivativePointer = derivative.begin();
Superclass::m_ThreaderMetricParameters.st_NormalizationFactor =
static_cast<DerivativeValueType>(Superclass::m_NumberOfPixelsCounted);

#ifdef ELASTIX_USE_OPENMP
/** compute multi-threadedly with openmp. Never used? */
else
{
const int spaceDimension = static_cast<int>(this->GetNumberOfParameters());

# pragma omp parallel for
for (int j = 0; j < spaceDimension; ++j)
{
DerivativeValueType sum{};
for (ThreadIdType i = 0; i < numberOfThreads; ++i)
{
sum += Superclass::m_GetValueAndDerivativePerThreadVariables[i].st_Derivative[j];
}
derivative[j] = sum / static_cast<DerivativeValueType>(Superclass::m_NumberOfPixelsCounted);
}
}
#endif
this->m_Threader->SetSingleMethodAndExecute(this->AccumulateDerivativesThreaderCallback,
&(Superclass::m_ThreaderMetricParameters));

} // end AfterThreadedGetValueAndDerivative()

Expand Down
Loading

0 comments on commit 0eef0e6

Please sign in to comment.