libstdc++
tags.h
Go to the documentation of this file.
1// -*- C++ -*-
2
3// Copyright (C) 2007-2021 Free Software Foundation, Inc.
4//
5// This file is part of the GNU ISO C++ Library. This library is free
6// software; you can redistribute it and/or modify it under the terms
7// of the GNU General Public License as published by the Free Software
8// Foundation; either version 3, or (at your option) any later
9// version.
10
11// This library is distributed in the hope that it will be useful, but
12// WITHOUT ANY WARRANTY; without even the implied warranty of
13// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14// General Public License for more details.
15
16// Under Section 7 of GPL version 3, you are granted additional
17// permissions described in the GCC Runtime Library Exception, version
18// 3.1, as published by the Free Software Foundation.
19
20// You should have received a copy of the GNU General Public License and
21// a copy of the GCC Runtime Library Exception along with this program;
22// see the files COPYING3 and COPYING.RUNTIME respectively. If not, see
23// <http://www.gnu.org/licenses/>.
24
25/**
26 * @file parallel/tags.h
27 * @brief Tags for compile-time selection.
28 * This file is a GNU parallel extension to the Standard C++ Library.
29 */
30
31// Written by Johannes Singler and Felix Putze.
32
33#ifndef _GLIBCXX_PARALLEL_TAGS_H
34#define _GLIBCXX_PARALLEL_TAGS_H 1
35
36#include <omp.h>
37#include <parallel/types.h>
38
39namespace __gnu_parallel
40{
41 /** @brief Forces sequential execution at compile time. */
42 struct sequential_tag { };
43
44 /** @brief Recommends parallel execution at compile time,
45 * optionally using a user-specified number of threads. */
47 {
48 private:
49 _ThreadIndex _M_num_threads;
50
51 public:
52 /** @brief Default constructor. Use default number of threads. */
54 { _M_num_threads = 0; }
55
56 /** @brief Default constructor. Recommend number of threads to use.
57 * @param __num_threads Desired number of threads. */
59 { _M_num_threads = __num_threads; }
60
61 /** @brief Find out desired number of threads.
62 * @return Desired number of threads. */
64 {
65 if(_M_num_threads == 0)
66 return omp_get_max_threads();
67 else
68 return _M_num_threads;
69 }
70
71 /** @brief Set the desired number of threads.
72 * @param __num_threads Desired number of threads. */
73 void set_num_threads(_ThreadIndex __num_threads)
74 { _M_num_threads = __num_threads; }
75 };
76
77 /** @brief Recommends parallel execution using the
78 default parallel algorithm. */
80 {
83 : parallel_tag(__num_threads) { }
84 };
85
86 /** @brief Recommends parallel execution using dynamic
87 load-balancing at compile time. */
88 struct balanced_tag : public parallel_tag { };
89
90 /** @brief Recommends parallel execution using static
91 load-balancing at compile time. */
92 struct unbalanced_tag : public parallel_tag { };
93
94 /** @brief Recommends parallel execution using OpenMP dynamic
95 load-balancing at compile time. */
96 struct omp_loop_tag : public parallel_tag { };
97
98 /** @brief Recommends parallel execution using OpenMP static
99 load-balancing at compile time. */
101
102
103 /** @brief Base class for for std::find() variants. */
104 struct find_tag { };
105
106
107 /** @brief Forces parallel merging
108 * with exact splitting, at compile time. */
109 struct exact_tag : public parallel_tag
110 {
111 exact_tag() { }
112 exact_tag(_ThreadIndex __num_threads)
113 : parallel_tag(__num_threads) { }
114 };
115
116 /** @brief Forces parallel merging
117 * with exact splitting, at compile time. */
119 {
120 sampling_tag() { }
121 sampling_tag(_ThreadIndex __num_threads)
122 : parallel_tag(__num_threads) { }
123 };
124
125
126 /** @brief Forces parallel sorting using multiway mergesort
127 * at compile time. */
129 {
132 : parallel_tag(__num_threads) { }
133 };
134
135 /** @brief Forces parallel sorting using multiway mergesort
136 * with exact splitting at compile time. */
138 {
141 : parallel_tag(__num_threads) { }
142 };
143
144 /** @brief Forces parallel sorting using multiway mergesort
145 * with splitting by sampling at compile time. */
147 {
150 : parallel_tag(__num_threads) { }
151 };
152
153 /** @brief Forces parallel sorting using unbalanced quicksort
154 * at compile time. */
156 {
157 quicksort_tag() { }
158 quicksort_tag(_ThreadIndex __num_threads)
159 : parallel_tag(__num_threads) { }
160 };
161
162 /** @brief Forces parallel sorting using balanced quicksort
163 * at compile time. */
165 {
168 : parallel_tag(__num_threads) { }
169 };
170
171
172 /** @brief Selects the growing block size variant for std::find().
173 @see _GLIBCXX_FIND_GROWING_BLOCKS */
174 struct growing_blocks_tag : public find_tag { };
175
176 /** @brief Selects the constant block size variant for std::find().
177 @see _GLIBCXX_FIND_CONSTANT_SIZE_BLOCKS */
179
180 /** @brief Selects the equal splitting variant for std::find().
181 @see _GLIBCXX_FIND_EQUAL_SPLIT */
182 struct equal_split_tag : public find_tag { };
183}
184
185#endif /* _GLIBCXX_PARALLEL_TAGS_H */
Basic types and typedefs. This file is a GNU parallel extension to the Standard C++ Library.
GNU parallel code for public use.
uint16_t _ThreadIndex
Unsigned integer to index a thread number. The maximum thread number (for each processor) must fit in...
Definition: types.h:123
Forces sequential execution at compile time.
Definition: tags.h:42
Recommends parallel execution at compile time, optionally using a user-specified number of threads.
Definition: tags.h:47
parallel_tag()
Default constructor. Use default number of threads.
Definition: tags.h:53
_ThreadIndex __get_num_threads()
Find out desired number of threads.
Definition: tags.h:63
parallel_tag(_ThreadIndex __num_threads)
Default constructor. Recommend number of threads to use.
Definition: tags.h:58
void set_num_threads(_ThreadIndex __num_threads)
Set the desired number of threads.
Definition: tags.h:73
Recommends parallel execution using the default parallel algorithm.
Definition: tags.h:80
Recommends parallel execution using dynamic load-balancing at compile time.
Definition: tags.h:88
Recommends parallel execution using static load-balancing at compile time.
Definition: tags.h:92
Recommends parallel execution using OpenMP dynamic load-balancing at compile time.
Definition: tags.h:96
Recommends parallel execution using OpenMP static load-balancing at compile time.
Definition: tags.h:100
Base class for for std::find() variants.
Definition: tags.h:104
Forces parallel merging with exact splitting, at compile time.
Definition: tags.h:110
Forces parallel merging with exact splitting, at compile time.
Definition: tags.h:119
Forces parallel sorting using multiway mergesort at compile time.
Definition: tags.h:129
Forces parallel sorting using multiway mergesort with exact splitting at compile time.
Definition: tags.h:138
Forces parallel sorting using multiway mergesort with splitting by sampling at compile time.
Definition: tags.h:147
Forces parallel sorting using unbalanced quicksort at compile time.
Definition: tags.h:156
Forces parallel sorting using balanced quicksort at compile time.
Definition: tags.h:165
Selects the growing block size variant for std::find().
Definition: tags.h:174
Selects the constant block size variant for std::find().
Definition: tags.h:178
Selects the equal splitting variant for std::find().
Definition: tags.h:182