NeoPZ
tpzdohrassemblelist.cpp
Go to the documentation of this file.
1 
6 #include "tpzdohrassemblelist.h"
7 
8 #include "pz_pthread.h"
9 
10 template<class TVar>
12 fAssembleIndexes(assembly), fOutput(&output)
13 {
14  PZ_PTHREAD_MUTEX_INIT(&fAssemblyLock, 0, "TPZDohrAssembleList::TPZDohrAssembleList");
15  PZ_PTHREAD_MUTEX_INIT(&fListAccessLock, 0, "TPZDohrAssembleList::TPZDohrAssembleList");
16 }
17 
18 template<class TVar>
20 {
21  PZ_PTHREAD_MUTEX_DESTROY(&fAssemblyLock, "TPZDohrAssembleList::TPZDohrAssembleList");
22  PZ_PTHREAD_MUTEX_DESTROY(&fListAccessLock, "TPZDohrAssembleList::TPZDohrAssembleList");
23 }
24 
25 // Add an item to the list in a thread safe way
26 template<class TVar>
28 {
29  PZ_PTHREAD_MUTEX_LOCK(&fListAccessLock,"TPZDohrAssembleList::AddItem()");
30  fWork.push_back(assembleItem);
31  fSemaphore.Post();
32  PZ_PTHREAD_MUTEX_UNLOCK(&fListAccessLock,"TPZDohrAssembleList::AddItem()");
33 }
34 // remove an item from the list
35 template<class TVar>
37 {
39  PZ_PTHREAD_MUTEX_LOCK(&fListAccessLock,"TPZDohrAssembleList::PopItem()");
40  if (fWork.begin() != fWork.end()) {
41  fNumItems--;
42  result = *fWork.begin();
43  fWork.pop_front();
44  }
45  PZ_PTHREAD_MUTEX_UNLOCK(&fListAccessLock,"TPZDohrAssembleList::PopItem()");
46  return result;
47 }
48 
49 template<class TVar>
51 {
52  TPZDohrAssembleList *myptr = (TPZDohrAssembleList *) voidptr;
53  while (myptr->fNumItems > 0) {
55  if (work) {
56  PZ_PTHREAD_MUTEX_LOCK(&myptr->fAssemblyLock,"TPZDohrAssembleList::Assemble()");
57  myptr->fAssembleIndexes->Assemble(work->fSubIndex,work->fAssembleData,*(myptr->fOutput));
58  PZ_PTHREAD_MUTEX_UNLOCK(&myptr->fAssemblyLock,"TPZDohrAssembleList::Assemble()");
59  }
60  else {
61  // wait for a signal
62  myptr->fSemaphore.Wait();
63  }
64  }
65  return voidptr;
66 }
67 
68 template struct TPZDohrAssembleList<float>;
69 template struct TPZDohrAssembleList<double>;
70 template struct TPZDohrAssembleList<long double>;
71 
#define PZ_PTHREAD_MUTEX_UNLOCK(mutex, fn)
Definition: pz_pthread.h:79
Assembling using Dohrmann algorithm. Sub structure.
TPZAutoPointer< TPZDohrAssembly< TVar > > fAssembleIndexes
Assembly indexes.
std::list< TPZAutoPointer< TPZDohrAssembleItem< TVar > > > fWork
List of objects needed to be assembled.
Contains the TPZDohrAssembleItem and TPZDohrAssembleList structs to assembling using Dohrman algorith...
TPZDohrAssembleList(int numitems, TPZFMatrix< TVar > &output, TPZAutoPointer< TPZDohrAssembly< TVar > > assembly)
Constructor indicating the number of items that will be assembled and the target matrix.
#define PZ_PTHREAD_MUTEX_LOCK(mutex, fn)
Definition: pz_pthread.h:76
void AddItem(TPZAutoPointer< TPZDohrAssembleItem< TVar > > assembleItem)
Add an item to the list in a thread safe way.
static void * Assemble(void *voidptr)
Procedure which performs the assembly process.
TPZSemaphore fSemaphore
Semaphore (to wake up assembly thread)
To assembling one item using Dohrmann algorithm. Sub structure.
List of items to assembling using Dohrmann algorithm.
#define PZ_PTHREAD_MUTEX_DESTROY(mutex, fn)
Definition: pz_pthread.h:73
Full matrix class. Matrix.
Definition: pzfmatrix.h:32
TPZAutoPointer< TPZDohrAssembleItem< TVar > > PopItem()
Remove an item from the list.
~TPZDohrAssembleList()
destructor
int fNumItems
The number of items that will be assembled before returning.
pthread_mutex_t fAssemblyLock
This is the mutex which controls the assembly.
TPZFMatrix< TVar > * fOutput
Target Matrix.
pthread_mutex_t fListAccessLock
This is the mutex which controls the access to the list.
#define PZ_PTHREAD_MUTEX_INIT(mutex, attr, fn)
Definition: pz_pthread.h:70
This class implements a reference counter mechanism to administer a dynamically allocated object...