VTK  9.3.1
vtkMPIPixelView.h
Go to the documentation of this file.
1 // SPDX-FileCopyrightText: Copyright (c) Ken Martin, Will Schroeder, Bill Lorensen
2 // SPDX-License-Identifier: BSD-3-Clause
8 #ifndef vtkMPIPixelView_h
9 #define vtkMPIPixelView_h
10 
11 #include "vtkMPI.h" // for mpi
12 #include "vtkMPIPixelTT.h" // for type traits
13 #include "vtkPixelExtent.h" // for pixel extent
14 #include <iostream> // for cerr
15 
16 //-----------------------------------------------------------------------------
17 VTK_ABI_NAMESPACE_BEGIN
18 template <typename T>
20  const vtkPixelExtent& domain, const vtkPixelExtent& decomp, int nComps, MPI_Datatype& view)
21 {
22 #ifndef NDEBUG
23  int mpiOk = 0;
24  MPI_Initialized(&mpiOk);
25  if (!mpiOk)
26  {
27  std::cerr << "This class requires the MPI runtime." << std::endl;
28  return -1;
29  }
30 #endif
31 
32  int iErr;
33 
34  MPI_Datatype nativeType;
35  iErr = MPI_Type_contiguous(nComps, vtkMPIPixelTT<T>::MPIType, &nativeType);
36  if (iErr)
37  {
38  return -2;
39  }
40 
41  int domainDims[2];
42  domain.Size(domainDims);
43 
44  int domainStart[2];
45  domain.GetStartIndex(domainStart);
46 
47  int decompDims[2];
48  decomp.Size(decompDims);
49 
50  int decompStart[2];
51  decomp.GetStartIndex(decompStart, domainStart);
52 
53  // use a contiguous type when possible.
54  if (domain == decomp)
55  {
56  unsigned long long nCells = decomp.Size();
57  iErr = MPI_Type_contiguous((int)nCells, nativeType, &view);
58  if (iErr)
59  {
60  MPI_Type_free(&nativeType);
61  return -3;
62  }
63  }
64  else
65  {
66  iErr = MPI_Type_create_subarray(
67  2, domainDims, decompDims, decompStart, MPI_ORDER_FORTRAN, nativeType, &view);
68  if (iErr)
69  {
70  MPI_Type_free(&nativeType);
71  return -4;
72  }
73  }
74  iErr = MPI_Type_commit(&view);
75  if (iErr)
76  {
77  MPI_Type_free(&nativeType);
78  return -5;
79  }
80 
81  MPI_Type_free(&nativeType);
82 
83  return 0;
84 }
85 
86 VTK_ABI_NAMESPACE_END
87 #endif
88 // VTK-HeaderTest-Exclude: vtkMPIPixelView.h
void GetStartIndex(int first[2]) const
Get the start/end index.
int vtkMPIPixelViewNew(const vtkPixelExtent &domain, const vtkPixelExtent &decomp, int nComps, MPI_Datatype &view)
Representation of a cartesian pixel plane and common operations on it.
void Size(T nCells[2]) const
Get the number in each direction.