All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
Classes | Typedefs | Functions
tbb_preduce_01_t.cc File Reference
#include "tbb/tbb.h"
#include <algorithm>
#include <cassert>
#include <iostream>
#include <iterator>
#include <numeric>

Go to the source code of this file.

Classes

class  Meanie
 
class  Minnie
 

Typedefs

typedef tbb::blocked_range< typename std::vector< double >::const_iteratorbr_t
 

Functions

int main ()
 

Typedef Documentation

typedef tbb::blocked_range<typename std::vector<double>::const_iterator> br_t

Definition at line 18 of file tbb_preduce_01_t.cc.

Function Documentation

int main ( )

Definition at line 55 of file tbb_preduce_01_t.cc.

56 {
57  // Setup.
58  size_t const n = 500000;
59  double const val = 27.125; // Exactly representable as a double in IEEE.
60  std::vector<double> v(n, val);
61  // Mean.
62  Meanie m;
63  tbb::parallel_reduce(br_t(v.cbegin(), v.cend()), m);
64  assert(m.count() == n);
65  assert(m.result() == val);
66  // Setup for min.
67  std::vector<double>::difference_type const loc = 47856;
68  double const minval = 22.3;
69  v[loc] = minval;
70  // Min.
71  Minnie mincalc;
72  tbb::parallel_reduce(br_t(v.cbegin(), v.cend()), mincalc);
73  assert(mincalc.valid() && std::distance(v.cbegin(), mincalc.min()) == loc);
74  assert(*mincalc.min() == minval);
75 }
static const double m
Definition: Units.h:79
tbb::blocked_range< typename std::vector< double >::const_iterator > br_t
size_t count() const
double result() const
br_t::const_iterator min() const
bool valid() const