Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

BUG: fixed test that made bad assumptions of GetGlobalDefaultNumberOf… #5191

Merged
merged 1 commit into from
Jan 30, 2025
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
Original file line number Diff line number Diff line change
Expand Up @@ -228,8 +228,8 @@ itkDataObjectAndProcessObjectTest(int, char *[])
ITK_TEST_SET_GET_VALUE(true, process->GetReleaseDataBeforeUpdateFlag());

ITK_TEST_EXPECT_TRUE(itk::MultiThreaderBase::GetGlobalDefaultNumberOfThreads() <= process->GetNumberOfWorkUnits());
process->SetNumberOfWorkUnits(11);
ITK_TEST_SET_GET_VALUE(11, process->GetNumberOfWorkUnits());
process->SetNumberOfWorkUnits(ITK_MAX_THREADS - 1);
ITK_TEST_SET_GET_VALUE(ITK_MAX_THREADS - 1, process->GetNumberOfWorkUnits());
process->SetNumberOfWorkUnits(0);
ITK_TEST_SET_GET_VALUE(1, process->GetNumberOfWorkUnits());
process->SetNumberOfWorkUnits(itk::NumericTraits<itk::ThreadIdType>::max());
Expand Down
6 changes: 4 additions & 2 deletions Modules/Core/Common/test/itkMultiThreaderExceptionsTest.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@
*
*=========================================================================*/

#include <algorithm>

#include "itkImageSource.h"
#include "itkTestingMacros.h"

Expand Down Expand Up @@ -56,7 +58,7 @@ class ITK_TEMPLATE_EXPORT DummyImageSource : public ImageSource<TOutputImage>
TOutputImage * output = nullptr;
output = this->GetOutput(0);
typename TOutputImage::RegionType largestPossibleRegion;
largestPossibleRegion.SetSize({ { 4 } });
largestPossibleRegion.SetSize({ { std::min(4, ITK_DEFAULT_MAX_THREADS) } });
output->SetLargestPossibleRegion(largestPossibleRegion);
}

Expand Down Expand Up @@ -96,7 +98,7 @@ itkMultiThreaderExceptionsTest(int, char *[])
const typename itk::DummyImageSource<OutputImageType>::Pointer dummySrc =
itk::DummyImageSource<OutputImageType>::New();
dummySrc->SetNumberOfWorkUnits(4);
for (itk::IndexValueType i = 0; i < 4; ++i)
for (itk::IndexValueType i = 0; i < dummySrc->GetNumberOfWorkUnits(); ++i)
{
dummySrc->SetExceptionIndex(i);
ITK_TRY_EXPECT_EXCEPTION(dummySrc->Update());
Expand Down
8 changes: 5 additions & 3 deletions Modules/Core/Common/test/itkMultiThreadingEnvironmentTest.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -34,10 +34,12 @@ itkMultiThreadingEnvironmentTest(int argc, char * argv[])
{
return EXIT_FAILURE;
}
if (itk::MultiThreaderBase::GetGlobalDefaultNumberOfThreads() != requiredValue)
const auto actualValue = itk::MultiThreaderBase::GetGlobalDefaultNumberOfThreads();
if ((actualValue != requiredValue) &&
(actualValue != ITK_MAX_THREADS))
{
std::cout << "ERROR: Wrong number of maximum number of threads set from environment. " << requiredValue
<< " != " << itk::MultiThreaderBase::GetGlobalDefaultNumberOfThreads() << std::endl;
std::cout << "ERROR: Wrong number of maximum number of threads set from environment. " << actualValue
<< " != " << requiredValue << " or " << ITK_MAX_THREADS << std::endl;
return EXIT_FAILURE;
}
return EXIT_SUCCESS;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -269,22 +269,23 @@ itkThreadedIteratorRangePartitionerTest3(int, char *[])
using DomainContainerType = IteratorRangeDomainThreaderAssociate::DomainContainerType;
auto container = DomainContainerType::New();

for (unsigned int i = 0; i < ITK_DEFAULT_MAX_THREADS + 10; ++i)
// ITK_DEFAULT_MAX_THREADS is at least 1, so we have at least 100 elements in container.
for (unsigned int i = 0; i < ITK_DEFAULT_MAX_THREADS + 99; ++i)
{
container->SetElement(static_cast<int>(i * 2), 2 * i + 1);
}
DomainType fullDomain(container->Begin(), container->End());

/* Test with single thread */
setStartEnd(0, 103, container, fullDomain);
setStartEnd(0, 100, container, fullDomain);
itk::ThreadIdType numberOfThreads = 1;
if (ThreadedIteratorRangePartitionerRunTest(enclosingClass, numberOfThreads, fullDomain) != EXIT_SUCCESS)
{
return EXIT_FAILURE;
}

/* Test with range that doesn't start at 0 */
setStartEnd(2, 105, container, fullDomain);
setStartEnd(5, 100, container, fullDomain);
numberOfThreads = 1;
if (ThreadedIteratorRangePartitionerRunTest(enclosingClass, numberOfThreads, fullDomain) != EXIT_SUCCESS)
{
Expand All @@ -295,7 +296,7 @@ itkThreadedIteratorRangePartitionerTest3(int, char *[])
if (domainThreader->GetMultiThreader()->GetGlobalMaximumNumberOfThreads() > 1)
{
/* Test with default number of threads. */
setStartEnd(6, 109, container, fullDomain);
setStartEnd(6, 89, container, fullDomain);
numberOfThreads = domainThreader->GetMultiThreader()->GetGlobalDefaultNumberOfThreads();
if (ThreadedIteratorRangePartitionerRunTest(enclosingClass, numberOfThreads, fullDomain) != EXIT_SUCCESS)
{
Expand Down