Skip to content
Toggle navigation
P
Projects
G
Groups
S
Snippets
Help
FORMUS3IC_LAS3
/
embb
This project
Loading...
Sign in
Toggle navigation
Go to a project
Project
Repository
Issues
0
Merge Requests
0
Pipelines
Wiki
Members
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Commit
db74f3e9
authored
Mar 02, 2015
by
Christian Kern
Browse files
Options
Browse Files
Download
Plain Diff
Merge branch 'development' into embb6_use_bin_sh
parents
59354d40
ad71c970
Hide whitespace changes
Inline
Side-by-side
Showing
19 changed files
with
247 additions
and
76 deletions
+247
-76
algorithms_cpp/include/embb/algorithms/internal/for_each-inl.h
+2
-0
algorithms_cpp/include/embb/algorithms/internal/merge_sort-inl.h
+18
-8
algorithms_cpp/include/embb/algorithms/internal/quick_sort-inl.h
+20
-7
algorithms_cpp/include/embb/algorithms/internal/reduce-inl.h
+3
-1
algorithms_cpp/include/embb/algorithms/internal/scan-inl.h
+4
-2
algorithms_cpp/include/embb/algorithms/invoke.h
+2
-2
algorithms_cpp/include/embb/algorithms/merge_sort.h
+12
-1
algorithms_cpp/include/embb/algorithms/reduce.h
+3
-3
algorithms_cpp/include/embb/algorithms/scan.h
+3
-3
algorithms_cpp/test/for_each_test.cc
+26
-1
algorithms_cpp/test/merge_sort_test.cc
+50
-24
algorithms_cpp/test/merge_sort_test.h
+1
-1
algorithms_cpp/test/quick_sort_test.cc
+26
-0
algorithms_cpp/test/reduce_test.cc
+25
-0
algorithms_cpp/test/scan_test.cc
+29
-0
base_cpp/include/embb/base/internal/thread_closures.h
+6
-6
base_cpp/include/embb/base/thread.h
+8
-8
mtapi_c/include/embb/mtapi/c/mtapi.h
+1
-1
mtapi_cpp/include/embb/mtapi/action.h
+8
-8
No files found.
algorithms_cpp/include/embb/algorithms/internal/for_each-inl.h
View file @
db74f3e9
...
@@ -107,6 +107,8 @@ void ForEachRecursive(RAI first, RAI last, Function unary,
...
@@ -107,6 +107,8 @@ void ForEachRecursive(RAI first, RAI last, Function unary,
difference_type
distance
=
std
::
distance
(
first
,
last
);
difference_type
distance
=
std
::
distance
(
first
,
last
);
if
(
distance
==
0
)
{
if
(
distance
==
0
)
{
return
;
return
;
}
else
if
(
distance
<
0
)
{
EMBB_THROW
(
embb
::
base
::
ErrorException
,
"Negative range for ForEach"
);
}
}
unsigned
int
num_cores
=
policy
.
GetCoreCount
();
unsigned
int
num_cores
=
policy
.
GetCoreCount
();
if
(
num_cores
==
0
)
{
if
(
num_cores
==
0
)
{
...
...
algorithms_cpp/include/embb/algorithms/internal/merge_sort-inl.h
View file @
db74f3e9
...
@@ -213,23 +213,24 @@ class MergeSortFunctor {
...
@@ -213,23 +213,24 @@ class MergeSortFunctor {
}
}
};
};
}
// namespace internal
template
<
typename
RAI
,
typename
RAITemp
,
typename
ComparisonFunction
>
template
<
typename
RAI
,
typename
RAITemp
,
typename
ComparisonFunction
>
void
MergeSort
(
void
MergeSort
IteratorCheck
(
RAI
first
,
RAI
first
,
RAI
last
,
RAI
last
,
RAITemp
temporary_first
,
RAITemp
temporary_first
,
ComparisonFunction
comparison
,
ComparisonFunction
comparison
,
const
embb
::
mtapi
::
ExecutionPolicy
&
policy
,
const
embb
::
mtapi
::
ExecutionPolicy
&
policy
,
size_t
block_size
size_t
block_size
,
std
::
random_access_iterator_tag
)
{
)
{
typedef
typename
std
::
iterator_traits
<
RAI
>::
difference_type
difference_type
;
typedef
typename
std
::
iterator_traits
<
RAI
>::
difference_type
difference_type
;
typedef
internal
::
MergeSortFunctor
<
RAI
,
RAITemp
,
ComparisonFunction
>
typedef
MergeSortFunctor
<
RAI
,
RAITemp
,
ComparisonFunction
>
functor_t
;
functor_t
;
difference_type
distance
=
std
::
distance
(
first
,
last
);
difference_type
distance
=
std
::
distance
(
first
,
last
);
if
(
distance
==
0
)
{
if
(
distance
==
0
)
{
EMBB_THROW
(
embb
::
base
::
ErrorException
,
"Distance for ForEach is 0"
);
return
;
}
else
if
(
distance
<
0
)
{
EMBB_THROW
(
embb
::
base
::
ErrorException
,
"Negative range for MergeSort"
);
}
}
unsigned
int
num_cores
=
policy
.
GetCoreCount
();
unsigned
int
num_cores
=
policy
.
GetCoreCount
();
if
(
num_cores
==
0
)
{
if
(
num_cores
==
0
)
{
...
@@ -247,7 +248,7 @@ void MergeSort(
...
@@ -247,7 +248,7 @@ void MergeSort(
"Not enough MTAPI tasks available to perform merge sort"
);
"Not enough MTAPI tasks available to perform merge sort"
);
}
}
internal
::
BlockSizePartitioner
<
RAI
>
partitioner
(
first
,
last
,
block_size
);
BlockSizePartitioner
<
RAI
>
partitioner
(
first
,
last
,
block_size
);
functor_t
functor
(
0
,
functor_t
functor
(
0
,
partitioner
.
Size
()
-
1
,
partitioner
.
Size
()
-
1
,
temporary_first
,
temporary_first
,
...
@@ -264,7 +265,16 @@ void MergeSort(
...
@@ -264,7 +265,16 @@ void MergeSort(
task
.
Wait
(
MTAPI_INFINITE
);
task
.
Wait
(
MTAPI_INFINITE
);
}
}
// @NOTE: Why is there no type guard for RAI?
}
// namespace internal
template
<
typename
RAI
,
typename
RAITemp
,
typename
ComparisonFunction
>
void
MergeSort
(
RAI
first
,
RAI
last
,
RAITemp
temporary_first
,
ComparisonFunction
comparison
,
const
embb
::
mtapi
::
ExecutionPolicy
&
policy
,
size_t
block_size
)
{
typedef
typename
std
::
iterator_traits
<
RAI
>::
iterator_category
category
;
internal
::
MergeSortIteratorCheck
(
first
,
last
,
temporary_first
,
comparison
,
policy
,
block_size
,
category
());
}
}
// namespace algorithms
}
// namespace algorithms
}
// namespace embb
}
// namespace embb
...
...
algorithms_cpp/include/embb/algorithms/internal/quick_sort-inl.h
View file @
db74f3e9
...
@@ -186,16 +186,19 @@ class QuickSortFunctor {
...
@@ -186,16 +186,19 @@ class QuickSortFunctor {
QuickSortFunctor
(
const
QuickSortFunctor
&
);
QuickSortFunctor
(
const
QuickSortFunctor
&
);
};
};
}
// namespace internal
template
<
typename
RAI
,
typename
ComparisonFunction
>
template
<
typename
RAI
,
typename
ComparisonFunction
>
void
QuickSort
(
RAI
first
,
RAI
last
,
ComparisonFunction
comparison
,
void
QuickSortIteratorCheck
(
RAI
first
,
RAI
last
,
const
embb
::
mtapi
::
ExecutionPolicy
&
policy
,
size_t
block_size
)
{
ComparisonFunction
comparison
,
const
embb
::
mtapi
::
ExecutionPolicy
&
policy
,
size_t
block_size
,
std
::
random_access_iterator_tag
)
{
embb
::
mtapi
::
Node
&
node
=
embb
::
mtapi
::
Node
::
GetInstance
();
embb
::
mtapi
::
Node
&
node
=
embb
::
mtapi
::
Node
::
GetInstance
();
typedef
typename
std
::
iterator_traits
<
RAI
>::
difference_type
difference_type
;
typedef
typename
std
::
iterator_traits
<
RAI
>::
difference_type
difference_type
;
difference_type
distance
=
std
::
distance
(
first
,
last
);
difference_type
distance
=
std
::
distance
(
first
,
last
);
if
(
distance
<
=
0
)
{
if
(
distance
=
=
0
)
{
return
;
return
;
}
else
if
(
distance
<
0
)
{
EMBB_THROW
(
embb
::
base
::
ErrorException
,
"Negative range for QuickSort"
);
}
}
unsigned
int
num_cores
=
policy
.
GetCoreCount
();
unsigned
int
num_cores
=
policy
.
GetCoreCount
();
if
(
num_cores
==
0
)
{
if
(
num_cores
==
0
)
{
...
@@ -210,13 +213,23 @@ void QuickSort(RAI first, RAI last, ComparisonFunction comparison,
...
@@ -210,13 +213,23 @@ void QuickSort(RAI first, RAI last, ComparisonFunction comparison,
EMBB_THROW
(
embb
::
base
::
ErrorException
,
EMBB_THROW
(
embb
::
base
::
ErrorException
,
"Not enough MTAPI tasks available for performing quick sort"
);
"Not enough MTAPI tasks available for performing quick sort"
);
}
}
internal
::
QuickSortFunctor
<
RAI
,
ComparisonFunction
>
functor
(
QuickSortFunctor
<
RAI
,
ComparisonFunction
>
functor
(
first
,
last
,
comparison
,
policy
,
block_size
);
first
,
last
,
comparison
,
policy
,
block_size
);
mtapi
::
Task
task
=
node
.
Spawn
(
mtapi
::
Action
(
base
::
MakeFunction
(
mtapi
::
Task
task
=
node
.
Spawn
(
mtapi
::
Action
(
base
::
MakeFunction
(
functor
,
&
internal
::
QuickSortFunctor
<
RAI
,
ComparisonFunction
>::
Action
)));
functor
,
&
QuickSortFunctor
<
RAI
,
ComparisonFunction
>::
Action
)));
task
.
Wait
(
MTAPI_INFINITE
);
task
.
Wait
(
MTAPI_INFINITE
);
}
}
}
// namespace internal
template
<
typename
RAI
,
typename
ComparisonFunction
>
void
QuickSort
(
RAI
first
,
RAI
last
,
ComparisonFunction
comparison
,
const
embb
::
mtapi
::
ExecutionPolicy
&
policy
,
size_t
block_size
)
{
typedef
typename
std
::
iterator_traits
<
RAI
>::
iterator_category
category
;
internal
::
QuickSortIteratorCheck
(
first
,
last
,
comparison
,
policy
,
block_size
,
category
());
}
}
// namespace algorithms
}
// namespace algorithms
}
// namespace embb
}
// namespace embb
...
...
algorithms_cpp/include/embb/algorithms/internal/reduce-inl.h
View file @
db74f3e9
...
@@ -129,7 +129,9 @@ ReturnType ReduceRecursive(RAI first, RAI last, ReturnType neutral,
...
@@ -129,7 +129,9 @@ ReturnType ReduceRecursive(RAI first, RAI last, ReturnType neutral,
typedef
typename
std
::
iterator_traits
<
RAI
>::
difference_type
difference_type
;
typedef
typename
std
::
iterator_traits
<
RAI
>::
difference_type
difference_type
;
difference_type
distance
=
std
::
distance
(
first
,
last
);
difference_type
distance
=
std
::
distance
(
first
,
last
);
if
(
distance
==
0
)
{
if
(
distance
==
0
)
{
EMBB_THROW
(
embb
::
base
::
ErrorException
,
"Distance for Reduce is 0"
);
return
neutral
;
}
else
if
(
distance
<
0
)
{
EMBB_THROW
(
embb
::
base
::
ErrorException
,
"Negative range for Reduce"
);
}
}
unsigned
int
num_cores
=
policy
.
GetCoreCount
();
unsigned
int
num_cores
=
policy
.
GetCoreCount
();
if
(
num_cores
==
0
)
{
if
(
num_cores
==
0
)
{
...
...
algorithms_cpp/include/embb/algorithms/internal/scan-inl.h
View file @
db74f3e9
...
@@ -173,14 +173,16 @@ void ScanIteratorCheck(RAIIn first, RAIIn last, RAIOut output_iterator,
...
@@ -173,14 +173,16 @@ void ScanIteratorCheck(RAIIn first, RAIIn last, RAIOut output_iterator,
std
::
random_access_iterator_tag
)
{
std
::
random_access_iterator_tag
)
{
typedef
typename
std
::
iterator_traits
<
RAIIn
>::
difference_type
difference_type
;
typedef
typename
std
::
iterator_traits
<
RAIIn
>::
difference_type
difference_type
;
difference_type
distance
=
std
::
distance
(
first
,
last
);
difference_type
distance
=
std
::
distance
(
first
,
last
);
if
(
distance
<
=
0
)
{
if
(
distance
=
=
0
)
{
return
;
return
;
}
else
if
(
distance
<
0
)
{
EMBB_THROW
(
embb
::
base
::
ErrorException
,
"Negative range for Scan"
);
}
}
unsigned
int
num_cores
=
policy
.
GetCoreCount
();
unsigned
int
num_cores
=
policy
.
GetCoreCount
();
if
(
num_cores
==
0
)
{
if
(
num_cores
==
0
)
{
EMBB_THROW
(
embb
::
base
::
ErrorException
,
"No cores in execution policy"
);
EMBB_THROW
(
embb
::
base
::
ErrorException
,
"No cores in execution policy"
);
}
}
ReturnType
values
[
MTAPI_NODE_MAX_TASKS_DEFAULT
];
ReturnType
values
[
MTAPI_NODE_MAX_TASKS_DEFAULT
];
if
(
block_size
==
0
)
{
if
(
block_size
==
0
)
{
block_size
=
static_cast
<
size_t
>
(
distance
)
/
num_cores
;
block_size
=
static_cast
<
size_t
>
(
distance
)
/
num_cores
;
...
...
algorithms_cpp/include/embb/algorithms/invoke.h
View file @
db74f3e9
...
@@ -58,7 +58,7 @@ typedef embb::base::Function<void> InvokeFunctionType;
...
@@ -58,7 +58,7 @@ typedef embb::base::Function<void> InvokeFunctionType;
template
<
typename
Function1
,
...
>
template
<
typename
Function1
,
...
>
void
Invoke
(
void
Invoke
(
Function1
func1
,
Function1
func1
,
/**< [in] First function to invoke */
/**< [in] First function
object
to invoke */
...);
...);
/**
/**
...
@@ -72,7 +72,7 @@ void Invoke(
...
@@ -72,7 +72,7 @@ void Invoke(
template
<
typename
Function1
,
...
>
template
<
typename
Function1
,
...
>
void
Invoke
(
void
Invoke
(
Function1
func1
,
Function1
func1
,
/**< [in] Function to invoke */
/**< [in] Function
object
to invoke */
...,
...,
const
embb
::
mtapi
::
ExecutionPolicy
&
policy
const
embb
::
mtapi
::
ExecutionPolicy
&
policy
/**< [in] embb::mtapi::ExecutionPolicy to use */
/**< [in] embb::mtapi::ExecutionPolicy to use */
...
...
algorithms_cpp/include/embb/algorithms/merge_sort.h
View file @
db74f3e9
...
@@ -167,9 +167,20 @@ void MergeSortAllocate(
...
@@ -167,9 +167,20 @@ void MergeSortAllocate(
typedef
base
::
Allocation
Alloc
;
typedef
base
::
Allocation
Alloc
;
typename
std
::
iterator_traits
<
RAI
>::
difference_type
distance
=
last
-
first
;
typename
std
::
iterator_traits
<
RAI
>::
difference_type
distance
=
last
-
first
;
typedef
typename
std
::
iterator_traits
<
RAI
>::
value_type
value_type
;
typedef
typename
std
::
iterator_traits
<
RAI
>::
value_type
value_type
;
if
(
distance
==
0
)
{
return
;
}
else
if
(
distance
<
0
)
{
EMBB_THROW
(
embb
::
base
::
ErrorException
,
"Negative range for MergeSort"
);
}
value_type
*
temporary
=
static_cast
<
value_type
*>
(
value_type
*
temporary
=
static_cast
<
value_type
*>
(
Alloc
::
Allocate
(
distance
*
sizeof
(
value_type
)));
Alloc
::
Allocate
(
distance
*
sizeof
(
value_type
)));
MergeSort
(
first
,
last
,
temporary
,
comparison
,
policy
,
block_size
);
EMBB_TRY
{
MergeSort
(
first
,
last
,
temporary
,
comparison
,
policy
,
block_size
);
}
EMBB_CATCH
(
embb
::
base
::
ErrorException
&
e
)
{
// embb exception handling does not support catch(...) and rethrow yet.
Alloc
::
Free
(
temporary
);
EMBB_THROW
(
embb
::
base
::
ErrorException
,
e
.
what
());
}
Alloc
::
Free
(
temporary
);
Alloc
::
Free
(
temporary
);
}
}
...
...
algorithms_cpp/include/embb/algorithms/reduce.h
View file @
db74f3e9
...
@@ -68,10 +68,10 @@ namespace algorithms {
...
@@ -68,10 +68,10 @@ namespace algorithms {
* \tparam RAI Random access iterator
* \tparam RAI Random access iterator
* \tparam ReturnType Type of result of reduction operation, deduced from
* \tparam ReturnType Type of result of reduction operation, deduced from
* \c neutral
* \c neutral
* \tparam ReductionFunction Binary reduction function with signature
* \tparam ReductionFunction Binary reduction function
object
with signature
* <tt>ReturnType ReductionFunction(ReturnType, ReturnType)</tt>.
* <tt>ReturnType ReductionFunction(ReturnType, ReturnType)</tt>.
* \tparam TransformationFunction Unary transformation function
with signature
* \tparam TransformationFunction Unary transformation function
object with
* <tt>ReturnType TransformationFunction(typename
*
signature
<tt>ReturnType TransformationFunction(typename
* std::iterator_traits<RAI>::value_type)</tt>
* std::iterator_traits<RAI>::value_type)</tt>
*/
*/
template
<
typename
RAI
,
typename
ReturnType
,
typename
ReductionFunction
,
template
<
typename
RAI
,
typename
ReturnType
,
typename
ReductionFunction
,
...
...
algorithms_cpp/include/embb/algorithms/scan.h
View file @
db74f3e9
...
@@ -71,10 +71,10 @@ namespace algorithms {
...
@@ -71,10 +71,10 @@ namespace algorithms {
* \tparam RAIOut Random access iterator type of output range
* \tparam RAIOut Random access iterator type of output range
* \tparam ReturnType Type of output elements of scan operation, deduced from
* \tparam ReturnType Type of output elements of scan operation, deduced from
* \c neutral
* \c neutral
* \tparam ScanFunction Binary scan function with signature
* \tparam ScanFunction Binary scan function
object
with signature
* <tt>ReturnType ScanFunction(ReturnType, ReturnType)</tt>
* <tt>ReturnType ScanFunction(ReturnType, ReturnType)</tt>
* \tparam TransformationFunction Unary transformation function
with signature
* \tparam TransformationFunction Unary transformation function
object with
* <tt>ReturnType TransformationFunction(typename
*
signature
<tt>ReturnType TransformationFunction(typename
* std::iterator_traits<RAIIn>::value_type)</tt>.
* std::iterator_traits<RAIIn>::value_type)</tt>.
*/
*/
template
<
typename
RAIIn
,
typename
RAIOut
,
typename
ReturnType
,
template
<
typename
RAIIn
,
typename
RAIOut
,
typename
ReturnType
,
...
...
algorithms_cpp/test/for_each_test.cc
View file @
db74f3e9
...
@@ -205,12 +205,37 @@ void ForEachTest::TestPolicy() {
...
@@ -205,12 +205,37 @@ void ForEachTest::TestPolicy() {
for
(
size_t
i
=
0
;
i
<
count
;
i
++
)
{
for
(
size_t
i
=
0
;
i
<
count
;
i
++
)
{
PT_EXPECT_EQ
(
vector
[
i
],
init
[
i
]
*
init
[
i
]);
PT_EXPECT_EQ
(
vector
[
i
],
init
[
i
]
*
init
[
i
]);
}
}
vector
=
init
;
vector
=
init
;
ForEach
(
vector
.
begin
(),
vector
.
end
(),
Square
(),
ExecutionPolicy
(
true
,
1
));
ForEach
(
vector
.
begin
(),
vector
.
end
(),
Square
(),
ExecutionPolicy
(
true
,
1
));
for
(
size_t
i
=
0
;
i
<
count
;
i
++
)
{
for
(
size_t
i
=
0
;
i
<
count
;
i
++
)
{
PT_EXPECT_EQ
(
vector
[
i
],
init
[
i
]
*
init
[
i
]);
PT_EXPECT_EQ
(
vector
[
i
],
init
[
i
]
*
init
[
i
]);
}
}
// ForEach on empty list should not throw:
ForEach
(
vector
.
begin
(),
vector
.
begin
(),
Square
());
#ifdef EMBB_USE_EXCEPTIONS
bool
empty_core_set_thrown
=
false
;
try
{
ForEach
(
vector
.
begin
(),
vector
.
end
(),
Square
(),
ExecutionPolicy
(
false
));
}
catch
(
embb
::
base
::
ErrorException
&
)
{
empty_core_set_thrown
=
true
;
}
PT_EXPECT_MSG
(
empty_core_set_thrown
,
"Empty core set should throw ErrorException"
);
bool
negative_range_thrown
=
false
;
try
{
std
::
vector
<
int
>::
iterator
second
=
vector
.
begin
()
+
1
;
ForEach
(
second
,
vector
.
begin
(),
Square
());
}
catch
(
embb
::
base
::
ErrorException
&
)
{
negative_range_thrown
=
true
;
}
PT_EXPECT_MSG
(
negative_range_thrown
,
"Negative range should throw ErrorException"
);
#endif
}
}
void
ForEachTest
::
StressTest
()
{
void
ForEachTest
::
StressTest
()
{
...
...
algorithms_cpp/test/merge_sort_test.cc
View file @
db74f3e9
...
@@ -156,28 +156,28 @@ void MergeSortTest::TestRanges() {
...
@@ -156,28 +156,28 @@ void MergeSortTest::TestRanges() {
}
}
}
}
//
void MergeSortTest::TestBlockSizes() {
void
MergeSortTest
::
TestBlockSizes
()
{
//
using embb::algorithms::MergeSortAllocate;
using
embb
::
algorithms
::
MergeSortAllocate
;
// using embb::algorithms
::ExecutionPolicy;
using
embb
::
mtapi
::
ExecutionPolicy
;
//
size_t count = 4;
size_t
count
=
4
;
//
std::vector<int> init(count);
std
::
vector
<
int
>
init
(
count
);
//
std::vector<int> vector(count);
std
::
vector
<
int
>
vector
(
count
);
//
std::vector<int> vector_copy(count);
std
::
vector
<
int
>
vector_copy
(
count
);
//
for (size_t i = count - 1; i > 0; i--) {
for
(
size_t
i
=
count
-
1
;
i
>
0
;
i
--
)
{
//
init[i] = static_cast<int>(i+2);
init
[
i
]
=
static_cast
<
int
>
(
i
+
2
);
//
}
}
//
vector_copy = init;
vector_copy
=
init
;
//
std::sort(vector_copy.begin(), vector_copy.end());
std
::
sort
(
vector_copy
.
begin
(),
vector_copy
.
end
());
//
//
for (size_t block_size = 1; block_size < count + 2; block_size++) {
for
(
size_t
block_size
=
1
;
block_size
<
count
+
2
;
block_size
++
)
{
//
vector = init;
vector
=
init
;
//
MergeSortAllocate(vector.begin(), vector.end(), std::less<int>(),
MergeSortAllocate
(
vector
.
begin
(),
vector
.
end
(),
std
::
less
<
int
>
(),
//
ExecutionPolicy(), block_size);
ExecutionPolicy
(),
block_size
);
//
for (size_t i = 0; i < count; i++) {
for
(
size_t
i
=
0
;
i
<
count
;
i
++
)
{
//
PT_EXPECT_EQ(vector[i], vector_copy[i]);
PT_EXPECT_EQ
(
vector
[
i
],
vector_copy
[
i
]);
//
}
}
//
}
}
//
}
}
void
MergeSortTest
::
TestPolicy
()
{
void
MergeSortTest
::
TestPolicy
()
{
using
embb
::
algorithms
::
MergeSortAllocate
;
using
embb
::
algorithms
::
MergeSortAllocate
;
...
@@ -201,17 +201,43 @@ void MergeSortTest::TestPolicy() {
...
@@ -201,17 +201,43 @@ void MergeSortTest::TestPolicy() {
vector
=
init
;
vector
=
init
;
MergeSortAllocate
(
vector
.
begin
(),
vector
.
end
(),
std
::
less
<
int
>
(),
MergeSortAllocate
(
vector
.
begin
(),
vector
.
end
(),
std
::
less
<
int
>
(),
ExecutionPolicy
(
true
));
ExecutionPolicy
(
true
));
for
(
size_t
i
=
0
;
i
<
count
;
i
++
)
{
for
(
size_t
i
=
0
;
i
<
count
;
i
++
)
{
PT_EXPECT_EQ
(
vector_copy
[
i
],
vector
[
i
]);
PT_EXPECT_EQ
(
vector_copy
[
i
],
vector
[
i
]);
}
}
vector
=
init
;
vector
=
init
;
MergeSortAllocate
(
vector
.
begin
(),
vector
.
end
(),
std
::
less
<
int
>
(),
MergeSortAllocate
(
vector
.
begin
(),
vector
.
end
(),
std
::
less
<
int
>
(),
ExecutionPolicy
(
true
,
1
));
ExecutionPolicy
(
true
,
1
));
for
(
size_t
i
=
0
;
i
<
count
;
i
++
)
{
for
(
size_t
i
=
0
;
i
<
count
;
i
++
)
{
PT_EXPECT_EQ
(
vector_copy
[
i
],
vector
[
i
]);
PT_EXPECT_EQ
(
vector_copy
[
i
],
vector
[
i
]);
}
}
// MergeSort on empty list should not throw:
MergeSortAllocate
(
vector
.
begin
(),
vector
.
begin
(),
std
::
less
<
int
>
());
#ifdef EMBB_USE_EXCEPTIONS
bool
empty_core_set_thrown
=
false
;
try
{
MergeSortAllocate
(
vector
.
begin
(),
vector
.
end
(),
std
::
less
<
int
>
(),
ExecutionPolicy
(
false
));
}
catch
(
embb
::
base
::
ErrorException
&
)
{
empty_core_set_thrown
=
true
;
}
PT_EXPECT_MSG
(
empty_core_set_thrown
,
"Empty core set should throw ErrorException"
);
bool
negative_range_thrown
=
false
;
try
{
std
::
vector
<
int
>::
iterator
second
=
vector
.
begin
()
+
1
;
MergeSortAllocate
(
second
,
vector
.
begin
(),
std
::
less
<
int
>
());
}
catch
(
embb
::
base
::
ErrorException
&
)
{
negative_range_thrown
=
true
;
}
PT_EXPECT_MSG
(
negative_range_thrown
,
"Negative range should throw ErrorException"
);
#endif
}
}
void
MergeSortTest
::
StressTest
()
{
void
MergeSortTest
::
StressTest
()
{
...
...
algorithms_cpp/test/merge_sort_test.h
View file @
db74f3e9
...
@@ -58,7 +58,7 @@ class MergeSortTest : public partest::TestCase {
...
@@ -58,7 +58,7 @@ class MergeSortTest : public partest::TestCase {
/**
/**
* Tests various block sizes for the workers.
* Tests various block sizes for the workers.
*/
*/
//
void TestBlockSizes();
void
TestBlockSizes
();
/**
/**
* Tests setting policies (without checking their actual execution).
* Tests setting policies (without checking their actual execution).
...
...
algorithms_cpp/test/quick_sort_test.cc
View file @
db74f3e9
...
@@ -218,6 +218,32 @@ void QuickSortTest::TestPolicy() {
...
@@ -218,6 +218,32 @@ void QuickSortTest::TestPolicy() {
for
(
size_t
i
=
0
;
i
<
count
;
i
++
)
{
for
(
size_t
i
=
0
;
i
<
count
;
i
++
)
{
PT_EXPECT_EQ
(
vector_copy
[
i
],
vector
[
i
]);
PT_EXPECT_EQ
(
vector_copy
[
i
],
vector
[
i
]);
}
}
// MergeSort on empty list should not throw:
QuickSort
(
vector
.
begin
(),
vector
.
begin
(),
std
::
less
<
int
>
());
#ifdef EMBB_USE_EXCEPTIONS
bool
empty_core_set_thrown
=
false
;
try
{
QuickSort
(
vector
.
begin
(),
vector
.
end
(),
std
::
less
<
int
>
(),
ExecutionPolicy
(
false
));
}
catch
(
embb
::
base
::
ErrorException
&
)
{
empty_core_set_thrown
=
true
;
}
PT_EXPECT_MSG
(
empty_core_set_thrown
,
"Empty core set should throw ErrorException"
);
bool
negative_range_thrown
=
false
;
try
{
std
::
vector
<
int
>::
iterator
second
=
vector
.
begin
()
+
1
;
QuickSort
(
second
,
vector
.
begin
(),
std
::
less
<
int
>
());
}
catch
(
embb
::
base
::
ErrorException
&
)
{
negative_range_thrown
=
true
;
}
PT_EXPECT_MSG
(
negative_range_thrown
,
"Negative range should throw ErrorException"
);
#endif
}
}
void
QuickSortTest
::
StressTest
()
{
void
QuickSortTest
::
StressTest
()
{
...
...
algorithms_cpp/test/reduce_test.cc
View file @
db74f3e9
...
@@ -181,6 +181,31 @@ void ReduceTest::TestPolicy() {
...
@@ -181,6 +181,31 @@ void ReduceTest::TestPolicy() {
Identity
(),
ExecutionPolicy
(
true
)),
sum
);
Identity
(),
ExecutionPolicy
(
true
)),
sum
);
PT_EXPECT_EQ
(
Reduce
(
vector
.
begin
(),
vector
.
end
(),
0
,
std
::
plus
<
int
>
(),
PT_EXPECT_EQ
(
Reduce
(
vector
.
begin
(),
vector
.
end
(),
0
,
std
::
plus
<
int
>
(),
Identity
(),
ExecutionPolicy
(
true
,
1
)),
sum
);
Identity
(),
ExecutionPolicy
(
true
,
1
)),
sum
);
// Empty list should return neutral element:
PT_EXPECT_EQ
(
Reduce
(
vector
.
begin
(),
vector
.
begin
(),
41
,
std
::
plus
<
int
>
(),
Identity
(),
ExecutionPolicy
(
true
,
1
)),
41
);
#ifdef EMBB_USE_EXCEPTIONS
bool
empty_core_set_thrown
=
false
;
try
{
Reduce
(
vector
.
begin
(),
vector
.
end
(),
0
,
std
::
plus
<
int
>
(),
Identity
(),
ExecutionPolicy
(
false
));
}
catch
(
embb
::
base
::
ErrorException
&
)
{
empty_core_set_thrown
=
true
;
}
PT_EXPECT_MSG
(
empty_core_set_thrown
,
"Empty core set should throw ErrorException"
);
bool
negative_range_thrown
=
false
;
try
{
std
::
vector
<
int
>::
iterator
second
=
vector
.
begin
()
+
1
;
Reduce
(
second
,
vector
.
begin
(),
0
,
std
::
plus
<
int
>
());
}
catch
(
embb
::
base
::
ErrorException
&
)
{
negative_range_thrown
=
true
;
}
PT_EXPECT_MSG
(
negative_range_thrown
,
"Negative range should throw ErrorException"
);
#endif
}
}
void
ReduceTest
::
StressTest
()
{
void
ReduceTest
::
StressTest
()
{
...
...
algorithms_cpp/test/scan_test.cc
View file @
db74f3e9
...
@@ -290,6 +290,35 @@ void ScanTest::TestPolicy() {
...
@@ -290,6 +290,35 @@ void ScanTest::TestPolicy() {
expected
+=
vector
[
i
];
expected
+=
vector
[
i
];
PT_EXPECT_EQ
(
expected
,
outputVector
[
i
]);
PT_EXPECT_EQ
(
expected
,
outputVector
[
i
]);
}
}
// Empty list should not throw and not change output:
outputVector
=
init
;
std
::
vector
<
int
>::
iterator
out_it
=
outputVector
.
begin
();
Scan
(
vector
.
begin
(),
vector
.
begin
(),
out_it
,
0
,
std
::
plus
<
int
>
());
PT_EXPECT
(
out_it
==
outputVector
.
begin
());
#ifdef EMBB_USE_EXCEPTIONS
bool
empty_core_set_thrown
=
false
;
try
{
Scan
(
vector
.
begin
(),
vector
.
end
(),
outputVector
.
begin
(),
0
,
std
::
plus
<
int
>
(),
Identity
(),
ExecutionPolicy
(
false
));
}
catch
(
embb
::
base
::
ErrorException
&
)
{
empty_core_set_thrown
=
true
;
}
PT_EXPECT_MSG
(
empty_core_set_thrown
,
"Empty core set should throw ErrorException"
);
bool
negative_range_thrown
=
false
;
try
{
std
::
vector
<
int
>::
iterator
second
=
vector
.
begin
()
+
1
;
Scan
(
second
,
vector
.
begin
(),
outputVector
.
begin
(),
0
,
std
::
plus
<
int
>
());
}
catch
(
embb
::
base
::
ErrorException
&
)
{
negative_range_thrown
=
true
;
}
PT_EXPECT_MSG
(
negative_range_thrown
,
"Negative range should throw ErrorException"
);
#endif
}
}
void
ScanTest
::
StressTest
()
{
void
ScanTest
::
StressTest
()
{
...
...
base_cpp/include/embb/base/internal/thread_closures.h
View file @
db74f3e9
...
@@ -36,8 +36,8 @@ namespace internal {
...
@@ -36,8 +36,8 @@ namespace internal {
/**
/**
* Thread closure for thread start function with no arguments.
* Thread closure for thread start function with no arguments.
*
*
* Provides a thread start function
calling a callable entity such as a function
* Provides a thread start function
from which a priorly stored function object
*
pointer or functor
.
*
is called
.
*/
*/
template
<
typename
Function
>
template
<
typename
Function
>
struct
ThreadClosure
{
struct
ThreadClosure
{
...
@@ -56,8 +56,8 @@ struct ThreadClosure {
...
@@ -56,8 +56,8 @@ struct ThreadClosure {
/**
/**
* Thread closure for thread start function with one argument.
* Thread closure for thread start function with one argument.
*
*
* Provides a thread start function
calling a callable entity such as a function
* Provides a thread start function
from which a priorly stored function object
*
pointer or functor
.
*
is called
.
*/
*/
template
<
typename
Function
,
typename
Arg1
>
template
<
typename
Function
,
typename
Arg1
>
struct
ThreadClosureArg1
{
struct
ThreadClosureArg1
{
...
@@ -78,8 +78,8 @@ struct ThreadClosureArg1 {
...
@@ -78,8 +78,8 @@ struct ThreadClosureArg1 {
/**
/**
* Thread closure for thread start function with two arguments.
* Thread closure for thread start function with two arguments.
*
*
* Provides a thread start function
calling a callable entity such as a function
* Provides a thread start function
from which a priorly stored function object
*
pointer or functor
.
*
is called
.
*/
*/
template
<
typename
Function
,
typename
Arg1
,
typename
Arg2
>
template
<
typename
Function
,
typename
Arg1
,
typename
Arg2
>
struct
ThreadClosureArg2
{
struct
ThreadClosureArg2
{
...
...
base_cpp/include/embb/base/thread.h
View file @
db74f3e9
...
@@ -154,12 +154,12 @@ class Thread {
...
@@ -154,12 +154,12 @@ class Thread {
* \memory A small constant amount of memory to store the function. This
* \memory A small constant amount of memory to store the function. This
* memory is freed the thread is joined.
* memory is freed the thread is joined.
* \notthreadsafe
* \notthreadsafe
* \tparam Function
Type of callabl
e
* \tparam Function
Function object typ
e
*/
*/
template
<
typename
Function
>
template
<
typename
Function
>
explicit
Thread
(
explicit
Thread
(
Function
function
Function
function
/**< [IN] C
allable (without arguments, must be copyable)
*/
/**< [IN] C
opyable function object, callable without arguments
*/
);
);
/**
/**
...
@@ -174,14 +174,14 @@ class Thread {
...
@@ -174,14 +174,14 @@ class Thread {
* \memory A small constant amount of memory to store the function. This
* \memory A small constant amount of memory to store the function. This
* memory is freed the thread is joined.
* memory is freed the thread is joined.
* \notthreadsafe
* \notthreadsafe
* \tparam Function
Type of callabl
e
* \tparam Function
Function object typ
e
*/
*/
template
<
typename
Function
>
template
<
typename
Function
>
explicit
Thread
(
explicit
Thread
(
CoreSet
&
core_set
,
CoreSet
&
core_set
,
/**< [IN] Set of cores on which the thread shall be executed. */
/**< [IN] Set of cores on which the thread shall be executed. */
Function
function
Function
function
/**< [IN] C
allable (without arguments, must be copyable)
*/
/**< [IN] C
opyable function object, callable without arguments
*/
);
);
/**
/**
...
@@ -196,13 +196,13 @@ class Thread {
...
@@ -196,13 +196,13 @@ class Thread {
* \memory A small constant amount of memory to store the function. This
* \memory A small constant amount of memory to store the function. This
* memory is freed the thread is joined.
* memory is freed the thread is joined.
* \notthreadsafe
* \notthreadsafe
* \tparam Function
Type of callabl
e
* \tparam Function
Function object typ
e
* \tparam Argument Type of argument
* \tparam Argument Type of argument
*/
*/
template
<
typename
Function
,
typename
Arg
>
template
<
typename
Function
,
typename
Arg
>
Thread
(
Thread
(
Function
function
,
Function
function
,
/**< [IN] C
allable (with one argument, must be copyable)
*/
/**< [IN] C
opyable function object, callable with one argument
*/
Arg
arg
Arg
arg
/**< [IN] Argument for function (must be copyable) */
/**< [IN] Argument for function (must be copyable) */
);
);
...
@@ -219,14 +219,14 @@ class Thread {
...
@@ -219,14 +219,14 @@ class Thread {
* \memory A small constant amount of memory to store the function. This
* \memory A small constant amount of memory to store the function. This
* memory is freed the thread is joined.
* memory is freed the thread is joined.
* \notthreadsafe
* \notthreadsafe
* \tparam Function
Type of callabl
e
* \tparam Function
Function object typ
e
* \tparam Arg1 Type of first argument
* \tparam Arg1 Type of first argument
* \tparam Arg2 Type of second argument
* \tparam Arg2 Type of second argument
*/
*/
template
<
typename
Function
,
typename
Arg1
,
typename
Arg2
>
template
<
typename
Function
,
typename
Arg1
,
typename
Arg2
>
Thread
(
Thread
(
Function
function
,
Function
function
,
/**< [IN] C
allable (with two arguments, must be copyable)
*/
/**< [IN] C
opyable function object, callable with two arguments
*/
Arg1
arg1
,
Arg1
arg1
,
/**< [IN] First argument for function (must be copyable) */
/**< [IN] First argument for function (must be copyable) */
Arg2
arg2
Arg2
arg2
...
...
mtapi_c/include/embb/mtapi/c/mtapi.h
View file @
db74f3e9
...
@@ -68,7 +68,7 @@
...
@@ -68,7 +68,7 @@
* </tr>
* </tr>
* <tr>
* <tr>
* <td>Action Function</td>
* <td>Action Function</td>
* <td>The
callable, an
executable function of an action, invoked by the
* <td>The executable function of an action, invoked by the
* MTAPI runtime when a task is started.</td>
* MTAPI runtime when a task is started.</td>
* </tr>
* </tr>
* <tr>
* <tr>
...
...
mtapi_cpp/include/embb/mtapi/action.h
View file @
db74f3e9
...
@@ -51,13 +51,13 @@ class Action {
...
@@ -51,13 +51,13 @@ class Action {
}
}
/**
/**
* Constructs an Action from any entity that provides an
* Constructs an Action from a function object.
* operator() (TaskContext &).
*
* \tparam Function Function object
*/
*/
template
<
typename
Function
>
template
<
typename
Function
>
Action
(
Action
(
Function
func
/**< [in] Anything that provides an
Function
func
/**< [in] Function object */
operator() (TaskContext &). */
)
)
:
function_
(
func
)
:
function_
(
func
)
,
execution_policy_
()
{
,
execution_policy_
()
{
...
@@ -65,13 +65,13 @@ class Action {
...
@@ -65,13 +65,13 @@ class Action {
}
}
/**
/**
* Constructs an Action from any entity that provides an
* Constructs an Action from a function object and an Affinity.
* operator() (TaskContext &) and an Affinity.
*
* \tparam Function Function object
*/
*/
template
<
typename
Function
>
template
<
typename
Function
>
Action
(
Action
(
Function
func
,
/**< [in] Anything that provides an
Function
func
,
/**< [in] Function object */
operator() (TaskContext &). */
ExecutionPolicy
execution_policy
/**< [in] Execution policy */
ExecutionPolicy
execution_policy
/**< [in] Execution policy */
)
)
:
function_
(
func
)
:
function_
(
func
)
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment