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  thread_index_t num_threads;
50 
51  public:
52  /** @brief Default constructor. Use default number of threads. */
54  {
55  this->num_threads = 0;
56  }
57 
58  /** @brief Default constructor. Recommend number of threads to use.
59  * @param num_threads Desired number of threads. */
61  {
62  this->num_threads = num_threads;
63  }
64 
65  /** @brief Find out desired number of threads.
66  * @return Desired number of threads. */
68  {
69  if(num_threads == 0)
70  return omp_get_max_threads();
71  else
72  return num_threads;
73  }
74 
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)
78  {
79  this->num_threads = num_threads;
80  }
81  };
82 
83  /** @brief Recommends parallel execution using the
84  default parallel algorithm. */
86  {
89  : parallel_tag(num_threads) { }
90  };
91 
92  /** @brief Recommends parallel execution using dynamic
93  load-balancing at compile time. */
94  struct balanced_tag : public parallel_tag { };
95 
96  /** @brief Recommends parallel execution using static
97  load-balancing at compile time. */
98  struct unbalanced_tag : public parallel_tag { };
99 
100  /** @brief Recommends parallel execution using OpenMP dynamic
101  load-balancing at compile time. */
102  struct omp_loop_tag : public parallel_tag { };
103 
104  /** @brief Recommends parallel execution using OpenMP static
105  load-balancing at compile time. */
106  struct omp_loop_static_tag : public parallel_tag { };
107 
108 
109  /** @brief Base class for for std::find() variants. */
110  struct find_tag { };
111 
112 
113  /** @brief Forces parallel merging
114  * with exact splitting, at compile time. */
115  struct exact_tag : public parallel_tag
116  {
117  exact_tag() { }
118  exact_tag(thread_index_t num_threads)
119  : parallel_tag(num_threads) { }
120  };
121 
122  /** @brief Forces parallel merging
123  * with exact splitting, at compile time. */
124  struct sampling_tag : public parallel_tag
125  {
126  sampling_tag() { }
127  sampling_tag(thread_index_t num_threads)
128  : parallel_tag(num_threads) { }
129  };
130 
131 
132  /** @brief Forces parallel sorting using multiway mergesort
133  * at compile time. */
135  {
138  : parallel_tag(num_threads) { }
139  };
140 
141  /** @brief Forces parallel sorting using multiway mergesort
142  * with exact splitting at compile time. */
144  {
147  : parallel_tag(num_threads) { }
148  };
149 
150  /** @brief Forces parallel sorting using multiway mergesort
151  * with splitting by sampling at compile time. */
153  {
156  : parallel_tag(num_threads) { }
157  };
158 
159  /** @brief Forces parallel sorting using unbalanced quicksort
160  * at compile time. */
161  struct quicksort_tag : public parallel_tag
162  {
163  quicksort_tag() { }
164  quicksort_tag(thread_index_t num_threads)
165  : parallel_tag(num_threads) { }
166  };
167 
168  /** @brief Forces parallel sorting using balanced quicksort
169  * at compile time. */
171  {
174  : parallel_tag(num_threads) { }
175  };
176 
177 
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 { };
181 
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 { };
185 
186  /** @brief Selects the equal splitting variant for std::find().
187  @see _GLIBCXX_FIND_EQUAL_SPLIT */
188  struct equal_split_tag : public find_tag { };
189 }
190 
191 #endif /* _GLIBCXX_PARALLEL_TAGS_H */
Forces parallel sorting using multiway mergesort at compile time.
Definition: tags.h:134
Forces parallel sorting using multiway mergesort with exact splitting at compile time.
Definition: tags.h:143
Selects the constant block size variant for std::find().
Definition: tags.h:184
Recommends parallel execution using OpenMP dynamic load-balancing at compile time.
Definition: tags.h:102
Forces parallel merging with exact splitting, at compile time.
Definition: tags.h:124
parallel_tag(thread_index_t num_threads)
Default constructor. Recommend number of threads to use.
Definition: tags.h:60
Selects the equal splitting variant for std::find().
Definition: tags.h:188
thread_index_t get_num_threads()
Find out desired number of threads.
Definition: tags.h:67
Forces parallel sorting using balanced quicksort at compile time.
Definition: tags.h:170
Forces parallel sorting using unbalanced quicksort at compile time.
Definition: tags.h:161
Forces parallel sorting using multiway mergesort with splitting by sampling at compile time...
Definition: tags.h:152
Recommends parallel execution using static load-balancing at compile time.
Definition: tags.h:98
void set_num_threads(thread_index_t num_threads)
Set the desired number of threads.
Definition: tags.h:77
parallel_tag()
Default constructor. Use default number of threads.
Definition: tags.h:53
Base class for for std::find() variants.
Definition: tags.h:110
Forces sequential execution at compile time.
Definition: tags.h:42
GNU parallel code for public use.
Selects the growing block size variant for std::find().
Definition: tags.h:180
Recommends parallel execution using OpenMP static load-balancing at compile time. ...
Definition: tags.h:106
Forces parallel merging with exact splitting, at compile time.
Definition: tags.h:115
Basic types and typedefs. This file is a GNU parallel extension to the Standard C++ Library...
uint16 thread_index_t
Unsigned integer to index a thread number. The maximum thread number (for each processor) must fit in...
Definition: types.h:141
Recommends parallel execution using dynamic load-balancing at compile time.
Definition: tags.h:94
Recommends parallel execution at compile time, optionally using a user-specified number of threads...
Definition: tags.h:46
Recommends parallel execution using the default parallel algorithm.
Definition: tags.h:85