vtkInformationVector** vtkNotUsed(inputVector), vtkInformationVector* outputVector)
{
auto output = vtkMultiBlockDataSet::GetData(outputVector, 0);
- output->SetNumberOfBlocks(this->GetNumberOfFileNames());
+ unsigned int nBlock = this->GetNumberOfFileNames();
+ output->SetNumberOfBlocks(nBlock);
vtkInformation* info = outputVector->GetInformationObject(0);
double time = info->Get(vtkStreamingDemandDrivenPipeline::UPDATE_TIME_STEP());
vtkMultiProcessController *vmpc(vtkMultiProcessController::GetGlobalController());
unsigned int iProc = vmpc ? vmpc->GetLocalProcessId() : 0;
unsigned int nProc = vmpc ? vmpc->GetNumberOfProcesses() : 1;
- unsigned int nFiles = this->GetNumberOfFileNames() / nProc;
- unsigned int offFile = iProc * nFiles;
- unsigned int supFiles = this->GetNumberOfFileNames() % nProc;
- if (iProc == nProc - 1)
+
+ // Simple case, one file/bloc for n proc
+ if (nBlock == 1)
{
- nFiles += supFiles;
+ // No need to set the FileName, already set by the subproxy mechanism
+ this->Reader->UpdateTimeStep(time);
+ vtkDataObject* outputReader = vtkMultiBlockDataSet::SafeDownCast(this->Reader->GetOutputDataObject(0))->GetBlock(0);
+ output->SetBlock(0, outputReader);
}
-
- for (unsigned int i = 0; i < nFiles; i++)
+ // N file/block read by m proc, with n <= m, means 0/1 file/block per proc
+ else if (nBlock <= nProc && iProc < nBlock)
{
- this->ReaderSetFileName(this->GetFileName(i + offFile));
- vtkMEDReader::SafeDownCast(this->Reader)->ReloadInternals();
+ // Distribute in MEDReader only when reading a single file in a single block
vtkMEDReader::SafeDownCast(this->Reader)->SetDistributeWithMPI(false);
+
+ // Needed as the MEDReader do not support changing its filename
+ // without reloading everything.
+ this->ReaderSetFileName(this->GetFileName(iProc));
+ vtkMEDReader::SafeDownCast(this->Reader)->ReloadInternals();
this->Reader->UpdateInformation();
+
this->Reader->UpdateTimeStep(time);
- vtkDataObject* outputReader = this->Reader->GetOutputDataObject(0);
- vtkSmartPointer<vtkDataObject> outputLeaf = vtkSmartPointer<vtkDataObject>::Take(outputReader->NewInstance());
- outputLeaf->DeepCopy(outputReader);
- output->SetBlock(i, outputLeaf);
+ vtkDataObject* outputReader = vtkMultiBlockDataSet::SafeDownCast(this->Reader->GetOutputDataObject(0))->GetBlock(0);
+ output->SetBlock(iProc, outputReader);
+ }
+ // Multiple files/block per proc
+ else
+ {
+ unsigned int nFiles = nBlock / nProc;
+ unsigned int offFile = iProc * nFiles;
+ unsigned int supFiles = nBlock % nProc;
+
+ // Last proc handle remaining files/block
+ if (iProc + 1 == nProc)
+ {
+ nFiles += supFiles;
+ }
+
+ for (unsigned int i = 0; i < nFiles; i++)
+ {
+ this->ReaderSetFileName(this->GetFileName(i + offFile));
+ vtkMEDReader::SafeDownCast(this->Reader)->SetDistributeWithMPI(false);
+ vtkMEDReader::SafeDownCast(this->Reader)->ReloadInternals();
+ this->Reader->UpdateInformation();
+ this->Reader->UpdateTimeStep(time);
+ vtkDataObject* outputReader = vtkMultiBlockDataSet::SafeDownCast(this->Reader->GetOutputDataObject(0))->GetBlock(0);
+ if (i + 1 == nFiles)
+ {
+ // Last reader, just use the reader output directly
+ output->SetBlock(i + offFile, outputReader);
+ }
+ else
+ {
+ // Need to deep copy as the reader will be reused
+ vtkSmartPointer<vtkDataObject> outputLeaf = vtkSmartPointer<vtkDataObject>::Take(outputReader->NewInstance());
+ outputLeaf->DeepCopy(outputReader);
+ output->SetBlock(i + offFile, outputLeaf);
+ }
+ }
}
-
return 1;
}