30 static LoggerPtr logger(Logger::getLogger(
"substruct.dohrprecond"));
31 static LoggerPtr loggerv1v2(Logger::getLogger(
"substruct.v1v2"));
36 template<
class TVar,
class TSubStruct>
38 :
TPZMatrix<TVar>(origin), fGlobal(origin.SubStructures()), fCoarse(0), fNumCoarse(origin.NumCoarse()), fNumThreads(0), fAssemble(assemble)
43 template<
class TVar,
class TSubStruct>
53 template<
class TVar,
class TSubStruct>
58 template<
class TVar,
class TSubStruct>
71 #include <tbb/blocked_range.h> 72 #include <tbb/partitioner.h> 73 #include <tbb/parallel_for.h> 76 template<
class TVar,
class TSubStruct>
81 std::vector<TPZDohrPrecondV2SubData<TVar,TSubStruct> >
mWorkItems;
93 mWorkItems.push_back(data);
98 void operator()(
const tbb::blocked_range<size_t>& range)
const 101 for(
size_t i=range.begin(); i!=range.end(); ++i )
108 fAssemblyStructure->AddItem(data.
fv2_local);
113 void run_parallel_for(tbb::affinity_partitioner &ap)
119 parallel_for(tbb::blocked_range<size_t>(0, mWorkItems.size()), *
this, ap);
128 template<
class TVar,
class TSubStruct>
133 this->
Error(
"Operator* <matrices with incompatible dimensions>" );
135 this->
Error (
"TPZFMatrix::MultiplyAdd incompatible dimensions\n");
138 int64_t rows = this->
Rows();
139 int64_t cols = this->
Cols();
150 &v1threaddata, __FUNCTION__);
156 typename std::list<TPZAutoPointer<TSubStruct> >::const_iterator it;
163 fAssemble->Extract(isub,x,*Residual_local);
165 tbb_work.addWorkItem(data);
169 tbb_work.run_parallel_for(
pzenviroment.fSubstructurePartitioner);
172 assemblelist.operator->(), __FUNCTION__);
174 for (
int i=0; i<2; i++) {
182 int64_t xcols = x.
Cols();
183 for (int64_t ic=0; ic<xcols; ic++)
185 for (int64_t c=0; c<rows; c++) {
193 template<
class TVar,
class TSubStruct>
202 this->
Error(
"Operator* <matrices with incompatible dimensions>" );
204 this->
Error (
"TPZFMatrix::MultiplyAdd incompatible dimensions\n");
207 int64_t rows = this->
Rows();
208 int64_t cols = this->
Cols();
213 std::stringstream sout;
214 x.
Print(
"x entry vector",sout);
215 if (logger->isDebugEnabled())
219 if (loggerv1v2->isDebugEnabled())
239 &v1threaddata, __FUNCTION__);
244 typename std::list<TPZAutoPointer<TSubStruct> >::const_iterator it;
251 fAssemble->Extract(isub,x,*Residual_local);
260 &v2work, __FUNCTION__);
265 assemblelist.operator->(), __FUNCTION__);
268 for (i=0; i<fNumThreads+2; i++) {
281 TPZFNMatrix<100> v2Expand((*it)->fNEquations,1,0.), v3Expand((*it)->fNEquations,1,0.);
282 int64_t neqs = (*it)->fGlobalEqs.NElements();
288 std::pair<int,int> ind = (*it)->fGlobalEqs[i];
289 v2Expand(ind.first,0) += v2_local(i,0);
292 (*it)->Contribute_v3_local(v2Expand,v3Expand);
295 std::pair<int,int> ind = (*it)->fGlobalEqs[i];
296 v3_local(i,0) += v3Expand(ind.first,0);
300 std::stringstream sout;
301 v2Expand.Print(
"v1+v2 Expand",sout);
302 v3Expand.
Print(
"v3 Expand", sout);
303 v2_local.
Print(
"v1+v2 local",sout);
304 v3_local.Print(
"v3 local",sout);
305 if (logger->isDebugEnabled())
317 int64_t xcols = x.
Cols();
318 for (int64_t ic=0; ic<xcols; ic++)
320 for (c=0; c<rows; c++) {
328 template<
class TVar,
class TSubStruct>
339 for (isub=0; isub<
nsub; isub++) {
340 int64_t nc =
fAssemble->fCoarseEqs[isub].NElements();
343 if(nc != 0) mineq =
fAssemble->fCoarseEqs[isub][0];
344 for (ic=0; ic<nc; ic++) {
345 int64_t eq =
fAssemble->fCoarseEqs[isub][ic];
346 mineq = mineq > eq ? eq : mineq;
348 for (ic=0; ic<nc; ic++) {
349 int64_t eq =
fAssemble->fCoarseEqs[isub][ic];
350 if(skyline[eq] > mineq) skyline[eq] = mineq;
358 for (isub=0; isub<
nsub; isub++) {
359 int64_t nc =
fAssemble->fCoarseEqs[isub].NElements();
361 for (ic=0; ic<nc; ic++) {
362 int64_t ieq =
fAssemble->fCoarseEqs[isub][ic];
364 for (jc=0; jc<nc; jc++) {
365 int64_t jeq =
fAssemble->fCoarseEqs[isub][jc];
366 coarse2(ieq,jeq) = 1.;
374 typename std::list<TPZAutoPointer<TSubStruct> >::iterator it;
378 (*it)->Contribute_Kc(*coarse,
fAssemble->fCoarseEqs[count]);
383 template<
class TVar,
class TSubStruct>
388 CoarseResidual.
Zero();
389 typename std::list<TPZAutoPointer<TSubStruct> >::const_iterator it;
396 (*it)->Contribute_rc_local(xloc,CoarseResidual_local);
397 fAssemble->AssembleCoarse(isub,CoarseResidual_local,CoarseResidual);
401 std::stringstream sout;
402 CoarseResidual.Print(
"Coarse Residual",sout);
403 if (logger->isDebugEnabled())
413 fCoarse->Solve(CoarseResidual,CoarseSolution);
416 std::stringstream sout;
417 CoarseSolution.Print(
"CoarseSolution",sout);
418 if (logger->isDebugEnabled())
432 fAssemble->ExtractCoarse(isub,CoarseSolution,CoarseSolution_local);
433 (*it)->Contribute_v1_local(v1_local,CoarseSolution_local);
439 std::stringstream sout;
440 v1.
Print(
"v1 vector",sout);
441 if (loggerv1v2->isDebugEnabled())
449 template<class TVar, class TSubStruct>
453 typename std::list<TPZAutoPointer<TSubStruct> >::const_iterator it;
461 fAssemble->Extract(isub,x,Residual_local);
462 (*it)->Contribute_v2_local(Residual_local,v2_local);
465 std::stringstream sout;
466 sout <<
"Substructure " << isub << std::endl;
467 Residual_local.
Print(
"Residual local",sout);
468 v2_local.
Print(
"v2_local",sout);
469 if (logger->isDebugEnabled())
480 std::stringstream sout;
481 v2.
Print(
"v2 vector",sout);
482 if (loggerv1v2->isDebugEnabled())
490 template<class TVar, class TSubStruct>
508 template<
class TVar,
class TSubStruct>
524 template<
class TVar,
class TSubStruct>
TPZAutoPointer< TPZFMatrix< TVar > > fInput_local
Input matrix.
Assembling using Dohrmann algorithm. Sub structure.
Contains the TPZTimeTemp class which takes times.
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.
void Write(TPZStream &buf, int withclassid) const override
Packs the object structure in a stream of bytes.
void VisualMatrix(TPZFMatrix< TVar > &matrix, const std::string &outfilename)
This function calls the function that create a Data Explorer file or VTK file that allow to visualiz...
Auxiliar structure for v2 vector to compute the preconditioner developed by Dohrmann. Sub Structure.
void ComputeV2(const TPZFMatrix< TVar > &x, TPZFMatrix< TVar > &v2) const
Compute the contribution of the sub domains.
TPZTimeTemp tempo
External variable to TPZTimeTemp (to take time)
static int Error(const char *msg, const char *msg2=0)
Returns error messages.
clarg::argInt nsub("-nsub", "number of substructs", 4)
Auxiliar structure with list for v2 vector data. Sub Structure.
Defines step solvers class. Solver.
TPZAutoPointer< TSubStruct > fSubStructure
Pointer to the dohr matrix.
Calculate the Times. Utility.
TPZStack< REAL > fPreCond
Time to PreCond for each iteration.
void PrepareZ(const TPZFMatrix< TVar > &y, TPZFMatrix< TVar > &z, const TVar beta, const int opt) const
Is an auxiliar method used by MultiplyAdd.
int64_t fNumCoarse
Size of the coarse system.
This class implements a simple vector storage scheme for a templated class T. Utility.
Implements sub structure matrices using Dohrman algorithm. Sub Structure.
Implements a matrix divided into substructures. Matrix Sub structure.
static TPZSavable * GetInstance(const int64_t &objId)
std::list< TPZAutoPointer< TSubStruct > > fGlobal
The matrix class is a placeholder for a list of substructures.
Contains the declaration of the VisualMatrix functions to VTK and DX packages.
Contains the TPZDohrAssembleItem and TPZDohrAssembleList structs to assembling using Dohrman algorith...
int fNumThreads
Number of threads used during preconditioning.
Implements a skyline storage format. A Skyline matrix is symmetric so square. Matrix.
TPZAutoPointer< TPZDohrAssembleItem< TVar > > fv2_local
The local contribution to the v2 vector.
#define PZ_PTHREAD_JOIN(thread, val, fn)
Implements a matrix which computes the preconditioner developed by Dohrmann. Sub Structure.
int Zero() override
Makes Zero all the elements.
TPZDohrPrecondV2SubData< TVar, TSubStruct > PopItem()
Interface to pop an item in a thread safe way.
void Push(const T object)
Pushes a copy of the object on the stack.
virtual void Write(const bool val)
void AddItem(TPZAutoPointer< TPZDohrAssembleItem< TVar > > assembleItem)
Add an item to the list in a thread safe way.
To condense matrix divided in sub structures. Sub Structure.
Contains the TPZParallelEnviroment class which store the parallel enviroment variables.
#define LOGPZ_DEBUG(A, B)
Define log for debug info.
TPZAutoPointer< TPZDohrAssembleList< TVar > > fAssemblyStructure
The local contribution to the v2 vector.
TPZAutoPointer< TPZDohrAssembleList< TVar > > fAssemblyStructure
The local contribution to the v2 vector.
void parallel_for(int n, body_t &obj)
Contains the TPZDohrPrecond class which implements a matrix which computes the preconditioner develop...
int64_t Rows() const
Returns number of rows.
List of items to assembling using Dohrmann algorithm.
Contains the TPZDohrSubstructCondense class which condenses matrix divided in sub structures...
double ReturnTimeDouble()
When called, returns the time since the creation of the object in a double.
Contains TPZSkyline class which implements a skyline storage format.
void Read(TPZStream &buf, void *context) override
Unpacks the object structure from a stream of bytes.
Contains the TPZfTime class which calculates times.
Full matrix class. Matrix.
virtual void MultAddTBB(const TPZFMatrix< TVar > &x, const TPZFMatrix< TVar > &y, TPZFMatrix< TVar > &z, const TVar alpha, const TVar beta, const int opt) const
virtual void MultAdd(const TPZFMatrix< TVar > &x, const TPZFMatrix< TVar > &y, TPZFMatrix< TVar > &z, const TVar alpha, const TVar beta, const int opt) const override
The only method any matrix class needs to implement.
Auxiliar structure with thread to compute the preconditioner developed by Dohrmann. Sub Structure.
TPZParallelEnviroment pzenviroment
const SubsList & SubStructures() const
TPZDohrPrecond()
Empty constructor for restoring.
#define PZ_PTHREAD_CREATE(thread, attr, routine, args, fn)
void addWorkItem(TPZDohrPrecondV2SubData< TVar, TSubStruct > data)
Add a new work item to the array.
void Read(TPZStream &buf, void *context) override
Unpacks the object structure from a stream of bytes.
int64_t Cols() const
Returns number of cols.
void Write(TPZStream &buf, int withclassid) const override
Packs the object structure in a stream of bytes.
virtual void Print(std::ostream &out) const
void ComputeV1(const TPZFMatrix< TVar > &x, TPZFMatrix< TVar > &v1) const
Compute the contribution of the coarse matrix.
Defines the interface for saving and reading data. Persistency.
ParallelAssembleTask(TPZAutoPointer< TPZDohrAssembleList< TVar > > assemblyStruct)
Constructor.
TPZStepSolver< TVar > * fCoarse
The global matrix associated with the coarse degrees of freedom.
void Initialize()
Initialize the necessary datastructures.
void ReallocForNuma(int node)
TVar & operator()(const int64_t row, const int64_t col)
The operators check on the bounds if the DEBUG variable is defined.
TPZAutoPointer< TPZDohrAssembly< TVar > > fAssemble
static void WritePointer(const TPZSavable *obj, TPZStream *stream)
TPZAutoPointer< TPZDohrAssembly< TVar > > fAssembly
std::vector< TPZDohrPrecondV2SubData< TVar, TSubStruct > > mWorkItems
Array of work items.
Implements an interface to register a class id and a restore function. Persistence.
Non abstract class which implements full matrices with preallocated storage with (N+1) entries...
virtual void Read(bool &val)
Root matrix class (abstract). Matrix.
This class implements a reference counter mechanism to administer a dynamically allocated object...