libstdc++
|
00001 // -*- C++ -*- 00002 00003 // Copyright (C) 2007, 2008, 2009 Free Software Foundation, Inc. 00004 // 00005 // This file is part of the GNU ISO C++ Library. This library is free 00006 // software; you can redistribute it and/or modify it under the terms 00007 // of the GNU General Public License as published by the Free Software 00008 // Foundation; either version 3, or (at your option) any later 00009 // version. 00010 00011 // This library is distributed in the hope that it will be useful, but 00012 // WITHOUT ANY WARRANTY; without even the implied warranty of 00013 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 00014 // General Public License for more details. 00015 00016 // Under Section 7 of GPL version 3, you are granted additional 00017 // permissions described in the GCC Runtime Library Exception, version 00018 // 3.1, as published by the Free Software Foundation. 00019 00020 // You should have received a copy of the GNU General Public License and 00021 // a copy of the GCC Runtime Library Exception along with this program; 00022 // see the files COPYING3 and COPYING.RUNTIME respectively. If not, see 00023 // <http://www.gnu.org/licenses/>. 00024 00025 /** 00026 * @file parallel/tags.h 00027 * @brief Tags for compile-time selection. 00028 * This file is a GNU parallel extension to the Standard C++ Library. 00029 */ 00030 00031 // Written by Johannes Singler and Felix Putze. 00032 00033 #ifndef _GLIBCXX_PARALLEL_TAGS_H 00034 #define _GLIBCXX_PARALLEL_TAGS_H 1 00035 00036 #include <omp.h> 00037 #include <parallel/types.h> 00038 00039 namespace __gnu_parallel 00040 { 00041 /** @brief Forces sequential execution at compile time. */ 00042 struct sequential_tag { }; 00043 00044 /** @brief Recommends parallel execution at compile time, 00045 * optionally using a user-specified number of threads. */ 00046 struct parallel_tag 00047 { 00048 private: 00049 _ThreadIndex _M_num_threads; 00050 00051 public: 00052 /** @brief Default constructor. Use default number of threads. */ 00053 parallel_tag() 00054 { _M_num_threads = 0; } 00055 00056 /** @brief Default constructor. Recommend number of threads to use. 00057 * @param __num_threads Desired number of threads. */ 00058 parallel_tag(_ThreadIndex __num_threads) 00059 { _M_num_threads = __num_threads; } 00060 00061 /** @brief Find out desired number of threads. 00062 * @return Desired number of threads. */ 00063 _ThreadIndex __get_num_threads() 00064 { 00065 if(_M_num_threads == 0) 00066 return omp_get_max_threads(); 00067 else 00068 return _M_num_threads; 00069 } 00070 00071 /** @brief Set the desired number of threads. 00072 * @param __num_threads Desired number of threads. */ 00073 void set_num_threads(_ThreadIndex __num_threads) 00074 { _M_num_threads = __num_threads; } 00075 }; 00076 00077 /** @brief Recommends parallel execution using the 00078 default parallel algorithm. */ 00079 struct default_parallel_tag : public parallel_tag 00080 { 00081 default_parallel_tag() { } 00082 default_parallel_tag(_ThreadIndex __num_threads) 00083 : parallel_tag(__num_threads) { } 00084 }; 00085 00086 /** @brief Recommends parallel execution using dynamic 00087 load-balancing at compile time. */ 00088 struct balanced_tag : public parallel_tag { }; 00089 00090 /** @brief Recommends parallel execution using static 00091 load-balancing at compile time. */ 00092 struct unbalanced_tag : public parallel_tag { }; 00093 00094 /** @brief Recommends parallel execution using OpenMP dynamic 00095 load-balancing at compile time. */ 00096 struct omp_loop_tag : public parallel_tag { }; 00097 00098 /** @brief Recommends parallel execution using OpenMP static 00099 load-balancing at compile time. */ 00100 struct omp_loop_static_tag : public parallel_tag { }; 00101 00102 00103 /** @brief Base class for for std::find() variants. */ 00104 struct find_tag { }; 00105 00106 00107 /** @brief Forces parallel merging 00108 * with exact splitting, at compile time. */ 00109 struct exact_tag : public parallel_tag 00110 { 00111 exact_tag() { } 00112 exact_tag(_ThreadIndex __num_threads) 00113 : parallel_tag(__num_threads) { } 00114 }; 00115 00116 /** @brief Forces parallel merging 00117 * with exact splitting, at compile time. */ 00118 struct sampling_tag : public parallel_tag 00119 { 00120 sampling_tag() { } 00121 sampling_tag(_ThreadIndex __num_threads) 00122 : parallel_tag(__num_threads) { } 00123 }; 00124 00125 00126 /** @brief Forces parallel sorting using multiway mergesort 00127 * at compile time. */ 00128 struct multiway_mergesort_tag : public parallel_tag 00129 { 00130 multiway_mergesort_tag() { } 00131 multiway_mergesort_tag(_ThreadIndex __num_threads) 00132 : parallel_tag(__num_threads) { } 00133 }; 00134 00135 /** @brief Forces parallel sorting using multiway mergesort 00136 * with exact splitting at compile time. */ 00137 struct multiway_mergesort_exact_tag : public parallel_tag 00138 { 00139 multiway_mergesort_exact_tag() { } 00140 multiway_mergesort_exact_tag(_ThreadIndex __num_threads) 00141 : parallel_tag(__num_threads) { } 00142 }; 00143 00144 /** @brief Forces parallel sorting using multiway mergesort 00145 * with splitting by sampling at compile time. */ 00146 struct multiway_mergesort_sampling_tag : public parallel_tag 00147 { 00148 multiway_mergesort_sampling_tag() { } 00149 multiway_mergesort_sampling_tag(_ThreadIndex __num_threads) 00150 : parallel_tag(__num_threads) { } 00151 }; 00152 00153 /** @brief Forces parallel sorting using unbalanced quicksort 00154 * at compile time. */ 00155 struct quicksort_tag : public parallel_tag 00156 { 00157 quicksort_tag() { } 00158 quicksort_tag(_ThreadIndex __num_threads) 00159 : parallel_tag(__num_threads) { } 00160 }; 00161 00162 /** @brief Forces parallel sorting using balanced quicksort 00163 * at compile time. */ 00164 struct balanced_quicksort_tag : public parallel_tag 00165 { 00166 balanced_quicksort_tag() { } 00167 balanced_quicksort_tag(_ThreadIndex __num_threads) 00168 : parallel_tag(__num_threads) { } 00169 }; 00170 00171 00172 /** @brief Selects the growing block size variant for std::find(). 00173 @see _GLIBCXX_FIND_GROWING_BLOCKS */ 00174 struct growing_blocks_tag : public find_tag { }; 00175 00176 /** @brief Selects the constant block size variant for std::find(). 00177 @see _GLIBCXX_FIND_CONSTANT_SIZE_BLOCKS */ 00178 struct constant_size_blocks_tag : public find_tag { }; 00179 00180 /** @brief Selects the equal splitting variant for std::find(). 00181 @see _GLIBCXX_FIND_EQUAL_SPLIT */ 00182 struct equal_split_tag : public find_tag { }; 00183 } 00184 00185 #endif /* _GLIBCXX_PARALLEL_TAGS_H */