VTK
vtkMPIPixelView.h
Go to the documentation of this file.
1 /*=========================================================================
2 
3  Program: Visualization Toolkit
4  Module: vtkMPIPixelView.h
5 
6  Copyright (c) Ken Martin, Will Schroeder, Bill Lorensen
7  All rights reserved.
8  See Copyright.txt or http://www.kitware.com/Copyright.htm for details.
9 
10  This software is distributed WITHOUT ANY WARRANTY; without even
11  the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
12  PURPOSE. See the above copyright notice for more information.
13 
14 =========================================================================*/
20 #ifndef vtkMPIPixelView_h
21 #define vtkMPIPixelView_h
22 
23 #include "vtkPixelExtent.h" // for pixel extent
24 #include "vtkMPI.h" // for mpi
25 #include "vtkMPIPixelTT.h" // for type traits
26 #include <iostream> // for cerr
27 
28 //-----------------------------------------------------------------------------
29 template<typename T>
31  const vtkPixelExtent &domain,
32  const vtkPixelExtent &decomp,
33  int nComps,
34  MPI_Datatype &view)
35 {
36  #ifndef NDEBUG
37  int mpiOk=0;
38  MPI_Initialized(&mpiOk);
39  if (!mpiOk)
40  {
41  std::cerr << "This class requires the MPI runtime." << std::endl;
42  return -1;
43  }
44  #endif
45 
46  int iErr;
47 
48  MPI_Datatype nativeType;
49  iErr=MPI_Type_contiguous(
50  nComps,
52  &nativeType);
53  if (iErr)
54  {
55  return -2;
56  }
57 
58  int domainDims[2];
59  domain.Size(domainDims);
60 
61  int domainStart[2];
62  domain.GetStartIndex(domainStart);
63 
64  int decompDims[2];
65  decomp.Size(decompDims);
66 
67  int decompStart[2];
68  decomp.GetStartIndex(decompStart, domainStart);
69 
70  // use a contiguous type when possible.
71  if (domain==decomp)
72  {
73  unsigned long long nCells=decomp.Size();
74  iErr=MPI_Type_contiguous((int)nCells, nativeType, &view);
75  if (iErr)
76  {
77  MPI_Type_free(&nativeType);
78  return -3;
79  }
80  }
81  else
82  {
83  iErr=MPI_Type_create_subarray(
84  2,
85  domainDims,
86  decompDims,
87  decompStart,
88  MPI_ORDER_FORTRAN,
89  nativeType,
90  &view);
91  if (iErr)
92  {
93  MPI_Type_free(&nativeType);
94  return -4;
95  }
96  }
97  iErr=MPI_Type_commit(&view);
98  if (iErr)
99  {
100  MPI_Type_free(&nativeType);
101  return -5;
102  }
103 
104  MPI_Type_free(&nativeType);
105 
106  return 0;
107 }
108 
109 #endif
110 // 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.