19 static LoggerPtr logger(Logger::getLogger(
"substruct.dohrsubstruct"));
23 template<
class TVar,
class TSubStruct>
25 :
TPZMatrix<TVar>(), fNumThreads(0), fAssembly(assembly)
29 template<
class TVar,
class TSubStruct>
37 #include <tbb/parallel_for.h> 38 #include <tbb/blocked_range.h> 39 #include <tbb/partitioner.h> 45 template<
class TVar,
class TSubStruct>
50 std::vector<TPZDohrThreadMultData<TSubStruct> >
mWorkItems;
61 std::list<TPZDohrThreadMultData<TSubStruct> >
fWork;
74 mWorkItems.push_back(data);
79 void operator()(
const blocked_range<size_t>& range)
const 82 for(
size_t i=range.begin(); i!=range.end(); ++i )
86 fAssembly->Extract(runner.
fisub,*(fInput),xlocal);
88 runner.
fSub->ContributeKULocal(fAlpha,xlocal,assembleItem->fAssembleData);
89 fAssemblyStructure->AddItem(assembleItem);
94 void run_parallel_for(affinity_partitioner &ap)
100 parallel_for(blocked_range<size_t>(0, mWorkItems.size()), *
this, ap);
107 template<
class TVar,
class TSubStruct>
109 const TVar alpha,
const TVar beta,
const int opt)
const 115 this->
Error(
"Operator* <matrixs with incompatible dimensions>" );
117 this->
Error (
"TPZFMatrix::MultiplyAdd incompatible dimensions\n");
122 unsigned int nglob =
fGlobal.size();
126 typename std::list<TPZAutoPointer<TSubStruct> >::const_iterator iter;
131 multwork.addWorkItem(data);
135 multwork.run_parallel_for(
pzenviroment.fSubstructurePartitioner);
138 assemblelist.operator->(), __FUNCTION__);
147 template<
class TVar,
class TSubStruct>
149 const TVar alpha,
const TVar beta,
const int opt)
const 159 this->
Error(
"Operator* <matrixs with incompatible dimensions>" );
161 this->
Error (
"TPZFMatrix::MultiplyAdd incompatible dimensions\n");
165 typename SubsList::const_iterator iter;
182 (*iter)->ContributeKULocal(alpha,xlocal,zlocal);
188 unsigned int nglob =
fGlobal.size();
192 typename std::list<TPZAutoPointer<TSubStruct> >::const_iterator iter;
203 &multwork, __FUNCTION__);
207 assemblelist.operator->(), __FUNCTION__);
209 for (i=0; i<fNumThreads+1; i++) {
217 template<
class TVar,
class TSubStruct>
220 std::cout <<
"Number of substructures " <<
fGlobal.size() << std::endl;
223 typename SubsList::iterator iter;
229 (*iter)->ContributeDiagonalLocal(diaglocal);
231 this->
fAssembly->Assemble(isub,diaglocal,diag);
234 std::stringstream sout;
235 sout <<
"Substructure " << isub <<
" ";
236 diag.
Print(
"Global Diagonal matrix",sout);
245 std::stringstream sout;
246 diag.
Print(
"Global Diagonal matrix",sout);
250 std::cout << std::endl;
251 for (iter=
fGlobal.begin(),isub=0;iter!=
fGlobal.end();iter++,isub++) {
254 this->
fAssembly->Extract(isub,diag,diaglocal);
255 (*iter)->ComputeWeightsLocal(diaglocal);
263 template<
class TVar,
class TSubStruct>
266 typename SubsList::iterator iter;
268 (*iter)->AdjustResidual(res);
275 template<
class TVar,
class TSubStruct>
278 typename SubsList::iterator iter;
280 (*iter)->AddInternalSolution(solution);
284 template<
class TVar,
class TSubStruct>
293 runner.
fSub->ContributeKULocal(myptr->
fAlpha,xlocal,assembleItem->fAssembleData);
305 template <
class TVar,
class TSubStruct>
319 for (
int i=0; i<sz; i++) {
337 template <
class TVar,
class TSubStruct>
358 buf.
Write(&classid );
void AdjustResidual(TPZFMatrix< TVar > &res)
Adjust the residual to zero the residual of the internal connects.
const TPZFMatrix< TVar > * fInput
The vector with which we will multiply.
Assembling using Dohrmann algorithm. Sub structure.
Contains the TPZTimeTemp class which takes times.
static void OpenWrite(const std::string &fileName, streamType=binary)
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.
int fNumSub
Number of Substructures.
void Write(TPZStream &buf, int withclassid) const override
Packs the object structure in a stream of bytes.
std::vector< TPZDohrThreadMultData< TSubStruct > > mWorkItems
Array of work items.
std::list< TPZDohrThreadMultData< TSubStruct > > fWork
The list of data objects which need to treated by the threads.
TPZTimeTemp tempo
External variable to TPZTimeTemp (to take time)
static int Error(const char *msg, const char *msg2=0)
Returns error messages.
Calculate the Times. Utility.
Contains the TPZDohrMatrix class which implements a matrix divided into substructures. Also contains the TPZDohrThreadMultData and TPZDohrThreadMultList structs.
void Read(TPZStream &buf, void *context) override
Unpacks the object structure from a stream of bytes.
void PrepareZ(const TPZFMatrix< TVar > &y, TPZFMatrix< TVar > &z, const TVar beta, const int opt) const
Is an auxiliar method used by MultiplyAdd.
TPZAutoPointer< TPZDohrAssembleList< TVar > > fAssemblyStructure
The local contribution to the v2 vector.
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.
Contains the TPZDohrAssembly class which implements assembling using Dohrmann algorithm.
virtual void MultAddTBB(const TPZFMatrix< TVar > &x, const TPZFMatrix< TVar > &y, TPZFMatrix< TVar > &z, const TVar alpha, const TVar beta, const int opt) const
It computes z = beta * y + alpha * opt(this)*x but z and x can not overlap in memory.
TVar fAlpha
Scalar multiplication factor.
pthread_mutex_t fAccessLock
Mutex which will enable the access protection of the list.
#define PZ_PTHREAD_JOIN(thread, val, fn)
static TPZAutoPointer< TPZSavable > GetAutoPointer(const int64_t &objId)
TVar fAlpha
Scalar multiplication factor.
ParallelAssembleTaskMatrix(const TPZFMatrix< TVar > &x, TVar alpha, TPZAutoPointer< TPZDohrAssembly< TVar > > assembly, TPZAutoPointer< TPZDohrAssembleList< TVar > > &assemblestruct)
Constructor.
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.
#define DebugStop()
Returns a message to user put a breakpoint in.
int fNumThreads
Number of threads that will be used during the matrix vector multiplication.
Contains the TPZParallelEnviroment class which store the parallel enviroment variables.
#define LOGPZ_DEBUG(A, B)
Define log for debug info.
void parallel_for(int n, body_t &obj)
To assembling one item using Dohrmann algorithm. Sub structure.
int64_t Rows() const
Returns number of rows.
List of items to assembling using Dohrmann algorithm.
double ReturnTimeDouble()
When called, returns the time since the creation of the object in a double.
void Read(TPZStream &buf, void *context) override
Unpacks the object structure from a stream of bytes.
TPZAutoPointer< TPZDohrAssembly< TVar > > fAssembly
The data structure which defines the assemble destinations.
void AddInternalSolution(TPZFMatrix< TVar > &solution)
Add the solution corresponding to the internal residual.
Contains the TPZfTime class which calculates times.
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
TPZStack< REAL > fMultiply
Time to Multiply for each iteration.
Full matrix class. Matrix.
int Redim(const int64_t newRows, const int64_t newCols) override
Redimension a matrix and ZERO your elements.
const TPZFMatrix< TVar > * fInput
The vector with which we will multiply.
static void WriteToFile(const TPZSavable *)
TPZDohrThreadMultData< TSubStruct > PopItem()
Interface to pop an item in a thread safe way.
TPZAutoPointer< TSubStruct > fSub
TPZParallelEnviroment pzenviroment
#define PZ_PTHREAD_CREATE(thread, attr, routine, args, fn)
void Write(TPZStream &buf, int withclassid) const override
Packs the object structure in a stream of bytes.
int64_t Cols() const
Returns number of cols.
int ClassId() const override
Routines to send and receive messages.
virtual void Print(std::ostream &out) const
Defines the interface for saving and reading data. Persistency.
void Initialize()
Initialize the necessary datastructures.
#define SAVEABLE_STR_NOTE(buf, str)
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 > > fAssembly
The data structure which defines the assemble destinations.
TPZAutoPointer< TPZDohrAssembleList< TVar > > fAssemblyStructure
The local contribution to the v2 vector.
static void * ThreadWork(void *voidptr)
The procedure which executes the lengthy process.
static void WritePointer(const TPZSavable *obj, TPZStream *stream)
void addWorkItem(TPZDohrThreadMultData< TSubStruct > data)
Add a new work item to the array.
TPZAutoPointer< TPZDohrAssembly< TVar > > fAssembly
Implements an interface to register a class id and a restore function. Persistence.
#define SAVEABLE_SKIP_NOTE(buf)
virtual void Read(bool &val)
Root matrix class (abstract). Matrix.
This class implements a reference counter mechanism to administer a dynamically allocated object...