summaryrefslogtreecommitdiff
path: root/libstdc++-v3/include/parallel/equally_split.h
diff options
context:
space:
mode:
Diffstat (limited to 'libstdc++-v3/include/parallel/equally_split.h')
-rw-r--r--libstdc++-v3/include/parallel/equally_split.h99
1 files changed, 49 insertions, 50 deletions
diff --git a/libstdc++-v3/include/parallel/equally_split.h b/libstdc++-v3/include/parallel/equally_split.h
index 31ed87d16f3..481c9886840 100644
--- a/libstdc++-v3/include/parallel/equally_split.h
+++ b/libstdc++-v3/include/parallel/equally_split.h
@@ -1,6 +1,6 @@
// -*- C++ -*-
-// Copyright (C) 2007, 2009 Free Software Foundation, Inc.
+// Copyright (C) 2007, 2008, 2009 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
@@ -33,57 +33,56 @@
namespace __gnu_parallel
{
-/** @brief function to split a sequence into parts of almost equal size.
- *
- * The resulting sequence __s of length __num_threads+1 contains the splitting
- * positions when splitting the range [0,__n) into parts of almost
- * equal size (plus minus 1). The first entry is 0, the last one
-* n. There may result empty parts.
- * @param __n Number of elements
- * @param __num_threads Number of parts
- * @param __s Splitters
- * @returns End of __splitter sequence, i.e. @__c __s+__num_threads+1 */
-template<typename _DifferenceType, typename _OutputIterator>
- _OutputIterator
- equally_split(_DifferenceType __n, _ThreadIndex __num_threads,
- _OutputIterator __s)
- {
- _DifferenceType __chunk_length = __n / __num_threads;
- _DifferenceType __num_longer_chunks = __n % __num_threads;
- _DifferenceType __pos = 0;
- for (_ThreadIndex __i = 0; __i < __num_threads; ++__i)
- {
- *__s++ = __pos;
- __pos += (__i < __num_longer_chunks) ?
- (__chunk_length + 1) : __chunk_length;
- }
- *__s++ = __n;
- return __s;
- }
+ /** @brief function to split a sequence into parts of almost equal size.
+ *
+ * The resulting sequence __s of length __num_threads+1 contains the
+ * splitting positions when splitting the range [0,__n) into parts of
+ * almost equal size (plus minus 1). The first entry is 0, the last
+ * one n. There may result empty parts.
+ * @param __n Number of elements
+ * @param __num_threads Number of parts
+ * @param __s Splitters
+ * @returns End of __splitter sequence, i.e. @c __s+__num_threads+1 */
+ template<typename _DifferenceType, typename _OutputIterator>
+ _OutputIterator
+ equally_split(_DifferenceType __n, _ThreadIndex __num_threads,
+ _OutputIterator __s)
+ {
+ _DifferenceType __chunk_length = __n / __num_threads;
+ _DifferenceType __num_longer_chunks = __n % __num_threads;
+ _DifferenceType __pos = 0;
+ for (_ThreadIndex __i = 0; __i < __num_threads; ++__i)
+ {
+ *__s++ = __pos;
+ __pos += ((__i < __num_longer_chunks)
+ ? (__chunk_length + 1) : __chunk_length);
+ }
+ *__s++ = __n;
+ return __s;
+ }
-
-/** @brief function to split a sequence into parts of almost equal size.
- *
- * Returns the position of the splitting point between
- * thread number __thread_no (included) and
- * thread number __thread_no+1 (excluded).
- * @param __n Number of elements
- * @param __num_threads Number of parts
- * @returns splitting point */
-template<typename _DifferenceType>
- _DifferenceType
- equally_split_point(_DifferenceType __n,
- _ThreadIndex __num_threads,
- _ThreadIndex __thread_no)
- {
- _DifferenceType __chunk_length = __n / __num_threads;
- _DifferenceType __num_longer_chunks = __n % __num_threads;
- if (__thread_no < __num_longer_chunks)
- return __thread_no * (__chunk_length + 1);
- else
- return __num_longer_chunks * (__chunk_length + 1)
+ /** @brief function to split a sequence into parts of almost equal size.
+ *
+ * Returns the position of the splitting point between
+ * thread number __thread_no (included) and
+ * thread number __thread_no+1 (excluded).
+ * @param __n Number of elements
+ * @param __num_threads Number of parts
+ * @returns splitting point */
+ template<typename _DifferenceType>
+ _DifferenceType
+ equally_split_point(_DifferenceType __n,
+ _ThreadIndex __num_threads,
+ _ThreadIndex __thread_no)
+ {
+ _DifferenceType __chunk_length = __n / __num_threads;
+ _DifferenceType __num_longer_chunks = __n % __num_threads;
+ if (__thread_no < __num_longer_chunks)
+ return __thread_no * (__chunk_length + 1);
+ else
+ return __num_longer_chunks * (__chunk_length + 1)
+ (__thread_no - __num_longer_chunks) * __chunk_length;
- }
+ }
}
#endif /* _GLIBCXX_PARALLEL_EQUALLY_SPLIT_H */