tags.h

Go to the documentation of this file.
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       thread_index_t num_threads;
00050 
00051     public:
00052       /** @brief Default constructor. Use default number of threads. */
00053       parallel_tag()
00054       {
00055         this->num_threads = 0;
00056       }
00057 
00058       /** @brief Default constructor. Recommend number of threads to use.
00059        *  @param num_threads Desired number of threads. */
00060       parallel_tag(thread_index_t num_threads)
00061       {
00062         this->num_threads = num_threads;
00063       }
00064 
00065       /** @brief Find out desired number of threads.
00066        *  @return Desired number of threads. */
00067       inline thread_index_t get_num_threads()
00068       {
00069         if(num_threads == 0)
00070           return omp_get_max_threads();
00071         else
00072           return num_threads;
00073       }
00074 
00075       /** @brief Set the desired number of threads.
00076        *  @param num_threads Desired number of threads. */
00077       inline void set_num_threads(thread_index_t num_threads)
00078       {
00079         this->num_threads = num_threads;
00080       }
00081   };
00082 
00083   /** @brief Recommends parallel execution using the
00084       default parallel algorithm. */
00085   struct default_parallel_tag : public parallel_tag
00086   {
00087       default_parallel_tag() { }
00088       default_parallel_tag(thread_index_t num_threads)
00089           : parallel_tag(num_threads) { }
00090   };
00091 
00092   /** @brief Recommends parallel execution using dynamic
00093       load-balancing at compile time. */
00094   struct balanced_tag : public parallel_tag { };
00095 
00096   /** @brief Recommends parallel execution using static
00097       load-balancing at compile time. */
00098   struct unbalanced_tag : public parallel_tag { };
00099 
00100   /** @brief Recommends parallel execution using OpenMP dynamic
00101       load-balancing at compile time. */
00102   struct omp_loop_tag : public parallel_tag { };
00103 
00104   /** @brief Recommends parallel execution using OpenMP static
00105       load-balancing at compile time. */
00106   struct omp_loop_static_tag : public parallel_tag { };
00107 
00108 
00109   /** @brief Base class for for std::find() variants. */
00110   struct find_tag { };
00111 
00112 
00113   /** @brief Forces parallel merging
00114    *  with exact splitting, at compile time. */
00115   struct exact_tag : public parallel_tag
00116   {
00117       exact_tag() { }
00118       exact_tag(thread_index_t num_threads)
00119           : parallel_tag(num_threads) { }
00120   };
00121 
00122   /** @brief Forces parallel merging
00123    *  with exact splitting, at compile time. */
00124   struct sampling_tag : public parallel_tag
00125   {
00126       sampling_tag() { }
00127       sampling_tag(thread_index_t num_threads)
00128           : parallel_tag(num_threads) { }
00129   };
00130 
00131 
00132   /** @brief Forces parallel sorting using multiway mergesort
00133    *  at compile time. */
00134   struct multiway_mergesort_tag : public parallel_tag
00135   {
00136       multiway_mergesort_tag() { }
00137       multiway_mergesort_tag(thread_index_t num_threads)
00138           : parallel_tag(num_threads) { }
00139   };
00140 
00141   /** @brief Forces parallel sorting using multiway mergesort
00142    *  with exact splitting at compile time. */
00143   struct multiway_mergesort_exact_tag : public parallel_tag
00144   {
00145       multiway_mergesort_exact_tag() { }
00146       multiway_mergesort_exact_tag(thread_index_t num_threads)
00147           : parallel_tag(num_threads) { }
00148   };
00149 
00150   /** @brief Forces parallel sorting using multiway mergesort
00151    *  with splitting by sampling at compile time. */
00152   struct multiway_mergesort_sampling_tag : public parallel_tag
00153   {
00154       multiway_mergesort_sampling_tag() { }
00155       multiway_mergesort_sampling_tag(thread_index_t num_threads)
00156           : parallel_tag(num_threads) { }
00157   };
00158 
00159   /** @brief Forces parallel sorting using unbalanced quicksort
00160    *  at compile time. */
00161   struct quicksort_tag : public parallel_tag
00162   {
00163       quicksort_tag() { }
00164       quicksort_tag(thread_index_t num_threads)
00165           : parallel_tag(num_threads) { }
00166   };
00167 
00168   /** @brief Forces parallel sorting using balanced quicksort
00169    *  at compile time. */
00170   struct balanced_quicksort_tag : public parallel_tag
00171   {
00172       balanced_quicksort_tag() { }
00173       balanced_quicksort_tag(thread_index_t num_threads)
00174           : parallel_tag(num_threads) { }
00175   };
00176 
00177 
00178   /** @brief Selects the growing block size variant for std::find().
00179       @see _GLIBCXX_FIND_GROWING_BLOCKS */
00180   struct growing_blocks_tag : public find_tag { };
00181 
00182   /** @brief Selects the constant block size variant for std::find().
00183       @see _GLIBCXX_FIND_CONSTANT_SIZE_BLOCKS */
00184   struct constant_size_blocks_tag : public find_tag { };
00185 
00186   /** @brief Selects the equal splitting variant for std::find().
00187       @see _GLIBCXX_FIND_EQUAL_SPLIT */
00188   struct equal_split_tag : public find_tag { };
00189 }
00190 
00191 #endif /* _GLIBCXX_PARALLEL_TAGS_H */

Generated on 19 Jun 2018 for libstdc++ by  doxygen 1.6.1