Skip to content
Toggle navigation
P
Projects
G
Groups
S
Snippets
Help
las3_pub
/
predictable_parallel_patterns
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
e3237abd
authored
May 13, 2019
by
FritzFlorian
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add parallel_for based on fork_join tasks.
parent
f724c1d0
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
118 additions
and
39 deletions
+118
-39
CMakeLists.txt
+1
-0
lib/pls/include/pls/algorithms/parallel_for.h
+15
-0
lib/pls/include/pls/algorithms/parallel_for_impl.h
+57
-0
lib/pls/include/pls/internal/scheduling/parallel_iterator_task.h
+20
-15
lib/pls/include/pls/internal/scheduling/parallel_iterator_task_impl.h
+23
-24
lib/pls/include/pls/pls.h
+2
-0
No files found.
CMakeLists.txt
View file @
e3237abd
...
@@ -35,6 +35,7 @@ add_subdirectory(app/test_for_new)
...
@@ -35,6 +35,7 @@ add_subdirectory(app/test_for_new)
add_subdirectory
(
app/invoke_parallel
)
add_subdirectory
(
app/invoke_parallel
)
add_subdirectory
(
app/benchmark_fft
)
add_subdirectory
(
app/benchmark_fft
)
add_subdirectory
(
app/benchmark_unbalanced
)
add_subdirectory
(
app/benchmark_unbalanced
)
add_subdirectory
(
app/benchmark_matrix
)
# Add optional tests
# Add optional tests
option
(
PACKAGE_TESTS
"Build the tests"
ON
)
option
(
PACKAGE_TESTS
"Build the tests"
ON
)
...
...
lib/pls/include/pls/algorithms/parallel_for.h
0 → 100644
View file @
e3237abd
#ifndef PLS_PARALLEL_FOR_H
#define PLS_PARALLEL_FOR_H
namespace
pls
{
namespace
algorithm
{
template
<
typename
RandomIt
,
typename
Function
>
void
parallel_for
(
RandomIt
first
,
RandomIt
last
,
const
Function
&
function
);
}
}
#include "parallel_for_impl.h"
#endif //PLS_PARALLEL_FOR_H
lib/pls/include/pls/algorithms/parallel_for_impl.h
0 → 100644
View file @
e3237abd
#ifndef PLS_PARALLEL_FOR_IMPL_H
#define PLS_PARALLEL_FOR_IMPL_H
#include "pls/internal/scheduling/fork_join_task.h"
#include "pls/internal/scheduling/scheduler.h"
#include "pls/internal/scheduling/scheduler.h"
#include "pls/internal/helpers/unique_id.h"
namespace
pls
{
namespace
algorithm
{
namespace
internal
{
template
<
typename
RandomIt
,
typename
Function
>
void
parallel_for
(
RandomIt
first
,
RandomIt
last
,
const
Function
&
function
)
{
using
namespace
::
pls
::
internal
::
scheduling
;
using
namespace
::
pls
::
internal
::
helpers
;
using
namespace
::
pls
::
internal
::
base
;
constexpr
long
min_elements
=
4
;
long
num_elements
=
std
::
distance
(
first
,
last
);
if
(
num_elements
<=
min_elements
)
{
// calculate last elements in loop to avoid overhead
for
(
auto
current
=
first
;
current
!=
last
;
current
++
)
{
function
(
*
current
);
}
}
else
{
// Cut in half recursively
long
middle_index
=
num_elements
/
2
;
auto
body
=
[
=
]
{
internal
::
parallel_for
(
first
+
middle_index
,
last
,
function
);
};
fork_join_lambda_by_reference
<
decltype
(
body
)
>
second_half_task
(
body
);
fork_join_sub_task
::
current
()
->
spawn_child
(
second_half_task
);
parallel_for
(
first
,
first
+
middle_index
,
function
);
fork_join_sub_task
::
current
()
->
wait_for_all
();
}
}
}
template
<
typename
RandomIt
,
typename
Function
>
void
parallel_for
(
RandomIt
first
,
RandomIt
last
,
const
Function
&
function
)
{
using
namespace
::
pls
::
internal
::
scheduling
;
using
namespace
::
pls
::
internal
::
helpers
;
using
namespace
::
pls
::
internal
::
base
;
static
abstract_task
::
id
id
=
unique_id
::
create
<
RandomIt
,
Function
>
();
auto
body
=
[
=
]
{
internal
::
parallel_for
(
first
,
last
,
function
);
};
fork_join_lambda_by_reference
<
decltype
(
body
)
>
root_body
(
body
);
fork_join_task
root_task
{
&
root_body
,
id
};
scheduler
::
execute_task
(
root_task
);
}
}
}
#endif //PLS_INVOKE_PARALLEL_IMPL_H
lib/pls/include/pls/internal/scheduling/parallel_iterator_task.h
View file @
e3237abd
...
@@ -5,23 +5,28 @@
...
@@ -5,23 +5,28 @@
#include "abstract_task.h"
#include "abstract_task.h"
namespace
pls
{
namespace
pls
{
namespace
internal
{
namespace
internal
{
namespace
scheduling
{
namespace
scheduling
{
template
<
typename
RandomIt
,
typename
Function
>
template
<
typename
RandomIt
,
typename
Function
>
class
parallel_iterator_task
:
public
abstract_task
{
class
parallel_iterator_task
:
public
abstract_task
{
RandomIt
first_
,
last_
;
RandomIt
first_
,
last_
;
Function
function_
;
Function
function_
;
protected
:
// External stealing
bool
internal_stealing
(
abstract_task
*
other_task
)
override
;
size_t
first_index_ava
,
last_index_ava
;
bool
split_task
(
base
::
spin_lock
*
/*lock*/
)
override
;
// My internal state
size_t
current_index
,
max_index
;
public
:
protected
:
explicit
parallel_iterator_task
(
RandomIt
first
,
RandomIt
last
,
Function
function
,
const
abstract_task
::
id
&
id
);
bool
internal_stealing
(
abstract_task
*
other_task
)
override
;
void
execute
()
override
;
bool
split_task
(
base
::
swmr_spin_lock
*
/*lock*/
)
override
;
};
}
public
:
}
explicit
parallel_iterator_task
(
RandomIt
first
,
RandomIt
last
,
Function
function
,
const
abstract_task
::
id
&
id
);
void
execute
()
override
;
};
}
}
}
}
#include "parallel_iterator_task_impl.h"
#include "parallel_iterator_task_impl.h"
...
...
lib/pls/include/pls/internal/scheduling/parallel_iterator_task_impl.h
View file @
e3237abd
...
@@ -2,34 +2,33 @@
...
@@ -2,34 +2,33 @@
#ifndef PLS_PARALLEL_ITERATOR_TASK_IMPL_H
#ifndef PLS_PARALLEL_ITERATOR_TASK_IMPL_H
#define PLS_PARALLEL_ITERATOR_TASK_IMPL_H
#define PLS_PARALLEL_ITERATOR_TASK_IMPL_H
namespace
pls
{
namespace
pls
{
namespace
internal
{
namespace
internal
{
namespace
scheduling
{
namespace
scheduling
{
template
<
typename
RandomIt
,
typename
Function
>
template
<
typename
RandomIt
,
typename
Function
>
parallel_iterator_task
<
RandomIt
,
Function
>::
parallel_iterator_task
parallel_iterator_task
<
RandomIt
,
Function
>::
parallel_iterator_task
(
RandomIt
first
,
RandomIt
last
,
Function
function
,
const
abstract_task
::
id
&
id
)
:
(
RandomIt
first
,
RandomIt
last
,
Function
function
,
const
abstract_task
::
id
&
id
)
:
abstract_task
(
0
,
id
),
abstract_task
(
0
,
id
),
first_
{
first
},
first_
{
first
},
last_
{
last
},
last_
{
last
},
function_
{
function
}
{}
function_
{
function
}
{}
template
<
typename
RandomIt
,
typename
Function
>
template
<
typename
RandomIt
,
typename
Function
>
void
parallel_iterator_task
<
RandomIt
,
Function
>::
execute
()
{
void
parallel_iterator_task
<
RandomIt
,
Function
>::
execute
()
{
}
}
template
<
typename
RandomIt
,
typename
Function
>
template
<
typename
RandomIt
,
typename
Function
>
bool
parallel_iterator_task
<
RandomIt
,
Function
>::
split_task
(
base
::
spin_lock
*
/*lock*/
)
{
bool
parallel_iterator_task
<
RandomIt
,
Function
>::
split_task
(
base
::
swmr_spin_lock
*
/*lock*/
)
{
return
false
;
return
false
;
}
}
template
<
typename
RandomIt
,
typename
Function
>
template
<
typename
RandomIt
,
typename
Function
>
bool
parallel_iterator_task
<
RandomIt
,
Function
>::
internal_stealing
(
abstract_task
*
other_task
)
{
bool
parallel_iterator_task
<
RandomIt
,
Function
>::
internal_stealing
(
abstract_task
*
other_task
)
{
return
false
;
return
false
;
}
}
}
}
}
}
}
}
#endif //PLS_PARALLEL_ITERATOR_TASK_IMPL_H
#endif //PLS_PARALLEL_ITERATOR_TASK_IMPL_H
lib/pls/include/pls/pls.h
View file @
e3237abd
...
@@ -2,6 +2,7 @@
...
@@ -2,6 +2,7 @@
#define PLS_LIBRARY_H
#define PLS_LIBRARY_H
#include "pls/algorithms/invoke_parallel.h"
#include "pls/algorithms/invoke_parallel.h"
#include "pls/algorithms/parallel_for.h"
#include "pls/internal/scheduling/abstract_task.h"
#include "pls/internal/scheduling/abstract_task.h"
#include "pls/internal/scheduling/fork_join_task.h"
#include "pls/internal/scheduling/fork_join_task.h"
#include "pls/internal/scheduling/scheduler.h"
#include "pls/internal/scheduling/scheduler.h"
...
@@ -23,6 +24,7 @@ using internal::scheduling::fork_join_lambda_by_value;
...
@@ -23,6 +24,7 @@ using internal::scheduling::fork_join_lambda_by_value;
using
internal
::
scheduling
::
fork_join_task
;
using
internal
::
scheduling
::
fork_join_task
;
using
algorithm
::
invoke_parallel
;
using
algorithm
::
invoke_parallel
;
using
algorithm
::
parallel_for
;
}
}
...
...
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