Import gcc-4.4.1
[dragonfly.git] / contrib / gcc-4.4 / libstdc++-v3 / include / parallel / tags.h
blobbc1a7e5c6352222fee694f15349f5934663661fd
1 // -*- C++ -*-
3 // Copyright (C) 2007, 2008, 2009 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.
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/>.
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.
31 // Written by Johannes Singler and Felix Putze.
33 #ifndef _GLIBCXX_PARALLEL_TAGS_H
34 #define _GLIBCXX_PARALLEL_TAGS_H 1
36 #include <omp.h>
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. */
46 struct parallel_tag
48 private:
49 thread_index_t num_threads;
51 public:
52 /** @brief Default constructor. Use default number of threads. */
53 parallel_tag()
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(thread_index_t num_threads)
62 this->num_threads = num_threads;
65 /** @brief Find out desired number of threads.
66 * @return Desired number of threads. */
67 inline thread_index_t get_num_threads()
69 if(num_threads == 0)
70 return omp_get_max_threads();
71 else
72 return num_threads;
75 /** @brief Set the desired number of threads.
76 * @param num_threads Desired number of threads. */
77 inline void set_num_threads(thread_index_t 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(thread_index_t 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. */
110 struct find_tag { };
113 /** @brief Forces parallel merging
114 * with exact splitting, at compile time. */
115 struct exact_tag : public parallel_tag
117 exact_tag() { }
118 exact_tag(thread_index_t 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
126 sampling_tag() { }
127 sampling_tag(thread_index_t 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(thread_index_t 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(thread_index_t 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(thread_index_t 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
163 quicksort_tag() { }
164 quicksort_tag(thread_index_t 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(thread_index_t 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 */