From: Wolfgang Bangerth Date: Thu, 28 Jan 2010 17:04:05 +0000 (+0000) Subject: Fix the same bug in PolynomialsABF. X-Git-Tag: v8.0.0~6574 X-Git-Url: https://gitweb.dealii.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=55a5b58653780f57bba91e0f30db6b51f14eba14;p=dealii.git Fix the same bug in PolynomialsABF. git-svn-id: https://svn.dealii.org/trunk@20468 0785d39b-7218-0410-832d-ea1e28bc413d --- diff --git a/deal.II/base/include/base/polynomials_abf.h b/deal.II/base/include/base/polynomials_abf.h index 0abd61ca1f..583bf75ca8 100644 --- a/deal.II/base/include/base/polynomials_abf.h +++ b/deal.II/base/include/base/polynomials_abf.h @@ -2,7 +2,7 @@ // $Id$ // Version: $Name$ // -// Copyright (C) 2004, 2005, 2006 by the deal.II authors +// Copyright (C) 2004, 2005, 2006, 2010 by the deal.II authors // // This file is subject to QPL and may not be distributed // without copyright and license information. Please refer @@ -22,6 +22,7 @@ #include #include #include +#include #include @@ -70,7 +71,7 @@ class PolynomialsABF * Destructor deleting the polynomials. */ ~PolynomialsABF (); - + /** * Computes the value and the * first and second derivatives @@ -98,20 +99,20 @@ class PolynomialsABF void compute (const Point &unit_point, std::vector > &values, std::vector > &grads, - std::vector > &grad_grads) const; - + std::vector > &grad_grads) const; + /** * Returns the number of ABF polynomials. */ unsigned int n () const; - + /** * Returns the degree of the ABF * space, which is two less than * the highest polynomial degree. */ unsigned int degree () const; - + /** * Return the number of * polynomials in the space @@ -122,14 +123,14 @@ class PolynomialsABF * classes. */ static unsigned int compute_n_pols(unsigned int degree); - + private: /** * The degree of this object as * given to the constructor. */ const unsigned int my_degree; - + /** * An object representing the * polynomial space for a single @@ -144,17 +145,23 @@ class PolynomialsABF * polynomials. */ unsigned int n_pols; - + + /** + * A mutex that guards the + * following scratch arrays. + */ + mutable Threads::Mutex mutex; + /** * Auxiliary memory. */ - mutable std::vector p_values; - + mutable std::vector p_values; + /** * Auxiliary memory. */ mutable std::vector > p_grads; - + /** * Auxiliary memory. */ diff --git a/deal.II/base/source/polynomials_abf.cc b/deal.II/base/source/polynomials_abf.cc index 5bc0a39f58..b67f325a1d 100644 --- a/deal.II/base/source/polynomials_abf.cc +++ b/deal.II/base/source/polynomials_abf.cc @@ -2,7 +2,7 @@ // $Id$ // Version: $Name$ // -// Copyright (C) 2004, 2005, 2006 by the deal.II authors +// Copyright (C) 2004, 2005, 2006, 2010 by the deal.II authors // // This file is subject to QPL and may not be distributed // without copyright and license information. Please refer @@ -60,10 +60,17 @@ PolynomialsABF::compute (const Point &unit_point, ExcDimensionMismatch(grad_grads.size(), n_pols)); const unsigned int n_sub = polynomial_space->n(); + // guard access to the scratch + // arrays in the following block + // using a mutex to make sure they + // are not used by multiple threads + // at once + Threads::Mutex::ScopedLock lock(mutex); + p_values.resize((values.size() == 0) ? 0 : n_sub); p_grads.resize((grads.size() == 0) ? 0 : n_sub); p_grad_grads.resize((grad_grads.size() == 0) ? 0 : n_sub); - + for (unsigned int d=0;d::compute (const Point &unit_point, Point p; for (unsigned int c=0;ccompute (p, p_values, p_grads, p_grad_grads); - + for (unsigned int i=0;i::compute_n_pols(unsigned int k) if (dim == 2) return 2*(k+1)*(k+3); //TODO:Check what are the correct numbers ... if (dim == 3) return 3*(k+1)*(k+1)*(k+2); - + Assert(false, ExcNotImplemented()); return 0; } diff --git a/deal.II/doc/news/changes.h b/deal.II/doc/news/changes.h index f3842f5a72..48c2580f5e 100644 --- a/deal.II/doc/news/changes.h +++ b/deal.II/doc/news/changes.h @@ -246,8 +246,8 @@ inconvenience this causes.

base

    -
  1. Fixed: The PolynomialsBDM had a race condition in multithreaded - programs. This now fixed. +

  2. Fixed: The PolynomialsBDM and PolynomialsABF classes had a race + condition in multithreaded programs. This now fixed.
    (WB 2010/01/27)