1*38fd1498Szrj // -*- C++ -*-
2*38fd1498Szrj 
3*38fd1498Szrj // Copyright (C) 2007-2018 Free Software Foundation, Inc.
4*38fd1498Szrj //
5*38fd1498Szrj // This file is part of the GNU ISO C++ Library.  This library is free
6*38fd1498Szrj // software; you can redistribute it and/or modify it under the terms
7*38fd1498Szrj // of the GNU General Public License as published by the Free Software
8*38fd1498Szrj // Foundation; either version 3, or (at your option) any later
9*38fd1498Szrj // version.
10*38fd1498Szrj 
11*38fd1498Szrj // This library is distributed in the hope that it will be useful, but
12*38fd1498Szrj // WITHOUT ANY WARRANTY; without even the implied warranty of
13*38fd1498Szrj // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
14*38fd1498Szrj // General Public License for more details.
15*38fd1498Szrj 
16*38fd1498Szrj // Under Section 7 of GPL version 3, you are granted additional
17*38fd1498Szrj // permissions described in the GCC Runtime Library Exception, version
18*38fd1498Szrj // 3.1, as published by the Free Software Foundation.
19*38fd1498Szrj 
20*38fd1498Szrj // You should have received a copy of the GNU General Public License and
21*38fd1498Szrj // a copy of the GCC Runtime Library Exception along with this program;
22*38fd1498Szrj // see the files COPYING3 and COPYING.RUNTIME respectively.  If not, see
23*38fd1498Szrj // <http://www.gnu.org/licenses/>.
24*38fd1498Szrj 
25*38fd1498Szrj /** @file parallel/types.h
26*38fd1498Szrj  *  @brief Basic types and typedefs.
27*38fd1498Szrj  *  This file is a GNU parallel extension to the Standard C++ Library.
28*38fd1498Szrj  */
29*38fd1498Szrj 
30*38fd1498Szrj // Written by Johannes Singler and Felix Putze.
31*38fd1498Szrj 
32*38fd1498Szrj #ifndef _GLIBCXX_PARALLEL_TYPES_H
33*38fd1498Szrj #define _GLIBCXX_PARALLEL_TYPES_H 1
34*38fd1498Szrj 
35*38fd1498Szrj #include <cstdlib>
36*38fd1498Szrj #include <limits>
37*38fd1498Szrj #include <tr1/cstdint>
38*38fd1498Szrj 
39*38fd1498Szrj namespace __gnu_parallel
40*38fd1498Szrj {
41*38fd1498Szrj   // Enumerated types.
42*38fd1498Szrj 
43*38fd1498Szrj   /// Run-time equivalents for the compile-time tags.
44*38fd1498Szrj   enum _Parallelism
45*38fd1498Szrj     {
46*38fd1498Szrj       /// Not parallel.
47*38fd1498Szrj       sequential,
48*38fd1498Szrj 
49*38fd1498Szrj       /// Parallel unbalanced (equal-sized chunks).
50*38fd1498Szrj       parallel_unbalanced,
51*38fd1498Szrj 
52*38fd1498Szrj       /// Parallel balanced (work-stealing).
53*38fd1498Szrj       parallel_balanced,
54*38fd1498Szrj 
55*38fd1498Szrj       /// Parallel with OpenMP dynamic load-balancing.
56*38fd1498Szrj       parallel_omp_loop,
57*38fd1498Szrj 
58*38fd1498Szrj       /// Parallel with OpenMP static load-balancing.
59*38fd1498Szrj       parallel_omp_loop_static,
60*38fd1498Szrj 
61*38fd1498Szrj       /// Parallel with OpenMP taskqueue construct.
62*38fd1498Szrj       parallel_taskqueue
63*38fd1498Szrj     };
64*38fd1498Szrj 
65*38fd1498Szrj   /// Strategies for run-time algorithm selection:
66*38fd1498Szrj   // force_sequential, force_parallel, heuristic.
67*38fd1498Szrj   enum _AlgorithmStrategy
68*38fd1498Szrj     {
69*38fd1498Szrj       heuristic,
70*38fd1498Szrj       force_sequential,
71*38fd1498Szrj       force_parallel
72*38fd1498Szrj     };
73*38fd1498Szrj 
74*38fd1498Szrj   /// Sorting algorithms:
75*38fd1498Szrj   // multi-way mergesort, quicksort, load-balanced quicksort.
76*38fd1498Szrj   enum _SortAlgorithm
77*38fd1498Szrj     {
78*38fd1498Szrj       MWMS,
79*38fd1498Szrj       QS,
80*38fd1498Szrj       QS_BALANCED
81*38fd1498Szrj     };
82*38fd1498Szrj 
83*38fd1498Szrj   /// Merging algorithms:
84*38fd1498Szrj   // bubblesort-alike, loser-tree variants, enum __sentinel.
85*38fd1498Szrj   enum _MultiwayMergeAlgorithm
86*38fd1498Szrj     {
87*38fd1498Szrj       LOSER_TREE
88*38fd1498Szrj     };
89*38fd1498Szrj 
90*38fd1498Szrj   /// Partial sum algorithms: recursive, linear.
91*38fd1498Szrj   enum _PartialSumAlgorithm
92*38fd1498Szrj     {
93*38fd1498Szrj       RECURSIVE,
94*38fd1498Szrj       LINEAR
95*38fd1498Szrj     };
96*38fd1498Szrj 
97*38fd1498Szrj   /// Sorting/merging algorithms: sampling, __exact.
98*38fd1498Szrj   enum _SplittingAlgorithm
99*38fd1498Szrj     {
100*38fd1498Szrj       SAMPLING,
101*38fd1498Szrj       EXACT
102*38fd1498Szrj     };
103*38fd1498Szrj 
104*38fd1498Szrj   /// Find algorithms:
105*38fd1498Szrj   // growing blocks, equal-sized blocks, equal splitting.
106*38fd1498Szrj   enum _FindAlgorithm
107*38fd1498Szrj     {
108*38fd1498Szrj       GROWING_BLOCKS,
109*38fd1498Szrj       CONSTANT_SIZE_BLOCKS,
110*38fd1498Szrj       EQUAL_SPLIT
111*38fd1498Szrj     };
112*38fd1498Szrj 
113*38fd1498Szrj   /**
114*38fd1498Szrj    * @brief Unsigned integer to index __elements.
115*38fd1498Szrj    * The total number of elements for each algorithm must fit into this type.
116*38fd1498Szrj    */
117*38fd1498Szrj   typedef uint64_t _SequenceIndex;
118*38fd1498Szrj 
119*38fd1498Szrj   /**
120*38fd1498Szrj    * @brief Unsigned integer to index a thread number.
121*38fd1498Szrj    * The maximum thread number (for each processor) must fit into this type.
122*38fd1498Szrj    */
123*38fd1498Szrj   typedef uint16_t _ThreadIndex;
124*38fd1498Szrj 
125*38fd1498Szrj   // XXX atomics interface?
126*38fd1498Szrj   /// Longest compare-and-swappable integer type on this platform.
127*38fd1498Szrj   typedef int64_t _CASable;
128*38fd1498Szrj 
129*38fd1498Szrj   /// Number of bits of _CASable.
130*38fd1498Szrj   static const int _CASable_bits = std::numeric_limits<_CASable>::digits;
131*38fd1498Szrj 
132*38fd1498Szrj   /// ::_CASable with the right half of bits set to 1.
133*38fd1498Szrj   static const _CASable _CASable_mask =
134*38fd1498Szrj                             ((_CASable(1) << (_CASable_bits / 2)) - 1);
135*38fd1498Szrj }
136*38fd1498Szrj 
137*38fd1498Szrj #endif /* _GLIBCXX_PARALLEL_TYPES_H */
138