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