[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Getfem-commits] r4599 - in /trunk/getfem/src: getfem/bgeot_small_vector
From: |
andriy . andreykiv |
Subject: |
[Getfem-commits] r4599 - in /trunk/getfem/src: getfem/bgeot_small_vector.h getfem/getfem_omp.h getfem_fem.cc |
Date: |
Thu, 10 Apr 2014 16:59:55 -0000 |
Author: andrico
Date: Thu Apr 10 18:59:55 2014
New Revision: 4599
URL: http://svn.gna.org/viewcvs/getfem?rev=4599&view=rev
Log:
"thread safeing" some local static variables in argyris_triangle_
Modified:
trunk/getfem/src/getfem/bgeot_small_vector.h
trunk/getfem/src/getfem/getfem_omp.h
trunk/getfem/src/getfem_fem.cc
Modified: trunk/getfem/src/getfem/bgeot_small_vector.h
URL:
http://svn.gna.org/viewcvs/getfem/trunk/getfem/src/getfem/bgeot_small_vector.h?rev=4599&r1=4598&r2=4599&view=diff
==============================================================================
--- trunk/getfem/src/getfem/bgeot_small_vector.h (original)
+++ trunk/getfem/src/getfem/bgeot_small_vector.h Thu Apr 10 18:59:55 2014
@@ -37,8 +37,8 @@
#ifndef BGEOT_SMALL_VECTOR_H
#define BGEOT_SMALL_VECTOR_H
+#include "dal_singleton.h"
#include "bgeot_config.h"
-#include "dal_singleton.h"
#ifdef DEBUG_SMALL_VECTOR
# include <cassert>
# define SVEC_ASSERT(x) assert(x)
@@ -275,6 +275,19 @@
}
};
+ template<class T> inline bool small_vector<T>::operator<(const
small_vector<T>& other) const
+ {
+ return std::lexicographical_compare(begin(), end(), other.begin(),
other.end());
+ }
+
+ template<class T> inline small_vector<T>& small_vector<T>::addmul(T v, const
small_vector<T>& other)
+ {
+ const_iterator b = other.begin(); iterator it = begin();
+ for (size_type i=0; i < size(); ++i) *it++ += v * *b++;
+ return *this;
+ }
+
+
#else
/**In case of multi-threaded assembly with OpenMP using std::vector derived
@@ -347,27 +360,25 @@
small_vector<T> operator/=(T v) { return operator*=(T(1)/v); }
- bool operator<(const small_vector<T>& other) const;
-
void fill(T v) { for (iterator it=std::vector<T>::begin(); it !=
std::vector<T>::end(); ++it) *it = v; }
small_vector<T>& operator<<(T x) { push_back(x); return *this; }
size_type memsize() const { return (std::vector<T>::size()*sizeof(T)) +
sizeof(*this); }
+ inline bool operator<(const small_vector<T>& other) const
+ {
+ return std::lexicographical_compare(std::vector<T>::begin(),
std::vector<T>::end(), other.begin(), other.end());
+ }
};
+ template<class T> inline small_vector<T>& small_vector<T>::addmul(T v,
const small_vector<T>& other)
+ {
+ const_iterator b = other.begin(); iterator it = std::vector<T>::begin();
+ for (size_type i=0; i < std::vector<T>::size(); ++i) *it++ += v * *b++;
+ return *this;
+ }
+
#endif // #if !defined GETFEM_HAVE_OPENMP
- template<class T> inline bool small_vector<T>::operator<(const
small_vector<T>& other) const
- {
- return std::lexicographical_compare(std::vector<T>::begin(),
std::vector<T>::end(), other.begin(), other.end());
- }
-
- template<class T> inline small_vector<T>& small_vector<T>::addmul(T v, const
small_vector<T>& other)
- {
- const_iterator b = other.begin(); iterator it = std::vector<T>::begin();
- for (size_type i=0; i < std::vector<T>::size(); ++i) *it++ += v * *b++;
- return *this;
- }
template<class T> std::ostream& operator<<(std::ostream& os, const
small_vector<T>& v) {
os << "["; for (size_type i=0; i < v.size(); ++i) { if (i) os << ", "; os
<< v[i]; }
Modified: trunk/getfem/src/getfem/getfem_omp.h
URL:
http://svn.gna.org/viewcvs/getfem/trunk/getfem/src/getfem/getfem_omp.h?rev=4599&r1=4598&r2=4599&view=diff
==============================================================================
--- trunk/getfem/src/getfem/getfem_omp.h (original)
+++ trunk/getfem/src/getfem/getfem_omp.h Thu Apr 10 18:59:55 2014
@@ -226,12 +226,20 @@
if(!ptr_##Var.get()) {ptr_##Var.reset(new Type());} \
Type& Var=*ptr_##Var;
+#define DEFINE_STATIC_THREAD_LOCAL_CONSTRUCTED(Type, Var, arguments) \
+ static boost::thread_specific_ptr<Type> ptr_##Var; \
+ if(!ptr_##Var.get()) {ptr_##Var.reset(new Type##arguments);} \
+ Type& Var=*ptr_##Var;
+
#else
#define DEFINE_STATIC_THREAD_LOCAL_INITIALIZED(Type,Var,initial) \
static Type Var(initial);
#define DEFINE_STATIC_THREAD_LOCAL(Type,Var) \
static Type Var;
+
+#define DEFINE_STATIC_THREAD_LOCAL_CONSTRUCTED(Type, Var, arguments) \
+ static Type Var##arguments;
#endif
Modified: trunk/getfem/src/getfem_fem.cc
URL:
http://svn.gna.org/viewcvs/getfem/trunk/getfem/src/getfem_fem.cc?rev=4599&r1=4598&r2=4599&view=diff
==============================================================================
--- trunk/getfem/src/getfem_fem.cc (original)
+++ trunk/getfem/src/getfem_fem.cc Thu Apr 10 18:59:55 2014
@@ -32,6 +32,7 @@
#include "getfem/getfem_fem.h"
#include "getfem/getfem_gauss_lobatto_fem_coef.h" /* for gauss-lobatto points*/
#include "getfem/getfem_integration.h"
+#include "getfem/getfem_omp.h"
namespace getfem {
@@ -1750,10 +1751,11 @@
void argyris_triangle__::mat_trans(base_matrix &M,
const base_matrix &G,
bgeot::pgeometric_trans pgt) const {
- static bgeot::pgeotrans_precomp pgp;
- static pfem_precomp pfp;
- static bgeot::pgeometric_trans pgt_stored = 0;
- static base_matrix K(2, 2);
+
+ DEFINE_STATIC_THREAD_LOCAL(bgeot::pgeotrans_precomp, pgp);
+ DEFINE_STATIC_THREAD_LOCAL(pfem_precomp, pfp);
+ DEFINE_STATIC_THREAD_LOCAL_INITIALIZED(bgeot::pgeometric_trans,
pgt_stored, 0);
+ DEFINE_STATIC_THREAD_LOCAL_CONSTRUCTED(base_matrix, K, (2, 2));
dim_type N = dim_type(G.nrows());
GMM_ASSERT1(N == 2, "Sorry, this version of argyris "
"element works only on dimension two.")
@@ -1792,7 +1794,7 @@
M(5+6*k, 3+6*k) = c*c; M(5+6*k, 4+6*k) = c*d; M(5+6*k, 5+6*k)
= d*d;
}
- static base_matrix W(3, 21);
+ DEFINE_STATIC_THREAD_LOCAL_CONSTRUCTED(base_matrix, W, (3, 21));
base_small_vector norient(M_PI, M_PI * M_PI);
if (pgt->is_linear()) gmm::lu_inverse(K);
for (unsigned i = 18; i < 21; ++i) {
@@ -1811,10 +1813,11 @@
for (unsigned j = 0; j < 21; ++j)
W(i-18, j) = t(j, 0, 0) * v[0] + t(j, 0, 1) * v[1];
}
-
- static base_matrix A(3, 3);
- static bgeot::base_vector w(3), coeff(3);
- static gmm::sub_interval SUBI(18, 3), SUBJ(0, 3);
+ DEFINE_STATIC_THREAD_LOCAL_CONSTRUCTED(base_matrix,A,(3,3));
+ DEFINE_STATIC_THREAD_LOCAL_CONSTRUCTED(bgeot::base_vector, w, (3));
+ DEFINE_STATIC_THREAD_LOCAL_CONSTRUCTED(bgeot::base_vector, coeff, (3));
+ DEFINE_STATIC_THREAD_LOCAL_CONSTRUCTED(gmm::sub_interval, SUBI, (18,3));
+ DEFINE_STATIC_THREAD_LOCAL_CONSTRUCTED(gmm::sub_interval, SUBJ, (0,3));
gmm::copy(gmm::sub_matrix(W, SUBJ, SUBI), A);
gmm::lu_inverse(A);
gmm::copy(gmm::transposed(A), gmm::sub_matrix(M, SUBI));
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [Getfem-commits] r4599 - in /trunk/getfem/src: getfem/bgeot_small_vector.h getfem/getfem_omp.h getfem_fem.cc,
andriy . andreykiv <=