Commit 4f99cef1 authored by Thomas Witkowski's avatar Thomas Witkowski
Browse files

Solved some bugs in parallel code.

parent 9420db7e
...@@ -11,6 +11,7 @@ ...@@ -11,6 +11,7 @@
#include "DOFVector.h" #include "DOFVector.h"
#include "DOFIterator.h" #include "DOFIterator.h"
#include "Serializer.h" #include "Serializer.h"
#include "VertexVector.h"
namespace AMDiS { namespace AMDiS {
...@@ -24,6 +25,7 @@ namespace AMDiS { ...@@ -24,6 +25,7 @@ namespace AMDiS {
init(); init();
} }
DOFAdmin::DOFAdmin(Mesh* m, std::string aName) DOFAdmin::DOFAdmin(Mesh* m, std::string aName)
: name(aName), : name(aName),
mesh(m), mesh(m),
...@@ -33,9 +35,11 @@ namespace AMDiS { ...@@ -33,9 +35,11 @@ namespace AMDiS {
init(); init();
} }
DOFAdmin::~DOFAdmin() DOFAdmin::~DOFAdmin()
{} {}
void DOFAdmin::init() void DOFAdmin::init()
{ {
firstHole = 0; firstHole = 0;
...@@ -46,6 +50,7 @@ namespace AMDiS { ...@@ -46,6 +50,7 @@ namespace AMDiS {
dofFree.clear(); dofFree.clear();
} }
DOFAdmin& DOFAdmin::operator=(const DOFAdmin& src) DOFAdmin& DOFAdmin::operator=(const DOFAdmin& src)
{ {
if (this != &src) { if (this != &src) {
...@@ -67,10 +72,7 @@ namespace AMDiS { ...@@ -67,10 +72,7 @@ namespace AMDiS {
return *this; return *this;
} }
/****************************************************************************/
/* use a bit vector to indicate used/unused dofs */
/* storage needed: one bit per dof */
/****************************************************************************/
bool DOFAdmin::operator==(const DOFAdmin& ad) const bool DOFAdmin::operator==(const DOFAdmin& ad) const
{ {
...@@ -90,9 +92,10 @@ namespace AMDiS { ...@@ -90,9 +92,10 @@ namespace AMDiS {
ERROR_EXIT("TODO\n"); ERROR_EXIT("TODO\n");
} }
void DOFAdmin::freeDOFIndex(int dof)
void DOFAdmin::freeDofIndex(int dof)
{ {
FUNCNAME("DOFAdmin::freeDOFIndex()"); FUNCNAME("DOFAdmin::freeDofIndex()");
TEST_EXIT_DBG(usedCount > 0)("no dofs in use\n"); TEST_EXIT_DBG(usedCount > 0)("no dofs in use\n");
TEST_EXIT_DBG((dof >= 0) && (dof < size))("invalid dof index %d\n",dof); TEST_EXIT_DBG((dof >= 0) && (dof < size))("invalid dof index %d\n",dof);
...@@ -107,7 +110,7 @@ namespace AMDiS { ...@@ -107,7 +110,7 @@ namespace AMDiS {
std::list<DOFContainer*>::iterator dcend = dofContainerList.end(); std::list<DOFContainer*>::iterator dcend = dofContainerList.end();
for (dc = dofContainerList.begin(); dc != dcend; ++dc) for (dc = dofContainerList.begin(); dc != dcend; ++dc)
(*dc)->freeDOFIndex(dof); (*dc)->freeDofIndex(dof);
dofFree[dof] = true; dofFree[dof] = true;
...@@ -118,6 +121,7 @@ namespace AMDiS { ...@@ -118,6 +121,7 @@ namespace AMDiS {
holeCount++; holeCount++;
} }
int DOFAdmin::getDOFIndex() int DOFAdmin::getDOFIndex()
{ {
FUNCNAME("DOFAdmin::getDOFIndex()"); FUNCNAME("DOFAdmin::getDOFIndex()");
...@@ -157,6 +161,7 @@ namespace AMDiS { ...@@ -157,6 +161,7 @@ namespace AMDiS {
return dof; return dof;
} }
void DOFAdmin::enlargeDOFLists(int minsize) void DOFAdmin::enlargeDOFLists(int minsize)
{ {
FUNCNAME("DOFAdmin::enlargeDOFLists()"); FUNCNAME("DOFAdmin::enlargeDOFLists()");
...@@ -184,6 +189,7 @@ namespace AMDiS { ...@@ -184,6 +189,7 @@ namespace AMDiS {
(*di)->resize(newval); (*di)->resize(newval);
} }
void DOFAdmin::addDOFIndexed(DOFIndexedBase* dofIndexed) void DOFAdmin::addDOFIndexed(DOFIndexedBase* dofIndexed)
{ {
FUNCNAME("DOFAdmin::addDOFIndexed()"); FUNCNAME("DOFAdmin::addDOFIndexed()");
...@@ -201,6 +207,7 @@ namespace AMDiS { ...@@ -201,6 +207,7 @@ namespace AMDiS {
} }
} }
void DOFAdmin::removeDOFIndexed(DOFIndexedBase* dofIndexed) void DOFAdmin::removeDOFIndexed(DOFIndexedBase* dofIndexed)
{ {
FUNCNAME("DOFAdmin::removeDOFIndexed()"); FUNCNAME("DOFAdmin::removeDOFIndexed()");
...@@ -221,16 +228,20 @@ namespace AMDiS { ...@@ -221,16 +228,20 @@ namespace AMDiS {
} }
} }
TEST_EXIT(removed)("DOFIndexed not in list\n"); TEST_EXIT(removed)("DOFIndexed not in list!\n");
} }
void DOFAdmin::addDOFContainer(DOFContainer* cont) void DOFAdmin::addDOFContainer(DOFContainer* cont)
{ {
FUNCNAME("DOFAdmin::addDOFContainer()"); FUNCNAME("DOFAdmin::addDOFContainer()");
TEST_EXIT_DBG(cont)("no container\n"); TEST_EXIT_DBG(cont)("no container\n");
dofContainerList.push_back(cont); dofContainerList.push_back(cont);
} }
void DOFAdmin::removeDOFContainer(DOFContainer* cont) void DOFAdmin::removeDOFContainer(DOFContainer* cont)
{ {
FUNCNAME("DOFAdmin::removeDOFContainer()"); FUNCNAME("DOFAdmin::removeDOFContainer()");
...@@ -243,7 +254,8 @@ namespace AMDiS { ...@@ -243,7 +254,8 @@ namespace AMDiS {
return; return;
} }
} }
ERROR("container not in list\n");
ERROR("Container not in list!\n");
} }
...@@ -262,7 +274,7 @@ namespace AMDiS { ...@@ -262,7 +274,7 @@ namespace AMDiS {
// mark used dofs // mark used dofs
DOFIteratorBase it(this, USED_DOFS); DOFIteratorBase it(this, USED_DOFS);
for (it.reset(); !it.end(); ++it) for (it.reset(); !it.end(); ++it)
new_dof[it.getDOFIndex()] = 1; new_dof[it.getDOFIndex()] = 1;
int n = 0, last = 0; int n = 0, last = 0;
for (int i = 0; i < size; i++) { /* create a MONOTONE compress */ for (int i = 0; i < size; i++) { /* create a MONOTONE compress */
...@@ -288,7 +300,7 @@ namespace AMDiS { ...@@ -288,7 +300,7 @@ namespace AMDiS {
// get index of first changed dof // get index of first changed dof
int first = last; int first = last;
for (int i = 0; i<size; i++) { for (int i = 0; i < size; i++) {
if (new_dof[i] < i && new_dof[i] >= 0) { if (new_dof[i] < i && new_dof[i] >= 0) {
first = i; first = i;
break; break;
...@@ -303,8 +315,8 @@ namespace AMDiS { ...@@ -303,8 +315,8 @@ namespace AMDiS {
std::list<DOFContainer*>::iterator dc; std::list<DOFContainer*>::iterator dc;
std::list<DOFContainer*>::iterator endc = dofContainerList.end(); std::list<DOFContainer*>::iterator endc = dofContainerList.end();
for (dc = dofContainerList.begin(); dc != endc; dc++) for (dc = dofContainerList.begin(); dc != endc; ++dc)
(*dc)->compressDOFContainer(n, new_dof); (*dc)->compressDofContainer(n, new_dof);
} }
...@@ -317,6 +329,7 @@ namespace AMDiS { ...@@ -317,6 +329,7 @@ namespace AMDiS {
nrDOF[i] = v; nrDOF[i] = v;
} }
void DOFAdmin::setNumberOfPreDOFs(int i, int v) void DOFAdmin::setNumberOfPreDOFs(int i, int v)
{ {
FUNCNAME("DOFAdmin::setNumberOfPreDOFs()"); FUNCNAME("DOFAdmin::setNumberOfPreDOFs()");
...@@ -326,11 +339,13 @@ namespace AMDiS { ...@@ -326,11 +339,13 @@ namespace AMDiS {
nr0DOF[i] = v; nr0DOF[i] = v;
} }
int DOFAdmin::calcMemoryUsage() int DOFAdmin::calcMemoryUsage()
{ {
return sizeof(DOFAdmin); return sizeof(DOFAdmin);
} }
void DOFAdmin::serialize(std::ostream &out) void DOFAdmin::serialize(std::ostream &out)
{ {
// write name // write name
...@@ -352,7 +367,8 @@ namespace AMDiS { ...@@ -352,7 +367,8 @@ namespace AMDiS {
nrDOF.serialize(out); nrDOF.serialize(out);
nr0DOF.serialize(out); nr0DOF.serialize(out);
} }
void DOFAdmin::deserialize(std::istream &in) void DOFAdmin::deserialize(std::istream &in)
{ {
......
...@@ -95,6 +95,11 @@ namespace AMDiS { ...@@ -95,6 +95,11 @@ namespace AMDiS {
/// Removes the given DOFContainer object from DOFAdmin. /// Removes the given DOFContainer object from DOFAdmin.
void removeDOFContainer(DOFContainer* dofContainer); void removeDOFContainer(DOFContainer* dofContainer);
std::list<DOFContainer*>& getDCL()
{
return dofContainerList;
}
/** \brief /** \brief
* Removes all holes of unused DOF indices by compressing the used range of * Removes all holes of unused DOF indices by compressing the used range of
* indices (it does not resize the vectors). While the global index of a DOF * indices (it does not resize the vectors). While the global index of a DOF
...@@ -257,7 +262,7 @@ namespace AMDiS { ...@@ -257,7 +262,7 @@ namespace AMDiS {
int getDOFIndex(); int getDOFIndex();
/// Frees index dof. Used by Mesh::getDOF() /// Frees index dof. Used by Mesh::getDOF()
void freeDOFIndex(int dof); void freeDofIndex(int dof);
/// ///
void serialize(std::ostream &out); void serialize(std::ostream &out);
......
...@@ -44,22 +44,25 @@ namespace AMDiS { ...@@ -44,22 +44,25 @@ namespace AMDiS {
*/ */
virtual DegreeOfFreedom& operator[](int i) = 0; virtual DegreeOfFreedom& operator[](int i) = 0;
virtual void freeDOFIndex(DegreeOfFreedom dof) {} virtual void freeDofIndex(DegreeOfFreedom dof) {}
/** \brief /** \brief
* Used by DOFAdmin to actualize the DOF indices in this container after * Used by DOFAdmin to actualize the DOF indices in this container after
* DOF compression. * DOF compression.
*/ */
virtual void compressDOFContainer(int size, std::vector<DegreeOfFreedom> &newDOF) virtual void compressDofContainer(int size, std::vector<DegreeOfFreedom> &newDOF)
{ {
FUNCNAME("DOFContainer::compressDofContainer()");
for (int i = 0; i < size; i++) { for (int i = 0; i < size; i++) {
int j = newDOF[operator[](i)]; int j = newDOF[operator[](i)];
if (j >= 0) if (j >= 0)
operator[](i) = j; operator[](i) = j;
else else
ERROR_EXIT("invalid dof in dof container\n"); ERROR_EXIT("Invalid DOF %d in DOF container! (%d %d)\n", j, i, operator[](i));
} }
} }
}; };
} }
......
...@@ -447,7 +447,7 @@ namespace AMDiS { ...@@ -447,7 +447,7 @@ namespace AMDiS {
{ {
FUNCNAME("DOFVector<T>::operator[]"); FUNCNAME("DOFVector<T>::operator[]");
TEST_EXIT_DBG(i >= 0 && i < static_cast<int>(vec.size())) TEST_EXIT_DBG(i >= 0 && i < static_cast<int>(vec.size()))
("Illegal vector index %d.\n",i); ("Illegal vector index %d.\n", i);
return vec[i]; return vec[i];
} }
...@@ -457,7 +457,7 @@ namespace AMDiS { ...@@ -457,7 +457,7 @@ namespace AMDiS {
FUNCNAME("DOFVector<T>::operator[]"); FUNCNAME("DOFVector<T>::operator[]");
TEST_EXIT_DBG(i >= 0 && i < static_cast<int>(vec.size())) TEST_EXIT_DBG(i >= 0 && i < static_cast<int>(vec.size()))
("Illegal vector index %d.\n",i); ("Illegal vector index %d.\n", i);
return vec[i]; return vec[i];
} }
...@@ -639,7 +639,7 @@ namespace AMDiS { ...@@ -639,7 +639,7 @@ namespace AMDiS {
/** \brief /** \brief
* Implements DOFContainer::operator[]() by calling * Implements DOFContainer::operator[]() by calling
* DOFVEctor<DegreeOfFreedom>::operator[]() * DOFVector<DegreeOfFreedom>::operator[]()
*/ */
DegreeOfFreedom& operator[](DegreeOfFreedom i) DegreeOfFreedom& operator[](DegreeOfFreedom i)
{ {
......
...@@ -191,7 +191,6 @@ namespace AMDiS { ...@@ -191,7 +191,6 @@ namespace AMDiS {
} }
return NULL; return NULL;
} }
...@@ -486,6 +485,32 @@ namespace AMDiS { ...@@ -486,6 +485,32 @@ namespace AMDiS {
} }
void printElementRefinementSequenz(Mesh *mesh, Element *el)
{
FUNCNAME("printElementRefinementSequenz()");
int elIndex = el->getIndex();
std::vector<int> refSeq;
Element *parent = getParentElement(mesh, el);
while (parent) {
if (parent->getChild(0) == el)
refSeq.push_back(0);
else
refSeq.push_back(1);
el = parent;
parent = getParentElement(mesh, el);
}
std::stringstream oss;
for (int i = refSeq.size() - 1; i >= 0; i--)
oss << refSeq[i];
MSG("Ref-Seq for element %d: %s\n", elIndex, oss.str().c_str());
}
int getLocalNeighbourIndex(Mesh *mesh, int elIndex, int neighIndex) int getLocalNeighbourIndex(Mesh *mesh, int elIndex, int neighIndex)
{ {
FUNCNAME("debug::getLocalNeighbourIndex()"); FUNCNAME("debug::getLocalNeighbourIndex()");
......
...@@ -137,6 +137,8 @@ namespace AMDiS { ...@@ -137,6 +137,8 @@ namespace AMDiS {
void printElementHierarchie(Mesh *mesh, int elIndex); void printElementHierarchie(Mesh *mesh, int elIndex);
void printElementRefinementSequenz(Mesh *mesh, Element *el);
int getLocalNeighbourIndex(Mesh *mesh, int elIndex, int neighIndex); int getLocalNeighbourIndex(Mesh *mesh, int elIndex, int neighIndex);
/** \brief /** \brief
......
...@@ -590,7 +590,7 @@ namespace AMDiS { ...@@ -590,7 +590,7 @@ namespace AMDiS {
TEST_EXIT_DBG(n + n0 <= ndof)("n=%d, n0=%d too large: ndof=%d\n", n, n0, ndof); TEST_EXIT_DBG(n + n0 <= ndof)("n=%d, n0=%d too large: ndof=%d\n", n, n0, ndof);
for (int j = 0; j < n; j++) for (int j = 0; j < n; j++)
localAdmin->freeDOFIndex(dof[n0 + j]); localAdmin->freeDofIndex(dof[n0 + j]);
} }
delete [] dof; delete [] dof;
......
...@@ -51,7 +51,7 @@ namespace AMDiS { ...@@ -51,7 +51,7 @@ namespace AMDiS {
// === Get the refinement patch. === // === Get the refinement patch. ===
getRefinePatch(&elInfo, edge, 0, refineList, &n_neigh); getRefinePatch(&elInfo, edge, 0, refineList, &n_neigh);
// === Check for periodic boundary === // === Check for periodic boundary ===
......
...@@ -740,6 +740,7 @@ namespace AMDiS { ...@@ -740,6 +740,7 @@ namespace AMDiS {
/* first, goto to leaf level, if necessary... */ /* first, goto to leaf level, if necessary... */
if (!(el->isLeaf()) && neighbour < 2) { if (!(el->isLeaf()) && neighbour < 2) {
if (stack_used >= static_cast<int>(elinfo_stack.size()) - 1) if (stack_used >= static_cast<int>(elinfo_stack.size()) - 1)
enlargeTraverseStack(); enlargeTraverseStack();
...@@ -780,6 +781,7 @@ namespace AMDiS { ...@@ -780,6 +781,7 @@ namespace AMDiS {
while (stack_used > 1) { while (stack_used > 1) {
stack_used--; stack_used--;
int elIsIthChild = info_stack[stack_used]; int elIsIthChild = info_stack[stack_used];
if (traverse_fill_flag.isSet(Mesh::CALL_REVERSE_MODE) && elIsIthChild != 0) if (traverse_fill_flag.isSet(Mesh::CALL_REVERSE_MODE) && elIsIthChild != 0)
elIsIthChild = (elIsIthChild == 1 ? 2 : 1); elIsIthChild = (elIsIthChild == 1 ? 2 : 1);
...@@ -790,8 +792,8 @@ namespace AMDiS { ...@@ -790,8 +792,8 @@ namespace AMDiS {
nb = coarse_nb[elIsIthChild][nb]; nb = coarse_nb[elIsIthChild][nb];
if (nb == -1) if (nb == -1)
break; break;
TEST_EXIT_DBG(nb >= 0)("invalid coarse_nb %d\n",nb); TEST_EXIT_DBG(nb >= 0)("invalid coarse_nb %d\n",nb);
} }
...@@ -818,7 +820,7 @@ namespace AMDiS { ...@@ -818,7 +820,7 @@ namespace AMDiS {
if (traverse_mel == NULL) if (traverse_mel == NULL)
return NULL; return NULL;
nb = i; nb = i;
stack_used = 1; stack_used = 1;
elinfo_stack[stack_used]->fillMacroInfo(const_cast<MacroElement*>(traverse_mel)); elinfo_stack[stack_used]->fillMacroInfo(const_cast<MacroElement*>(traverse_mel));
info_stack[stack_used] = 0; info_stack[stack_used] = 0;
...@@ -834,15 +836,27 @@ namespace AMDiS { ...@@ -834,15 +836,27 @@ namespace AMDiS {
if (stack_used >= stack_size - 1) if (stack_used >= stack_size - 1)
enlargeTraverseStack(); enlargeTraverseStack();
int i = 2 - info_stack[stack_used]; TEST_EXIT_DBG(info_stack[stack_used] == 1 || info_stack[stack_used] == 2)
info_stack[stack_used] = i + 1; ("Should not happen!\n");
int fillIthChild = i;
if (traverse_fill_flag.isSet(Mesh::CALL_REVERSE_MODE)) int fillIthChild = -1;
if (info_stack[stack_used] == 1) {
info_stack[stack_used] = 2;
fillIthChild = 1;
nb = 0;
} else {
info_stack[stack_used] = 1;
fillIthChild = 0;
nb = 1;
}
if (traverse_fill_flag.isSet(Mesh::CALL_REVERSE_MODE)) {
fillIthChild = 1 - fillIthChild; fillIthChild = 1 - fillIthChild;
nb = 1 - nb;
}
elinfo_stack[stack_used + 1]->fillElInfo(fillIthChild, elinfo_stack[stack_used]); elinfo_stack[stack_used + 1]->fillElInfo(fillIthChild, elinfo_stack[stack_used]);
stack_used++; stack_used++;
nb = 1 - i;
} }
/****************************************************************************/ /****************************************************************************/
...@@ -861,12 +875,16 @@ namespace AMDiS { ...@@ -861,12 +875,16 @@ namespace AMDiS {
if (stack_used >= stack_size - 1) if (stack_used >= stack_size - 1)
enlargeTraverseStack(); enlargeTraverseStack();
if (traverse_fill_flag.isSet(Mesh::CALL_REVERSE_MODE)) {
int t = 2 - nb;
info_stack[stack_used] = (t == 2 ? 1 : 2);
} else {
info_stack[stack_used] = 2 - nb;
}
int fillIthChild = 1 - nb; int fillIthChild = 1 - nb;
if (traverse_fill_flag.isSet(Mesh::CALL_REVERSE_MODE))
fillIthChild = 1 - fillIthChild;
elinfo_stack[stack_used + 1]->fillElInfo(fillIthChild, elinfo_stack[stack_used]); elinfo_stack[stack_used + 1]->fillElInfo(fillIthChild, elinfo_stack[stack_used]);
info_stack[stack_used] = 2 - nb;
stack_used++; stack_used++;
nb = 2; nb = 2;
} }
...@@ -882,12 +900,16 @@ namespace AMDiS { ...@@ -882,12 +900,16 @@ namespace AMDiS {
info_stack[stack_used] = i + 1; info_stack[stack_used] = i + 1;
int fillIthChild = i; int fillIthChild = i;
if (traverse_fill_flag.isSet(Mesh::CALL_REVERSE_MODE)) nb = i;