3 // Copyright (C) 2007, 2008, 2009 Free Software Foundation, Inc.
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
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.
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.
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/>.
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.
31 // Written by Johannes Singler and Felix Putze.
33 #ifndef _GLIBCXX_PARALLEL_TAGS_H
34 #define _GLIBCXX_PARALLEL_TAGS_H 1
37 #include <parallel/types.h>
39 namespace __gnu_parallel
41 /** @brief Forces sequential execution at compile time. */
42 struct sequential_tag
{ };
44 /** @brief Recommends parallel execution at compile time,
45 * optionally using a user-specified number of threads. */
49 _ThreadIndex __num_threads
;
52 /** @brief Default constructor. Use default number of threads. */
55 this->__num_threads
= 0;
58 /** @brief Default constructor. Recommend number of threads to use.
59 * @param __num_threads Desired number of threads. */
60 parallel_tag(_ThreadIndex __num_threads
)
62 this->__num_threads
= __num_threads
;
65 /** @brief Find __out desired number of threads.
66 * @return Desired number of threads. */
67 inline _ThreadIndex
__get_num_threads()
69 if(__num_threads
== 0)
70 return omp_get_max_threads();
75 /** @brief Set the desired number of threads.
76 * @param __num_threads Desired number of threads. */
77 inline void set_num_threads(_ThreadIndex __num_threads
)
79 this->__num_threads
= __num_threads
;
83 /** @brief Recommends parallel execution using the
84 default parallel algorithm. */
85 struct default_parallel_tag
: public parallel_tag
87 default_parallel_tag() { }
88 default_parallel_tag(_ThreadIndex __num_threads
)
89 : parallel_tag(__num_threads
) { }
92 /** @brief Recommends parallel execution using dynamic
93 load-balancing at compile time. */
94 struct balanced_tag
: public parallel_tag
{ };
96 /** @brief Recommends parallel execution using static
97 load-balancing at compile time. */
98 struct unbalanced_tag
: public parallel_tag
{ };
100 /** @brief Recommends parallel execution using OpenMP dynamic
101 load-balancing at compile time. */
102 struct omp_loop_tag
: public parallel_tag
{ };
104 /** @brief Recommends parallel execution using OpenMP static
105 load-balancing at compile time. */
106 struct omp_loop_static_tag
: public parallel_tag
{ };
109 /** @brief Base class for for std::find() variants. */
113 /** @brief Forces parallel merging
114 * with __exact splitting, at compile time. */
115 struct exact_tag
: public parallel_tag
118 exact_tag(_ThreadIndex __num_threads
)
119 : parallel_tag(__num_threads
) { }
122 /** @brief Forces parallel merging
123 * with __exact splitting, at compile time. */
124 struct sampling_tag
: public parallel_tag
127 sampling_tag(_ThreadIndex __num_threads
)
128 : parallel_tag(__num_threads
) { }
132 /** @brief Forces parallel sorting using multiway mergesort
133 * at compile time. */
134 struct multiway_mergesort_tag
: public parallel_tag
136 multiway_mergesort_tag() { }
137 multiway_mergesort_tag(_ThreadIndex __num_threads
)
138 : parallel_tag(__num_threads
) { }
141 /** @brief Forces parallel sorting using multiway mergesort
142 * with __exact splitting at compile time. */
143 struct multiway_mergesort_exact_tag
: public parallel_tag
145 multiway_mergesort_exact_tag() { }
146 multiway_mergesort_exact_tag(_ThreadIndex __num_threads
)
147 : parallel_tag(__num_threads
) { }
150 /** @brief Forces parallel sorting using multiway mergesort
151 * with splitting by sampling at compile time. */
152 struct multiway_mergesort_sampling_tag
: public parallel_tag
154 multiway_mergesort_sampling_tag() { }
155 multiway_mergesort_sampling_tag(_ThreadIndex __num_threads
)
156 : parallel_tag(__num_threads
) { }
159 /** @brief Forces parallel sorting using unbalanced quicksort
160 * at compile time. */
161 struct quicksort_tag
: public parallel_tag
164 quicksort_tag(_ThreadIndex __num_threads
)
165 : parallel_tag(__num_threads
) { }
168 /** @brief Forces parallel sorting using balanced quicksort
169 * at compile time. */
170 struct balanced_quicksort_tag
: public parallel_tag
172 balanced_quicksort_tag() { }
173 balanced_quicksort_tag(_ThreadIndex __num_threads
)
174 : parallel_tag(__num_threads
) { }
178 /** @brief Selects the growing block size variant for std::find().
179 @see _GLIBCXX_FIND_GROWING_BLOCKS */
180 struct growing_blocks_tag
: public find_tag
{ };
182 /** @brief Selects the constant block size variant for std::find().
183 @see _GLIBCXX_FIND_CONSTANT_SIZE_BLOCKS */
184 struct constant_size_blocks_tag
: public find_tag
{ };
186 /** @brief Selects the equal splitting variant for std::find().
187 @see _GLIBCXX_FIND_EQUAL_SPLIT */
188 struct equal_split_tag
: public find_tag
{ };
191 #endif /* _GLIBCXX_PARALLEL_TAGS_H */