diff options
author | Benjamin Kosnik <bkoz@redhat.com> | 2008-02-15 22:55:14 +0000 |
---|---|---|
committer | Benjamin Kosnik <bkoz@gcc.gnu.org> | 2008-02-15 22:55:14 +0000 |
commit | 847eb5516fad658dfdf9d1d4b5ec2eec5e628fdd (patch) | |
tree | 9f3bbe671a305300df03669d118aef62e91ed107 /libstdc++-v3/include | |
parent | 750606c6b235a3d7e1d5fcdfbc5f3f1f68efcefe (diff) | |
download | gcc-847eb5516fad658dfdf9d1d4b5ec2eec5e628fdd.zip gcc-847eb5516fad658dfdf9d1d4b5ec2eec5e628fdd.tar.gz gcc-847eb5516fad658dfdf9d1d4b5ec2eec5e628fdd.tar.bz2 |
types.h: Move enum parallelism here.
2008-02-15 Benjamin Kosnik <bkoz@redhat.com>
* include/parallel/types.h: Move enum parallelism here. Use
tr1/cstdint's int16_t, uint16_t, int32_t, uint32_t, int64_t,
uint64_t.
* include/parallel/multiseq_selection.h: Adjust for cstdint.
* include/parallel/compatibility.h: Same.
* include/parallel/tags.h: Just compile-time tags.
* include/parallel/base.h: Put namespace bits here.
* src/Makefile.am (PARALLEL_FLAGS): Use it.
* src/Makefile.in: Regenerate.
* testsuite/25_algorithms/nth_element/1.cc: Add test variable.
From-SVN: r132354
Diffstat (limited to 'libstdc++-v3/include')
-rw-r--r-- | libstdc++-v3/include/parallel/base.h | 39 | ||||
-rw-r--r-- | libstdc++-v3/include/parallel/compatibility.h | 56 | ||||
-rw-r--r-- | libstdc++-v3/include/parallel/multiseq_selection.h | 3 | ||||
-rw-r--r-- | libstdc++-v3/include/parallel/random_number.h | 38 | ||||
-rw-r--r-- | libstdc++-v3/include/parallel/random_shuffle.h | 4 | ||||
-rw-r--r-- | libstdc++-v3/include/parallel/tags.h | 54 | ||||
-rw-r--r-- | libstdc++-v3/include/parallel/types.h | 129 |
7 files changed, 185 insertions, 138 deletions
diff --git a/libstdc++-v3/include/parallel/base.h b/libstdc++-v3/include/parallel/base.h index 8d1c073..23ad7d6 100644 --- a/libstdc++-v3/include/parallel/base.h +++ b/libstdc++-v3/include/parallel/base.h @@ -44,6 +44,37 @@ #include <parallel/parallel.h> #include <cstdio> + +// Parallel mode namespaces. +namespace std +{ + namespace __parallel { } +} + +/** + * @namespace __gnu_parallel + * @brief GNU parallel classes for public use. + */ +namespace __gnu_parallel +{ + // Import all the parallel versions of components in namespace std. + using namespace std::__parallel; +} + +/** + * @namespace __gnu_sequential + * @brief GNU sequential classes for public use. + */ +namespace __gnu_sequential +{ +#ifdef _GLIBCXX_PARALLEL + using namespace std::__norm; +#else + using namespace std; +#endif +} + + namespace __gnu_parallel { // XXX remove std::duplicates from here if possible, @@ -357,8 +388,8 @@ template<typename T, typename _DifferenceTp> public: typedef _DifferenceTp difference_type; - // Better case down to uint64, than up to _DifferenceTp. - typedef pseudo_sequence_iterator<T, uint64> iterator; + // Better case down to uint64_t, than up to _DifferenceTp. + typedef pseudo_sequence_iterator<T, uint64_t> iterator; /** @brief Constructor. * @param val Element of the sequence. @@ -437,8 +468,8 @@ __replacement_assert(const char* __file, int __line, #define _GLIBCXX_PARALLEL_ASSERT(_Condition) \ do \ { \ - if (!(_Condition)) \ - __gnu_parallel::__replacement_assert(__FILE__, __LINE__, \ + if (!(_Condition)) \ + __gnu_parallel::__replacement_assert(__FILE__, __LINE__, \ __PRETTY_FUNCTION__, #_Condition); \ } while (false) diff --git a/libstdc++-v3/include/parallel/compatibility.h b/libstdc++-v3/include/parallel/compatibility.h index c4e9061..849849b 100644 --- a/libstdc++-v3/include/parallel/compatibility.h +++ b/libstdc++-v3/include/parallel/compatibility.h @@ -68,7 +68,7 @@ namespace __gnu_parallel { #if defined(__ICC) template<typename must_be_int = int> - int32 faa32(int32* x, int32 inc) + int32_t faa32(int32_t* x, int32_t inc) { asm volatile("lock xadd %0,%1" : "=r" (inc), "=m" (*x) @@ -78,7 +78,7 @@ namespace __gnu_parallel } #if defined(__x86_64) template<typename must_be_int = int> - int64 faa64(int64* x, int64 inc) + int64_t faa64(int64_t* x, int64_t inc) { asm volatile("lock xadd %0,%1" : "=r" (inc), "=m" (*x) @@ -97,8 +97,8 @@ namespace __gnu_parallel * @param ptr Pointer to a 32-bit signed integer. * @param addend Value to add. */ - inline int32 - fetch_and_add_32(volatile int32* ptr, int32 addend) + inline int32_t + fetch_and_add_32(volatile int32_t* ptr, int32_t addend) { #if defined(__ICC) //x86 version return _InterlockedExchangeAdd((void*)ptr, addend); @@ -110,7 +110,7 @@ namespace __gnu_parallel #elif defined(__GNUC__) return __sync_fetch_and_add(ptr, addend); #elif defined(__SUNPRO_CC) && defined(__sparc) - volatile int32 before, after; + volatile int32_t before, after; do { before = *ptr; @@ -120,7 +120,7 @@ namespace __gnu_parallel return before; #else //fallback, slow #pragma message("slow fetch_and_add_32") - int32 res; + int32_t res; #pragma omp critical { res = *ptr; @@ -136,11 +136,11 @@ namespace __gnu_parallel * @param ptr Pointer to a 64-bit signed integer. * @param addend Value to add. */ - inline int64 - fetch_and_add_64(volatile int64* ptr, int64 addend) + inline int64_t + fetch_and_add_64(volatile int64_t* ptr, int64_t addend) { #if defined(__ICC) && defined(__x86_64) //x86 version - return faa64<int>((int64*)ptr, addend); + return faa64<int>((int64_t*)ptr, addend); #elif defined(__ECC) //IA-64 version return _InterlockedExchangeAdd64((void*)ptr, addend); #elif defined(__ICL) || defined(_MSC_VER) @@ -156,7 +156,7 @@ namespace __gnu_parallel (defined(__i686) || defined(__pentium4) || defined(__athlon)) return __sync_fetch_and_add(ptr, addend); #elif defined(__SUNPRO_CC) && defined(__sparc) - volatile int64 before, after; + volatile int64_t before, after; do { before = *ptr; @@ -170,7 +170,7 @@ namespace __gnu_parallel //#warning "please compile with -march=i686 or better" #endif #pragma message("slow fetch_and_add_64") - int64 res; + int64_t res; #pragma omp critical { res = *ptr; @@ -190,10 +190,10 @@ namespace __gnu_parallel inline T fetch_and_add(volatile T* ptr, T addend) { - if (sizeof(T) == sizeof(int32)) - return (T)fetch_and_add_32((volatile int32*) ptr, (int32)addend); - else if (sizeof(T) == sizeof(int64)) - return (T)fetch_and_add_64((volatile int64*) ptr, (int64)addend); + if (sizeof(T) == sizeof(int32_t)) + return (T)fetch_and_add_32((volatile int32_t*) ptr, (int32_t)addend); + else if (sizeof(T) == sizeof(int64_t)) + return (T)fetch_and_add_64((volatile int64_t*) ptr, (int64_t)addend); else _GLIBCXX_PARALLEL_ASSERT(false); } @@ -202,10 +202,10 @@ namespace __gnu_parallel #if defined(__ICC) template<typename must_be_int = int> - inline int32 - cas32(volatile int32* ptr, int32 old, int32 nw) + inline int32_t + cas32(volatile int32_t* ptr, int32_t old, int32_t nw) { - int32 before; + int32_t before; __asm__ __volatile__("lock; cmpxchgl %1,%2" : "=a"(before) : "q"(nw), "m"(*(volatile long long*)(ptr)), "0"(old) @@ -215,10 +215,10 @@ namespace __gnu_parallel #if defined(__x86_64) template<typename must_be_int = int> - inline int64 - cas64(volatile int64 *ptr, int64 old, int64 nw) + inline int64_t + cas64(volatile int64_t *ptr, int64_t old, int64_t nw) { - int64 before; + int64_t before; __asm__ __volatile__("lock; cmpxchgq %1,%2" : "=a"(before) : "q"(nw), "m"(*(volatile long long*)(ptr)), "0"(old) @@ -238,7 +238,7 @@ namespace __gnu_parallel * @param replacement Replacement value. */ inline bool - compare_and_swap_32(volatile int32* ptr, int32 comparand, int32 replacement) + compare_and_swap_32(volatile int32_t* ptr, int32_t comparand, int32_t replacement) { #if defined(__ICC) //x86 version return _InterlockedCompareExchange((void*)ptr, replacement, @@ -278,7 +278,7 @@ namespace __gnu_parallel * @param replacement Replacement value. */ inline bool - compare_and_swap_64(volatile int64* ptr, int64 comparand, int64 replacement) + compare_and_swap_64(volatile int64_t* ptr, int64_t comparand, int64_t replacement) { #if defined(__ICC) && defined(__x86_64) //x86 version return cas64<int>(ptr, comparand, replacement) == comparand; @@ -332,12 +332,10 @@ namespace __gnu_parallel inline bool compare_and_swap(volatile T* ptr, T comparand, T replacement) { - if (sizeof(T) == sizeof(int32)) - return compare_and_swap_32((volatile int32*) ptr, - (int32)comparand, (int32)replacement); - else if (sizeof(T) == sizeof(int64)) - return compare_and_swap_64((volatile int64*) ptr, - (int64)comparand, (int64)replacement); + if (sizeof(T) == sizeof(int32_t)) + return compare_and_swap_32((volatile int32_t*) ptr, (int32_t)comparand, (int32_t)replacement); + else if (sizeof(T) == sizeof(int64_t)) + return compare_and_swap_64((volatile int64_t*) ptr, (int64_t)comparand, (int64_t)replacement); else _GLIBCXX_PARALLEL_ASSERT(false); } diff --git a/libstdc++-v3/include/parallel/multiseq_selection.h b/libstdc++-v3/include/parallel/multiseq_selection.h index 32f1b53..88d2a50 100644 --- a/libstdc++-v3/include/parallel/multiseq_selection.h +++ b/libstdc++-v3/include/parallel/multiseq_selection.h @@ -67,7 +67,6 @@ namespace __gnu_parallel public: lexicographic(Comparator& _comp) : comp(_comp) { } - // XXX const bool operator()(const std::pair<T1, T2>& p1, const std::pair<T1, T2>& p2) const @@ -265,7 +264,7 @@ namespace __gnu_parallel } difference_type skew = static_cast<difference_type> - (static_cast<uint64>(total) * rank / N - leftsize); + (static_cast<uint64_t>(total) * rank / N - leftsize); if (skew > 0) { diff --git a/libstdc++-v3/include/parallel/random_number.h b/libstdc++-v3/include/parallel/random_number.h index ae52372..5eb2462 100644 --- a/libstdc++-v3/include/parallel/random_number.h +++ b/libstdc++-v3/include/parallel/random_number.h @@ -330,11 +330,11 @@ namespace __gnu_parallel } - typedef mersenne_twister<uint32,32,351,175,19,0xccab8ee7,11, + typedef mersenne_twister<uint32_t,32,351,175,19,0xccab8ee7,11, 7,0x31b6ab00,15,0xffe50000,17, 0xa37d3c92> mt11213b; // validation by experiment from mt19937.c - typedef mersenne_twister<uint32,32,624,397,31,0x9908b0df,11, + typedef mersenne_twister<uint32_t,32,624,397,31,0x9908b0df,11, 7,0x9d2c5680,15,0xefc60000,18, 3346425566U> mt19937; /** @brief Random number generator, based on the Mersenne twister. */ @@ -342,24 +342,24 @@ namespace __gnu_parallel { private: mt19937 mt; - uint64 supremum, RAND_SUP; + uint64_t supremum, RAND_SUP; double supremum_reciprocal, RAND_SUP_REC; - uint64 cache; /* assumed to be twice as long as the usual random number */ + uint64_t cache; /* assumed to be twice as long as the usual random number */ int bits_left; /* bit results */ - static uint32 - scale_down(uint64 x, + static uint32_t + scale_down(uint64_t x, #if _GLIBCXX_SCALE_DOWN_FPU - uint64 /*supremum*/, double supremum_reciprocal) + uint64_t /*supremum*/, double supremum_reciprocal) #else - uint64 supremum, double /*supremum_reciprocal*/) + uint64_t supremum, double /*supremum_reciprocal*/) #endif { #if _GLIBCXX_SCALE_DOWN_FPU - return (uint32)(x * supremum_reciprocal); + return (uint32_t)(x * supremum_reciprocal); #else - return static_cast<uint32>(x % supremum); + return static_cast<uint32_t>(x % supremum); #endif } @@ -367,7 +367,7 @@ namespace __gnu_parallel /** @brief Default constructor. Seed with 0. */ random_number() : mt(0), supremum(0x100000000ULL), - RAND_SUP(1ULL << (sizeof(uint32) * 8)), + RAND_SUP(1ULL << (sizeof(uint32_t) * 8)), supremum_reciprocal((double)supremum / (double)RAND_SUP), RAND_SUP_REC(1.0 / (double)RAND_SUP), cache(0), bits_left(0) { } @@ -376,22 +376,22 @@ namespace __gnu_parallel * @param seed Random seed. * @param supremum Generate integer random numbers in the * interval @c [0,supremum). */ - random_number(uint32 seed, uint64 supremum = 0x100000000ULL) + random_number(uint32_t seed, uint64_t supremum = 0x100000000ULL) : mt(seed), supremum(supremum), - RAND_SUP(1ULL << (sizeof(uint32) * 8)), + RAND_SUP(1ULL << (sizeof(uint32_t) * 8)), supremum_reciprocal((double)supremum / (double)RAND_SUP), RAND_SUP_REC(1.0 / (double)RAND_SUP), cache(0), bits_left(0) { } /** @brief Generate unsigned random 32-bit integer. */ - uint32 + uint32_t operator()() { return scale_down(mt(), supremum, supremum_reciprocal); } /** @brief Generate unsigned random 32-bit integer in the interval @c [0,local_supremum). */ - uint32 - operator()(uint64 local_supremum) + uint32_t + operator()(uint64_t local_supremum) { return scale_down(mt(), local_supremum, (double)local_supremum * RAND_SUP_REC); @@ -400,7 +400,7 @@ namespace __gnu_parallel /** @brief Set the random seed. * @param seed to set. */ void - set_seed(uint32 seed) + set_seed(uint32_t seed) { mt.seed(seed); cache = mt(); @@ -417,7 +417,7 @@ namespace __gnu_parallel bits_left -= bits; if (bits_left < 32) { - cache |= (((uint64)mt()) << bits_left); + cache |= (((uint64_t)mt()) << bits_left); bits_left += 32; } return res; @@ -433,7 +433,7 @@ namespace __gnu_parallel bits_left -= bits; if (bits_left < 32) { - cache |= (((uint64)mt()) << bits_left); + cache |= (((uint64_t)mt()) << bits_left); bits_left += 32; } return res; diff --git a/libstdc++-v3/include/parallel/random_shuffle.h b/libstdc++-v3/include/parallel/random_shuffle.h index 348a3a3..2b71789 100644 --- a/libstdc++-v3/include/parallel/random_shuffle.h +++ b/libstdc++-v3/include/parallel/random_shuffle.h @@ -106,7 +106,7 @@ template<typename RandomAccessIterator, typename RandomNumberGenerator> bin_index bins_end; /** @brief Random seed for this thread. */ - uint32 seed; + uint32_t seed; /** @brief Pointer to global data. */ DRandomShufflingGlobalData<RandomAccessIterator>* sd; @@ -368,7 +368,7 @@ template<typename RandomAccessIterator, typename RandomNumberGenerator> for (; j < bin_cursor; ++j) sd.bin_proc[j] = i; pus[i].num_threads = num_threads; - pus[i].seed = rng(std::numeric_limits<uint32>::max()); + pus[i].seed = rng(std::numeric_limits<uint32_t>::max()); pus[i].sd = &sd; } starts[num_threads] = start; diff --git a/libstdc++-v3/include/parallel/tags.h b/libstdc++-v3/include/parallel/tags.h index c3d33e8..1389aed 100644 --- a/libstdc++-v3/include/parallel/tags.h +++ b/libstdc++-v3/include/parallel/tags.h @@ -30,7 +30,7 @@ /** * @file parallel/tags.h - * @brief Tags for compile-time options. + * @brief Tags for compile-time selection. * This file is a GNU parallel extension to the Standard C++ Library. */ @@ -39,59 +39,8 @@ #ifndef _GLIBCXX_PARALLEL_TAGS_H #define _GLIBCXX_PARALLEL_TAGS_H 1 -// Parallel mode namespaces. -namespace std -{ - namespace __parallel { } -} - -/** - * @namespace __gnu_sequential - * @brief GNU sequential classes for public use. - */ -namespace __gnu_sequential -{ -#ifdef _GLIBCXX_PARALLEL - using namespace std::__norm; -#else - using namespace std; -#endif -} - -/** - * @namespace __gnu_parallel - * @brief GNU parallel classes for public use. - */ namespace __gnu_parallel { - // Import all the parallel versions of components in namespace std. - using namespace std::__parallel; - - enum parallelism - { - /// Not parallel. - sequential, - - /// Parallel unbalanced (equal-sized chunks). - parallel_unbalanced, - - /// Parallel balanced (work-stealing). - parallel_balanced, - - /// Parallel with OpenMP dynamic load-balancing. - parallel_omp_loop, - - /// Parallel with OpenMP static load-balancing. - parallel_omp_loop_static, - - /// Parallel with OpenMP taskqueue construct. - parallel_taskqueue - }; - - inline bool - is_parallel(const parallelism __p) { return __p != sequential; } - - /** @brief Forces sequential execution at compile time. */ struct sequential_tag { }; @@ -115,6 +64,7 @@ namespace __gnu_parallel struct omp_loop_static_tag : public parallel_tag { }; + // XXX settings.h Settings::FindDistribution /** @brief Selects the growing block size variant for std::find(). @see _GLIBCXX_FIND_GROWING_BLOCKS */ struct growing_blocks_tag { }; diff --git a/libstdc++-v3/include/parallel/types.h b/libstdc++-v3/include/parallel/types.h index 5f8014f..2f0e459 100644 --- a/libstdc++-v3/include/parallel/types.h +++ b/libstdc++-v3/include/parallel/types.h @@ -1,6 +1,6 @@ // -*- C++ -*- -// Copyright (C) 2007 Free Software Foundation, Inc. +// Copyright (C) 2007, 2008 Free Software Foundation, Inc. // // This file is part of the GNU ISO C++ Library. This library is free // software; you can redistribute it and/or modify it under the terms @@ -29,7 +29,7 @@ // Public License. /** @file parallel/types.h - * @brief Basic typedefs. + * @brief Basic types and typedefs. * This file is a GNU parallel extension to the Standard C++ Library. */ @@ -39,51 +39,120 @@ #define _GLIBCXX_PARALLEL_TYPES_H 1 #include <cstdlib> +#include <tr1/cstdint> namespace __gnu_parallel { - // XXX need to use <cstdint> - /** @brief 8-bit signed integer. */ - typedef char int8; - - /** @brief 8-bit unsigned integer. */ - typedef unsigned char uint8; - - /** @brief 16-bit signed integer. */ - typedef short int16; - - /** @brief 16-bit unsigned integer. */ - typedef unsigned short uint16; - - /** @brief 32-bit signed integer. */ - typedef int int32; - - /** @brief 32-bit unsigned integer. */ - typedef unsigned int uint32; - - /** @brief 64-bit signed integer. */ - typedef long long int64; - - /** @brief 64-bit unsigned integer. */ - typedef unsigned long long uint64; + // Enumerated types. + + /// @brief Run-time equivalents for the compile-time tags. + enum parallelism + { + /// Not parallel. + sequential, + + /// Parallel unbalanced (equal-sized chunks). + parallel_unbalanced, + + /// Parallel balanced (work-stealing). + parallel_balanced, + + /// Parallel with OpenMP dynamic load-balancing. + parallel_omp_loop, + + /// Parallel with OpenMP static load-balancing. + parallel_omp_loop_static, + + /// Parallel with OpenMP taskqueue construct. + parallel_taskqueue + }; + + inline bool + is_parallel(const parallelism __p) { return __p != sequential; } + + /// @brief Sorting algorithms: multi-way mergesort, quicksort, + /// load-balanced quicksort. + enum SortAlgorithm + { + MWMS, + QS, + QS_BALANCED + }; + + /// @brief Merging algorithms: bubblesort-alike, loser-tree + /// variants, enum sentinel. + enum MultiwayMergeAlgorithm + { + BUBBLE, + LOSER_TREE_EXPLICIT, + LOSER_TREE, + LOSER_TREE_COMBINED, + LOSER_TREE_SENTINEL, + MWM_ALGORITHM_LAST + }; + + /// @brief Partial sum algorithms: recursive, linear. + enum PartialSumAlgorithm + { + RECURSIVE, + LINEAR + }; + + /// @brief Splitting strategies for sorting/merging: sampling, exact. + enum Splitting + { + SAMPLING, + EXACT + }; + + /// @brief Find distribution strategies: growing blocks, equal-sized + /// blocks, equal splitting. + enum FindDistribution + { + GROWING_BLOCKS, + CONSTANT_SIZE_BLOCKS, + EQUAL_SPLIT + }; + + /// @brief Strategies for run-time algorithm selection: + /// force_sequential, force_parallel, heuristic. + enum AlgorithmSelection + { + heuristic, + force_sequential, + force_parallel + }; + + + /// Integer Types. + using std::tr1::int16_t; + using std::tr1::uint16_t; + + using std::tr1::int32_t; + using std::tr1::uint32_t; + + using std::tr1::int64_t; + using std::tr1::uint64_t; /** * @brief Unsigned integer to index elements. * The total number of elements for each algorithm must fit into this type. */ - typedef uint64 sequence_index_t; + typedef uint64_t sequence_index_t; /** * @brief Unsigned integer to index a thread number. * The maximum thread number (for each processor) must fit into this type. */ - typedef uint16 thread_index_t; + typedef uint16_t thread_index_t; + // XXX atomics interface? /** * @brief Longest compare-and-swappable integer type on this platform. */ - typedef int64 lcas_t; + typedef int64_t lcas_t; + // XXX numeric_limits::digits? /** * @brief Number of bits of ::lcas_t. */ @@ -92,7 +161,7 @@ namespace __gnu_parallel /** * @brief ::lcas_t with the right half of bits set to 1. */ - static const lcas_t lcas_t_mask = (((lcas_t)1 << (lcas_t_bits / 2)) - 1); + static const lcas_t lcas_t_mask = ((lcas_t(1) << (lcas_t_bits / 2)) - 1); } #endif /* _GLIBCXX_TYPES_H */ |