NeoPZ
pzstrmatrixgc.h
Go to the documentation of this file.
1 
6 #ifndef TPZStructMatrixGC_H
7 #define TPZStructMatrixGC_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 class TPZStructMatrixGC;
22 #include "TPZStructMatrixBase.h"
23 
28 //void UniformRefine(int num, TPZGeoMesh &m);
29 
35 
36 public:
37 
39 
41 
43 
45 
46  virtual ~TPZStructMatrixGC(){};
47 
48  virtual TPZMatrix<STATE> * Create() override;
49 
51  unsigned numthreads_assemble, unsigned numthreads_decompose) {
52  SetNumThreads(numthreads_assemble);
53  return CreateAssemble(rhs, guiInterface);
54  }
55 
57 
58  virtual TPZStructMatrixGC * Clone() override;
59 
61  virtual void Assemble(TPZMatrix<STATE> & mat, TPZFMatrix<STATE> & rhs, TPZAutoPointer<TPZGuiInterface> guiInterface) override;
63  unsigned numthreads_assemble, unsigned numthreads_decompose) {
64  std::cout << "Nothing to do." << std::endl;
65  }
66 
68  virtual void Assemble(TPZFMatrix<STATE> & rhs, TPZAutoPointer<TPZGuiInterface> guiInterface) override;
69 
70  public:
71 int ClassId() const override;
72  void Read(TPZStream &buf, void *context) override;
73  void Write(TPZStream &buf, int withclassid) const override;
74 
75 
76 protected:
77 
80 
82  virtual void Serial_Assemble(TPZFMatrix<STATE> & rhs, TPZAutoPointer<TPZGuiInterface> guiInterface);
83 
86 
89 
90 public:
92  static void OrderElement(TPZCompMesh *cmesh, TPZVec<int64_t> &ElementOrder);
93 
95  static void ElementColoring(TPZCompMesh *cmesh, TPZVec<int64_t> &elSequence, TPZVec<int64_t> &elSequenceColor, TPZVec<int64_t> &elBlocked);
96 
97 protected:
98 
100  struct ThreadData
101  {
105  ThreadData(TPZStructMatrixGC *strmat, TPZFMatrix<STATE> &rhs, std::set<int> &MaterialIds, TPZAutoPointer<TPZGuiInterface> guiInterface);
107  ~ThreadData();
109  static void *ThreadWork(void *threaddata);
111  bool ShouldCompute(int matid)
112  {
113  return fStruct->ShouldCompute(matid);
114  }
115 
125  std::map<int, std::pair< TPZAutoPointer<TPZElementMatrix>, TPZAutoPointer<TPZElementMatrix> > > fSubmitted;
127  std::set<int> fProcessed;
129  int64_t fNextElement;
131  pthread_mutex_t fAccessElement;
134 
135  pthread_cond_t fCondition;
136  bool fSleeping;
137 
138  // Vectors for mesh coloring
139  std::map<int,int> felBlocked;
142 
143  static void *ThreadWorkResidual(void *datavoid);
144  };
145 
146  friend struct ThreadData;
147 protected:
150 };
151 
152 #endif
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.
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.
virtual TPZStructMatrixGC * Clone() override
Contains declaration of the TPZSemaphore class which implements semaphore to threads.
TPZStructMatrixGC * fStruct
Current structmatrix object.
virtual TPZMatrix< STATE > * Create() override
Implements semaphore to threads. Utility.
Definition: TPZSemaphore.h:15
std::map< int, std::pair< TPZAutoPointer< TPZElementMatrix >, TPZAutoPointer< TPZElementMatrix > > > fSubmitted
List of computed element matrices (autopointers?)
std::map< int, int > felBlocked
int ClassId() const override
Define the class id associated with the class.
static void * ThreadWorkResidual(void *datavoid)
static void ElementColoring(TPZCompMesh *cmesh, TPZVec< int64_t > &elSequence, TPZVec< int64_t > &elSequenceColor, TPZVec< int64_t > &elBlocked)
Create blocks of elements to parallel processing.
void Read(TPZStream &buf, void *context) override
read objects from the stream
Templated vector implementation.
Contains declaration of TPZGuiInterface class.
static void * ThreadWork(void *threaddata)
The function which will compute the matrices.
int64_t fNextElement
Current element.
TPZSemaphore fAssembly
Semaphore (to wake up assembly thread)
virtual void MultiThread_Assemble(TPZFMatrix< STATE > &rhs, TPZAutoPointer< TPZGuiInterface > guiInterface)
Assemble the global right hand side.
Contains declaration of TPZElementMatrix struct which associates an element matrix with the coeficien...
virtual const std::set< int > & MaterialIds()
Returns the material ids.
TPZVec< int64_t > * felSequenceColor
Contains TPZMatrixclass which implements full matrix (using column major representation).
Structure to manipulate thread to solve system equations.
virtual void SetNumThreads(int n)
static void OrderElement(TPZCompMesh *cmesh, TPZVec< int64_t > &ElementOrder)
Find the order to assemble the elements.
TPZMatrix< STATE > * fGlobMatrix
Global matrix.
ThreadData(TPZStructMatrixGC *strmat, TPZMatrix< STATE > &mat, TPZFMatrix< STATE > &rhs, std::set< int > &MaterialIds, TPZAutoPointer< TPZGuiInterface > guiInterface)
Initialize the mutex semaphores and others.
virtual TPZMatrix< STATE > * CreateAssemble(TPZFMatrix< STATE > &rhs, TPZAutoPointer< TPZGuiInterface > guiInterface, unsigned numthreads_assemble, unsigned numthreads_decompose)
Definition: pzstrmatrixgc.h:50
TPZAutoPointer< TPZGuiInterface > fGuiInterface
Gui interface object.
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.
TPZVec< int64_t > * fnextBlocked
Vector for mesh coloring.
TPZVec< int64_t > fnextBlocked
Vectors for mesh coloring.
Contains declaration of TPZCompMesh class which is a repository for computational elements...
Refines geometrical mesh (all the elements) num times.
Definition: pzstrmatrixgc.h:34
Contains TPZMatrix<TVar>class, root matrix class.
virtual ~TPZStructMatrixGC()
Definition: pzstrmatrixgc.h:46
~ThreadData()
Destructor: Destroy the mutex semaphores and others.
Implements computational mesh. Computational Mesh.
Definition: pzcmesh.h:47
pthread_mutex_t fAccessElement
Mutexes (to choose which element is next)
Defines the interface for saving and reading data. Persistency.
Definition: TPZStream.h:50
void Write(TPZStream &buf, int withclassid) const override
Writes this object to the TPZStream buffer. Include the classid if withclassid = true.
std::set< int > fProcessed
Elements which are being processed.
virtual void Assemble(TPZMatrix< STATE > &mat, TPZFMatrix< STATE > &rhs, TPZAutoPointer< TPZGuiInterface > guiInterface, unsigned numthreads_assemble, unsigned numthreads_decompose)
Definition: pzstrmatrixgc.h:62
TPZFMatrix< STATE > * fGlobRhs
Global rhs vector.
bool ShouldCompute(int matid)
The function which will compute the assembly.