Commit ac656639 authored by Julien Michel's avatar Julien Michel

BUG: Actual number of threads may be less that GetNumberOfThreads() if...

BUG: Actual number of threads may be less that GetNumberOfThreads() if requested region has nb lines < GetNumberOfThreads()
parent f3be43ea
......@@ -174,6 +174,16 @@ PersistentSamplingFilterBase<TInputImage,TMaskImage>
// clean temporary inputs
this->m_InMemoryInputs.clear();
unsigned int numberOfThreads = this->GetNumberOfThreads();
unsigned int actualNumberOfThreads = numberOfThreads;
if(numberOfThreads > this->GetOutput()->GetRequestedRegion().GetSize()[1])
{
actualNumberOfThreads = this->GetOutput()->GetRequestedRegion().GetSize()[1];
}
// gather temporary outputs and write to output
const otb::ogr::DataSource* vectors = this->GetOGRData();
itk::TimeProbe chrono;
......@@ -195,7 +205,7 @@ PersistentSamplingFilterBase<TInputImage,TMaskImage>
itkExceptionMacro(<< "Unable to start transaction for OGR layer " << outLayer.ogr().GetName() << ".");
}
for (unsigned int thread=0 ; thread < this->GetNumberOfThreads() ; thread++)
for (unsigned int thread=0 ; thread < actualNumberOfThreads ; thread++)
{
ogr::Layer inLayer = this->m_InMemoryOutputs[thread][count]->GetLayerChecked(0);
if (!inLayer)
......@@ -247,7 +257,7 @@ PersistentSamplingFilterBase<TInputImage,TMaskImage>
TInputImage* outputImage = this->GetOutput();
RegionType requestedRegion = outputImage->GetRequestedRegion();
ogr::Layer layer = this->m_InMemoryInputs[threadid]->GetLayerChecked(0);
ogr::Layer layer = this->m_InMemoryInputs.at(threadid)->GetLayerChecked(0);
if (! layer)
{
return;
......@@ -618,6 +628,13 @@ PersistentSamplingFilterBase<TInputImage,TMaskImage>
unsigned int numberOfThreads = this->GetNumberOfThreads();
unsigned int actualNumberOfThreads = numberOfThreads;
if(numberOfThreads > this->GetOutput()->GetRequestedRegion().GetSize()[1])
{
actualNumberOfThreads = this->GetOutput()->GetRequestedRegion().GetSize()[1];
}
// prepare temporary input : split input features between available threads
this->m_InMemoryInputs.clear();
std::string tmpLayerName("thread");
......@@ -628,7 +645,7 @@ PersistentSamplingFilterBase<TInputImage,TMaskImage>
}
OGRFeatureDefn &layerDefn = inLayer.GetLayerDefn();
std::vector<ogr::Layer> tmpLayers;
for (unsigned int i=0 ; i < numberOfThreads ; i++)
for (unsigned int i=0 ; i < actualNumberOfThreads ; i++)
{
ogr::DataSource::Pointer tmpOgrDS = ogr::DataSource::New();
ogr::Layer tmpLayer = tmpOgrDS->CreateLayer(
......@@ -678,9 +695,17 @@ PersistentSamplingFilterBase<TInputImage,TMaskImage>
{
// Prepare in-memory outputs
unsigned int numberOfThreads = this->GetNumberOfThreads();
unsigned int actualNumberOfThreads = numberOfThreads;
if(numberOfThreads > this->GetOutput()->GetRequestedRegion().GetSize()[1])
{
actualNumberOfThreads = this->GetOutput()->GetRequestedRegion().GetSize()[1];
}
this->m_InMemoryOutputs.clear();
std::string tmpLayerName("threadOut");
for (unsigned int i=0 ; i < numberOfThreads ; i++)
for (unsigned int i=0 ; i < actualNumberOfThreads ; i++)
{
std::vector<OGRDataPointer> tmpContainer;
// iterate over outputs, only process ogr::DataSource
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment