File: parallel_algorithms.h

package info (click to toggle)
seqan2 2.4.0%2Bdfsg-16
  • links: PTS, VCS
  • area: main
  • in suites: sid, trixie
  • size: 224,180 kB
  • sloc: cpp: 256,886; ansic: 91,672; python: 8,330; sh: 995; xml: 570; makefile: 252; awk: 51; javascript: 21
file content (839 lines) | stat: -rw-r--r-- 31,944 bytes parent folder | download | duplicates (5)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
// ==========================================================================
//                 SeqAn - The Library for Sequence Analysis
// ==========================================================================
// Copyright (c) 2006-2018, Knut Reinert, FU Berlin
// All rights reserved.
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions are met:
//
//     * Redistributions of source code must retain the above copyright
//       notice, this list of conditions and the following disclaimer.
//     * Redistributions in binary form must reproduce the above copyright
//       notice, this list of conditions and the following disclaimer in the
//       documentation and/or other materials provided with the distribution.
//     * Neither the name of Knut Reinert or the FU Berlin nor the names of
//       its contributors may be used to endorse or promote products derived
//       from this software without specific prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
// AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
// ARE DISCLAIMED. IN NO EVENT SHALL KNUT REINERT OR THE FU BERLIN BE LIABLE
// FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
// DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
// SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
// CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
// LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
// OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
// DAMAGE.
//
// ==========================================================================
// Author: David Weese <david.weese@fu-berlin.de>
// ==========================================================================
// Basic parallel algorithms.
// ==========================================================================

#ifndef SEQAN_PARALLEL_PARALLEL_ALGORITHMS_H_
#define SEQAN_PARALLEL_PARALLEL_ALGORITHMS_H_

namespace seqan {

// ============================================================================
// Functions
// ============================================================================

// ----------------------------------------------------------------------------
// Function arrayFill
// ----------------------------------------------------------------------------

template <typename TIterator, typename TValue, typename TParallelTag>
inline void
arrayFill(TIterator begin_,
          TIterator end_,
          TValue const & value,
          Tag<TParallelTag> parallelTag)
{
    Splitter<TIterator> splitter(begin_, end_, parallelTag);

    SEQAN_OMP_PRAGMA(parallel for)
    for (int job = 0; job < (int)length(splitter); ++job)
        arrayFill(splitter[job], splitter[job + 1], value, Serial());
}

// ----------------------------------------------------------------------------
// Function sum
// ----------------------------------------------------------------------------

/*!
 * @fn sum
 * @headerfile <seqan/parallel.h>
 * @brief Returns the sum of all elements in a sequence.
 *
 * @signature TValue sum(seq[, parallelTag]);
 *
 * @param[in] seq         The sequence to sum up, o ftype <tt>TSequence</tt>.
 * @param[in] parallelTag Tag to enable/disable parallelism, one of <tt>Serial</tt> and <tt>Parallel</tt>,
 *                        default is <tt>Serial</tt>.
 *
 * @return TValue The sum of the elements in <tt>seq</tt>, of type <tt>Value&lt;TSequence&gt;::Type</tt>.
 *
 * The sequence alphabet must support the <tt>operator+</tt> and conversion from zero.
 *
 * @see partialSum
 */

template <typename TSequence>
inline typename Value<TSequence>::Type
sum(TSequence const &seq, Serial)
{
    typename Iterator<TSequence const>::Type it = begin(seq, Standard());
    typename Iterator<TSequence const>::Type itEnd = end(seq, Standard());
    typename Value<TSequence>::Type sum = 0;
    for (; it != itEnd; ++it)
        sum += *it;
    return sum;
}

template <typename TSequence, typename TParallelTag>
inline typename Value<TSequence>::Type
sum(TSequence const &seq, Tag<TParallelTag> parallelTag)
{
    Splitter<typename Size<TSequence>::Type> splitter(0, length(seq), parallelTag);

    typename Value<TSequence>::Type threadSum = 0;
    SEQAN_OMP_PRAGMA(parallel for reduction(+:threadSum))
    for (int job = 0; job < (int)length(splitter); ++job)
        threadSum += sum(infix(seq, splitter[job], splitter[job + 1]), Serial());
    return threadSum;
}

template <typename TSequence>
inline typename Value<TSequence>::Type
sum(TSequence const &seq)
{
    return sum(seq, Serial());
}

// ----------------------------------------------------------------------------
// Function partialSum
// ----------------------------------------------------------------------------

/*!
 * @fn partialSum
 * @headerfile <seqan/parallel.h>
 * @brief Computes the partial sum of a sequence.
 *
 * @signature TValue partialSum(target, source[, parallelTag]);
 *
 * @param[in]  source      A sequence of elements that should be partially summed.  The sequence alphabet must support
 *                         the <tt>operator+</tt> and conversion from zero, the type is <tt>TSource</tt>.
 * @param[in]  parallelTag Tag to enable/disable parallelism, one of <tt>Serial</tt>, <tt>Parallel</tt>, default is
 *                         <tt>Serial</tt>.
 * @param[out] target      The resulting partial sum.  This sequence will have the same length as <tt>source</tt> and
 *                         contains at position <tt>i</tt> the sum of elements <tt>source[0]</tt>, <tt>source[1]</tt>,
 *                         ..., <tt>source[i]</tt>.
 *
 * @return TValue The sum of all elements in <tt>source</tt>.  The returned value equals the last value in target.
 *                <tt>TValue</tt> is <tt>Value&lt;TSource&gt;::Type</tt>.
 *
 * @see sum
 */

template <typename TTarget, typename TSource, typename TParallelTag>
inline typename Value<TSource>::Type
partialSum(TTarget &target, TSource const &source, Tag<TParallelTag> parallelTag)
{
    typedef typename Value<TSource>::Type TValue;
    typedef typename Size<TSource>::Type TSize;
    typedef typename Iterator<TSource const, Standard>::Type TConstIterator;
    typedef typename Iterator<TTarget, Standard>::Type TIterator;

    resize(target, length(source), Exact());
    if (empty(target))
        return 0;

    Splitter<TSize> splitter(0, length(source), parallelTag);
    String<TValue> localSums;
    resize(localSums, length(splitter), Exact());
    localSums[0] = 0;

    // STEP 1: compute sums of all subintervals (in parallel)
    //
    SEQAN_OMP_PRAGMA(parallel for num_threads(length(splitter)))
    for (int job = 0; job < (int)length(splitter) - 1; ++job)
        localSums[job + 1] = sum(infix(source, splitter[job], splitter[job + 1]), Serial());

    // STEP 2: compute partial sums (of subinterval sums) to get offsets for each subinterval (sequentially)
    //
    for (int job = 2; job < (int)length(splitter); ++job)
        localSums[job] += localSums[job - 1];

    // STEP 3: compute partial sums of each subinterval starting from offset (in parallel)
    //
    SEQAN_OMP_PRAGMA(parallel for num_threads(length(splitter)))
    for (int job = 0; job < (int)length(splitter); ++job)
    {
        TConstIterator it = begin(source, Standard()) + splitter[job];
        TConstIterator itEnd = begin(source, Standard()) + splitter[job + 1];
        TIterator dstIt = begin(target, Standard()) + splitter[job];
        TValue sum = localSums[job];
        for (; it != itEnd; ++it, ++dstIt)
        {
            sum += *it;
            *dstIt = sum;
        }
        localSums[job] = sum;
    }

    return back(localSums);
}

template <typename TTarget, typename TParallelTag>
inline typename Value<TTarget>::Type
partialSum(TTarget & target, Tag<TParallelTag> parallelTag)
{
    return partialSum(target, target, parallelTag);
}

template <typename TTarget, typename TSource>
inline typename Value<TSource>::Type
partialSum(TTarget & target, TSource const & source)
{
    return partialSum(target, source, Serial());
}

template <typename TTarget>
inline typename Value<TTarget>::Type
partialSum(TTarget & target)
{
    return partialSum(target, target);
}

// ----------------------------------------------------------------------------
// Function iterate()
// ----------------------------------------------------------------------------

template <typename TContainer, typename TFunctor, typename TIterTag, typename TParallelTag>
inline void iterate(TContainer & c, TFunctor f, Tag<TIterTag> const & iterTag, Tag<TParallelTag> const & /* tag */)
{
    typedef Tag<TIterTag> const                                     TIterSpec;
    typedef typename Iterator<TContainer, TIterSpec>::Type          TIter;

    for (TIter it = begin(c, iterTag); !atEnd(it, c); ++it)
        f(it);
}

// ----------------------------------------------------------------------------
// Function iterate(Parallel)
// ----------------------------------------------------------------------------

template <typename TContainer, typename TFunctor, typename TIterTag>
inline void iterate(TContainer & c, TFunctor f, Tag<TIterTag> const & iterTag, Parallel)
{
    typedef Tag<TIterTag> const                                     TIterSpec;
    typedef typename Position<TContainer>::Type                     TPos;
    typedef typename std::make_signed<TPos>::type                   TSignedPos;
    typedef typename Iterator<TContainer, TIterSpec>::Type          TIter;

    Splitter<TPos> splitter(0, length(c), Parallel());

    SEQAN_OMP_PRAGMA(parallel for firstprivate(f))
    for (TSignedPos i = 0; i < static_cast<TSignedPos>(length(splitter)); ++i)
    {
       TIter it = begin(c, iterTag) + splitter[i];
       TIter itEnd = begin(c, iterTag) + splitter[i + 1];

       for (; it != itEnd; ++it)
            f(it);
    }
}

// ----------------------------------------------------------------------------
// Function iterate()
// ----------------------------------------------------------------------------

template <typename TContainer, typename TFunctor>
inline void iterate(TContainer & c, TFunctor f)
{
    iterate(c, f, typename DefaultIteratorSpec<TContainer>::Type(), Serial());
}

// ============================================================================
// STL Wrappers
// ============================================================================

// ----------------------------------------------------------------------------
// Function forEach()
// ----------------------------------------------------------------------------

template <typename TContainer, typename TFunctor, typename TParallelTag>
inline TFunctor
forEach(TContainer & c, TFunctor f, Tag<TParallelTag> const & /* tag */)
{
    return std::for_each(begin(c, Standard()), end(c, Standard()), f);
}

template <typename TContainer, typename TFunctor, typename TParallelTag>
inline TFunctor
forEach(TContainer const & c, TFunctor f, Tag<TParallelTag> const & /* tag */)
{
    return std::for_each(begin(c, Standard()), end(c, Standard()), f);
}

// ----------------------------------------------------------------------------
// Function transform()
// ----------------------------------------------------------------------------

template <typename TTarget, typename TSource, typename TUnaryOperator, typename TParallelTag>
inline void transform(TTarget & target, TSource & source, TUnaryOperator o, Tag<TParallelTag> const & /* tag */)
{
    SEQAN_ASSERT_GEQ(length(target), length(source));
    std::transform(begin(source, Standard()), end(source, Standard()), begin(target, Standard()), o);
}

template <typename TContainer, typename TUnaryOperator, typename TParallelTag>
inline void transform(TContainer & c, TUnaryOperator o, Tag<TParallelTag> const & tag)
{
    transform(c, c, o, tag);
}

// ----------------------------------------------------------------------------
// Function generate()
// ----------------------------------------------------------------------------

template <typename TTarget, typename TGenerator, typename TParallelTag>
inline void generate(TTarget & target, TGenerator g, Tag<TParallelTag> const & /* tag */)
{
    std::generate(begin(target, Standard()), end(target, Standard()), g);
}

// ----------------------------------------------------------------------------
// Function iota()
// ----------------------------------------------------------------------------

template <typename TTarget, typename TValue, typename TParallelTag>
inline void iota(TTarget && target, TValue val, Tag<TParallelTag> const & /* tag */)
{
    std::iota(begin(target, Standard()), end(target, Standard()), val);
}

// ----------------------------------------------------------------------------
// Function count()
// ----------------------------------------------------------------------------

template <typename TContainer, typename TValue, typename TParallelTag>
inline typename Difference<TContainer>::Type
count(TContainer const & c, TValue const & v, Tag<TParallelTag> const & /* tag */)
{
    return std::count(begin(c, Standard()), end(c, Standard()), v);
}

// ----------------------------------------------------------------------------
// Function countIf()
// ----------------------------------------------------------------------------

template <typename TContainer, typename TUnaryPredicate, typename TParallelTag>
inline typename Difference<TContainer>::Type
countIf(TContainer const & c, TUnaryPredicate p, Tag<TParallelTag> const & /* tag */)
{
    return std::count_if(begin(c, Standard()), end(c, Standard()), p);
}

// ----------------------------------------------------------------------------
// Function removeIf()
// ----------------------------------------------------------------------------

template <typename TContainer, typename TUnaryPredicate, typename TParallelTag>
inline void
removeIf(TContainer & c, TUnaryPredicate p, Tag<TParallelTag> const & /* tag */)
{
    typename Iterator<TContainer, Standard>::Type newEnd = std::remove_if(begin(c, Standard()), end(c, Standard()), p);
    resize(c, position(newEnd, c), Exact());
}

// ----------------------------------------------------------------------------
// Function accumulate()
// ----------------------------------------------------------------------------

template <typename TContainer, typename TValue, typename TParallelTag>
inline typename Value<TContainer>::Type
accumulate(TContainer const & c, TValue const & v, Tag<TParallelTag> const & /* tag */)
{
    return std::accumulate(begin(c, Standard()), end(c, Standard()), v);
}

// ----------------------------------------------------------------------------
// Function innerProduct()
// ----------------------------------------------------------------------------

template <typename TContainer, typename TValue, typename TParallelTag>
inline typename Value<TContainer>::Type
innerProduct(TContainer const & c, TValue const & v, Tag<TParallelTag> const & /* tag */)
{
    return std::inner_product(begin(c, Standard()), end(c, Standard()), begin(c, Standard()), v);
}

// ----------------------------------------------------------------------------
// Function nthElement()
// ----------------------------------------------------------------------------

template <typename TContainer, typename TPosition, typename TParallelTag>
inline typename Value<TContainer>::Type
nthElement(TContainer & c, TPosition p, Tag<TParallelTag> const & /* tag */)
{
    std::nth_element(begin(c, Standard()), begin(c, Standard()) + p, end(c, Standard()));
    return getValue(c, p);
}

// ----------------------------------------------------------------------------
// Function maxElement()
// ----------------------------------------------------------------------------

template <typename TContainer, typename TUnaryPredicate, typename TParallelTag>
inline typename Reference<TContainer const>::Type
maxElement(TContainer const & c, TUnaryPredicate p, Tag<TParallelTag> const & /* tag */)
{
    SEQAN_ASSERT_NOT(empty(c));
    return value(std::max_element(begin(c, Standard()), end(c, Standard()), p));
}

template <typename TContainer, typename TParallelTag>
inline typename Reference<TContainer const>::Type
maxElement(TContainer const & c, Tag<TParallelTag> const & /* tag */)
{
    SEQAN_ASSERT_NOT(empty(c));
    return value(std::max_element(begin(c, Standard()), end(c, Standard())));
}

// ----------------------------------------------------------------------------
// Function minElement()
// ----------------------------------------------------------------------------

template <typename TContainer, typename TUnaryPredicate, typename TParallelTag>
inline typename Reference<TContainer const>::Type
minElement(TContainer const & c, TUnaryPredicate p, Tag<TParallelTag> const & /* tag */)
{
    SEQAN_ASSERT_NOT(empty(c));
    return value(std::min_element(begin(c, Standard()), end(c, Standard()), p));
}

template <typename TContainer, typename TParallelTag>
inline typename Reference<TContainer const>::Type
minElement(TContainer const & c, Tag<TParallelTag> const & /* tag */)
{
    SEQAN_ASSERT_NOT(empty(c));
    return value(std::min_element(begin(c, Standard()), end(c, Standard())));
}

// ----------------------------------------------------------------------------
// Function sort()
// ----------------------------------------------------------------------------

template <typename TContainer, typename TBinaryPredicate, typename TParallelTag>
inline void sort(TContainer && c, TBinaryPredicate p, Tag<TParallelTag> const & /* tag */)
{
    return std::sort(begin(c, Standard()), end(c, Standard()), p);
}

template <typename TContainer, typename TParallelTag>
inline void sort(TContainer && c, Tag<TParallelTag> const & /* tag */)
{
    return std::sort(begin(c, Standard()), end(c, Standard()));
}

// ----------------------------------------------------------------------------
// Function stableSort()
// ----------------------------------------------------------------------------

template <typename TContainer, typename TBinaryPredicate, typename TParallelTag>
inline void stableSort(TContainer && c, TBinaryPredicate p, Tag<TParallelTag> const & /* tag */)
{
    return std::stable_sort(begin(c, Standard()), end(c, Standard()), p);
}

template <typename TContainer, typename TParallelTag>
inline void stableSort(TContainer && c, Tag<TParallelTag> const & /* tag */)
{
    return std::stable_sort(begin(c, Standard()), end(c, Standard()));
}

// ============================================================================
// MCSTL Wrappers
// ============================================================================

// use MCSTL which is part of the GCC since version 4.3
#if defined(_OPENMP) && defined(COMPILER_GCC)

// ----------------------------------------------------------------------------
// Function forEach(Parallel)
// ----------------------------------------------------------------------------

template <typename TContainer, typename TFunctor>
inline TFunctor forEach(TContainer & c, TFunctor f, Parallel)
{
    return __gnu_parallel::for_each(begin(c, Standard()), end(c, Standard()), f);
}

template <typename TContainer, typename TFunctor>
inline TFunctor forEach(TContainer const & c, TFunctor f, Parallel)
{
    return __gnu_parallel::for_each(begin(c, Standard()), end(c, Standard()), f);
}

// ----------------------------------------------------------------------------
// Function transform(Parallel)
// ----------------------------------------------------------------------------

template <typename TTarget, typename TSource, typename TUnaryOperator>
inline void transform(TTarget & target, TSource & source, TUnaryOperator o, Parallel)
{
    SEQAN_ASSERT_GEQ(length(target), length(source));
    __gnu_parallel::transform(begin(source, Standard()), end(source, Standard()), begin(target, Standard()), o);
}

// ----------------------------------------------------------------------------
// Function generate(Parallel)
// ----------------------------------------------------------------------------

template <typename TTarget, typename TGenerator>
inline void generate(TTarget & target, TGenerator g, Parallel)
{
    __gnu_parallel::generate(begin(target, Standard()), end(target, Standard()), g);
}

// ----------------------------------------------------------------------------
// Function count(Parallel)
// ----------------------------------------------------------------------------

template <typename TContainer, typename TValue>
inline typename Difference<TContainer>::Type
count(TContainer const & c, TValue const & v, Parallel)
{
    return __gnu_parallel::count(begin(c, Standard()), end(c, Standard()), v);
}

// ----------------------------------------------------------------------------
// Function countIf(Parallel)
// ----------------------------------------------------------------------------

template <typename TContainer, typename TUnaryPredicate>
inline typename Difference<TContainer>::Type
countIf(TContainer const & c, TUnaryPredicate p, Parallel)
{
    return __gnu_parallel::count_if(begin(c, Standard()), end(c, Standard()), p);
}

// ----------------------------------------------------------------------------
// Function removeIf(Parallel)
// ----------------------------------------------------------------------------

//template <typename TContainer, typename TUnaryPredicate>
//inline void
//removeIf(TContainer & c, TUnaryPredicate p, Parallel)
//{
//    typename Iterator<TContainer, Standard>::Type newEnd = __gnu_parallel::remove_if(begin(c, Standard()), end(c, Standard()), p);
//    resize(c, position(newEnd, c), Exact());
//}

// ----------------------------------------------------------------------------
// Function accumulate(Parallel)
// ----------------------------------------------------------------------------

template <typename TContainer, typename TValue>
inline typename Value<TContainer>::Type
accumulate(TContainer const & c, TValue const & v, Parallel)
{
    return __gnu_parallel::accumulate(begin(c, Standard()), end(c, Standard()), v);
}

// ----------------------------------------------------------------------------
// Function innerProduct(Parallel)
// ----------------------------------------------------------------------------

template <typename TContainer, typename TValue>
inline typename Value<TContainer>::Type
innerProduct(TContainer const & c, TValue const & v, Parallel)
{
    return __gnu_parallel::inner_product(begin(c, Standard()), end(c, Standard()), begin(c, Standard()), v);
}

// ----------------------------------------------------------------------------
// Function nthElement(Parallel)
// ----------------------------------------------------------------------------

template <typename TContainer, typename TPosition>
inline typename Value<TContainer>::Type
nthElement(TContainer & c, TPosition p, Parallel)
{
    __gnu_parallel::nth_element(begin(c, Standard()), begin(c, Standard()) + p, end(c, Standard()));
    return getValue(c, p);
}

// ----------------------------------------------------------------------------
// Function maxElement(Parallel)
// ----------------------------------------------------------------------------

template <typename TContainer, typename TUnaryPredicate>
inline typename Reference<TContainer const>::Type
maxElement(TContainer const & c, TUnaryPredicate p, Parallel)
{
    SEQAN_ASSERT_NOT(empty(c));
    return value(__gnu_parallel::max_element(begin(c, Standard()), end(c, Standard()), p));
}

template <typename TContainer>
inline typename Reference<TContainer const>::Type
maxElement(TContainer const & c, Parallel)
{
    SEQAN_ASSERT_NOT(empty(c));
    return value(__gnu_parallel::max_element(begin(c, Standard()), end(c, Standard())));
}

// ----------------------------------------------------------------------------
// Function minElement(Parallel)
// ----------------------------------------------------------------------------

template <typename TContainer, typename TUnaryPredicate>
inline typename Reference<TContainer const>::Type
minElement(TContainer const & c, TUnaryPredicate p, Parallel)
{
    SEQAN_ASSERT_NOT(empty(c));
    return value(__gnu_parallel::min_element(begin(c, Standard()), end(c, Standard()), p));
}

template <typename TContainer>
inline typename Reference<TContainer const>::Type
minElement(TContainer const & c, Parallel)
{
    SEQAN_ASSERT_NOT(empty(c));
    return value(__gnu_parallel::min_element(begin(c, Standard()), end(c, Standard())));
}

// ----------------------------------------------------------------------------
// Function sort(Parallel)
// ----------------------------------------------------------------------------

template <typename TContainer, typename TBinaryPredicate>
inline void sort(TContainer && c, TBinaryPredicate p, Parallel)
{
    return __gnu_parallel::sort(begin(c, Standard()), end(c, Standard()), p);
}

template <typename TContainer>
inline void sort(TContainer && c, Parallel)
{
    return __gnu_parallel::sort(begin(c, Standard()), end(c, Standard()));
}

// ----------------------------------------------------------------------------
// Function stableSort(Parallel)
// ----------------------------------------------------------------------------

template <typename TContainer, typename TBinaryPredicate>
inline void stableSort(TContainer && c, TBinaryPredicate p, Parallel)
{
    return __gnu_parallel::stable_sort(begin(c, Standard()), end(c, Standard()), p);
}

template <typename TContainer>
inline void stableSort(TContainer && c, Parallel)
{
    return __gnu_parallel::stable_sort(begin(c, Standard()), end(c, Standard()));
}

#endif  // #ifdef COMPILER_GCC

// ============================================================================
// Shortcuts for STL Wrappers
// ============================================================================

// ----------------------------------------------------------------------------
// Function forEach()
// ----------------------------------------------------------------------------

template <typename TContainer, typename TFunctor>
inline TFunctor forEach(TContainer & c, TFunctor f)
{
    return forEach(c, f, Serial());
}

template <typename TContainer, typename TFunctor>
inline TFunctor forEach(TContainer const & c, TFunctor f)
{
    return forEach(c, f, Serial());
}

// ----------------------------------------------------------------------------
// Function transform()
// ----------------------------------------------------------------------------

template <typename TTarget, typename TSource, typename TUnaryOperator>
inline void transform(TTarget & target, TSource & source, TUnaryOperator o)
{
    transform(target, source, o, Serial());
}

template <typename TContainer, typename TUnaryOperator>
inline void transform(TContainer & c, TUnaryOperator o)
{
    transform(c, o, Serial());
}

// ----------------------------------------------------------------------------
// Function generate()
// ----------------------------------------------------------------------------

template <typename TTarget, typename TGenerator>
inline void generate(TTarget & target, TGenerator g)
{
    generate(target, g, Serial());
}

// ----------------------------------------------------------------------------
// Function iota()
// ----------------------------------------------------------------------------

template <typename TTarget, typename TValue>
inline void iota(TTarget && target, TValue val)
{
    iota(target, val, Serial());
}

// ----------------------------------------------------------------------------
// Function count()
// ----------------------------------------------------------------------------

template <typename TContainer, typename TValue>
inline typename Difference<TContainer>::Type
count(TContainer const & c, TValue const & v)
{
    return count(c, v, Serial());
}

// ----------------------------------------------------------------------------
// Function countIf()
// ----------------------------------------------------------------------------

template <typename TContainer, typename TUnaryPredicate>
inline typename Difference<TContainer>::Type
countIf(TContainer const & c, TUnaryPredicate p)
{
    return countIf(c, p, Serial());
}

// ----------------------------------------------------------------------------
// Function removeIf()
// ----------------------------------------------------------------------------

template <typename TContainer, typename TUnaryPredicate>
inline void
removeIf(TContainer & c, TUnaryPredicate p)
{
    removeIf(c, p, Serial());
}

// ----------------------------------------------------------------------------
// Function accumulate()
// ----------------------------------------------------------------------------

template <typename TContainer, typename TValue>
inline typename Value<TContainer>::Type
accumulate(TContainer const & c, TValue const & v)
{
    return accumulate(c, v, Serial());
}

// ----------------------------------------------------------------------------
// Function innerProduct()
// ----------------------------------------------------------------------------

template <typename TContainer, typename TValue>
inline typename Value<TContainer>::Type
innerProduct(TContainer const & c, TValue const & v)
{
    return innerProduct(c, v, Serial());
}

// ----------------------------------------------------------------------------
// Function nthElement()
// ----------------------------------------------------------------------------

template <typename TContainer, typename TPosition>
inline typename Value<TContainer>::Type
nthElement(TContainer & c, TPosition p)
{
    return nthElement(c, p, Serial());
}

// ----------------------------------------------------------------------------
// Function maxElement()
// ----------------------------------------------------------------------------

template <typename TContainer, typename TUnaryPredicate>
inline typename Reference<TContainer const>::Type
maxElement(TContainer const & c, TUnaryPredicate p)
{
    return maxElement(c, p, Serial());
}

template <typename TContainer>
inline typename Reference<TContainer const>::Type
maxElement(TContainer const & c)
{
    return maxElement(c, Serial());
}

// ----------------------------------------------------------------------------
// Function minElement()
// ----------------------------------------------------------------------------

template <typename TContainer, typename TUnaryPredicate>
inline typename Reference<TContainer const>::Type
minElement(TContainer const & c, TUnaryPredicate p)
{
    return minElement(c, p, Serial());
}

template <typename TContainer>
inline typename Reference<TContainer const>::Type
minElement(TContainer const & c)
{
    return minElement(c, Serial());
}

// ----------------------------------------------------------------------------
// Function sort()
// ----------------------------------------------------------------------------

template <typename TContainer, typename TBinaryPredicate>
inline void sort(TContainer && c, TBinaryPredicate p)
{
    sort(c, p, Serial());
}

template <typename TContainer>
inline void sort(TContainer && c)
{
    sort(c, Serial());
}

// ----------------------------------------------------------------------------
// Function stableSort()
// ----------------------------------------------------------------------------

template <typename TContainer, typename TBinaryPredicate>
inline void stableSort(TContainer && c, TBinaryPredicate p)
{
    stableSort(c, p, Serial());
}

template <typename TContainer>
inline void stableSort(TContainer && c)
{
    stableSort(c, Serial());
}

}  // namespace seqan

#endif  // #ifndef SEQAN_PARALLEL_PARALLEL_ALGORITHMS_H_