From 373227829192108d6ae3b66f1cec4dc415645e66 Mon Sep 17 00:00:00 2001
From: Thomas Witkowski <thomas.witkowski@gmx.de>
Date: Mon, 7 Jul 2008 08:26:52 +0000
Subject: [PATCH] * OpenMP bug fix

---
 AMDiS/src/ElInfo3d.cc   | 16 +++++++---------
 AMDiS/src/ElInfo3d.h    |  9 ++-------
 AMDiS/src/ProblemVec.cc | 11 ++++++-----
 AMDiS/src/Traverse.cc   | 19 +++++++++----------
 4 files changed, 24 insertions(+), 31 deletions(-)

diff --git a/AMDiS/src/ElInfo3d.cc b/AMDiS/src/ElInfo3d.cc
index 1d2b4d56..8865b711 100644
--- a/AMDiS/src/ElInfo3d.cc
+++ b/AMDiS/src/ElInfo3d.cc
@@ -114,12 +114,10 @@ namespace AMDiS {
     TEST_EXIT_DBG(dimOfWorld == 3)
       ("dim != dim_of_world ! use parametric elements!\n");
 
-    int myRank = omp_get_thread_num();
-
-    WorldVector<double> *e1 = &tmpWorldVecs[myRank][0];
-    WorldVector<double> *e2 = &tmpWorldVecs[myRank][1];
-    WorldVector<double> *e3 = &tmpWorldVecs[myRank][2];
-    WorldVector<double> *v0 = &tmpWorldVecs[myRank][3];
+    WorldVector<double> *e1 = &tmpWorldVecs[0];
+    WorldVector<double> *e2 = &tmpWorldVecs[1];
+    WorldVector<double> *e3 = &tmpWorldVecs[2];
+    WorldVector<double> *v0 = &tmpWorldVecs[3];
 
     double det, adet;
     double a11, a12, a13, a21, a22, a23, a31, a32, a33;
@@ -318,9 +316,9 @@ namespace AMDiS {
 
     int myRank = omp_get_thread_num();
 
-    WorldVector<double> *e0 = &tmpWorldVecs[myRank][0];
-    WorldVector<double> *e1 = &tmpWorldVecs[myRank][1];
-    WorldVector<double> *e2 = &tmpWorldVecs[myRank][2];
+    WorldVector<double> *e0 = &tmpWorldVecs[0];
+    WorldVector<double> *e1 = &tmpWorldVecs[1];
+    WorldVector<double> *e2 = &tmpWorldVecs[2];
 
     if (dimOfWorld == 3) {
       int i0 = (face + 1) % 4;
diff --git a/AMDiS/src/ElInfo3d.h b/AMDiS/src/ElInfo3d.h
index 6d5f82a4..de133f5a 100644
--- a/AMDiS/src/ElInfo3d.h
+++ b/AMDiS/src/ElInfo3d.h
@@ -48,11 +48,7 @@ namespace AMDiS {
     ElInfo3d(Mesh* aMesh) 
       : ElInfo(aMesh) 
     {
-      tmpWorldVecs.resize(omp_get_max_threads());
-
-      for (int i = 0; i < static_cast<int>(tmpWorldVecs.size()); i++) {
-	tmpWorldVecs[i].resize(4);
-      }
+      tmpWorldVecs.resize(4);
     };
 
     /** \brief
@@ -138,9 +134,8 @@ namespace AMDiS {
 
     /** \brief
      * Tmp vectors used for calculations in calcGrdLambda and getNormal().
-     * Thread safe!
      */
-    ::std::vector< ::std::vector< WorldVector<double> > > tmpWorldVecs;
+    ::std::vector< WorldVector<double> > tmpWorldVecs;
   };
 
 }
diff --git a/AMDiS/src/ProblemVec.cc b/AMDiS/src/ProblemVec.cc
index 7c6a4942..7434c9ad 100644
--- a/AMDiS/src/ProblemVec.cc
+++ b/AMDiS/src/ProblemVec.cc
@@ -736,7 +736,7 @@ namespace AMDiS {
 	  if (useGetBound_) {
 	    bound = GET_MEMORY(BoundaryType, componentSpaces_[i]->getBasisFcts()->getNumber());
 	  }
-
+	  
 	  TraverseStack stack;
 	  ElInfo *elInfo = stack.traverseFirst(componentMeshes_[i], -1, assembleFlag);
 	  
@@ -750,7 +750,7 @@ namespace AMDiS {
 	      
 	      if (matrix->getBoundaryManager()) {
 		matrix->
-	      	  getBoundaryManager()->
+		  getBoundaryManager()->
 		  fillBoundaryConditions(elInfo, matrix);		
 	      }		      
 	    }
@@ -761,13 +761,14 @@ namespace AMDiS {
 	    
 	    elInfo = stack.traverseNext(elInfo);
 	  }
+	  
 
 	  if (assembleMatrix && matrix->getBoundaryManager())
-	    matrix->getBoundaryManager()->exitMatrix(matrix);	  
+	  	    matrix->getBoundaryManager()->exitMatrix(matrix);	  
 
 	  if (useGetBound_) {
 	    FREE_MEMORY(bound, BoundaryType, componentSpaces_[i]->getBasisFcts()->getNumber());
-	  }
+	  }	  
 	}
 	
 	assembledMatrix_[i][j] = true;
@@ -796,7 +797,7 @@ namespace AMDiS {
       if (rhs_->getDOFVector(i)->getBoundaryManager())
 	rhs_->getDOFVector(i)->getBoundaryManager()->exitVector(rhs_->getDOFVector(i));
       if (solution_->getDOFVector(i)->getBoundaryManager())
-      	solution_->getDOFVector(i)->getBoundaryManager()->exitVector(solution_->getDOFVector(i));     
+      solution_->getDOFVector(i)->getBoundaryManager()->exitVector(solution_->getDOFVector(i));    
     }
 
 #ifdef _OPENMP
diff --git a/AMDiS/src/Traverse.cc b/AMDiS/src/Traverse.cc
index 1fcc7d22..04d26b97 100644
--- a/AMDiS/src/Traverse.cc
+++ b/AMDiS/src/Traverse.cc
@@ -40,17 +40,16 @@ namespace AMDiS {
 
     traverse_mel = NULL;
     stack_used = 0;
-    
+   
     return(traverseNext(NULL));  
   }
 
   ElInfo* TraverseStack::traverseNext(ElInfo* elinfo_old)
   {
     FUNCNAME("TraverseStack::traverseNext()");
+\
     ElInfo *elinfo = NULL;
-
     ElInfo::traverseId = id;
-
     Parametric *parametric = traverse_mesh->getParametric();
 
     if (stack_used) {
@@ -63,9 +62,9 @@ namespace AMDiS {
       TEST_EXIT_DBG(elinfo_old == NULL)("invalid old elinfo != nil\n");
     }
 
-    if (traverse_fill_flag.isSet(Mesh::CALL_LEAF_EL)) 
+    if (traverse_fill_flag.isSet(Mesh::CALL_LEAF_EL)) {
       elinfo = traverseLeafElement();
-    else
+    } else {
       if (traverse_fill_flag.isSet(Mesh::CALL_LEAF_EL_LEVEL))
 	elinfo = traverseLeafElementLevel();
       else if (traverse_fill_flag.isSet(Mesh::CALL_EL_LEVEL))
@@ -81,6 +80,7 @@ namespace AMDiS {
 	  elinfo = traverseEveryElementPostorder();
 	else
 	  ERROR_EXIT("invalid traverse_flag\n");
+    }
 
     if (elinfo) {
       if (parametric) {
@@ -114,12 +114,11 @@ namespace AMDiS {
 
   int Traverse::recursive(ElInfo *elinfo)
   {
-    FUNCNAME("Traverse::recursive");
-    Element    *el = elinfo->getElement();
-    int        mg_level,sum=0;
+    FUNCNAME("Traverse::recursive()");
 
+    Element *el = elinfo->getElement();
+    int mg_level, sum=0;
     Parametric *parametric = mesh->getParametric();
-
     ElInfo::traverseId = id;
 
     if (flag.isSet(Mesh::CALL_LEAF_EL)) {
@@ -376,7 +375,7 @@ namespace AMDiS {
 	}
       }
     }
-    
+   
     /* go down tree until leaf */
     while (el->getFirstChild()) {
       if (stack_used >= stack_size-1) 
-- 
GitLab