NeoPZ
pzstrmatrixot.h
Go to the documentation of this file.
1 
6 #ifndef TPZStructMatrixOT_H
7 #define TPZStructMatrixOT_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 
22 class TPZStructMatrixOT;
23 #include "TPZStructMatrixBase.h"
24 
25 //#ifdef USING_TBB
26 //#include "tbb/tbb.h"
27 //#include "tbb/task_group.h"
28 //#endif
29 
30 #ifdef USING_BOOST
31 #include <boost/atomic.hpp>
32 #endif
33 
38 //void UniformRefine(int num, TPZGeoMesh &m);
39 
45 
46 public:
47 
49 
51 
53 
55 
56  virtual ~TPZStructMatrixOT(){};
57 
58  virtual TPZMatrix<STATE> * Create() override;
59 
61  unsigned numthreads_assemble, unsigned numthreads_decompose) {
62  SetNumThreads(numthreads_assemble);
63  return CreateAssemble(rhs, guiInterface);
64  }
65 
67 
68  virtual TPZStructMatrixOT * Clone() override;
69 
71  virtual void Assemble(TPZMatrix<STATE> & mat, TPZFMatrix<STATE> & rhs, TPZAutoPointer<TPZGuiInterface> guiInterface) override;
73  unsigned numthreads_assemble, unsigned numthreads_decompose) {
74  std::cout << "Nothing to do." << std::endl;
75  }
76 
78  virtual void Assemble(TPZFMatrix<STATE> & rhs, TPZAutoPointer<TPZGuiInterface> guiInterface) override;
79 
80  public:
81 int ClassId() const override;
82  void Read(TPZStream &buf, void *context) override;
83  void Write(TPZStream &buf, int withclassid) const override;
84 
85 protected:
86 
89 
91  virtual void Serial_Assemble(TPZFMatrix<STATE> & rhs, TPZAutoPointer<TPZGuiInterface> guiInterface);
92 
95 
98 
99 public:
100 
102  static void OrderElement(TPZCompMesh *cmesh, TPZVec<int64_t> &ElementOrder);
103 
105  static void ElementColoring(TPZCompMesh *cmesh, TPZVec<int64_t> &elSequence, TPZVec<int64_t> &elSequenceColor, TPZVec<int64_t> &elBlocked, TPZVec<int64_t> &NumelColors);
106 
108  virtual void FilterEquations(TPZVec<int64_t> &origindex, TPZVec<int64_t> &destindex) const override;
109 
111  void SetMaterialIds(const std::set<int> &materialids) override;
112 
114  bool ShouldCompute(int matid) const override
115  {
116  const size_t size = fMaterialIds.size();
117  return size == 0 || fMaterialIds.find(matid) != fMaterialIds.end();
118  }
120  const std::set<int> &MaterialIds() override
121  {
122  return fMaterialIds;
123  }
124 
125 protected:
126 
128  struct ThreadData
129  {
131  ThreadData(TPZStructMatrixOT *strmat,int seqnum, TPZMatrix<STATE> &mat, TPZFMatrix<STATE> &rhs, std::set<int> &MaterialIds, TPZAutoPointer<TPZGuiInterface> guiInterface);
133  ThreadData(TPZStructMatrixOT *strmat, int seqnum, TPZFMatrix<STATE> &rhs, std::set<int> &MaterialIds, TPZAutoPointer<TPZGuiInterface> guiInterface);
135  ~ThreadData();
137  static void *ThreadWork(void *threaddata);
139  bool ShouldCompute(int matid)
140  {
141  return fStruct->ShouldCompute(matid);
142  }
143 
152 
153 #ifdef USING_BOOST
154  boost::atomic<int64_t> *fCurrentIndex;
155 #else
156 #endif
157 
159 
163  pthread_mutex_t *fAccessElement;
164 
165  pthread_cond_t *fCondition;
166 
168 
171 
174 
175  static void *ThreadWorkResidual(void *datavoid);
176  };
177 
178 //#ifdef USING_TBB
179 // struct WorkResidualTBB {
180 //
181 // int fElem;
182 // ThreadData *data;
183 //
184 // WorkResidualTBB(int elem, ThreadData *data);
185 // void operator()();
186 //
187 // };
188 //
189 //#endif
190  friend struct ThreadData;
191 protected:
192 
195 
198 
201 
204 
205 #ifdef USING_BOOST
206  boost::atomic<int64_t> fCurrentIndex;
207 #endif
208 
209 
211  pthread_mutex_t fAccessElement;
212 
213  pthread_cond_t fCondition;
214 };
215 
216 #endif
Contains declaration of the TPZSemaphore class which implements semaphore to threads.
int fSomeoneIsSleeping
variable indicating if a thread is sleeping
ThreadData(TPZStructMatrixOT *strmat, int seqnum, TPZMatrix< STATE > &mat, TPZFMatrix< STATE > &rhs, std::set< int > &MaterialIds, TPZAutoPointer< TPZGuiInterface > guiInterface)
Initialize the mutex semaphores and others.
TPZVec< int64_t > * fElSequenceColor
TPZVec< int64_t > * fElBlocked
Vector for mesh coloring.
virtual void Assemble(TPZMatrix< STATE > &mat, TPZFMatrix< STATE > &rhs, TPZAutoPointer< TPZGuiInterface > guiInterface, unsigned numthreads_assemble, unsigned numthreads_decompose)
Definition: pzstrmatrixot.h:72
static void * ThreadWorkResidual(void *datavoid)
virtual void Serial_Assemble(TPZMatrix< STATE > &mat, TPZFMatrix< STATE > &rhs, TPZAutoPointer< TPZGuiInterface > guiInterface)
Assemble the global system of equations into the matrix which has already been created.
Templated vector implementation.
Contains declaration of TPZGuiInterface class.
~ThreadData()
Destructor: Destroy the mutex semaphores and others.
int ClassId() const override
Define the class id associated with the class.
Structure to manipulate thread to solve system equations.
void SetMaterialIds(const std::set< int > &materialids) override
Set the set of material ids which will be considered when assembling the system.
virtual TPZMatrix< STATE > * CreateAssemble(TPZFMatrix< STATE > &rhs, TPZAutoPointer< TPZGuiInterface > guiInterface, unsigned numthreads_assemble, unsigned numthreads_decompose)
Definition: pzstrmatrixot.h:60
static void ElementColoring(TPZCompMesh *cmesh, TPZVec< int64_t > &elSequence, TPZVec< int64_t > &elSequenceColor, TPZVec< int64_t > &elBlocked, TPZVec< int64_t > &NumelColors)
Create blocks of elements to parallel processing.
int64_t * fElementCompleted
All elements below or equal this index have been computed.
static void * ThreadWork(void *threaddata)
The function which will compute the matrices.
virtual void FilterEquations(TPZVec< int64_t > &origindex, TPZVec< int64_t > &destindex) const override
Filter out the equations which are out of the range.
Refines geometrical mesh (all the elements) num times.
Definition: pzstrmatrixot.h:44
Contains declaration of TPZElementMatrix struct which associates an element matrix with the coeficien...
int64_t fElementCompleted
All elements below or equal this index have been computed.
TPZVec< int64_t > fElSequenceColor
virtual void MultiThread_Assemble(TPZFMatrix< STATE > &rhs, TPZAutoPointer< TPZGuiInterface > guiInterface)
Assemble the global right hand side.
pthread_mutex_t fAccessElement
Mutexes (to choose which element is next)
const std::set< int > & MaterialIds() override
Returns the material ids.
bool ShouldCompute(int matid)
The function which will compute the assembly.
Contains TPZMatrixclass which implements full matrix (using column major representation).
virtual void SetNumThreads(int n)
virtual ~TPZStructMatrixOT()
Definition: pzstrmatrixot.h:56
TPZAutoPointer< TPZGuiInterface > fGuiInterface
Gui interface object.
Contains declaration of the TPZAutoPointer class which has Increment and Decrement actions are mutexe...
void Write(TPZStream &buf, int withclassid) const override
Writes this object to the TPZStream buffer. Include the classid if withclassid = true.
TPZMatrix< STATE > * fGlobMatrix
Global matrix.
std::set< int > fMaterialIds
Set of material ids to be considered. It is a private attribute.
Contains declaration of TPZCompMesh class which is a repository for computational elements...
virtual TPZStructMatrixOT * Clone() override
Contains TPZMatrix<TVar>class, root matrix class.
TPZVec< int64_t > * fComputedElements
vector indicating whether an element has been computed
TPZFMatrix< STATE > * fGlobRhs
Global rhs vector.
void Read(TPZStream &buf, void *context) override
read objects from the stream
pthread_cond_t fCondition
Implements computational mesh. Computational Mesh.
Definition: pzcmesh.h:47
int fThreadSeqNum
sequence number of the thread
pthread_mutex_t * fAccessElement
Mutexes (to choose which element is next)
Defines the interface for saving and reading data. Persistency.
Definition: TPZStream.h:50
virtual TPZMatrix< STATE > * Create() override
bool ShouldCompute(int matid) const override
Establish whether the element should be computed.
static void OrderElement(TPZCompMesh *cmesh, TPZVec< int64_t > &ElementOrder)
Find the order to assemble the elements.
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.
TPZVec< int64_t > fElementsComputed
vector of the size of the elements containing 0 or 1 if the element has been computed (in the order o...
TPZStructMatrixOT * fStruct
Current structmatrix object.