NeoPZ
pzstrmatrix.h
Go to the documentation of this file.
1 
6 #ifndef TPZStructMatrixOR_H
7 #define TPZStructMatrixOR_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 TPZStructMatrixOR;
23 #include "TPZStructMatrixBase.h"
24 
29 //void UniformRefine(int num, TPZGeoMesh &m);
30 
36 
37 protected:
38 
40  struct ThreadData
41  {
45  ThreadData(TPZStructMatrixOR *strmat, TPZFMatrix<STATE> &rhs, std::set<int> &MaterialIds, TPZAutoPointer<TPZGuiInterface> guiInterface);
47  ~ThreadData();
49  int64_t NextElement();
53  static void *ThreadWork(void *threaddata);
55  static void *ThreadAssembly(void *threaddata);
57  bool ShouldCompute(int matid)
58  {
59  return fStruct->ShouldCompute(matid);
60  }
61 
71  std::map<int, std::pair< TPZAutoPointer<TPZElementMatrix>, TPZAutoPointer<TPZElementMatrix> > > fSubmitted;
73  std::set<int> fProcessed;
75  int64_t fNextElement;
77  pthread_mutex_t fAccessElement;
80  };
81 
82 public:
83 
85 
87 
89 
91 
92  virtual ~TPZStructMatrixOR(){};
93 
94  virtual TPZMatrix<STATE> * Create() override;
95 
96  virtual TPZStructMatrixOR * Clone() override;
97 
99 
101  unsigned numthreads_assemble, unsigned numthreads_decompose) {
102  SetNumThreads(numthreads_assemble);
103  return CreateAssemble(rhs, guiInterface);
104  }
105 
106  //virtual TPZMatrix<STATE> * CreateAssemble(TPZFMatrix<STATE> &rhs, TPZAutoPointer<TPZGuiInterface> guiInterface);
107 
109  virtual void Assemble(TPZMatrix<STATE> & mat, TPZFMatrix<STATE> & rhs, TPZAutoPointer<TPZGuiInterface> guiInterface) override;
111  unsigned numthreads_assemble, unsigned numthreads_decompose) {
112  std::cout << "Nothing to do." << std::endl;
113  }
114 
116  virtual void Assemble(TPZFMatrix<STATE> & rhs, TPZAutoPointer<TPZGuiInterface> guiInterface) override;
117 
118  public:
119 int ClassId() const override;
120  void Read(TPZStream &buf, void *context) override;
121  void Write(TPZStream &buf, int withclassid) const override;
122 
123 
124 protected:
125 
126 
129 
131  virtual void Serial_Assemble(TPZFMatrix<STATE> & rhs, TPZAutoPointer<TPZGuiInterface> guiInterface);
132 
135 
138 
139 
140  friend struct ThreadData;
141 };
142 
143 #endif
int ClassId() const override
Define the class id associated with the class.
virtual TPZMatrix< STATE > * CreateAssemble(TPZFMatrix< STATE > &rhs, TPZAutoPointer< TPZGuiInterface > guiInterface)
TPZAutoPointer< TPZGuiInterface > fGuiInterface
Gui interface object.
Definition: pzstrmatrix.h:65
Contains declaration of the TPZSemaphore class which implements semaphore to threads.
void Write(TPZStream &buf, int withclassid) const override
Writes this object to the TPZStream buffer. Include the classid if withclassid = true.
Implements semaphore to threads. Utility.
Definition: TPZSemaphore.h:15
Structure to manipulate thread to solve system equations.
Definition: pzstrmatrix.h:40
virtual ~TPZStructMatrixOR()
Definition: pzstrmatrix.h:92
Templated vector implementation.
pthread_mutex_t fAccessElement
Mutexes (to choose which element is next)
Definition: pzstrmatrix.h:77
Contains declaration of TPZGuiInterface class.
TPZFMatrix< STATE > * fGlobRhs
Global rhs vector.
Definition: pzstrmatrix.h:69
~ThreadData()
Destructor: Destroy the mutex semaphores and others.
std::map< int, std::pair< TPZAutoPointer< TPZElementMatrix >, TPZAutoPointer< TPZElementMatrix > > > fSubmitted
List of computed element matrices (autopointers?)
Definition: pzstrmatrix.h:71
static void * ThreadWork(void *threaddata)
The function which will compute the matrices.
virtual void Assemble(TPZMatrix< STATE > &mat, TPZFMatrix< STATE > &rhs, TPZAutoPointer< TPZGuiInterface > guiInterface, unsigned numthreads_assemble, unsigned numthreads_decompose)
Definition: pzstrmatrix.h:110
Refines geometrical mesh (all the elements) num times.
Definition: pzstrmatrix.h:35
Contains declaration of TPZElementMatrix struct which associates an element matrix with the coeficien...
virtual const std::set< int > & MaterialIds()
Returns the material ids.
virtual TPZStructMatrixOR * Clone() override
Definition: pzstrmatrix.cpp:70
int64_t fNextElement
Current element.
Definition: pzstrmatrix.h:75
ThreadData(TPZStructMatrixOR *strmat, TPZMatrix< STATE > &mat, TPZFMatrix< STATE > &rhs, std::set< int > &MaterialIds, TPZAutoPointer< TPZGuiInterface > guiInterface)
Initialize the mutex semaphores and others.
TPZStructMatrixOR * fStruct
Current structmatrix object.
Definition: pzstrmatrix.h:63
Contains TPZMatrixclass which implements full matrix (using column major representation).
virtual void SetNumThreads(int n)
TPZMatrix< STATE > * fGlobMatrix
Global matrix.
Definition: pzstrmatrix.h:67
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.
int64_t NextElement()
Look for an element index which needs to be computed and put it on the stack.
virtual void MultiThread_Assemble(TPZFMatrix< STATE > &rhs, TPZAutoPointer< TPZGuiInterface > guiInterface)
Assemble the global right hand side.
Contains declaration of the TPZAutoPointer class which has Increment and Decrement actions are mutexe...
virtual bool ShouldCompute(int matid) const
Establish whether the element should be computed.
Contains declaration of TPZCompMesh class which is a repository for computational 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.
Definition: pzstrmatrix.cpp:80
Contains TPZMatrix<TVar>class, root matrix class.
static void * ThreadAssembly(void *threaddata)
The function which will compute the assembly.
bool ShouldCompute(int matid)
Establish whether the element should be computed.
Definition: pzstrmatrix.h:57
std::set< int > fProcessed
Elements which are being processed.
Definition: pzstrmatrix.h:73
TPZSemaphore fAssembly
Semaphore (to wake up assembly thread)
Definition: pzstrmatrix.h:79
Implements computational mesh. Computational Mesh.
Definition: pzcmesh.h:47
Defines the interface for saving and reading data. Persistency.
Definition: TPZStream.h:50
void Read(TPZStream &buf, void *context) override
read objects from the stream
void ComputedElementMatrix(int64_t iel, TPZAutoPointer< TPZElementMatrix > &ek, TPZAutoPointer< TPZElementMatrix > &ef)
Put the computed element matrices in the map.
virtual TPZMatrix< STATE > * CreateAssemble(TPZFMatrix< STATE > &rhs, TPZAutoPointer< TPZGuiInterface > guiInterface, unsigned numthreads_assemble, unsigned numthreads_decompose)
Definition: pzstrmatrix.h:100
virtual TPZMatrix< STATE > * Create() override
Definition: pzstrmatrix.cpp:65