From: bangerth Date: Mon, 13 Oct 2008 18:09:20 +0000 (+0000) Subject: Fix a multithreading problem with the Raviart Thomas polynomials. X-Git-Url: https://gitweb.dealii.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=828c5b1be6fd77f4d930a41422205aad54cabf2a;p=dealii-svn.git Fix a multithreading problem with the Raviart Thomas polynomials. git-svn-id: https://svn.dealii.org/trunk@17196 0785d39b-7218-0410-832d-ea1e28bc413d --- diff --git a/deal.II/base/include/base/polynomials_raviart_thomas.h b/deal.II/base/include/base/polynomials_raviart_thomas.h index 34cfe921be..cad7acf20f 100644 --- a/deal.II/base/include/base/polynomials_raviart_thomas.h +++ b/deal.II/base/include/base/polynomials_raviart_thomas.h @@ -2,7 +2,7 @@ // $Id$ // Version: $Name$ // -// Copyright (C) 2004, 2005, 2006, 2007 by the deal.II authors +// Copyright (C) 2004, 2005, 2006, 2007, 2008 by the deal.II authors // // This file is subject to QPL and may not be distributed // without copyright and license information. Please refer @@ -135,22 +135,7 @@ class PolynomialsRaviartThomas * Number of Raviart-Thomas * polynomials. */ - unsigned int n_pols; - - /** - * Auxiliary memory. - */ - mutable std::vector p_values; - - /** - * Auxiliary memory. - */ - mutable std::vector > p_grads; - - /** - * Auxiliary memory. - */ - mutable std::vector > p_grad_grads; + const unsigned int n_pols; /** * A static member function that diff --git a/deal.II/base/source/polynomials_raviart_thomas.cc b/deal.II/base/source/polynomials_raviart_thomas.cc index e49a5cfb23..17cba34667 100644 --- a/deal.II/base/source/polynomials_raviart_thomas.cc +++ b/deal.II/base/source/polynomials_raviart_thomas.cc @@ -2,7 +2,7 @@ // $Id$ // Version: $Name$ // -// Copyright (C) 2004, 2005, 2006, 2007 by the deal.II authors +// Copyright (C) 2004, 2005, 2006, 2007, 2008 by the deal.II authors // // This file is subject to QPL and may not be distributed // without copyright and license information. Please refer @@ -13,6 +13,7 @@ #include #include +#include #include #include @@ -51,9 +52,9 @@ PolynomialsRaviartThomas::create_polynomials (const unsigned int k) template void PolynomialsRaviartThomas::compute (const Point &unit_point, - std::vector > &values, - std::vector > &grads, - std::vector > &grad_grads) const + std::vector > &values, + std::vector > &grads, + std::vector > &grad_grads) const { Assert(values.size()==n_pols || values.size()==0, ExcDimensionMismatch(values.size(), n_pols)); @@ -62,7 +63,27 @@ PolynomialsRaviartThomas::compute (const Point &unit_point, Assert(grad_grads.size()==n_pols|| grad_grads.size()==0, ExcDimensionMismatch(grad_grads.size(), n_pols)); - const unsigned int n_sub = polynomial_space.n(); + // have a few scratch + // arrays. because we don't want to + // re-allocate them every time this + // function is called, we make them + // static. however, in return we + // have to ensure that the calls to + // the use of these variables is + // locked with a mutex. if the + // mutex is removed, several tests + // (notably + // deal.II/create_mass_matrix_05) + // will start to produce random + // results in multithread mode + static Threads::ThreadMutex mutex; + Threads::ThreadMutex::ScopedLock lock(mutex); + + static std::vector p_values; + static std::vector > p_grads; + static std::vector > p_grad_grads; + + const unsigned int n_sub = polynomial_space.n(); 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); diff --git a/deal.II/doc/news/changes.h b/deal.II/doc/news/changes.h index dede3f62d4..313d6ee4d7 100644 --- a/deal.II/doc/news/changes.h +++ b/deal.II/doc/news/changes.h @@ -196,6 +196,15 @@ inconvenience this causes.

base

    +
  1. +

    + Fixed: The PolynomialsRaviartThomas class had a bug that led to random + results when used from multiple threads. As a consequence the FE_RaviartThomas + class was unusable in a multithreaded context. This has now been fixed. +
    + (WB 2008/10/13) +

    +
  2. New: There is a new function scalar_product(const Tensor<2,dim> &,