| 238 | //------------------------------------------------------------------------------ |
| 239 | #ifdef VTK_USE_MPI_IO |
| 240 | void vtkMPIImageReader::ReadSlice(int slice, const int extent[6], void* buffer) |
| 241 | { |
| 242 | this->ComputeInternalFileName(slice); |
| 243 | |
| 244 | vtkMPICommunicator* mpiComm = |
| 245 | vtkMPICommunicator::SafeDownCast(this->GroupedController->GetCommunicator()); |
| 246 | |
| 247 | // Open the file for this slice. |
| 248 | vtkMPIOpaqueFileHandle file; |
| 249 | int result; |
| 250 | result = MPI_File_open(*mpiComm->GetMPIComm()->GetHandle(), this->InternalFileName, |
| 251 | MPI_MODE_RDONLY, MPI_INFO_NULL, &file.Handle); |
| 252 | if (!(result == MPI_SUCCESS)) |
| 253 | { |
| 254 | vtkErrorMacro("Could not open file: " << this->InternalFileName); |
| 255 | return; |
| 256 | } |
| 257 | |
| 258 | // Set up the file view based on the extents. |
| 259 | this->SetupFileView(file, extent); |
| 260 | |
| 261 | // Figure out how many bytes to read. |
| 262 | vtkIdType length = this->GetDataScalarTypeSize(); |
| 263 | length *= this->NumberOfScalarComponents; |
| 264 | length *= extent[1] - extent[0] + 1; |
| 265 | length *= extent[3] - extent[2] + 1; |
| 266 | if (this->GetFileDimensionality() == 3) |
| 267 | length *= extent[5] - extent[4] + 1; |
| 268 | |
| 269 | vtkIdType pos = 0; |
| 270 | while (length > pos) |
| 271 | { |
| 272 | MPI_Status stat; |
| 273 | // we know this will fit in an int because it can't exceed VTK_INT_MAX. |
| 274 | const int remaining = |
| 275 | static_cast<int>(std::min(length - pos, static_cast<vtkIdType>(VTK_INT_MAX))); |
| 276 | MPICall( |
| 277 | MPI_File_read(file.Handle, (static_cast<char*>(buffer)) + pos, remaining, MPI_BYTE, &stat)); |
| 278 | int rd = 0; |
| 279 | MPICall(MPI_Get_elements(&stat, MPI_BYTE, &rd)); |
| 280 | if (MPI_UNDEFINED == rd) |
| 281 | { |
| 282 | vtkErrorMacro("Error obtaining number of values read in " << remaining << "-byte read."); |
| 283 | } |
| 284 | pos += static_cast<vtkIdType>(rd); |
| 285 | } |
| 286 | |
| 287 | MPICall(MPI_File_close(&file.Handle)); |
| 288 | } |
| 289 | #else // VTK_USE_MPI_IO |
| 290 | void vtkMPIImageReader::ReadSlice(int, const int[6], void*) |
| 291 | { |
no test coverage detected