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