Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
E
emper
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container Registry
Model registry
Operate
Environments
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Lehrstuhl für Informatik 4 (Systemsoftware)
manycore
emper
Commits
ca5bcf5c
Commit
ca5bcf5c
authored
3 years ago
by
Florian Schmaus
Browse files
Options
Downloads
Patches
Plain Diff
[apps]: Modernize 'fib' app
parent
43e1fbe7
No related branches found
No related tags found
1 merge request
!353
Work-Stealing queue fill-size stats
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
apps/FibChildStealing.cpp
+122
-0
122 additions, 0 deletions
apps/FibChildStealing.cpp
apps/fsearch/meson.build
+0
-14
0 additions, 14 deletions
apps/fsearch/meson.build
apps/meson.build
+22
-6
22 additions, 6 deletions
apps/meson.build
iwyu-mappings.imp
+1
-0
1 addition, 0 deletions
iwyu-mappings.imp
with
145 additions
and
20 deletions
apps/
Ma
in.cpp
→
apps/
FibChildSteal
in
g
.cpp
+
122
−
0
View file @
ca5bcf5c
// SPDX-License-Identifier: LGPL-3.0-or-later
// Copyright © 2020 Florian Schmaus
#include
<cstdlib>
// for exit, EXIT_SUCCESS
// Copyright © 2020-2022 Florian Schmaus
#include
<boost/program_options.hpp>
#include
<cstdint>
#include
<iostream>
// for basic_ostream::operator<<
#include
<memory>
#include
<thread>
#include
"BinaryPrivateSemaphore.hpp"
// for BPS
#include
"CountingPrivateSemaphore.hpp"
// for CPS
...
...
@@ -9,18 +12,20 @@
#include
"Fiber.hpp"
// for Fiber
#include
"PrivateSemaphore.hpp"
// for PS
#include
"Runtime.hpp"
// for Runtime
#include
"emper-common.h"
// for UNUSED_ARG
#include
"lib/sync/Semaphore.hpp"
namespace
po
=
boost
::
program_options
;
using
fibParams
=
struct
{
int
n
;
int
*
result
;
u
int
64_t
n
;
u
int
64_t
*
result
;
PS
*
sem
;
};
static
void
fib
(
void
*
voidParams
)
{
auto
*
params
=
static_cast
<
fibParams
*>
(
voidParams
);
int
n
=
params
->
n
;
int
*
result
=
params
->
result
;
u
int
64_t
n
=
params
->
n
;
auto
*
result
=
params
->
result
;
PS
*
sem
=
params
->
sem
;
if
(
n
<
2
)
{
...
...
@@ -28,12 +33,15 @@ static void fib(void* voidParams) {
}
else
{
CPS
newSem
(
2
);
int
a
,
b
;
u
int
64_t
a
,
b
;
fibParams
newParams1
;
newParams1
.
n
=
n
-
1
;
newParams1
.
result
=
&
a
;
newParams1
.
sem
=
&
newSem
;
// Note that this is the inefficient spawn/sync variant, we
// usually would compute one previous fib number without spawning.
fibParams
newParams2
;
newParams2
.
n
=
n
-
2
;
newParams2
.
result
=
&
b
;
...
...
@@ -56,35 +64,59 @@ static void fib(void* voidParams) {
sem
->
signalAndExit
();
}
static
void
fibKickoff
()
{
const
int
fibNum
=
4
;
int
result
;
BPS
sem
;
fibParams
params
=
{
fibNum
,
&
result
,
&
sem
};
// NOLINTNEXTLINE(bugprone-exception-escape)
auto
main
(
int
argc
,
char
*
argv
[])
->
int
{
uint64_t
fibNum
=
-
1
;
po
::
options_description
desc
(
"Allowed options"
);
// clang-format off
desc
.
add_options
()
(
"help"
,
"Show help"
)
(
"nthreads"
,
po
::
value
<
unsigned
int
>
()
->
default_value
(
std
::
thread
::
hardware_concurrency
()),
"Number of worker threads used by EMPER's runtime system"
)
(
"fibnum"
,
po
::
value
<
uint64_t
>
(
&
fibNum
)
->
default_value
(
12
),
"The Fibonacci number to compute"
)
;
// clang-format on
// Make 'fibnum' a positional option.
po
::
positional_options_description
pos_desc
;
pos_desc
.
add
(
"fibnum"
,
-
1
);
// clang-format off
auto
parse_result
=
po
::
command_line_parser
(
argc
,
argv
)
.
options
(
desc
)
.
positional
(
pos_desc
)
.
run
()
;
// clang-format on
po
::
variables_map
vm
;
po
::
store
(
parse_result
,
vm
);
po
::
notify
(
vm
);
const
unsigned
nthreads
=
vm
[
"nthreads"
].
as
<
unsigned
int
>
();
fib
(
&
params
)
;
std
::
cout
<<
"Number of threads: "
<<
nthreads
<<
std
::
endl
;
sem
.
wait
(
);
Runtime
runtime
(
nthreads
);
std
::
cout
<<
"fib("
<<
fibNum
<<
") = "
<<
result
<<
std
::
endl
;
exit
(
EXIT_SUCCESS
);
}
emper
::
lib
::
sync
::
Semaphore
semaphore
;
auto
main
(
UNUSED_ARG
int
argc
,
UNUSED_ARG
char
*
argv
[])
->
int
{
// const unsigned nthreads = std::thread::hardware_concurrency()
;
const
unsigned
nthreads
=
2
;
Fiber
*
fibFiber
=
Fiber
::
from
([
&
]
{
uint64_t
result
;
BPS
sem
;
fibParams
params
=
{
fibNum
,
&
result
,
&
sem
};
std
::
cout
<<
"Number of threads: "
<<
nthreads
<<
std
::
endl
;
fib
(
&
params
)
;
Runtime
runtime
(
nthreads
);
sem
.
wait
(
);
Fiber
*
fibFiber
=
Fiber
::
from
(
&
fibKickoff
)
;
std
::
cout
<<
"fib("
<<
fibNum
<<
") = "
<<
result
<<
std
::
endl
;
std
::
cout
<<
"Just alloacted alpha fiber at "
<<
fibFiber
<<
std
::
endl
;
semaphore
.
notify
();
});
runtime
.
scheduleFromAnywhere
(
*
fibFiber
);
runtime
.
waitUntilFinished
();
semaphore
.
wait
();
return
0
;
}
This diff is collapsed.
Click to expand it.
apps/fsearch/meson.build
+
0
−
14
View file @
ca5bcf5c
boost_program_options_dep
=
dependency
(
'boost'
,
modules
:
[
'program_options'
])
boost_program_options_code
=
'''
#include <boost/program_options.hpp>
int main(int argc, char* argv[]) {
boost::program_options::options_description desc("Allowed options");
}
'''
cpp_can_link_with_boost_program_options
=
cpp_compiler
.
links
(
boost_program_options_code
,
name
:
'boost_progam_options'
,
dependencies
:
boost_program_options_dep
,
)
if
cpp_has_fs_recursive_directory_iterator
and
cpp_can_link_with_boost_program_options
fsearch_exe
=
executable
(
'fsearch'
,
...
...
This diff is collapsed.
Click to expand it.
apps/meson.build
+
22
−
6
View file @
ca5bcf5c
fib_exe
=
executable
(
'fib'
,
'Main.cpp'
,
dependencies
:
emper_dep
,
)
worker_sleep_example_exe
=
executable
(
'worker_sleep_example'
,
'WorkerSleepExample.cpp'
,
...
...
@@ -40,4 +34,26 @@ qsort = executable(
dependencies
:
emper_dep
,
)
boost_program_options_dep
=
dependency
(
'boost'
,
modules
:
[
'program_options'
])
boost_program_options_code
=
'''
#include <boost/program_options.hpp>
int main(int argc, char* argv[]) {
boost::program_options::options_description desc("Allowed options");
}
'''
cpp_can_link_with_boost_program_options
=
cpp_compiler
.
links
(
boost_program_options_code
,
name
:
'boost_progam_options'
,
dependencies
:
boost_program_options_dep
,
)
if
cpp_can_link_with_boost_program_options
fib_child_stealing_exe
=
executable
(
'fib-child-stealing'
,
'FibChildStealing.cpp'
,
dependencies
:
[
emper_dep
,
boost_program_options_dep
],
)
endif
subdir
(
'fsearch'
)
This diff is collapsed.
Click to expand it.
iwyu-mappings.imp
+
1
−
0
View file @
ca5bcf5c
...
...
@@ -20,6 +20,7 @@
{ include: ["<boost/program_options/parsers.hpp>", "private", "<boost/program_options.hpp>", "public"], },
{ include: ["<boost/program_options/positional_options.hpp>", "private", "<boost/program_options.hpp>", "public"], },
{ include: ["<boost/type_index/type_index_facade.hpp>", "private", "<boost/program_options.hpp>", "public"], },
{ include: ["<boost/cstdint.hpp>", "private", "<cstdint>", "public"], },
{ symbol: ["__kernel_timespec", "private", "<liburing.h>", "public" ] },
{ symbol: ["std::filesystem", "private", "<filesystem>", "public" ] },
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment