From 4bb76cc8ae98e9db67e5b2e9455e1a7210c8da83 Mon Sep 17 00:00:00 2001 From: kanschat Date: Tue, 24 Oct 2006 17:17:19 +0000 Subject: [PATCH] make add_fe_name thread safe and add documentation git-svn-id: https://svn.dealii.org/trunk@14065 0785d39b-7218-0410-832d-ea1e28bc413d --- deal.II/deal.II/include/fe/fe_tools.h | 18 +++++++++++++ deal.II/deal.II/source/fe/fe_tools.cc | 37 ++++++++++++++++++++++++--- deal.II/doc/news/changes.html | 16 +++++++++++- 3 files changed, 67 insertions(+), 4 deletions(-) diff --git a/deal.II/deal.II/include/fe/fe_tools.h b/deal.II/deal.II/include/fe/fe_tools.h index ac7f35606a..cbda33164a 100644 --- a/deal.II/deal.II/include/fe/fe_tools.h +++ b/deal.II/deal.II/include/fe/fe_tools.h @@ -1022,6 +1022,24 @@ class FETools * everything after the first * non-name character will be * chopped off. + * + * If the name of the element + * already exists, an exception + * is thrown. Thus, functionality + * of get_fe_from_name() can only + * be added, not changed. + * + * @note This function + * manipulates a global table + * (one table for each space + * dimension). It is thread safe + * in the sense that every access + * to this table is secured by a + * lock. Nevertheless, since each + * name can be added only once, + * user code has to make sure + * that only one thread adds a + * new element. */ template static void add_fe_name(const std::string& name, diff --git a/deal.II/deal.II/source/fe/fe_tools.cc b/deal.II/deal.II/source/fe/fe_tools.cc index 1983c61874..63eddecc68 100644 --- a/deal.II/deal.II/source/fe/fe_tools.cc +++ b/deal.II/deal.II/source/fe/fe_tools.cc @@ -16,6 +16,7 @@ #include #include #include +#include #include #include #include @@ -47,15 +48,31 @@ DEAL_II_NAMESPACE_OPEN +namespace +{ +// have a lock that guarantees that at most one thread is changing and +// accessing the @p{coefficients} arrays of classes implementing +// polynomials with tables. make this lock local to this file. +// +// having only one lock for all of these classes is probably not going +// to be a problem since we only need it on very rare occasions. if +// someone finds this is a bottleneck, feel free to replace it by a +// more fine-grained solution + Threads::ThreadMutex fe_name_map_lock; + // This is the map used by FETools::get_fe_from_name and // FETools::add_fe_name. Since FEFactoryBase has a template parameter // dim, it could not be a member variable of FETools. On the other // hand, it is only accessed by functions in this file, so it is safe // to make it a static variable here. It must be static so that we can // link several dimensions together. -static std::map > > -fe_name_map; + std::map > > + fe_name_map; +} + + + @@ -1401,6 +1418,16 @@ FETools::add_fe_name(const std::string& parameter_name, name.find_first_not_of(std::string("abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789_")); if (name_end < name.size()) name.erase(name_end); + // first make sure that no other + // thread intercepts the + // operation of this function; + // for this, acquire the lock + // until we quit this function + Threads::ThreadMutex::ScopedLock lock(fe_name_map_lock); + + Assert(fe_name_map.find(name) != fe_name_map.end(), + ExcMessage("Cannot change existing element in finite element name list")); + // Insert the normalized name into // the map fe_name_map.insert(std::make_pair(name, factory)); @@ -1680,6 +1707,10 @@ FETools::get_fe_from_name_aux (std::string &name) } else { + // Make sure no other thread + // is just adding an element + Threads::ThreadMutex::ScopedLock lock (fe_name_map_lock); + typename std::map > >::const_iterator entry = fe_name_map.find(name_part); diff --git a/deal.II/doc/news/changes.html b/deal.II/doc/news/changes.html index becd43aa74..0315d4a61a 100644 --- a/deal.II/doc/news/changes.html +++ b/deal.II/doc/news/changes.html @@ -878,9 +878,23 @@ inconvenience this causes.

deal.II

    + +
  1. Improved: The lookup mechanism in FETools::get_fe_from_name has been changed, so + additional custom finite elements can be added using FETools::add_fe_name. In the course of this + change, the implementation of the lookup mechanism has been + simplified. +
    + (GK 2006/10/24) +

    +
  2. New: There is a new functions GridTools::create_union_triangulation + class="class">GridTools::create_union_triangulation that generates a triangulation that contains the respectively finest cells of two input triangulations.
    -- 2.39.5