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 =========================================================================*/
19 #ifndef vtkMPIPixelView_h
20 #define vtkMPIPixelView_h
21 
22 #include "vtkPixelExtent.h" // for pixel extent
23 #include "vtkMPI.h" // for mpi
24 #include "vtkMPIPixelTT.h" // for type traits
25 #include <iostream> // for cerr
26 
27 //-----------------------------------------------------------------------------
28 template<typename T>
30  const vtkPixelExtent &domain,
31  const vtkPixelExtent &decomp,
32  int nComps,
33  MPI_Datatype &view)
34 {
35  #ifndef NDEBUG
36  int mpiOk=0;
37  MPI_Initialized(&mpiOk);
38  if (!mpiOk)
39  {
40  std::cerr << "This class requires the MPI runtime." << std::endl;
41  return -1;
42  }
43  #endif
44 
45  int iErr;
46 
47  MPI_Datatype nativeType;
48  iErr=MPI_Type_contiguous(
49  nComps,
51  &nativeType);
52  if (iErr)
53  {
54  return -2;
55  }
56 
57  int domainDims[2];
58  domain.Size(domainDims);
59 
60  int domainStart[2];
61  domain.GetStartIndex(domainStart);
62 
63  int decompDims[2];
64  decomp.Size(decompDims);
65 
66  int decompStart[2];
67  decomp.GetStartIndex(decompStart, domainStart);
68 
69  // use a contiguous type when possible.
70  if (domain==decomp)
71  {
72  unsigned long long nCells=decomp.Size();
73  iErr=MPI_Type_contiguous((int)nCells, nativeType, &view);
74  if (iErr)
75  {
76  MPI_Type_free(&nativeType);
77  return -3;
78  }
79  }
80  else
81  {
82  iErr=MPI_Type_create_subarray(
83  2,
84  domainDims,
85  decompDims,
86  decompStart,
87  MPI_ORDER_FORTRAN,
88  nativeType,
89  &view);
90  if (iErr)
91  {
92  MPI_Type_free(&nativeType);
93  return -4;
94  }
95  }
96  iErr=MPI_Type_commit(&view);
97  if (iErr)
98  {
99  MPI_Type_free(&nativeType);
100  return -5;
101  }
102 
103  MPI_Type_free(&nativeType);
104 
105  return 0;
106 }
107 
108 #endif
109 // VTK-HeaderTest-Exclude: vtkMPIPixelView.h
void GetStartIndex(int first[2]) const
int vtkMPIPixelViewNew(const vtkPixelExtent &domain, const vtkPixelExtent &decomp, int nComps, MPI_Datatype &view)
void Size(T nCells[2]) const