NeoPZ
pzstrmatrixflowtbb.h
Go to the documentation of this file.
1 
6 #ifndef TPZStructMatrixTBBFlow_H
7 #define TPZStructMatrixTBBFlow_H
8 
9 #include <set>
10 #include <map>
11 #include <semaphore.h>
12 #include "pzvec.h"
13 #include "tpzautopointer.h"
14 #include "pzcmesh.h"
15 #include "pzelmat.h"
16 #include "TPZSemaphore.h"
17 #include "TPZEquationFilter.h"
18 #include "TPZGuiInterface.h"
19 #include "pzmatrix.h"
20 #include "pzfmatrix.h"
21 
23 #include "TPZStructMatrixBase.h"
24 #ifdef USING_TBB
25 #include "tbb/tbb.h"
26 #include "tbb/flow_graph.h"
27 #endif
28 
29 
34 //void UniformRefine(int num, TPZGeoMesh &m);
35 
41 {
42 
43 public:
44 
46 
48 
50 
52 
53  virtual ~TPZStructMatrixTBBFlow();
54 
55  virtual TPZMatrix<STATE> * Create() override;
56 
58  unsigned numthreads_assemble, unsigned numthreads_decompose) {
59  SetNumThreads(numthreads_assemble);
60  return CreateAssemble(rhs, guiInterface);
61  }
62 
64 
65  virtual TPZStructMatrixTBBFlow * Clone() override;
66 
68  virtual void Assemble(TPZMatrix<STATE> & mat, TPZFMatrix<STATE> & rhs, TPZAutoPointer<TPZGuiInterface> guiInterface) override;
70  unsigned numthreads_assemble, unsigned numthreads_decompose) {
71  std::cout << "Nothing to do." << std::endl;
72  }
73 
75  virtual void Assemble(TPZFMatrix<STATE> & rhs, TPZAutoPointer<TPZGuiInterface> guiInterface) override;
76 
77  public:
78 int ClassId() const override;
79  void Read(TPZStream &buf, void *context) override;
80  void Write(TPZStream &buf, int withclassid) const override;
81 
82 
83 protected:
84 
85  // /** @brief Assemble the global system of equations into the matrix which has already been created */
86  // virtual void Serial_Assemble(TPZMatrix<STATE> & mat, TPZFMatrix<STATE> & rhs, TPZAutoPointer<TPZGuiInterface> guiInterface);
87  //
88  // /** @brief Assemble the global right hand side */
89  // virtual void Serial_Assemble(TPZFMatrix<STATE> & rhs, TPZAutoPointer<TPZGuiInterface> guiInterface);
90 
93 
96 
97 protected:
98 
99 #ifdef USING_TBB
100 
101  class TPZFlowGraph {
102  public:
103  TPZFlowGraph(TPZStructMatrixTBBFlow *strmat);
104  ~TPZFlowGraph();
105  TPZFlowGraph(TPZFlowGraph const &copy);
106 
107  // vectors for mesh coloring
108  TPZVec<int> fnextBlocked, felSequenceColor, felSequenceColorInv;
109  TPZManVector<int> fElementOrder;
110 
111  TPZCompMesh *cmesh;
112 
113  tbb::flow::graph fGraph;
114  tbb::flow::broadcast_node<tbb::flow::continue_msg> fStartNode;
115  std::vector<tbb::flow::continue_node<tbb::flow::continue_msg>* > fNodes;
116 
117  void OrderElements();
118  void ElementColoring();
119  void CreateGraph();
120  void ExecuteGraph(TPZFMatrix<STATE> *rhs, TPZMatrix<STATE> *matrix = 0);
121 
123  TPZStructMatrixTBBFlow *fStruct;
125  TPZAutoPointer<TPZGuiInterface> fGuiInterface;
127  TPZMatrix<STATE> *fGlobMatrix;
129  TPZFMatrix<STATE> *fGlobRhs;
130  };
131 
132  class TPZFlowNode {
133  public:
134  TPZFlowNode(TPZFlowGraph *graph, int el):
135  myGraph(graph), iel(el) {};
136 
137  ~TPZFlowNode() {};
138 
139  void operator()(tbb::flow::continue_msg) const;
140 
141  TPZFlowGraph *myGraph;
142 
144  int iel;
145 
146 
147  };
148 
149 
150  struct TPZGraphThreadData {
151  // copy constructor
152  TPZGraphThreadData(TPZCompMesh *cmesh, TPZVec<int> &fnextBlocked, TPZVec<int> &felSequenceColor, TPZVec<int> &felSequenceColorInv);
153  // destructor
154  ~TPZGraphThreadData();
155  // tbb tasks graph
156  tbb::flow::graph fAssembleGraph;
157  // initial node
158  tbb::flow::broadcast_node<tbb::flow::continue_msg> fStart;
159  // store all the nodes
160  std::vector<tbb::flow::continue_node<tbb::flow::continue_msg>* > fGraphNodes;
161  // vector for coloring mesh
162  TPZVec<int> felSequenceColor;
163 
164 
165 
167  TPZStructMatrixTBBFlow *fStruct;
169  TPZAutoPointer<TPZGuiInterface> fGuiInterface;
171  TPZMatrix<STATE> *fGlobMatrix;
173  TPZFMatrix<STATE> *fGlobRhs;
174  };
175 
176  struct TPZGraphThreadNode {
177  TPZGraphThreadData *data;
178  int iel;
179  TPZGraphThreadNode(TPZGraphThreadData *data, int el)
180  : data(data), iel(el) {}
181  void operator()(tbb::flow::continue_msg) const;
182  };
183 
184 #endif
185 
186 
187 protected:
188 
195 
196 #ifdef USING_TBB
197  TPZFlowGraph *fFlowGraph;
198 #endif
199 
200 protected:
201 
204  std::set<int> fMaterialIds;
205 
208 };
209 
210 #endif
Contains declaration of the TPZSemaphore class which implements semaphore to threads.
void Read(TPZStream &buf, void *context) override
read objects from the stream
Templated vector implementation.
Contains declaration of TPZGuiInterface class.
TPZEquationFilter fEquationFilter
Object which will determine which equations will be assembled.
virtual TPZStructMatrixTBBFlow * Clone() override
TPZSkylMatrix< REAL > matrix
Definition: numatst.cpp:255
Contains declaration of TPZElementMatrix struct which associates an element matrix with the coeficien...
virtual TPZMatrix< STATE > * Create() override
virtual void Assemble(TPZMatrix< STATE > &mat, TPZFMatrix< STATE > &rhs, TPZAutoPointer< TPZGuiInterface > guiInterface, unsigned numthreads_assemble, unsigned numthreads_decompose)
TPZCompMesh * fMesh
Pointer to the computational mesh from which the matrix will be generated.
Contains TPZMatrixclass which implements full matrix (using column major representation).
virtual void SetNumThreads(int n)
Refines geometrical mesh (all the elements) num times.
virtual void MultiThread_Assemble(TPZFMatrix< STATE > &rhs, TPZAutoPointer< TPZGuiInterface > guiInterface)
Assemble the global system of equations into the matrix which has already been created.
Contains declaration of the TPZAutoPointer class which has Increment and Decrement actions are mutexe...
Contains declaration of TPZCompMesh class which is a repository for computational elements...
virtual TPZMatrix< STATE > * CreateAssemble(TPZFMatrix< STATE > &rhs, TPZAutoPointer< TPZGuiInterface > guiInterface, unsigned numthreads_assemble, unsigned numthreads_decompose)
Contains TPZMatrix<TVar>class, root matrix class.
std::set< int > fMaterialIds
Set of material ids to be considered. It is a private attribute.
int fNumThreads
Number of threads in Assemble process.
void Write(TPZStream &buf, int withclassid) const override
Writes this object to the TPZStream buffer. Include the classid if withclassid = true.
Implements computational mesh. Computational Mesh.
Definition: pzcmesh.h:47
TPZAutoPointer< TPZCompMesh > fCompMesh
Autopointer control of the computational mesh.
Defines the interface for saving and reading data. Persistency.
Definition: TPZStream.h:50
int ClassId() const override
Define the class id associated with the class.
virtual void Assemble(TPZMatrix< STATE > &mat, TPZFMatrix< STATE > &rhs, TPZAutoPointer< TPZGuiInterface > guiInterface) override
Assemble the global system of equations into the matrix which has already been created.