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. */ 53 parallel_tag() 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. */ 60 parallel_tag(thread_index_t num_threads) 61 { 62 this->num_threads = num_threads; 63 } 64 65 /** @brief Find out desired number of threads. 66 * @return Desired number of threads. */ 67 inline thread_index_t get_num_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. */ 85 struct default_parallel_tag : public parallel_tag 86 { 87 default_parallel_tag() { } 88 default_parallel_tag(thread_index_t num_threads) 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. */ 134 struct multiway_mergesort_tag : public parallel_tag 135 { 136 multiway_mergesort_tag() { } 137 multiway_mergesort_tag(thread_index_t num_threads) 138 : parallel_tag(num_threads) { } 139 }; 140 141 /** @brief Forces parallel sorting using multiway mergesort 142 * with exact splitting at compile time. */ 143 struct multiway_mergesort_exact_tag : public parallel_tag 144 { 145 multiway_mergesort_exact_tag() { } 146 multiway_mergesort_exact_tag(thread_index_t num_threads) 147 : parallel_tag(num_threads) { } 148 }; 149 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 153 { 154 multiway_mergesort_sampling_tag() { } 155 multiway_mergesort_sampling_tag(thread_index_t num_threads) 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. */ 170 struct balanced_quicksort_tag : public parallel_tag 171 { 172 balanced_quicksort_tag() { } 173 balanced_quicksort_tag(thread_index_t num_threads) 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 */ 192