34 static LoggerPtr logger(Logger::getLogger(
"pz.strmatrix.TPZStructMatrixTBBFlow"));
35 static LoggerPtr loggerel(Logger::getLogger(
"pz.strmatrix.element"));
36 static LoggerPtr loggerel2(Logger::getLogger(
"pz.strmatrix.elementinterface"));
37 static LoggerPtr loggerelmat(Logger::getLogger(
"pz.strmatrix.elementmat"));
38 static LoggerPtr loggerCheck(Logger::getLogger(
"pz.strmatrix.checkconsistency"));
41 #ifdef CHECKCONSISTENCY 48 static RunStatsTable stat_ass_graph_tbb(
"-ass_graph_tbb",
"Run statistics table for the graph creation, coloring and tbb::flow::graph TPZStructMatrixTBBFlow.");
55 this->fFlowGraph =
new TPZFlowGraph(
this);
60 fMesh = cmesh.operator->();
63 this->fFlowGraph =
new TPZFlowGraph(
this);
75 fFlowGraph =
new TPZFlowGraph(*copy.fFlowGraph);
91 std::cout <<
"TPZStructMatrixTBBFlow::Create should never be called\n";
96 std::cout <<
"TPZStructMatrixTBBFlow::Clone should never be called\n";
108 if (stiffness.
Rows() != neqcondense) {
130 if(rhs.
Rows() != neqexpand ||
Norm(rhs) != 0.)
149 int64_t cols =
MAX(1, rhs.
Cols());
155 if(loggerel->isDebugEnabled())
157 std::stringstream sout;
158 stiff->
Print(
"Stiffness matrix",sout);
159 rhs.
Print(
"Right hand side", sout);
170 this->fFlowGraph->ExecuteGraph(&rhs, &mat);
172 std::cout <<
"To use the tbb flow graph assemble please compile the NeoPZ with USING_TBB." << std::endl;
180 this->fFlowGraph->ExecuteGraph(&rhs);
182 std::cout <<
"To use the tbb flow graph assemble please compile the NeoPZ with USING_TBB." << std::endl;
192 for (
int i = 0 ; i < connectlist.
NElements() ; i++)
194 if (elContribute[connectlist[i]] >= 0){
203 for (
int i = 0 ; i < connectlist.
NElements() ; i++)
205 elContribute[connectlist[i]] = el;
212 for (
int i = 0 ; i < connectlist.
NElements() ; i++)
214 int elBlocked = elContribute[connectlist[i]];
215 if (elBlocked == -1)
continue;
216 int elBlockedIndex = elSeqinv[elBlocked];
217 if (el == -1) el = elBlockedIndex;
218 if (elBlockedIndex < el) el = elBlockedIndex;
229 for (
int i = 0 ; i < connectlist.
NElements() ; i++)
231 int conindex = connectlist[i];
232 if (elContribute[conindex] != elSequence){
235 elContribute[conindex] = -1;
241 int minPassIndex = -1;
242 for (
int i = 0 ; i < connectlist.
NElements() ; i++)
244 int elcont = elContribute[connectlist[i]];
247 passindex = passIndex[elcont];
248 if (minPassIndex == -1) minPassIndex = passindex;
250 if (minPassIndex < passindex) minPassIndex = passindex;
263 fFlowGraph =
new TPZFlowGraph(
this);
282 void TPZStructMatrixTBBFlow::TPZFlowGraph::ElementColoring()
285 const int nnodes = cmesh->NConnects();
286 const int nel = cmesh->ElementVec().NElements();
289 felSequenceColor.Resize(nel);
290 felSequenceColor.Fill(-1);
291 felSequenceColorInv.Resize(nel, -1);
292 felSequenceColorInv.Fill(-1);
293 fnextBlocked.Resize(nel);
294 fnextBlocked.Fill(-1);
295 int nelProcessed = 0;
297 int currentPassIndex = 0;
298 while (nelProcessed < fElementOrder.NElements()){
300 int elindex = fElementOrder[currentEl];
302 if(felSequenceColorInv[elindex] == -1)
304 TPZCompEl *cel = cmesh->ElementVec()[elindex];
312 int minPass =
MinPassIndex(connectlist,elContribute,passIndex);
314 passIndex[elindex] = currentPassIndex;
316 felSequenceColor[nelProcessed] = elindex;
317 felSequenceColorInv[elindex] = nelProcessed;
320 else if (minPass == currentPassIndex){
322 else if (minPass < currentPassIndex){
324 const int el =
WhoBlockedMe(connectlist,elContribute, felSequenceColorInv);
325 if (fnextBlocked[el] == -1) fnextBlocked[el] = nelProcessed;
326 int locindex = felSequenceColor[el];
327 RemoveEl(locindex,cmesh,elContribute,locindex);
330 passIndex[elindex] = currentPassIndex;
332 felSequenceColor[nelProcessed] = elindex;
333 felSequenceColorInv[elindex] = nelProcessed;
341 if (currentEl == fElementOrder.NElements()){
353 std::ofstream toto(
"../ColorMeshDebug.txt");
354 toto <<
"elSequence\n" << fElementOrder << std::endl;
355 toto <<
"elSequenceColor\n" << felSequenceColor << std::endl;
356 toto <<
"elSequenceColorInv\n" << felSequenceColorInv << std::endl;
357 toto <<
"elBlocked\n" << fnextBlocked << std::endl;
358 toto <<
"elContribute\n" << elContribute << std::endl;
359 toto <<
"passIndex\n" << passIndex << std::endl;
365 : cmesh(strmat->
Mesh()), fStartNode(fGraph), fStruct(strmat), fGlobMatrix(0), fGlobRhs(0)
367 this->OrderElements();
368 this->ElementColoring();
372 TPZStructMatrixTBBFlow::TPZFlowGraph::~TPZFlowGraph()
374 for (
int k = 0; k < fNodes.size(); ++k) {
383 this->fGlobMatrix =
matrix;
384 this->fGlobRhs = rhs;
385 this->fStartNode.try_put(tbb::flow::continue_msg());
386 this->fGraph.wait_for_all();
390 TPZStructMatrixTBBFlow::TPZFlowGraph::TPZFlowGraph(TPZFlowGraph
const ©)
391 : cmesh(copy.fStruct->Mesh()), fStartNode(fGraph), fStruct(copy.fStruct), fGlobMatrix(0), fGlobRhs(0)
393 this->fnextBlocked = copy.fnextBlocked;
394 this->felSequenceColor = copy.felSequenceColor;
395 this->felSequenceColorInv = copy.felSequenceColorInv;
396 this->fElementOrder = copy.fElementOrder;
400 void TPZStructMatrixTBBFlow::TPZFlowNode::operator()(tbb::flow::continue_msg)
const 407 if (logger->isDebugEnabled()) {
408 std::stringstream sout;
409 sout <<
"Computing element " << iel;
414 std::stringstream sout;
415 sout <<
"Element " << iel <<
" elapsed time ";
420 int element = myGraph->felSequenceColor[iel];
428 if (myGraph->fGlobMatrix)
435 if (myGraph->fGlobMatrix) {
445 if (myGraph->fGlobMatrix) {
459 if(myGraph->fGlobMatrix) {
480 if (logger->isDebugEnabled())
482 std::stringstream sout;
483 sout << timeforel.processName() << timeforel;
490 void TPZStructMatrixTBBFlow::TPZFlowGraph::CreateGraph()
492 int64_t nelem = cmesh->NElements();
493 int64_t nconnects = cmesh->NConnects();
494 int64_t numberOfElements=felSequenceColor.NElements();
497 fNodes.resize(felSequenceColor.NElements());
498 for (int64_t i=0; i<felSequenceColor.NElements(); i++) {
499 fNodes[i]=
new tbb::flow::continue_node<tbb::flow::continue_msg>(fGraph, TPZFlowNode(
this, i));
503 for (int64_t graphindex = 0; graphindex<numberOfElements; graphindex++) {
504 int64_t el = felSequenceColor[graphindex];
512 std::set<int64_t> fromwhere;
513 for (
int ic=0; ic<connects.
size(); ic++) {
514 int64_t c = connects[ic];
515 if (elementloaded[c] != -1) {
516 int64_t elorig = elementloaded[c];
518 if (fromwhere.find(elorig) == fromwhere.end()) {
520 if (logger->isDebugEnabled()) {
521 std::stringstream sout;
522 sout <<
"Adding edge from " << elorig <<
" to " << graphindex;
526 make_edge(*fNodes[elorig], *fNodes[graphindex]);
528 fromwhere.insert(elorig);
534 if (logger->isDebugEnabled()) {
535 std::stringstream sout;
536 sout <<
"Setting start element " << graphindex;
541 make_edge(fStartNode, *fNodes[graphindex]);
543 for (
int ic=0; ic<connects.
size(); ic++) {
544 int64_t c = connects[ic];
545 elementloaded[c] = graphindex;
551 void TPZStructMatrixTBBFlow::TPZFlowGraph::OrderElements()
553 int numelconnected = 0;
554 int nconnect = cmesh->ConnectVec().
NElements();
558 firstelconnect[0] = 0;
559 for(ic=0; ic<nconnect; ic++) {
560 numelconnected += cmesh->ConnectVec()[ic].NElConnected();
561 firstelconnect[ic+1] = firstelconnect[ic]+cmesh->ConnectVec()[ic].NElConnected();
569 for(el=0; el<cmesh->ElementVec().NElements(); el++) {
570 cel = cmesh->ElementVec()[el];
576 for(ic=0; ic<nc; ic++) {
577 int cindex = connectlist[ic];
578 elconnect[firstelconnect[cindex]] = el;
579 firstelconnect[cindex]++;
583 firstelconnect[0] = 0;
584 for(ic=0; ic<nconnect; ic++) {
585 firstelconnect[ic+1] = firstelconnect[ic]+cmesh->ConnectVec()[ic].NElConnected();
595 fElementOrder.
Resize(cmesh->ElementVec().NElements(),-1);
596 fElementOrder.Fill(-1);
597 TPZVec<int> nodeorder(cmesh->ConnectVec().NElements(),-1);
598 firstelconnect[0] = 0;
599 for(ic=0; ic<nconnect; ic++) {
600 int seqnum = cmesh->ConnectVec()[ic].SequenceNumber();
601 if(seqnum >= 0) nodeorder[seqnum] = ic;
609 TPZVec<int> elorderinv(cmesh->ElementVec().NElements(),-1);
610 for(seq=0; seq<nconnect; seq++) {
612 if(ic == -1)
continue;
613 int firstind = firstelconnect[ic];
614 int lastind = firstelconnect[ic+1];
616 for(ind=firstind; ind<lastind; ind++) {
621 if(elorderinv[el]==-1) elorderinv[el] = elsequence++;
628 for(seq=0;seq<cmesh->ElementVec().NElements();seq++) {
629 if(elorderinv[seq] == -1)
continue;
630 fElementOrder[elorderinv[seq]] = seq;
633 for(seq=0;seq<cmesh->ElementVec().NElements();seq++) {
634 if(fElementOrder[seq]==-1)
break;
637 fElementOrder.
Resize(seq);
Contains a class to record running statistics on CSV tables.
The timer class. Utility.
static int MinPassIndex(TPZStack< int64_t > &connectlist, TPZVec< int > &elContribute, TPZVec< int > &passIndex)
static void RemoveEl(int el, TPZCompMesh *cmesh, TPZVec< int > &elContribute, int elSequence)
Contains TPZAnalysis class which implements the sequence of actions to perform a finite element analy...
void Scatter(const TPZFMatrix< TVar > &vsmall, TPZFMatrix< TVar > &vexpand) const
Contains definitions to LOGPZ_DEBUG, LOGPZ_INFO, LOGPZ_WARN, LOGPZ_ERROR and LOGPZ_FATAL, and the implementation of the inline InitializePZLOG(string) function using log4cxx library or not. It must to be called out of "#ifdef LOG4CXX" scope.
virtual ~TPZStructMatrixTBBFlow()
static RunStatsTable ass_rhs("-ass_rhs", "Assemble Stiffness")
Timing class. Absolutely copied from GNU time. Take a look at
virtual void BuildConnectList(std::set< int64_t > &indepconnectlist, std::set< int64_t > &depconnectlist)
Builds the list of all connectivities related to the element including the connects pointed to by dep...
Contains declaration of TPZGeoNode class which defines a geometrical node.
virtual TPZCompMesh * Mesh() const
Access method for the mesh pointer.
void Read(TPZStream &buf, void *context) override
read objects from the stream
static bool CanAssemble(TPZStack< int64_t > &connectlist, TPZVec< int > &elContribute)
TPZFNMatrix< 1000, STATE > fMat
Pointer to a blocked matrix object.
Contains declaration of TPZCompEl class which defines the interface of a computational element...
Templated vector implementation.
virtual void CalcStiff(TPZElementMatrix &ek, TPZElementMatrix &ef)
Computes the element stifness matrix and right hand side.
void Write(TPZStream &buf, int withclassid) const override
Writes this object to the TPZStream buffer. Include the classid if withclassid = true.
Contains the TPZStructMatrixTBBFlow class which responsible for a interface among Matrix and Finite E...
Declarates the TPZBlock<REAL>class which implements block matrices.
TPZEquationFilter fEquationFilter
Object which will determine which equations will be assembled.
#define MAX(a, b)
Gets maxime value between a and b.
int ClassId() const override
Define the class id associated with the class.
static TPZSavable * GetInstance(const int64_t &objId)
virtual TPZStructMatrixTBBFlow * Clone() override
TPZManVector< int64_t > fDestinationIndex
void ComputeDestinationIndices()
TPZSkylMatrix< REAL > matrix
static RunStatsTable stat_ass_graph_tbb("-ass_graph_tbb", "Run statistics table for the graph creation, coloring and tbb::flow::graph TPZStructMatrixTBBFlow.")
Contains declaration of TPZElementMatrix struct which associates an element matrix with the coeficien...
virtual TPZMatrix< STATE > * Create() override
static TPZAutoPointer< TPZSavable > GetAutoPointer(const int64_t &objId)
static void AssembleColor(int el, TPZStack< int64_t > &connectlist, TPZVec< int > &elContribute)
int64_t size() const
Returns the number of elements of the vector.
virtual void Resize(const int64_t newsize, const T &object)
Resizes the vector object reallocating the necessary storage, copying the existing objects to the new...
Contains declaration of TPZMesh class which defines a geometrical mesh and contains a corresponding l...
int64_t NActiveEquations() const
Retorna o numero de equacoes ativas do sistema.
void start()
Turns the timer on.
virtual void Write(const bool val)
TPZCompMesh * fMesh
Pointer to the computational mesh from which the matrix will be generated.
TVar Norm(const TPZFMatrix< TVar > &A)
Returns the norm of the matrix A.
Contains TPZMatrixclass which implements full matrix (using column major representation).
#define DebugStop()
Returns a message to user put a breakpoint in.
virtual void SetNumThreads(int n)
#define LOGPZ_DEBUG(A, B)
Define log for debug info.
Refines geometrical mesh (all the elements) num times.
Free store vector implementation.
int64_t Rows() const
Returns number of rows.
virtual void MultiThread_Assemble(TPZFMatrix< STATE > &rhs, TPZAutoPointer< TPZGuiInterface > guiInterface)
Assemble the global system of equations into the matrix which has already been created.
void Write(TPZStream &buf, int withclassid) const override
Writes this object to the TPZStream buffer. Include the classid if withclassid = true.
int64_t NEqExpand() const
Retorna o numero de equacoes do sistema original.
Implements an interface to check the consistency of two implementations. Utility. ...
TPZManVector< int64_t > fSourceIndex
Contains declaration of TPZCompMesh class which is a repository for computational elements...
int Redim(const int64_t newRows, const int64_t newCols) override
Redimension a matrix and ZERO your elements.
virtual TPZMatrix< STATE > * CreateAssemble(TPZFMatrix< STATE > &rhs, TPZAutoPointer< TPZGuiInterface > guiInterface, unsigned numthreads_assemble, unsigned numthreads_decompose)
int32_t Hash(std::string str)
This class associates an element matrix with the coeficients of its contribution in the global stiffn...
TPZFNMatrix< 1000, STATE > fConstrMat
Pointer to the constrained matrix object.
void ApplyConstraints()
Apply the constraints applied to the nodes by transforming the tangent matrix and right hand side...
std::set< int > fMaterialIds
Set of material ids to be considered. It is a private attribute.
int fNumThreads
Number of threads in Assemble process.
Contains declaration of TPZSubCompMesh class which implements a group of computational elements as a ...
void Write(TPZStream &buf, int withclassid) const override
Writes this object to the TPZStream buffer. Include the classid if withclassid = true.
virtual void CalcResidual(TPZElementMatrix &ef)
Computes the element right hand side.
Implements computational mesh. Computational Mesh.
TPZAdmChunkVector< TPZCompEl * > & ElementVec()
Returns a reference to the element pointers vector.
Contains declaration of TPZInterpolatedElement class which implements computational element of the in...
TPZAutoPointer< TPZCompMesh > fCompMesh
Autopointer control of the computational mesh.
int64_t Cols() const
Returns number of cols.
virtual void Print(std::ostream &out) const
Defines the interface for saving and reading data. Persistency.
int64_t NElements() const
Returns the number of elements of the vector.
void Read(TPZStream &buf, void *context) override
read objects from the stream
int ClassId() const override
Define the class id associated with the class.
static RunStatsTable ass_stiff("-ass_stiff", "Assemble Stiffness")
static int WhoBlockedMe(TPZStack< int64_t > &connectlist, TPZVec< int > &elContribute, TPZVec< int > &elSeqinv)
Defines the interface of a computational element. Computational Element.
virtual int HasDependency()
Returns 1 if the element has at least one dependent node. Returns 0 otherwise.
bool HasDependency()
Returns true if the element has at least one dependent node. Returns false otherwise.
static void WritePointer(const TPZSavable *obj, TPZStream *stream)
void Read(TPZStream &buf, void *context) override
read objects from the stream
Implements an interface to register a class id and a restore function. Persistence.
Contains TPZSFMatrix class which implements a symmetric full matrix.
virtual void Read(bool &val)
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.