Reference documentation for deal.II version 9.0.0
parallel.cc
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 at
12 // the top level of the deal.II distribution.
13 //
14 // ---------------------------------------------------------------------
15 
16 
17 #include <deal.II/base/parallel.h>
18 
19 
20 DEAL_II_NAMESPACE_OPEN
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  }
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  }
50 }
51 
52 namespace parallel
53 {
54  namespace internal
55  {
56 #ifdef DEAL_II_WITH_THREADS
57  TBBPartitioner::TBBPartitioner()
58  :
59  my_partitioner(std::make_shared<tbb::affinity_partitioner>()),
60  in_use(false)
61  {}
62 
63 
64 
65  TBBPartitioner::~TBBPartitioner()
66  {
67  AssertNothrow(in_use == false,
68  ExcInternalError("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>
75  TBBPartitioner::acquire_one_partitioner()
76  {
77  ::Threads::Mutex::ScopedLock 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
88  TBBPartitioner::release_one_partitioner(std::shared_ptr<tbb::affinity_partitioner> &p)
89  {
90  if (p.get() == my_partitioner.get())
91  {
92  ::Threads::Mutex::ScopedLock lock(mutex);
93  in_use = false;
94  }
95  }
96 #else
97  TBBPartitioner::TBBPartitioner() = default;
98 #endif
99  }
100 }
101 
102 
103 
104 
105 DEAL_II_NAMESPACE_CLOSE
#define AssertNothrow(cond, exc)
Definition: exceptions.h:1183
STL namespace.
static ::ExceptionBase & ExcInternalError()