NeoPZ
pzstrmatrixcs.h
Go to the documentation of this file.
1 
6 #ifndef TPZStructMatrixCS_H
7 #define TPZStructMatrixCS_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 TPZStructMatrixCS;
23 #include "TPZStructMatrixBase.h"
24 
25 #ifdef USING_TBB
26 #include <tbb/tbb.h>
27 #endif
28 
33 //void UniformRefine(int num, TPZGeoMesh &m);
34 
40 
41 public:
42 
44 
46 
48 
50 
51  virtual ~TPZStructMatrixCS(){};
52 
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 TPZStructMatrixCS * 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 protected:
83 
86 
88  virtual void Serial_Assemble(TPZFMatrix<STATE> & rhs, TPZAutoPointer<TPZGuiInterface> guiInterface);
89 
92 
95 
96 protected:
97 
99  struct ThreadData
100  {
104  ThreadData(TPZStructMatrixCS *strmat, TPZFMatrix<STATE> &rhs, std::set<int> &MaterialIds, TPZAutoPointer<TPZGuiInterface> guiInterface);
106  ~ThreadData();
108  int64_t NextElement();
110  static void *ThreadWork(void *threaddata);
112  bool ShouldCompute(int matid)
113  {
114  return fStruct->ShouldCompute(matid);
115  }
116 
126  std::map<int, std::pair< TPZAutoPointer<TPZElementMatrix>, TPZAutoPointer<TPZElementMatrix> > > fSubmitted;
128  int64_t fNextElement;
130  pthread_mutex_t fAccessElement;
132  pthread_mutex_t fAccessElementK;
134  pthread_mutex_t fAccessElementF;
137  };
138 
139 #ifdef USING_TBB
140  struct AssembleTask {
141  ThreadData *data;
142  AssembleTask(ThreadData *dt) : data(dt) {};
143  void operator()(const tbb::blocked_range<size_t>& range) const;
144  };
145 #endif
146 
147  friend struct ThreadData;
148 };
149 
150 #endif
virtual TPZMatrix< STATE > * Create() override
Sets number of threads in Assemble process.
Contains declaration of the TPZSemaphore class which implements semaphore to threads.
std::map< int, std::pair< TPZAutoPointer< TPZElementMatrix >, TPZAutoPointer< TPZElementMatrix > > > fSubmitted
List of computed element matrices (autopointers?)
Implements semaphore to threads. Utility.
Definition: TPZSemaphore.h:15
pthread_mutex_t fAccessElementF
Mutexes (to choose which element is next)
Templated vector implementation.
Contains declaration of TPZGuiInterface class.
TPZSemaphore fAssembly
Semaphore (to wake up assembly thread)
Refines geometrical mesh (all the elements) num times.
Definition: pzstrmatrixcs.h:39
int64_t fNextElement
Current element.
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.
pthread_mutex_t fAccessElement
Mutexes (to choose which element is next)
Contains declaration of TPZElementMatrix struct which associates an element matrix with the coeficien...
virtual const std::set< int > & MaterialIds()
Returns the material ids.
void Read(TPZStream &buf, void *context) override
read objects from the stream
pthread_mutex_t fAccessElementK
Mutexes (to choose which element is next)
TPZMatrix< STATE > * fGlobMatrix
Global matrix.
virtual void MultiThread_Assemble(TPZFMatrix< STATE > &rhs, TPZAutoPointer< TPZGuiInterface > guiInterface)
Assemble the global right hand side.
Contains TPZMatrixclass which implements full matrix (using column major representation).
virtual void SetNumThreads(int n)
virtual ~TPZStructMatrixCS()
Definition: pzstrmatrixcs.h:51
virtual TPZMatrix< STATE > * CreateAssemble(TPZFMatrix< STATE > &rhs, TPZAutoPointer< TPZGuiInterface > guiInterface, unsigned numthreads_assemble, unsigned numthreads_decompose)
Definition: pzstrmatrixcs.h:57
virtual void Assemble(TPZMatrix< STATE > &mat, TPZFMatrix< STATE > &rhs, TPZAutoPointer< TPZGuiInterface > guiInterface, unsigned numthreads_assemble, unsigned numthreads_decompose)
Definition: pzstrmatrixcs.h:69
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.
TPZFMatrix< STATE > * fGlobRhs
Global rhs vector.
virtual bool ShouldCompute(int matid) const
Establish whether the element should be computed.
ThreadData(TPZStructMatrixCS *strmat, TPZMatrix< STATE > &mat, TPZFMatrix< STATE > &rhs, std::set< int > &MaterialIds, TPZAutoPointer< TPZGuiInterface > guiInterface)
Initialize the mutex semaphores and others.
Contains declaration of TPZCompMesh class which is a repository for computational elements...
TPZAutoPointer< TPZGuiInterface > fGuiInterface
Gui interface object.
~ThreadData()
Destructor: Destroy the mutex semaphores and others.
Contains TPZMatrix<TVar>class, root matrix class.
TPZStructMatrixCS * fStruct
Current structmatrix object.
int ClassId() const override
Define the class id associated with the class.
virtual TPZStructMatrixCS * Clone() override
int64_t NextElement()
Look for an element index which needs to be computed and put it on the stack.
Implements computational mesh. Computational Mesh.
Definition: pzcmesh.h:47
Defines the interface for saving and reading data. Persistency.
Definition: TPZStream.h:50
bool ShouldCompute(int matid)
Establish whether the element should be computed.
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.
Structure to manipulate thread to solve system equations.
Definition: pzstrmatrixcs.h:99
static void * ThreadWork(void *threaddata)
The function which will compute the matrices.