libstdc++
tags.h
Go to the documentation of this file.
1 // -*- C++ -*-
2 
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.
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 
39 namespace __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. */
46  struct parallel_tag
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. */
58  parallel_tag(_ThreadIndex __num_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  {
82  default_parallel_tag(_ThreadIndex __num_threads)
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. */
100  struct omp_loop_static_tag : public parallel_tag { };
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. */
118  struct sampling_tag : public parallel_tag
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  {
131  multiway_mergesort_tag(_ThreadIndex __num_threads)
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. */
155  struct quicksort_tag : public parallel_tag
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  {
167  balanced_quicksort_tag(_ThreadIndex __num_threads)
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 */
178  struct constant_size_blocks_tag : public find_tag { };
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 */