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
f3fe5ac3
authored
Apr 02, 2019
by
FritzFlorian
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fix: use new id type in all tasks.
parent
2eb9674a
Show whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
22 additions
and
17 deletions
+22
-17
app/playground/main.cpp
+5
-6
lib/pls/include/pls/internal/scheduling/abstract_task.h
+5
-2
lib/pls/include/pls/internal/scheduling/root_task.h
+2
-2
lib/pls/include/pls/internal/scheduling/run_on_n_threads_task.h
+2
-2
lib/pls/include/pls/internal/scheduling/tbb_task.h
+3
-2
lib/pls/include/pls/pls.h
+4
-2
lib/pls/src/internal/scheduling/tbb_task.cpp
+1
-1
No files found.
app/playground/main.cpp
View file @
f3fe5ac3
...
...
@@ -5,6 +5,7 @@
#include <atomic>
#include <pls/pls.h>
#include <pls/internal/base/prohibit_new.h>
using
namespace
pls
;
...
...
@@ -42,10 +43,8 @@ protected:
int
left_result
;
int
right_result
;
fib
left_child
{
num_
-
1
,
&
left_result
};
spawn_child
(
left_child
);
fib
right_child
{
num_
-
2
,
&
right_result
};
spawn_child
(
right_child
);
spawn_child
(
fib
{
num_
-
1
,
&
left_result
});
spawn_child
(
fib
{
num_
-
2
,
&
right_result
});
wait_for_all
();
*
result_
=
left_result
+
right_result
;
...
...
@@ -58,14 +57,14 @@ public:
int
main
()
{
scheduler
my_scheduler
{
&
my_scheduler_memory
,
1
};
scheduler
my_scheduler
{
&
my_scheduler_memory
,
4
};
auto
start
=
std
::
chrono
::
high_resolution_clock
::
now
();
my_scheduler
.
perform_work
([]
(){
int
result
;
fib
fib_sub_task
{
45
,
&
result
};
tbb_task
tbb_task
{
&
fib_sub_task
};
tbb_task
tbb_task
{
&
fib_sub_task
,
task_id
{
1
}
};
scheduler
::
execute_task
(
tbb_task
);
std
::
cout
<<
"Result: "
<<
result
<<
std
::
endl
;
...
...
lib/pls/include/pls/internal/scheduling/abstract_task.h
View file @
f3fe5ac3
...
...
@@ -10,23 +10,25 @@ namespace pls {
namespace
internal
{
namespace
scheduling
{
class
abstract_task
{
public
:
struct
id
{
uint32_t
id_
;
bool
auto_generated_
;
explicit
id
(
uint32_t
id
,
bool
auto_generated
=
tru
e
)
:
id_
{
id
},
auto_generated_
{
auto_generated
}
{};
explicit
id
(
uint32_t
id
,
bool
auto_generated
=
fals
e
)
:
id_
{
id
},
auto_generated_
{
auto_generated
}
{};
bool
operator
==
(
const
abstract_task
::
id
&
other
)
const
{
return
id_
==
other
.
id_
&&
auto_generated_
==
other
.
auto_generated_
;
}
};
private
:
int
depth_
;
abstract_task
::
id
unique_id_
;
abstract_task
*
child_task_
;
public
:
abstract_task
(
int
depth
,
abstract_task
::
id
unique_id
)
:
abstract_task
(
const
int
depth
,
const
abstract_task
::
id
&
unique_id
)
:
depth_
{
depth
},
unique_id_
{
unique_id
},
child_task_
{
nullptr
}
{}
...
...
@@ -37,6 +39,7 @@ namespace pls {
void
set_depth
(
int
depth
)
{
depth_
=
depth
;
}
int
depth
()
const
{
return
depth_
;
}
id
unique_id
()
const
{
return
unique_id_
;
}
protected
:
virtual
bool
internal_stealing
(
abstract_task
*
other_task
)
=
0
;
virtual
bool
split_task
(
base
::
spin_lock
*
lock
)
=
0
;
...
...
lib/pls/include/pls/internal/scheduling/root_task.h
View file @
f3fe5ac3
...
...
@@ -19,7 +19,7 @@ namespace pls {
base
::
spin_lock
finished_lock_
;
public
:
explicit
root_task
(
Function
function
)
:
abstract_task
{
0
,
0
},
abstract_task
{
0
,
id
{
0
,
true
}
},
function_
{
function
},
finished_
{
false
}
{}
...
...
@@ -51,7 +51,7 @@ namespace pls {
public
:
explicit
root_worker_task
(
root_task
<
Function
>*
master_task
)
:
abstract_task
{
0
,
0
},
abstract_task
{
0
,
id
{
0
,
true
}
},
master_task_
{
master_task
}
{}
void
execute
()
override
{
...
...
lib/pls/include/pls/internal/scheduling/run_on_n_threads_task.h
View file @
f3fe5ac3
...
...
@@ -37,7 +37,7 @@ namespace pls {
}
public
:
run_on_n_threads_task
(
Function
function
,
int
num_threads
)
:
abstract_task
{
PLS_UNIQUE_ID
,
0
},
abstract_task
{
0
,
id
{
PLS_UNIQUE_ID
,
true
}
},
function_
{
function
},
counter
{
num_threads
-
1
}
{}
...
...
@@ -66,7 +66,7 @@ namespace pls {
run_on_n_threads_task
<
Function
>*
root_
;
public
:
run_on_n_threads_task_worker
(
Function
function
,
run_on_n_threads_task
<
Function
>*
root
)
:
abstract_task
{
PLS_UNIQUE_ID
,
0
},
abstract_task
{
0
,
id
{
PLS_UNIQUE_ID
,
true
}
},
function_
{
function
},
root_
{
root
}
{}
...
...
lib/pls/include/pls/internal/scheduling/tbb_task.h
View file @
f3fe5ac3
...
...
@@ -70,9 +70,10 @@ namespace pls {
bool
split_task
(
base
::
spin_lock
*
/*lock*/
)
override
;
public
:
explicit
tbb_task
(
tbb_sub_task
*
root_task
)
:
abstract_task
{
0
,
0
},
explicit
tbb_task
(
tbb_sub_task
*
root_task
,
const
abstract_task
::
id
&
id
)
:
abstract_task
{
0
,
id
},
root_task_
{
root_task
},
my_stack_
{
nullptr
},
deque_
{},
last_stolen_
{
nullptr
}
{};
...
...
lib/pls/include/pls/pls.h
View file @
f3fe5ac3
#ifndef PLS_LIBRARY_H
#define PLS_LIBRARY_H
#include <pls/internal/scheduling/scheduler.h>
#include <pls/internal/scheduling/tbb_task.h>
#include "pls/internal/scheduling/scheduler.h"
#include "pls/internal/scheduling/tbb_task.h"
#include "pls/internal/scheduling/abstract_task.h"
namespace
pls
{
using
internal
::
scheduling
::
scheduler
;
using
internal
::
scheduling
::
static_scheduler_memory
;
using
task_id
=
internal
::
scheduling
::
abstract_task
::
id
;
using
internal
::
scheduling
::
tbb_sub_task
;
using
internal
::
scheduling
::
tbb_task
;
...
...
lib/pls/src/internal/scheduling/tbb_task.cpp
View file @
f3fe5ac3
...
...
@@ -82,7 +82,7 @@ namespace pls {
if
(
stolen_sub_task
==
nullptr
)
{
return
false
;
}
tbb_task
task
{
stolen_sub_task
};
tbb_task
task
{
stolen_sub_task
,
this
->
unique_id
()
};
// In success case, unlock.
// TODO: this locking is complicated and error prone.
...
...
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