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
This commit is contained in:
Benjamin Kosnik 2008-02-15 22:55:14 +00:00 committed by Benjamin Kosnik
parent 750606c6b2
commit 847eb5516f
12 changed files with 214 additions and 150 deletions

View File

@ -1,3 +1,18 @@
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.
2008-02-15 Hans-Peter Nilsson <hp@axis.com> 2008-02-15 Hans-Peter Nilsson <hp@axis.com>
* testsuite/config/default.exp: Load gcc dejapatches.exp. * testsuite/config/default.exp: Load gcc dejapatches.exp.
@ -20,7 +35,7 @@
2008-02-13 Benjamin Kosnik <bkoz@redhat.com> 2008-02-13 Benjamin Kosnik <bkoz@redhat.com>
* doc/doxygen/mainpage.html: Correct links. * doc/doxygen/mainpage.html: Correct links.
2008-02-11 Benjamin Kosnik <bkoz@redhat.com> 2008-02-11 Benjamin Kosnik <bkoz@redhat.com>
* doc/html/*: Populate with regenerated files. * doc/html/*: Populate with regenerated files.
@ -30,7 +45,7 @@
* doc/html/*: Remove all but contents of ext/pb_ds. * doc/html/*: Remove all but contents of ext/pb_ds.
* doc/html/index.html: New. * doc/html/index.html: New.
* doc/html/README: New. * doc/html/README: New.
2008-02-11 Benjamin Kosnik <bkoz@redhat.com> 2008-02-11 Benjamin Kosnik <bkoz@redhat.com>
* doc/doxygen/mainpage.html: Add in corrected links. * doc/doxygen/mainpage.html: Add in corrected links.
@ -40,7 +55,7 @@
* doc/xml/spine.xml: Edit file names. * doc/xml/spine.xml: Edit file names.
* doc/Makefile.am: Edit xml_sources. * doc/Makefile.am: Edit xml_sources.
* doc/Makefile.in: Regenerate. * doc/Makefile.in: Regenerate.
2008-02-11 Paolo Carlini <pcarlini@suse.de> 2008-02-11 Paolo Carlini <pcarlini@suse.de>
* configure: Regenerate with documented autoconf and automake * configure: Regenerate with documented autoconf and automake
@ -134,13 +149,13 @@
* doc/doxygen/guide.html: Removed, integrated into other docs. * doc/doxygen/guide.html: Removed, integrated into other docs.
* doc/doxygen/user.cfg.in: Clean up XML generation. * doc/doxygen/user.cfg.in: Clean up XML generation.
* doc/doxygen/run_doxygen: Move to.. * doc/doxygen/run_doxygen: Move to..
* scripts/run_doxygen: ...here. * scripts/run_doxygen: ...here.
* configure: Regenerate. * configure: Regenerate.
* Makefile.in: Regenerate. * Makefile.in: Regenerate.
* src/Makefile.in: Regenerate. * src/Makefile.in: Regenerate.
* doc/Makefile.in: Regenerate. * doc/Makefile.in: Regenerate.
* po/Makefile.in: Regenerate. * po/Makefile.in: Regenerate.
* libmath/Makefile.in: Regenerate. * libmath/Makefile.in: Regenerate.
* include/Makefile.in: Regenerate. * include/Makefile.in: Regenerate.
@ -162,7 +177,7 @@
* testsuite/27_io/basic_iostream/cons/2020.cc: Minor tweaks. * testsuite/27_io/basic_iostream/cons/2020.cc: Minor tweaks.
2008-01-31 Ralf Wildenhues <Ralf.Wildenhues@gmx.de> 2008-01-31 Ralf Wildenhues <Ralf.Wildenhues@gmx.de>
* include/backward/auto_ptr.h: Fix comment typos. * include/backward/auto_ptr.h: Fix comment typos.
* include/bits/algorithmfwd.h: Likewise. * include/bits/algorithmfwd.h: Likewise.
* include/bits/basic_ios.h: Likewise. * include/bits/basic_ios.h: Likewise.
@ -309,7 +324,7 @@
* doc/doxygen/run_doxygen: Same, more namespace fixups for man * doc/doxygen/run_doxygen: Same, more namespace fixups for man
generation. generation.
* doc/doxygen/user.cfg.in: Update for doxygen 1.5.4. * doc/doxygen/user.cfg.in: Update for doxygen 1.5.4.
* include/tr1_impl/random: Remove maint from doxygen markup. * include/tr1_impl/random: Remove maint from doxygen markup.
* include/tr1_impl/functional: Same. * include/tr1_impl/functional: Same.
* include/std/tuple: Same. * include/std/tuple: Same.
@ -343,7 +358,7 @@
* include/backward/auto_ptr.h: Same. * include/backward/auto_ptr.h: Same.
* testsuite/23_containers/vector/requirements/dr438/assign_neg.cc: * testsuite/23_containers/vector/requirements/dr438/assign_neg.cc:
Fixups for line number changes. Fixups for line number changes.
* testsuite/23_containers/vector/requirements/dr438/insert_neg.cc: Same. * testsuite/23_containers/vector/requirements/dr438/insert_neg.cc: Same.
* testsuite/23_containers/vector/requirements/dr438/ * testsuite/23_containers/vector/requirements/dr438/
constructor_1_neg.cc: Same. constructor_1_neg.cc: Same.
@ -375,7 +390,7 @@
* testsuite/Makefile.in: Regenerate. * testsuite/Makefile.in: Regenerate.
* scripts/make_graphs.py: Correct paths for new layout. * scripts/make_graphs.py: Correct paths for new layout.
2008-01-17 Benjamin Kosnik <bkoz@redhat.com> 2008-01-17 Benjamin Kosnik <bkoz@redhat.com>
* acinclude.m4 (AC_LC_MESSAGES): Remove serial. * acinclude.m4 (AC_LC_MESSAGES): Remove serial.

View File

@ -44,6 +44,37 @@
#include <parallel/parallel.h> #include <parallel/parallel.h>
#include <cstdio> #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 namespace __gnu_parallel
{ {
// XXX remove std::duplicates from here if possible, // XXX remove std::duplicates from here if possible,
@ -357,8 +388,8 @@ template<typename T, typename _DifferenceTp>
public: public:
typedef _DifferenceTp difference_type; typedef _DifferenceTp difference_type;
// Better case down to uint64, than up to _DifferenceTp. // Better case down to uint64_t, than up to _DifferenceTp.
typedef pseudo_sequence_iterator<T, uint64> iterator; typedef pseudo_sequence_iterator<T, uint64_t> iterator;
/** @brief Constructor. /** @brief Constructor.
* @param val Element of the sequence. * @param val Element of the sequence.
@ -437,8 +468,8 @@ __replacement_assert(const char* __file, int __line,
#define _GLIBCXX_PARALLEL_ASSERT(_Condition) \ #define _GLIBCXX_PARALLEL_ASSERT(_Condition) \
do \ do \
{ \ { \
if (!(_Condition)) \ if (!(_Condition)) \
__gnu_parallel::__replacement_assert(__FILE__, __LINE__, \ __gnu_parallel::__replacement_assert(__FILE__, __LINE__, \
__PRETTY_FUNCTION__, #_Condition); \ __PRETTY_FUNCTION__, #_Condition); \
} while (false) } while (false)

View File

@ -68,7 +68,7 @@ namespace __gnu_parallel
{ {
#if defined(__ICC) #if defined(__ICC)
template<typename must_be_int = int> 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" asm volatile("lock xadd %0,%1"
: "=r" (inc), "=m" (*x) : "=r" (inc), "=m" (*x)
@ -78,7 +78,7 @@ namespace __gnu_parallel
} }
#if defined(__x86_64) #if defined(__x86_64)
template<typename must_be_int = int> 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" asm volatile("lock xadd %0,%1"
: "=r" (inc), "=m" (*x) : "=r" (inc), "=m" (*x)
@ -97,8 +97,8 @@ namespace __gnu_parallel
* @param ptr Pointer to a 32-bit signed integer. * @param ptr Pointer to a 32-bit signed integer.
* @param addend Value to add. * @param addend Value to add.
*/ */
inline int32 inline int32_t
fetch_and_add_32(volatile int32* ptr, int32 addend) fetch_and_add_32(volatile int32_t* ptr, int32_t addend)
{ {
#if defined(__ICC) //x86 version #if defined(__ICC) //x86 version
return _InterlockedExchangeAdd((void*)ptr, addend); return _InterlockedExchangeAdd((void*)ptr, addend);
@ -110,7 +110,7 @@ namespace __gnu_parallel
#elif defined(__GNUC__) #elif defined(__GNUC__)
return __sync_fetch_and_add(ptr, addend); return __sync_fetch_and_add(ptr, addend);
#elif defined(__SUNPRO_CC) && defined(__sparc) #elif defined(__SUNPRO_CC) && defined(__sparc)
volatile int32 before, after; volatile int32_t before, after;
do do
{ {
before = *ptr; before = *ptr;
@ -120,7 +120,7 @@ namespace __gnu_parallel
return before; return before;
#else //fallback, slow #else //fallback, slow
#pragma message("slow fetch_and_add_32") #pragma message("slow fetch_and_add_32")
int32 res; int32_t res;
#pragma omp critical #pragma omp critical
{ {
res = *ptr; res = *ptr;
@ -136,11 +136,11 @@ namespace __gnu_parallel
* @param ptr Pointer to a 64-bit signed integer. * @param ptr Pointer to a 64-bit signed integer.
* @param addend Value to add. * @param addend Value to add.
*/ */
inline int64 inline int64_t
fetch_and_add_64(volatile int64* ptr, int64 addend) fetch_and_add_64(volatile int64_t* ptr, int64_t addend)
{ {
#if defined(__ICC) && defined(__x86_64) //x86 version #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 #elif defined(__ECC) //IA-64 version
return _InterlockedExchangeAdd64((void*)ptr, addend); return _InterlockedExchangeAdd64((void*)ptr, addend);
#elif defined(__ICL) || defined(_MSC_VER) #elif defined(__ICL) || defined(_MSC_VER)
@ -156,7 +156,7 @@ namespace __gnu_parallel
(defined(__i686) || defined(__pentium4) || defined(__athlon)) (defined(__i686) || defined(__pentium4) || defined(__athlon))
return __sync_fetch_and_add(ptr, addend); return __sync_fetch_and_add(ptr, addend);
#elif defined(__SUNPRO_CC) && defined(__sparc) #elif defined(__SUNPRO_CC) && defined(__sparc)
volatile int64 before, after; volatile int64_t before, after;
do do
{ {
before = *ptr; before = *ptr;
@ -170,7 +170,7 @@ namespace __gnu_parallel
//#warning "please compile with -march=i686 or better" //#warning "please compile with -march=i686 or better"
#endif #endif
#pragma message("slow fetch_and_add_64") #pragma message("slow fetch_and_add_64")
int64 res; int64_t res;
#pragma omp critical #pragma omp critical
{ {
res = *ptr; res = *ptr;
@ -190,10 +190,10 @@ namespace __gnu_parallel
inline T inline T
fetch_and_add(volatile T* ptr, T addend) fetch_and_add(volatile T* ptr, T addend)
{ {
if (sizeof(T) == sizeof(int32)) if (sizeof(T) == sizeof(int32_t))
return (T)fetch_and_add_32((volatile int32*) ptr, (int32)addend); return (T)fetch_and_add_32((volatile int32_t*) ptr, (int32_t)addend);
else if (sizeof(T) == sizeof(int64)) else if (sizeof(T) == sizeof(int64_t))
return (T)fetch_and_add_64((volatile int64*) ptr, (int64)addend); return (T)fetch_and_add_64((volatile int64_t*) ptr, (int64_t)addend);
else else
_GLIBCXX_PARALLEL_ASSERT(false); _GLIBCXX_PARALLEL_ASSERT(false);
} }
@ -202,10 +202,10 @@ namespace __gnu_parallel
#if defined(__ICC) #if defined(__ICC)
template<typename must_be_int = int> template<typename must_be_int = int>
inline int32 inline int32_t
cas32(volatile int32* ptr, int32 old, int32 nw) cas32(volatile int32_t* ptr, int32_t old, int32_t nw)
{ {
int32 before; int32_t before;
__asm__ __volatile__("lock; cmpxchgl %1,%2" __asm__ __volatile__("lock; cmpxchgl %1,%2"
: "=a"(before) : "=a"(before)
: "q"(nw), "m"(*(volatile long long*)(ptr)), "0"(old) : "q"(nw), "m"(*(volatile long long*)(ptr)), "0"(old)
@ -215,10 +215,10 @@ namespace __gnu_parallel
#if defined(__x86_64) #if defined(__x86_64)
template<typename must_be_int = int> template<typename must_be_int = int>
inline int64 inline int64_t
cas64(volatile int64 *ptr, int64 old, int64 nw) cas64(volatile int64_t *ptr, int64_t old, int64_t nw)
{ {
int64 before; int64_t before;
__asm__ __volatile__("lock; cmpxchgq %1,%2" __asm__ __volatile__("lock; cmpxchgq %1,%2"
: "=a"(before) : "=a"(before)
: "q"(nw), "m"(*(volatile long long*)(ptr)), "0"(old) : "q"(nw), "m"(*(volatile long long*)(ptr)), "0"(old)
@ -238,7 +238,7 @@ namespace __gnu_parallel
* @param replacement Replacement value. * @param replacement Replacement value.
*/ */
inline bool 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 #if defined(__ICC) //x86 version
return _InterlockedCompareExchange((void*)ptr, replacement, return _InterlockedCompareExchange((void*)ptr, replacement,
@ -278,7 +278,7 @@ namespace __gnu_parallel
* @param replacement Replacement value. * @param replacement Replacement value.
*/ */
inline bool 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 #if defined(__ICC) && defined(__x86_64) //x86 version
return cas64<int>(ptr, comparand, replacement) == comparand; return cas64<int>(ptr, comparand, replacement) == comparand;
@ -332,12 +332,10 @@ namespace __gnu_parallel
inline bool inline bool
compare_and_swap(volatile T* ptr, T comparand, T replacement) compare_and_swap(volatile T* ptr, T comparand, T replacement)
{ {
if (sizeof(T) == sizeof(int32)) if (sizeof(T) == sizeof(int32_t))
return compare_and_swap_32((volatile int32*) ptr, return compare_and_swap_32((volatile int32_t*) ptr, (int32_t)comparand, (int32_t)replacement);
(int32)comparand, (int32)replacement); else if (sizeof(T) == sizeof(int64_t))
else if (sizeof(T) == sizeof(int64)) return compare_and_swap_64((volatile int64_t*) ptr, (int64_t)comparand, (int64_t)replacement);
return compare_and_swap_64((volatile int64*) ptr,
(int64)comparand, (int64)replacement);
else else
_GLIBCXX_PARALLEL_ASSERT(false); _GLIBCXX_PARALLEL_ASSERT(false);
} }

View File

@ -67,7 +67,6 @@ namespace __gnu_parallel
public: public:
lexicographic(Comparator& _comp) : comp(_comp) { } lexicographic(Comparator& _comp) : comp(_comp) { }
// XXX const
bool bool
operator()(const std::pair<T1, T2>& p1, operator()(const std::pair<T1, T2>& p1,
const std::pair<T1, T2>& p2) const const std::pair<T1, T2>& p2) const
@ -265,7 +264,7 @@ namespace __gnu_parallel
} }
difference_type skew = static_cast<difference_type> 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) if (skew > 0)
{ {

View File

@ -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; 7,0x31b6ab00,15,0xffe50000,17, 0xa37d3c92> mt11213b;
// validation by experiment from mt19937.c // 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; 7,0x9d2c5680,15,0xefc60000,18, 3346425566U> mt19937;
/** @brief Random number generator, based on the Mersenne twister. */ /** @brief Random number generator, based on the Mersenne twister. */
@ -342,24 +342,24 @@ namespace __gnu_parallel
{ {
private: private:
mt19937 mt; mt19937 mt;
uint64 supremum, RAND_SUP; uint64_t supremum, RAND_SUP;
double supremum_reciprocal, RAND_SUP_REC; 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 */ int bits_left; /* bit results */
static uint32 static uint32_t
scale_down(uint64 x, scale_down(uint64_t x,
#if _GLIBCXX_SCALE_DOWN_FPU #if _GLIBCXX_SCALE_DOWN_FPU
uint64 /*supremum*/, double supremum_reciprocal) uint64_t /*supremum*/, double supremum_reciprocal)
#else #else
uint64 supremum, double /*supremum_reciprocal*/) uint64_t supremum, double /*supremum_reciprocal*/)
#endif #endif
{ {
#if _GLIBCXX_SCALE_DOWN_FPU #if _GLIBCXX_SCALE_DOWN_FPU
return (uint32)(x * supremum_reciprocal); return (uint32_t)(x * supremum_reciprocal);
#else #else
return static_cast<uint32>(x % supremum); return static_cast<uint32_t>(x % supremum);
#endif #endif
} }
@ -367,7 +367,7 @@ namespace __gnu_parallel
/** @brief Default constructor. Seed with 0. */ /** @brief Default constructor. Seed with 0. */
random_number() random_number()
: mt(0), supremum(0x100000000ULL), : mt(0), supremum(0x100000000ULL),
RAND_SUP(1ULL << (sizeof(uint32) * 8)), RAND_SUP(1ULL << (sizeof(uint32_t) * 8)),
supremum_reciprocal((double)supremum / (double)RAND_SUP), supremum_reciprocal((double)supremum / (double)RAND_SUP),
RAND_SUP_REC(1.0 / (double)RAND_SUP), RAND_SUP_REC(1.0 / (double)RAND_SUP),
cache(0), bits_left(0) { } cache(0), bits_left(0) { }
@ -376,22 +376,22 @@ namespace __gnu_parallel
* @param seed Random seed. * @param seed Random seed.
* @param supremum Generate integer random numbers in the * @param supremum Generate integer random numbers in the
* interval @c [0,supremum). */ * interval @c [0,supremum). */
random_number(uint32 seed, uint64 supremum = 0x100000000ULL) random_number(uint32_t seed, uint64_t supremum = 0x100000000ULL)
: mt(seed), supremum(supremum), : mt(seed), supremum(supremum),
RAND_SUP(1ULL << (sizeof(uint32) * 8)), RAND_SUP(1ULL << (sizeof(uint32_t) * 8)),
supremum_reciprocal((double)supremum / (double)RAND_SUP), supremum_reciprocal((double)supremum / (double)RAND_SUP),
RAND_SUP_REC(1.0 / (double)RAND_SUP), RAND_SUP_REC(1.0 / (double)RAND_SUP),
cache(0), bits_left(0) { } cache(0), bits_left(0) { }
/** @brief Generate unsigned random 32-bit integer. */ /** @brief Generate unsigned random 32-bit integer. */
uint32 uint32_t
operator()() operator()()
{ return scale_down(mt(), supremum, supremum_reciprocal); } { return scale_down(mt(), supremum, supremum_reciprocal); }
/** @brief Generate unsigned random 32-bit integer in the /** @brief Generate unsigned random 32-bit integer in the
interval @c [0,local_supremum). */ interval @c [0,local_supremum). */
uint32 uint32_t
operator()(uint64 local_supremum) operator()(uint64_t local_supremum)
{ {
return scale_down(mt(), local_supremum, return scale_down(mt(), local_supremum,
(double)local_supremum * RAND_SUP_REC); (double)local_supremum * RAND_SUP_REC);
@ -400,7 +400,7 @@ namespace __gnu_parallel
/** @brief Set the random seed. /** @brief Set the random seed.
* @param seed to set. */ * @param seed to set. */
void void
set_seed(uint32 seed) set_seed(uint32_t seed)
{ {
mt.seed(seed); mt.seed(seed);
cache = mt(); cache = mt();
@ -417,7 +417,7 @@ namespace __gnu_parallel
bits_left -= bits; bits_left -= bits;
if (bits_left < 32) if (bits_left < 32)
{ {
cache |= (((uint64)mt()) << bits_left); cache |= (((uint64_t)mt()) << bits_left);
bits_left += 32; bits_left += 32;
} }
return res; return res;
@ -433,7 +433,7 @@ namespace __gnu_parallel
bits_left -= bits; bits_left -= bits;
if (bits_left < 32) if (bits_left < 32)
{ {
cache |= (((uint64)mt()) << bits_left); cache |= (((uint64_t)mt()) << bits_left);
bits_left += 32; bits_left += 32;
} }
return res; return res;

View File

@ -106,7 +106,7 @@ template<typename RandomAccessIterator, typename RandomNumberGenerator>
bin_index bins_end; bin_index bins_end;
/** @brief Random seed for this thread. */ /** @brief Random seed for this thread. */
uint32 seed; uint32_t seed;
/** @brief Pointer to global data. */ /** @brief Pointer to global data. */
DRandomShufflingGlobalData<RandomAccessIterator>* sd; DRandomShufflingGlobalData<RandomAccessIterator>* sd;
@ -368,7 +368,7 @@ template<typename RandomAccessIterator, typename RandomNumberGenerator>
for (; j < bin_cursor; ++j) for (; j < bin_cursor; ++j)
sd.bin_proc[j] = i; sd.bin_proc[j] = i;
pus[i].num_threads = num_threads; 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; pus[i].sd = &sd;
} }
starts[num_threads] = start; starts[num_threads] = start;

View File

@ -30,7 +30,7 @@
/** /**
* @file parallel/tags.h * @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. * This file is a GNU parallel extension to the Standard C++ Library.
*/ */
@ -39,59 +39,8 @@
#ifndef _GLIBCXX_PARALLEL_TAGS_H #ifndef _GLIBCXX_PARALLEL_TAGS_H
#define _GLIBCXX_PARALLEL_TAGS_H 1 #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 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. */ /** @brief Forces sequential execution at compile time. */
struct sequential_tag { }; struct sequential_tag { };
@ -115,6 +64,7 @@ namespace __gnu_parallel
struct omp_loop_static_tag : public parallel_tag { }; struct omp_loop_static_tag : public parallel_tag { };
// XXX settings.h Settings::FindDistribution
/** @brief Selects the growing block size variant for std::find(). /** @brief Selects the growing block size variant for std::find().
@see _GLIBCXX_FIND_GROWING_BLOCKS */ @see _GLIBCXX_FIND_GROWING_BLOCKS */
struct growing_blocks_tag { }; struct growing_blocks_tag { };

View File

@ -1,6 +1,6 @@
// -*- C++ -*- // -*- 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 // 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 // software; you can redistribute it and/or modify it under the terms
@ -29,7 +29,7 @@
// Public License. // Public License.
/** @file parallel/types.h /** @file parallel/types.h
* @brief Basic typedefs. * @brief Basic types and typedefs.
* This file is a GNU parallel extension to the Standard C++ Library. * This file is a GNU parallel extension to the Standard C++ Library.
*/ */
@ -39,51 +39,120 @@
#define _GLIBCXX_PARALLEL_TYPES_H 1 #define _GLIBCXX_PARALLEL_TYPES_H 1
#include <cstdlib> #include <cstdlib>
#include <tr1/cstdint>
namespace __gnu_parallel namespace __gnu_parallel
{ {
// XXX need to use <cstdint> // Enumerated types.
/** @brief 8-bit signed integer. */
typedef char int8;
/** @brief 8-bit unsigned integer. */ /// @brief Run-time equivalents for the compile-time tags.
typedef unsigned char uint8; enum parallelism
{
/// Not parallel.
sequential,
/** @brief 16-bit signed integer. */ /// Parallel unbalanced (equal-sized chunks).
typedef short int16; parallel_unbalanced,
/** @brief 16-bit unsigned integer. */ /// Parallel balanced (work-stealing).
typedef unsigned short uint16; parallel_balanced,
/** @brief 32-bit signed integer. */ /// Parallel with OpenMP dynamic load-balancing.
typedef int int32; parallel_omp_loop,
/** @brief 32-bit unsigned integer. */ /// Parallel with OpenMP static load-balancing.
typedef unsigned int uint32; parallel_omp_loop_static,
/** @brief 64-bit signed integer. */ /// Parallel with OpenMP taskqueue construct.
typedef long long int64; parallel_taskqueue
};
/** @brief 64-bit unsigned integer. */ inline bool
typedef unsigned long long uint64; 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. * @brief Unsigned integer to index elements.
* The total number of elements for each algorithm must fit into this type. * 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. * @brief Unsigned integer to index a thread number.
* The maximum thread number (for each processor) must fit into this type. * 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. * @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. * @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. * @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 */ #endif /* _GLIBCXX_TYPES_H */

View File

@ -214,11 +214,12 @@ concept-inst.lo: concept-inst.cc
concept-inst.o: concept-inst.cc concept-inst.o: concept-inst.cc
$(CXXCOMPILE) -D_GLIBCXX_CONCEPT_CHECKS -fimplicit-templates -c $< $(CXXCOMPILE) -D_GLIBCXX_CONCEPT_CHECKS -fimplicit-templates -c $<
# Use special rules for parallel_list.cc compile. # Use special rules for parallel mode compilation.
PARALLEL_FLAGS = -fopenmp -D_GLIBCXX_PARALLEL -I$(glibcxx_builddir)/../libgomp
parallel_list.lo: parallel_list.cc parallel_list.lo: parallel_list.cc
$(LTCXXCOMPILE) -I$(glibcxx_builddir)/../libgomp -c $< $(LTCXXCOMPILE) $(PARALLEL_FLAGS) -c $<
parallel_list.o: parallel_list.cc parallel_list.o: parallel_list.cc
$(CXXCOMPILE) -I$(glibcxx_builddir)/../libgomp -c $< $(CXXCOMPILE) $(PARALLEL_FLAGS) -c $<
# Use special rules for the C++0x sources so that the proper flags are passed. # Use special rules for the C++0x sources so that the proper flags are passed.
system_error.lo: system_error.cc system_error.lo: system_error.cc

View File

@ -429,6 +429,9 @@ libstdc___la_LDFLAGS = \
# deprecated include files. # deprecated include files.
GLIBCXX_INCLUDE_DIR = $(glibcxx_builddir)/include GLIBCXX_INCLUDE_DIR = $(glibcxx_builddir)/include
# Use special rules for parallel mode compilation.
PARALLEL_FLAGS = -fopenmp -D_GLIBCXX_PARALLEL -I$(glibcxx_builddir)/../libgomp
# AM_CXXFLAGS needs to be in each subdirectory so that it can be # AM_CXXFLAGS needs to be in each subdirectory so that it can be
# modified in a per-library or per-sub-library way. Need to manually # modified in a per-library or per-sub-library way. Need to manually
# set this option because CONFIG_CXXFLAGS has to be after # set this option because CONFIG_CXXFLAGS has to be after
@ -802,12 +805,10 @@ concept-inst.lo: concept-inst.cc
$(LTCXXCOMPILE) -D_GLIBCXX_CONCEPT_CHECKS -fimplicit-templates -c $< $(LTCXXCOMPILE) -D_GLIBCXX_CONCEPT_CHECKS -fimplicit-templates -c $<
concept-inst.o: concept-inst.cc concept-inst.o: concept-inst.cc
$(CXXCOMPILE) -D_GLIBCXX_CONCEPT_CHECKS -fimplicit-templates -c $< $(CXXCOMPILE) -D_GLIBCXX_CONCEPT_CHECKS -fimplicit-templates -c $<
# Use special rules for parallel_list.cc compile.
parallel_list.lo: parallel_list.cc parallel_list.lo: parallel_list.cc
$(LTCXXCOMPILE) -I$(glibcxx_builddir)/../libgomp -c $< $(LTCXXCOMPILE) $(PARALLEL_FLAGS) -c $<
parallel_list.o: parallel_list.cc parallel_list.o: parallel_list.cc
$(CXXCOMPILE) -I$(glibcxx_builddir)/../libgomp -c $< $(CXXCOMPILE) $(PARALLEL_FLAGS) -c $<
# Use special rules for the C++0x sources so that the proper flags are passed. # Use special rules for the C++0x sources so that the proper flags are passed.
system_error.lo: system_error.cc system_error.lo: system_error.cc

View File

@ -27,6 +27,4 @@
// invalidate any other reasons why the executable file might be covered by // invalidate any other reasons why the executable file might be covered by
// the GNU General Public License. // the GNU General Public License.
#define _GLIBCXX_PARALLEL
#include "list.cc" #include "list.cc"

View File

@ -49,6 +49,7 @@ test2()
void void
test3() test3()
{ {
bool test __attribute__((unused)) = true;
int array[] = {6, 5, 4, 3, 2, 1, 0}; int array[] = {6, 5, 4, 3, 2, 1, 0};
Container con(array, array + 7); Container con(array, array + 7);
nth_element(con.begin(), con.it(3), con.end()); nth_element(con.begin(), con.it(3), con.end());
@ -61,6 +62,7 @@ test3()
void void
test4() test4()
{ {
bool test __attribute__((unused)) = true;
int array[] = {0, 6, 1, 5, 2, 4, 3}; int array[] = {0, 6, 1, 5, 2, 4, 3};
Container con(array,array + 7); Container con(array,array + 7);
nth_element(con.begin(), con.it(3), con.end()); nth_element(con.begin(), con.it(3), con.end());