Loading [MathJax]/extensions/TeX/AMSsymbols.js
 deal.II version GIT relicensing-3075-gc235bd4825 2025-04-15 08:10:00+00:00
\(\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\}}\)
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages Concepts
parallel.cc
Go to the documentation of this file.
1// ------------------------------------------------------------------------
2//
3// SPDX-License-Identifier: LGPL-2.1-or-later
4// Copyright (C) 2009 - 2024 by the deal.II authors
5//
6// This file is part of the deal.II library.
7//
8// Part of the source code is dual licensed under Apache-2.0 WITH
9// LLVM-exception OR LGPL-2.1-or-later. Detailed license information
10// governing the source code and code contributions can be found in
11// LICENSE.md and CONTRIBUTING.md at the top level directory of deal.II.
12//
13// ------------------------------------------------------------------------
14
15
18
19#ifdef DEAL_II_WITH_TASKFLOW
21
22# include <taskflow/algorithm/for_each.hpp>
23# include <taskflow/taskflow.hpp>
24#endif
25
26#ifdef DEAL_II_WITH_TBB
27# include <tbb/blocked_range.h>
28# include <tbb/parallel_for.h>
29# include <tbb/parallel_reduce.h>
30# include <tbb/partitioner.h>
31#else
32# include <boost/range/iterator_range.hpp>
33#endif
34
35
37
38namespace internal
39{
40 namespace VectorImplementation
41 {
42 // set minimum grain size. this value has been determined by experiments
43 // with the actual ::Vector implementation and takes vectorization
44 // that is done inside most functions of ::Vector into account
45 // (without vectorization, we would land at around 1000). for smaller
46 // values than this, the scheduling overhead will be significant. if the
47 // value becomes too large, on the other hand, the work load cannot be
48 // split into enough chunks and the problem becomes badly balanced. the
49 // tests are documented at https://github.com/dealii/dealii/issues/2496
50 unsigned int minimum_parallel_grain_size = 4096;
51 } // namespace VectorImplementation
52
53
54 namespace SparseMatrixImplementation
55 {
56 // set this value to 1/16 of the value of the minimum grain size of
57 // vectors (a factor of 4 because we assume that sparse matrix-vector
58 // products do not vectorize and the other factor of 4 because we expect
59 // at least four entries per row). this rests on the fact that we have to
60 // do a lot more work per row of a matrix than per element of a vector. it
61 // could possibly be reduced even further but that doesn't appear worth it
62 // any more for anything but very small matrices that we don't care that
63 // much about anyway.
64 unsigned int minimum_parallel_grain_size = 256;
65 } // namespace SparseMatrixImplementation
66} // namespace internal
67
68namespace parallel
69{
70 namespace internal
71 {
72#ifdef DEAL_II_WITH_TBB
74 : my_partitioner(std::make_shared<tbb::affinity_partitioner>())
75 , in_use(false)
76 {}
77
78
79
81 {
82 AssertNothrow(in_use == false,
84 "A vector partitioner goes out of scope, but "
85 "it appears to be still in use."));
86 }
87
88
89
90 std::shared_ptr<tbb::affinity_partitioner>
92 {
93 std::lock_guard<std::mutex> lock(mutex);
94 if (in_use)
95 return std::make_shared<tbb::affinity_partitioner>();
96
97 in_use = true;
98 return my_partitioner;
99 }
100
101
102
103 void
105 const std::shared_ptr<tbb::affinity_partitioner> &p)
106 {
107 if (p.get() == my_partitioner.get())
108 {
109 std::lock_guard<std::mutex> lock(mutex);
110 in_use = false;
111 }
112 }
113#else
115#endif
116 } // namespace internal
117} // namespace parallel
118
119
120
std::shared_ptr< tbb::affinity_partitioner > acquire_one_partitioner()
Definition parallel.cc:91
void release_one_partitioner(const std::shared_ptr< tbb::affinity_partitioner > &p)
Definition parallel.cc:104
std::shared_ptr< tbb::affinity_partitioner > my_partitioner
Definition parallel.h:773
#define DEAL_II_NAMESPACE_OPEN
Definition config.h:35
#define DEAL_II_NAMESPACE_CLOSE
Definition config.h:36
#define AssertNothrow(cond, exc)
static ::ExceptionBase & ExcInternalError()
unsigned int minimum_parallel_grain_size
Definition parallel.cc:50
STL namespace.