Reference documentation for deal.II version 9.2.0
\(\newcommand{\dealvcentcolon}{\mathrel{\mathop{:}}}\) \(\newcommand{\dealcoloneq}{\dealvcentcolon\mathrel{\mkern-1.2mu}=}\) \(\newcommand{\jump}[1]{\left[\!\left[ #1 \right]\!\right]}\) \(\newcommand{\average}[1]{\left\{\!\left\{ #1 \right\}\!\right\}}\)
parallel.cc
Go to the documentation of this file.
1 // ---------------------------------------------------------------------
2 //
3 // Copyright (C) 2009 - 2018 by the deal.II authors
4 //
5 // This file is part of the deal.II library.
6 //
7 // The deal.II library is free software; you can use it, redistribute
8 // it, and/or modify it under the terms of the GNU Lesser General
9 // Public License as published by the Free Software Foundation; either
10 // version 2.1 of the License, or (at your option) any later version.
11 // The full text of the license can be found in the file LICENSE.md at
12 // the top level directory of deal.II.
13 //
14 // ---------------------------------------------------------------------
15 
16 
17 #include <deal.II/base/parallel.h>
18 
19 
21 
22 namespace internal
23 {
24  namespace VectorImplementation
25  {
26  // set minimum grain size. this value has been determined by experiments
27  // with the actual ::Vector implementation and takes vectorization
28  // that is done inside most functions of ::Vector into account
29  // (without vectorization, we would land at around 1000). for smaller
30  // values than this, the scheduling overhead will be significant. if the
31  // value becomes too large, on the other hand, the work load cannot be
32  // split into enough chunks and the problem becomes badly balanced. the
33  // tests are documented at https://github.com/dealii/dealii/issues/2496
34  unsigned int minimum_parallel_grain_size = 4096;
35  } // namespace VectorImplementation
36 
37 
38  namespace SparseMatrixImplementation
39  {
40  // set this value to 1/16 of the value of the minimum grain size of
41  // vectors (a factor of 4 because we assume that sparse matrix-vector
42  // products do not vectorize and the other factor of 4 because we expect
43  // at least four entries per row). this rests on the fact that we have to
44  // do a lot more work per row of a matrix than per element of a vector. it
45  // could possibly be reduced even further but that doesn't appear worth it
46  // any more for anything but very small matrices that we don't care that
47  // much about anyway.
48  unsigned int minimum_parallel_grain_size = 256;
49  } // namespace SparseMatrixImplementation
50 } // namespace internal
51 
52 namespace parallel
53 {
54  namespace internal
55  {
56 #ifdef DEAL_II_WITH_THREADS
58  : my_partitioner(std::make_shared<tbb::affinity_partitioner>())
59  , in_use(false)
60  {}
61 
62 
63 
65  {
66  AssertNothrow(in_use == false,
68  "A vector partitioner goes out of scope, but "
69  "it appears to be still in use."));
70  }
71 
72 
73 
74  std::shared_ptr<tbb::affinity_partitioner>
76  {
77  std::lock_guard<std::mutex> lock(mutex);
78  if (in_use)
79  return std::make_shared<tbb::affinity_partitioner>();
80 
81  in_use = true;
82  return my_partitioner;
83  }
84 
85 
86 
87  void
89  std::shared_ptr<tbb::affinity_partitioner> &p)
90  {
91  if (p.get() == my_partitioner.get())
92  {
93  std::lock_guard<std::mutex> lock(mutex);
94  in_use = false;
95  }
96  }
97 #else
99 #endif
100  } // namespace internal
101 } // namespace parallel
102 
103 
104 
parallel::internal::TBBPartitioner::my_partitioner
std::shared_ptr< tbb::affinity_partitioner > my_partitioner
Definition: parallel.h:766
parallel::internal::TBBPartitioner::in_use
bool in_use
Definition: parallel.h:772
parallel::internal::TBBPartitioner::mutex
std::mutex mutex
Definition: parallel.h:777
parallel::internal::TBBPartitioner::TBBPartitioner
TBBPartitioner()
Definition: parallel.cc:57
internal::SparseMatrixImplementation::minimum_parallel_grain_size
unsigned int minimum_parallel_grain_size
Definition: parallel.cc:48
parallel::internal::TBBPartitioner::release_one_partitioner
void release_one_partitioner(std::shared_ptr< tbb::affinity_partitioner > &p)
Definition: parallel.cc:88
DEAL_II_NAMESPACE_OPEN
#define DEAL_II_NAMESPACE_OPEN
Definition: config.h:358
internal::VectorImplementation::minimum_parallel_grain_size
unsigned int minimum_parallel_grain_size
Definition: parallel.cc:34
parallel::internal::TBBPartitioner::acquire_one_partitioner
std::shared_ptr< tbb::affinity_partitioner > acquire_one_partitioner()
Definition: parallel.cc:75
StandardExceptions::ExcInternalError
static ::ExceptionBase & ExcInternalError()
parallel::internal::TBBPartitioner::~TBBPartitioner
~TBBPartitioner()
Definition: parallel.cc:64
AssertNothrow
#define AssertNothrow(cond, exc)
Definition: exceptions.h:1483
internal
Definition: aligned_vector.h:369
parallel.h
DEAL_II_NAMESPACE_CLOSE
#define DEAL_II_NAMESPACE_CLOSE
Definition: config.h:359
parallel
Definition: distributed.h:416