VTK
|
00001 /*========================================================================= 00002 00003 Program: Visualization Toolkit 00004 Module: vtkMPIPixelView.h 00005 00006 Copyright (c) Ken Martin, Will Schroeder, Bill Lorensen 00007 All rights reserved. 00008 See Copyright.txt or http://www.kitware.com/Copyright.htm for details. 00009 00010 This software is distributed WITHOUT ANY WARRANTY; without even 00011 the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR 00012 PURPOSE. See the above copyright notice for more information. 00013 00014 =========================================================================*/ 00019 #ifndef vtkMPIPixelView_h 00020 #define vtkMPIPixelView_h 00021 00022 #include "vtkPixelExtent.h" // for pixel extent 00023 #include "vtkMPI.h" // for mpi 00024 #include "vtkMPIPixelTT.h" // for type traits 00025 #include <iostream> // for cerr 00026 00027 //----------------------------------------------------------------------------- 00028 template<typename T> 00029 int vtkMPIPixelViewNew( 00030 const vtkPixelExtent &domain, 00031 const vtkPixelExtent &decomp, 00032 int nComps, 00033 MPI_Datatype &view) 00034 { 00035 #ifndef NDEBUG 00036 int mpiOk=0; 00037 MPI_Initialized(&mpiOk); 00038 if (!mpiOk) 00039 { 00040 std::cerr << "This class requires the MPI runtime." << std::endl; 00041 return -1; 00042 } 00043 #endif 00044 00045 int iErr; 00046 00047 MPI_Datatype nativeType; 00048 iErr=MPI_Type_contiguous( 00049 nComps, 00050 vtkMPIPixelTT<T>::MPIType, 00051 &nativeType); 00052 if (iErr) 00053 { 00054 return -2; 00055 } 00056 00057 int domainDims[2]; 00058 domain.Size(domainDims); 00059 00060 int domainStart[2]; 00061 domain.GetStartIndex(domainStart); 00062 00063 int decompDims[2]; 00064 decomp.Size(decompDims); 00065 00066 int decompStart[2]; 00067 decomp.GetStartIndex(decompStart, domainStart); 00068 00069 // use a contiguous type when possible. 00070 if (domain==decomp) 00071 { 00072 unsigned long long nCells=decomp.Size(); 00073 iErr=MPI_Type_contiguous((int)nCells, nativeType, &view); 00074 if (iErr) 00075 { 00076 MPI_Type_free(&nativeType); 00077 return -3; 00078 } 00079 } 00080 else 00081 { 00082 iErr=MPI_Type_create_subarray( 00083 2, 00084 domainDims, 00085 decompDims, 00086 decompStart, 00087 MPI_ORDER_FORTRAN, 00088 nativeType, 00089 &view); 00090 if (iErr) 00091 { 00092 MPI_Type_free(&nativeType); 00093 return -4; 00094 } 00095 } 00096 iErr=MPI_Type_commit(&view); 00097 if (iErr) 00098 { 00099 MPI_Type_free(&nativeType); 00100 return -5; 00101 } 00102 00103 MPI_Type_free(&nativeType); 00104 00105 return 0; 00106 } 00107 00108 #endif 00109 // VTK-HeaderTest-Exclude: vtkMPIPixelView.h