/usr/include/openturns/TBB.hxx is in libopenturns-dev 0.15-2.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
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 | // -*- C++ -*-
/**
* @file TBB.hxx
* @brief This file supplies support for multithreading
*
* (C) Copyright 2005-2011 EDF-EADS-Phimeca
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License.
*
* This library is distributed in the hope that it will be useful
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*
* @author: $LastChangedBy: schueller $
* @date: $LastChangedDate: 2007-05-10 16:43:31 +0200 (Thu, 10 May 2007) $
* Id: $Id: AtomicFunctions.hxx 434 2007-05-10 14:43:31Z dutka $
*/
#ifndef OPENTURNS_TBB_HXX
#define OPENTURNS_TBB_HXX
#include "OTprivate.hxx"
#include "OTconfig.hxx"
#include <algorithm>
#ifdef HAVE_TBB
# include "tbb/tbb.h"
#else /* HAVE_TBB */
#include "Exception.hxx"
// We redefine some TBB elements to simulate TBB availability through the code
// Those redefinitions are single threaded
namespace tbb {
template <typename T>
class blocked_range
{
public:
typedef T value_type;
typedef std::size_t size_type;
blocked_range(value_type from, value_type to, size_type gs = 1)
: from_(from), to_(to), grainSize_(gs)
{
#ifdef DEBUG_BOUNDCHECKING
if (from_ > to_)
throw OpenTURNS::Base::Common::InvalidArgumentException(HERE) << "Range is malformed (from > to) with from=" << from_
<< " and to=" << to;
if (grainSize_ < 1)
throw OpenTURNS::Base::Common::InvalidArgumentException(HERE) << "Range is malformed (grainSize < 1) with grainSize=" << grainSize_;
#endif /* DEBUG_BOUNDCHECKING */
}
value_type begin() const { return from_; }
value_type end() const { return to_; }
size_type size() const { return size_t(to_ - from_); }
size_type grainsize() const { return grainSize_; }
private:
value_type from_;
value_type to_;
size_type grainSize_;
}; // end class blocked_range
template <typename RANGE, typename BODY>
void parallel_for( const RANGE & range, const BODY & body )
{
body( range );
}
template <typename RANGE, typename BODY>
void parallel_reduce( const RANGE & range, BODY & body )
{
body( range );
}
template <typename ITERATOR>
void parallel_sort( ITERATOR first, ITERATOR last )
{
std::stable_sort( first, last );
}
} // namespace tbb
#endif /* HAVE_TBB */
namespace OpenTURNS
{
class TBB
{
public:
#ifdef HAVE_TBB
typedef tbb::split Split;
#else /* HAVE_TBB */
struct Split {};
#endif /* HAVE_TBB */
template <typename T>
struct BlockedRange : public tbb::blocked_range<T>
{
typedef T value_type;
typedef typename tbb::blocked_range<T>::size_type size_type;
BlockedRange(value_type from, value_type to, size_type gs = 1) : tbb::blocked_range<T>(from,to,gs) {}
BlockedRange(const tbb::blocked_range<T> & range) : tbb::blocked_range<T>(range) {}
};
private:
static const UnsignedLong GrainSize_;
/** Start the machinery of multithreading */
static void Initialization();
/** End the machinery of multithreading */
static void Release();
public:
template <typename BODY>
static inline
void ParallelFor( UnsignedLong from, UnsignedLong to, const BODY & body )
{
tbb::parallel_for( tbb::blocked_range<UnsignedLong>( from, to, GrainSize_ ), body );
}
template <typename BODY>
static inline
void ParallelReduce( UnsignedLong from, UnsignedLong to, BODY & body )
{
tbb::parallel_reduce( tbb::blocked_range<UnsignedLong>( from, to, GrainSize_ ), body );
}
template <typename ITERATOR>
static inline
void ParallelSort( ITERATOR first, ITERATOR last )
{
tbb::parallel_sort( first, last );
}
private:
friend class TBB_init; /* friendship for static member initialization */
}; /* end class TBB */
/** This struct initializes all static members of TBB */
struct TBB_init {
TBB_init();
}; /* end class TBB_init */
static TBB_init __TBB_initializer;
} // end namespace OpenTURNS
#endif /* OPENTURNS_TBB_HXX */
|