Skip to content

Commit a70ab27

Browse files
committed
initial commit
0 parents  commit a70ab27

602 files changed

Lines changed: 176879 additions & 0 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.Rbuildignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
^.*\.Rproj$
2+
^\.Rproj\.user$

.gitignore

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
.Rproj.user
2+
.Rhistory
3+
.RData
4+
.DS_Store

DESCRIPTION

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
Package: tbb
2+
Type: Package
3+
Title: What the package does (short line)
4+
Version: 1.0
5+
Date: 2014-01-04
6+
Author: Who wrote it
7+
Maintainer: Who to complain to <yourfault@somewhere.net>
8+
Description: More about what it does (maybe more than one line)
9+
License: GPL-2
10+

NAMESPACE

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
exportPattern("^[[:alpha:]]+")

R/tbb.R

Whitespace-only changes.
Lines changed: 209 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,209 @@
1+
/*
2+
Copyright 2005-2013 Intel Corporation. All Rights Reserved.
3+
4+
This file is part of Threading Building Blocks.
5+
6+
Threading Building Blocks is free software; you can redistribute it
7+
and/or modify it under the terms of the GNU General Public License
8+
version 2 as published by the Free Software Foundation.
9+
10+
Threading Building Blocks is distributed in the hope that it will be
11+
useful, but WITHOUT ANY WARRANTY; without even the implied warranty
12+
of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13+
GNU General Public License for more details.
14+
15+
You should have received a copy of the GNU General Public License
16+
along with Threading Building Blocks; if not, write to the Free Software
17+
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
18+
19+
As a special exception, you may use this file as part of a free software
20+
library without restriction. Specifically, if other files instantiate
21+
templates or use macros or inline functions from this file, or you compile
22+
this file and link it with other files to produce an executable, this
23+
file does not by itself cause the resulting executable to be covered by
24+
the GNU General Public License. This exception does not however
25+
invalidate any other reasons why the executable file might be covered by
26+
the GNU General Public License.
27+
*/
28+
29+
#ifndef __TBB_SERIAL_parallel_for_H
30+
#define __TBB_SERIAL_parallel_for_H
31+
32+
#if !TBB_USE_EXCEPTIONS && _MSC_VER
33+
// Suppress "C++ exception handler used, but unwind semantics are not enabled" warning in STL headers
34+
#pragma warning (push)
35+
#pragma warning (disable: 4530)
36+
#endif
37+
38+
#include <stdexcept>
39+
#include <string> // required to construct std exception classes
40+
41+
#if !TBB_USE_EXCEPTIONS && _MSC_VER
42+
#pragma warning (pop)
43+
#endif
44+
45+
#include "tbb_annotate.h"
46+
47+
#ifndef __TBB_NORMAL_EXECUTION
48+
#include "tbb/blocked_range.h"
49+
#include "tbb/partitioner.h"
50+
#endif
51+
52+
namespace tbb {
53+
namespace serial {
54+
namespace interface6 {
55+
56+
// parallel_for serial annotated implementation
57+
58+
template< typename Range, typename Body, typename Partitioner >
59+
class start_for : tbb::internal::no_copy {
60+
Range my_range;
61+
const Body my_body;
62+
typename Partitioner::task_partition_type my_partition;
63+
void execute();
64+
65+
//! Constructor for root task.
66+
start_for( const Range& range, const Body& body, Partitioner& partitioner ) :
67+
my_range( range ),
68+
my_body( body ),
69+
my_partition( partitioner )
70+
{
71+
}
72+
73+
//! Splitting constructor used to generate children.
74+
/** this becomes left child. Newly constructed object is right child. */
75+
start_for( start_for& parent_, split ) :
76+
my_range( parent_.my_range, split() ),
77+
my_body( parent_.my_body ),
78+
my_partition( parent_.my_partition, split() )
79+
{
80+
}
81+
82+
public:
83+
static void run( const Range& range, const Body& body, Partitioner& partitioner ) {
84+
if( !range.empty() ) {
85+
ANNOTATE_SITE_BEGIN( tbb_parallel_for );
86+
{
87+
start_for a( range, body, partitioner );
88+
a.execute();
89+
}
90+
ANNOTATE_SITE_END( tbb_parallel_for );
91+
}
92+
}
93+
};
94+
95+
template< typename Range, typename Body, typename Partitioner >
96+
void start_for< Range, Body, Partitioner >::execute() {
97+
if( !my_range.is_divisible() || !my_partition.divisions_left() ) {
98+
ANNOTATE_TASK_BEGIN( tbb_parallel_for_range );
99+
{
100+
my_body( my_range );
101+
}
102+
ANNOTATE_TASK_END( tbb_parallel_for_range );
103+
} else {
104+
start_for b( *this, split() );
105+
this->execute(); // Execute the left interval first to keep the serial order.
106+
b.execute(); // Execute the right interval then.
107+
}
108+
}
109+
110+
//! Parallel iteration over range with default partitioner.
111+
/** @ingroup algorithms **/
112+
template<typename Range, typename Body>
113+
void parallel_for( const Range& range, const Body& body ) {
114+
serial::interface6::start_for<Range,Body,const __TBB_DEFAULT_PARTITIONER>::run(range,body,__TBB_DEFAULT_PARTITIONER());
115+
}
116+
117+
//! Parallel iteration over range with simple partitioner.
118+
/** @ingroup algorithms **/
119+
template<typename Range, typename Body>
120+
void parallel_for( const Range& range, const Body& body, const simple_partitioner& partitioner ) {
121+
serial::interface6::start_for<Range,Body,const simple_partitioner>::run(range,body,partitioner);
122+
}
123+
124+
//! Parallel iteration over range with auto_partitioner.
125+
/** @ingroup algorithms **/
126+
template<typename Range, typename Body>
127+
void parallel_for( const Range& range, const Body& body, const auto_partitioner& partitioner ) {
128+
serial::interface6::start_for<Range,Body,const auto_partitioner>::run(range,body,partitioner);
129+
}
130+
131+
//! Parallel iteration over range with affinity_partitioner.
132+
/** @ingroup algorithms **/
133+
template<typename Range, typename Body>
134+
void parallel_for( const Range& range, const Body& body, affinity_partitioner& partitioner ) {
135+
serial::interface6::start_for<Range,Body,affinity_partitioner>::run(range,body,partitioner);
136+
}
137+
138+
//! Implementation of parallel iteration over stepped range of integers with explicit step and partitioner (ignored)
139+
template <typename Index, typename Function, typename Partitioner>
140+
void parallel_for_impl(Index first, Index last, Index step, const Function& f, Partitioner& ) {
141+
if (step <= 0 )
142+
throw std::invalid_argument( "nonpositive_step" );
143+
else if (last > first) {
144+
// Above "else" avoids "potential divide by zero" warning on some platforms
145+
ANNOTATE_SITE_BEGIN( tbb_parallel_for );
146+
for( Index i = first; i < last; i = i + step ) {
147+
ANNOTATE_TASK_BEGIN( tbb_parallel_for_iteration );
148+
{ f( i ); }
149+
ANNOTATE_TASK_END( tbb_parallel_for_iteration );
150+
}
151+
ANNOTATE_SITE_END( tbb_parallel_for );
152+
}
153+
}
154+
155+
//! Parallel iteration over a range of integers with explicit step and default partitioner
156+
template <typename Index, typename Function>
157+
void parallel_for(Index first, Index last, Index step, const Function& f) {
158+
parallel_for_impl<Index,Function,const auto_partitioner>(first, last, step, f, auto_partitioner());
159+
}
160+
//! Parallel iteration over a range of integers with explicit step and simple partitioner
161+
template <typename Index, typename Function>
162+
void parallel_for(Index first, Index last, Index step, const Function& f, const simple_partitioner& p) {
163+
parallel_for_impl<Index,Function,const simple_partitioner>(first, last, step, f, p);
164+
}
165+
//! Parallel iteration over a range of integers with explicit step and auto partitioner
166+
template <typename Index, typename Function>
167+
void parallel_for(Index first, Index last, Index step, const Function& f, const auto_partitioner& p) {
168+
parallel_for_impl<Index,Function,const auto_partitioner>(first, last, step, f, p);
169+
}
170+
//! Parallel iteration over a range of integers with explicit step and affinity partitioner
171+
template <typename Index, typename Function>
172+
void parallel_for(Index first, Index last, Index step, const Function& f, affinity_partitioner& p) {
173+
parallel_for_impl(first, last, step, f, p);
174+
}
175+
176+
//! Parallel iteration over a range of integers with default step and default partitioner
177+
template <typename Index, typename Function>
178+
void parallel_for(Index first, Index last, const Function& f) {
179+
parallel_for_impl<Index,Function,const auto_partitioner>(first, last, static_cast<Index>(1), f, auto_partitioner());
180+
}
181+
//! Parallel iteration over a range of integers with default step and simple partitioner
182+
template <typename Index, typename Function>
183+
void parallel_for(Index first, Index last, const Function& f, const simple_partitioner& p) {
184+
parallel_for_impl<Index,Function,const simple_partitioner>(first, last, static_cast<Index>(1), f, p);
185+
}
186+
//! Parallel iteration over a range of integers with default step and auto partitioner
187+
template <typename Index, typename Function>
188+
void parallel_for(Index first, Index last, const Function& f, const auto_partitioner& p) {
189+
parallel_for_impl<Index,Function,const auto_partitioner>(first, last, static_cast<Index>(1), f, p);
190+
}
191+
//! Parallel iteration over a range of integers with default step and affinity_partitioner
192+
template <typename Index, typename Function>
193+
void parallel_for(Index first, Index last, const Function& f, affinity_partitioner& p) {
194+
parallel_for_impl(first, last, static_cast<Index>(1), f, p);
195+
}
196+
197+
} // namespace interface6
198+
199+
using interface6::parallel_for;
200+
201+
} // namespace serial
202+
203+
#ifndef __TBB_NORMAL_EXECUTION
204+
using serial::interface6::parallel_for;
205+
#endif
206+
207+
} // namespace tbb
208+
209+
#endif /* __TBB_SERIAL_parallel_for_H */
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
/*
2+
Copyright 2005-2013 Intel Corporation. All Rights Reserved.
3+
4+
This file is part of Threading Building Blocks.
5+
6+
Threading Building Blocks is free software; you can redistribute it
7+
and/or modify it under the terms of the GNU General Public License
8+
version 2 as published by the Free Software Foundation.
9+
10+
Threading Building Blocks is distributed in the hope that it will be
11+
useful, but WITHOUT ANY WARRANTY; without even the implied warranty
12+
of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13+
GNU General Public License for more details.
14+
15+
You should have received a copy of the GNU General Public License
16+
along with Threading Building Blocks; if not, write to the Free Software
17+
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
18+
19+
As a special exception, you may use this file as part of a free software
20+
library without restriction. Specifically, if other files instantiate
21+
templates or use macros or inline functions from this file, or you compile
22+
this file and link it with other files to produce an executable, this
23+
file does not by itself cause the resulting executable to be covered by
24+
the GNU General Public License. This exception does not however
25+
invalidate any other reasons why the executable file might be covered by
26+
the GNU General Public License.
27+
*/
28+
29+
#ifndef __TBB_annotate_H
30+
#define __TBB_annotate_H
31+
32+
// Macros used by the Intel(R) Parallel Advisor.
33+
#ifdef __TBB_NORMAL_EXECUTION
34+
#define ANNOTATE_SITE_BEGIN( site )
35+
#define ANNOTATE_SITE_END( site )
36+
#define ANNOTATE_TASK_BEGIN( task )
37+
#define ANNOTATE_TASK_END( task )
38+
#define ANNOTATE_LOCK_ACQUIRE( lock )
39+
#define ANNOTATE_LOCK_RELEASE( lock )
40+
#else
41+
#include <advisor-annotate.h>
42+
#endif
43+
44+
#endif /* __TBB_annotate_H */

0 commit comments

Comments
 (0)