vtkMaterialInterfacePieceTransactionMatrix.h
Go to the documentation of this file.
1 /*=========================================================================
2 
3  Program: Visualization Toolkit
4  Module: $RCSfile$
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 =========================================================================*/
29 #ifndef vtkMaterialInterfacePieceTransactionMatrix_h
30 #define vtkMaterialInterfacePieceTransactionMatrix_h
31 
33 #include "vtkPVVTKExtensionsFiltersMaterialInterfaceModule.h" //needed for exports
34 #include "vtkType.h" //
35 #include <vector> //
36 
37 class vtkCommunicator;
38 
40 {
41 public:
50  vtkMaterialInterfacePieceTransactionMatrix(int nFragments, int nProcs);
52 
57  void Initialize(int nProcs, int nFragments);
59 
63  void Clear();
68  vtkIdType GetNumberOfTransactions(int procId);
73  std::vector<vtkMaterialInterfacePieceTransaction>& GetTransactions(int fragmentId, int procId);
78  void PushTransaction(
79  int fragmentId, int procId, vtkMaterialInterfacePieceTransaction& transaction);
81 
85  void Broadcast(vtkCommunicator* comm, int srcProc);
86  //
87  void Print();
89 
93  {
94  return this->FlatMatrixSize +
95  this->NumberOfTransactions * sizeof(vtkMaterialInterfacePieceTransaction);
96  }
97 
98 private:
105  vtkIdType Pack(int*& buffer);
110  vtkIdType PackPartial(int*& buffer, int* rows, int nRows);
112 
116  int UnPack(int* buffer);
117  int UnPackPartial(int* buffer);
119  int NProcs;
120  int NFragments;
121  std::vector<vtkMaterialInterfacePieceTransaction>* Matrix;
122  vtkIdType FlatMatrixSize;
123  vtkIdType NumberOfTransactions;
124 };
125 //
126 inline std::vector<vtkMaterialInterfacePieceTransaction>&
128 {
129  int idx = fragmentId + procId * this->NFragments;
130  return this->Matrix[idx];
131 }
132 //
134 {
135  size_t nTransactions = 0;
137 
138  for (int fragmentId = 0; fragmentId < this->NFragments; ++fragmentId)
139  {
140  nTransactions += this->GetTransactions(fragmentId, procId).size();
141  }
142 
143  return static_cast<vtkIdType>(nTransactions);
144 }
145 #endif
146 
147 // VTK-HeaderTest-Exclude: vtkMaterialInterfacePieceTransactionMatrix.h
Container to hold a sets of transactions (sends/recvs) indexed by fragment and proc, intended to facilitate moving fragment pieces around.
std::vector< vtkMaterialInterfacePieceTransaction > & GetTransactions(int fragmentId, int procId)
Given a proc and a fragment, return a ref to the associated list of transactions. ...
#define VTKPVVTKEXTENSIONSFILTERSMATERIALINTERFACE_EXPORT
vtkIdType GetNumberOfTransactions(int procId)
Get the number of transaction a given process will execute.
int vtkIdType
vtkIdType Capacity()
Tells how much memory the matrix has allocated.