Skip to content
Snippets Groups Projects

Compare revisions

Changes are shown as if the source revision was being merged into the target revision. Learn more about comparing revisions.

Source

Select target project
No results found

Target

Select target project
  • flow/emper
  • aj46ezos/emper
  • i4/manycore/emper
3 results
Show changes
Commits on Source (222)
......@@ -6,14 +6,18 @@ Checks: >
performance-*,
portability-*,
readability-*,
-bugprone-assignment-in-if-condition,
-bugprone-easily-swappable-parameters,
-cert-err58-cpp,
-clang-diagnostic-empty-translation-unit,
-performance-avoid-endl,
-readability-braces-around-statements,
-readability-function-cognitive-complexity,
-readability-identifier-length,
-readability-implicit-bool-conversion,
-readability-isolate-declaration,
-readability-magic-numbers,
-readability-simplify-boolean-expr,
WarningsAsErrors: >
bugprone-*,
......
......@@ -6,6 +6,8 @@
/.cache/
/.clangd/
/clang-tidy-report
tools/gdb/__pycache__/
subprojects/packagecache/
......
*
!.gitignore
image: "flowdalic/debian-testing-dev:1.20"
image: "flowdalic/gentoo-dev:20241216"
before_script:
- ulimit -a
......@@ -19,6 +19,10 @@ before_script:
valgrind
EOF
for tool in ${TOOLS[@]}; do
if ! command -v $tool; then
echo "No $tool binary found"
continue
fi
echo -n "$tool version: "
$tool --version
done
......@@ -29,8 +33,10 @@ cache:
variables:
BUILDDTYPE: debugoptimized
CC: gcc
CXX: g++
GCC: gcc
GXX: g++
CC: $GCC
CXX: $GXX
EXTRA_NINJA_ARGS: -v
stages:
......@@ -87,8 +93,8 @@ clang-tidy:
.gcc:
variables:
CC: gcc
CXX: g++
CC: $GCC
CXX: $GXX
.clang:
variables:
......@@ -103,6 +109,10 @@ clang-tidy:
EMPER_CPP_ARGS: "-stdlib=libc++"
EMPER_CPP_LINK_ARGS: "-stdlib=libc++"
.lto:
variables:
EMPER_B_LTO: "true"
.emper-ws-scheduling:
variables:
EMPER_DEFAULT_SCHEDULING_STRATEGY: "work_stealing"
......@@ -117,7 +127,7 @@ clang-tidy:
.emper-stats:
variables:
EMPER_STATS: 'true'
EMPER_STATS_ALL: 'true'
.emper-userspace-rcu:
variables:
......@@ -151,6 +161,10 @@ clang-tidy:
variables:
EMPER_IO_SINGLE_URING: 'true'
.emper-synchronous-io:
variables:
EMPER_IO_SYNCHRONOUS: 'true'
.emper-io-stealing:
variables:
EMPER_IO_STEALING: 'true'
......@@ -159,6 +173,10 @@ clang-tidy:
variables:
EMPER_IO_LOCKLESS_CQ: 'true'
.emper-io-waitfree-stealing:
variables:
EMPER_IO_WAITFREE_STEALING: 'true'
.default-library-static:
variables:
EMPER_DEFAULT_LIBRARY: 'static'
......@@ -221,6 +239,14 @@ clang-tidy:
variables:
EMPER_WS_QUEUE_SCHEDULER: "cl2"
.ws-queue-scheduler-cl3:
variables:
EMPER_WS_QUEUE_SCHEDULER: "cl3"
.ws-queue-scheduler-cl4:
variables:
EMPER_WS_QUEUE_SCHEDULER: "cl4"
.waitfree-ws:
variables:
EMPER_WAITFREE_WORK_STEALING: "true"
......@@ -277,6 +303,11 @@ smoke-test-libc++:
- .fast-variant-check
- .libc++
test-lto:
extends:
- .test
- .lto
test-libc++:
extends:
- .test
......@@ -349,6 +380,16 @@ test-ws-queue-scheduler-cl2:
- .test
- .ws-queue-scheduler-cl2
test-ws-queue-scheduler-cl3:
extends:
- .test
- .ws-queue-scheduler-cl3
test-ws-queue-scheduler-cl3:
extends:
- .test
- .ws-queue-scheduler-cl3
test-waitfree-ws:
extends:
- .test
......@@ -390,6 +431,11 @@ test-single-uring:
- .test
- .emper-single-uring
test-synchronous-io:
extends:
- .test
- .emper-synchronous-io
test-pipe-sleep-strategy:
extends:
- .test
......@@ -417,6 +463,13 @@ test-lockless-io-stealing:
- .emper-io-stealing
- .emper-lockless-cq
test-waitfree-io-stealing:
extends:
- .test
- .emper-io-stealing
- .emper-lockless-cq
- .emper-io-waitfree-stealing
test-io-stealing-pipe-no-completer:
extends:
- .test
......@@ -491,3 +544,9 @@ stack-guard-page:
- .test
variables:
EMPER_STACK_GUARD_PAGE: 'true'
build-only-emper-dep:
extends:
- .build
variables:
EMPER_BUILD_ONLY_EMPER_DEP: 'true'
GNU LESSER GENERAL PUBLIC LICENSE
Version 3, 29 June 2007
Copyright (C) 2007 Free Software Foundation, Inc. <https://fsf.org/>
Everyone is permitted to copy and distribute verbatim copies
of this license document, but changing it is not allowed.
This version of the GNU Lesser General Public License incorporates
the terms and conditions of version 3 of the GNU General Public
License, supplemented by the additional permissions listed below.
0. Additional Definitions.
As used herein, "this License" refers to version 3 of the GNU Lesser
General Public License, and the "GNU GPL" refers to version 3 of the GNU
General Public License.
"The Library" refers to a covered work governed by this License,
other than an Application or a Combined Work as defined below.
An "Application" is any work that makes use of an interface provided
by the Library, but which is not otherwise based on the Library.
Defining a subclass of a class defined by the Library is deemed a mode
of using an interface provided by the Library.
A "Combined Work" is a work produced by combining or linking an
Application with the Library. The particular version of the Library
with which the Combined Work was made is also called the "Linked
Version".
The "Minimal Corresponding Source" for a Combined Work means the
Corresponding Source for the Combined Work, excluding any source code
for portions of the Combined Work that, considered in isolation, are
based on the Application, and not on the Linked Version.
The "Corresponding Application Code" for a Combined Work means the
object code and/or source code for the Application, including any data
and utility programs needed for reproducing the Combined Work from the
Application, but excluding the System Libraries of the Combined Work.
1. Exception to Section 3 of the GNU GPL.
You may convey a covered work under sections 3 and 4 of this License
without being bound by section 3 of the GNU GPL.
2. Conveying Modified Versions.
If you modify a copy of the Library, and, in your modifications, a
facility refers to a function or data to be supplied by an Application
that uses the facility (other than as an argument passed when the
facility is invoked), then you may convey a copy of the modified
version:
a) under this License, provided that you make a good faith effort to
ensure that, in the event an Application does not supply the
function or data, the facility still operates, and performs
whatever part of its purpose remains meaningful, or
b) under the GNU GPL, with none of the additional permissions of
this License applicable to that copy.
3. Object Code Incorporating Material from Library Header Files.
The object code form of an Application may incorporate material from
a header file that is part of the Library. You may convey such object
code under terms of your choice, provided that, if the incorporated
material is not limited to numerical parameters, data structure
layouts and accessors, or small macros, inline functions and templates
(ten or fewer lines in length), you do both of the following:
a) Give prominent notice with each copy of the object code that the
Library is used in it and that the Library and its use are
covered by this License.
b) Accompany the object code with a copy of the GNU GPL and this license
document.
4. Combined Works.
You may convey a Combined Work under terms of your choice that,
taken together, effectively do not restrict modification of the
portions of the Library contained in the Combined Work and reverse
engineering for debugging such modifications, if you also do each of
the following:
a) Give prominent notice with each copy of the Combined Work that
the Library is used in it and that the Library and its use are
covered by this License.
b) Accompany the Combined Work with a copy of the GNU GPL and this license
document.
c) For a Combined Work that displays copyright notices during
execution, include the copyright notice for the Library among
these notices, as well as a reference directing the user to the
copies of the GNU GPL and this license document.
d) Do one of the following:
0) Convey the Minimal Corresponding Source under the terms of this
License, and the Corresponding Application Code in a form
suitable for, and under terms that permit, the user to
recombine or relink the Application with a modified version of
the Linked Version to produce a modified Combined Work, in the
manner specified by section 6 of the GNU GPL for conveying
Corresponding Source.
1) Use a suitable shared library mechanism for linking with the
Library. A suitable mechanism is one that (a) uses at run time
a copy of the Library already present on the user's computer
system, and (b) will operate properly with a modified version
of the Library that is interface-compatible with the Linked
Version.
e) Provide Installation Information, but only if you would otherwise
be required to provide such information under section 6 of the
GNU GPL, and only to the extent that such information is
necessary to install and execute a modified version of the
Combined Work produced by recombining or relinking the
Application with a modified version of the Linked Version. (If
you use option 4d0, the Installation Information must accompany
the Minimal Corresponding Source and Corresponding Application
Code. If you use option 4d1, you must provide the Installation
Information in the manner specified by section 6 of the GNU GPL
for conveying Corresponding Source.)
5. Combined Libraries.
You may place library facilities that are a work based on the
Library side by side in a single library together with other library
facilities that are not Applications and are not covered by this
License, and convey such a combined library under terms of your
choice, if you do both of the following:
a) Accompany the combined library with a copy of the same work based
on the Library, uncombined with any other library facilities,
conveyed under the terms of this License.
b) Give prominent notice with the combined library that part of it
is a work based on the Library, and explaining where to find the
accompanying uncombined form of the same work.
6. Revised Versions of the GNU Lesser General Public License.
The Free Software Foundation may publish revised and/or new versions
of the GNU Lesser General Public License from time to time. Such new
versions will be similar in spirit to the present version, but may
differ in detail to address new problems or concerns.
Each version is given a distinguishing version number. If the
Library as you received it specifies that a certain numbered version
of the GNU Lesser General Public License "or any later version"
applies to it, you have the option of following the terms and
conditions either of that published version or of any later version
published by the Free Software Foundation. If the Library as you
received it does not specify a version number of the GNU Lesser
General Public License, you may choose any version of the GNU Lesser
General Public License ever published by the Free Software Foundation.
If the Library as you received it specifies that a proxy can decide
whether future versions of the GNU Lesser General Public License shall
apply, that proxy's public statement of acceptance of any version is
permanent authorization for you to choose that version for the
Library.
GNU Lesser General Public License, version 3 or any later version.
See LGPL-3 for the full text of this license.
GNU LESSER GENERAL PUBLIC LICENSE
Version 3, 29 June 2007
Copyright (C) 2007 Free Software Foundation, Inc. <https://fsf.org/>
Everyone is permitted to copy and distribute verbatim copies
of this license document, but changing it is not allowed.
This version of the GNU Lesser General Public License incorporates
the terms and conditions of version 3 of the GNU General Public
License, supplemented by the additional permissions listed below.
0. Additional Definitions.
As used herein, "this License" refers to version 3 of the GNU Lesser
General Public License, and the "GNU GPL" refers to version 3 of the GNU
General Public License.
"The Library" refers to a covered work governed by this License,
other than an Application or a Combined Work as defined below.
An "Application" is any work that makes use of an interface provided
by the Library, but which is not otherwise based on the Library.
Defining a subclass of a class defined by the Library is deemed a mode
of using an interface provided by the Library.
A "Combined Work" is a work produced by combining or linking an
Application with the Library. The particular version of the Library
with which the Combined Work was made is also called the "Linked
Version".
The "Minimal Corresponding Source" for a Combined Work means the
Corresponding Source for the Combined Work, excluding any source code
for portions of the Combined Work that, considered in isolation, are
based on the Application, and not on the Linked Version.
The "Corresponding Application Code" for a Combined Work means the
object code and/or source code for the Application, including any data
and utility programs needed for reproducing the Combined Work from the
Application, but excluding the System Libraries of the Combined Work.
1. Exception to Section 3 of the GNU GPL.
You may convey a covered work under sections 3 and 4 of this License
without being bound by section 3 of the GNU GPL.
2. Conveying Modified Versions.
If you modify a copy of the Library, and, in your modifications, a
facility refers to a function or data to be supplied by an Application
that uses the facility (other than as an argument passed when the
facility is invoked), then you may convey a copy of the modified
version:
a) under this License, provided that you make a good faith effort to
ensure that, in the event an Application does not supply the
function or data, the facility still operates, and performs
whatever part of its purpose remains meaningful, or
b) under the GNU GPL, with none of the additional permissions of
this License applicable to that copy.
3. Object Code Incorporating Material from Library Header Files.
The object code form of an Application may incorporate material from
a header file that is part of the Library. You may convey such object
code under terms of your choice, provided that, if the incorporated
material is not limited to numerical parameters, data structure
layouts and accessors, or small macros, inline functions and templates
(ten or fewer lines in length), you do both of the following:
a) Give prominent notice with each copy of the object code that the
Library is used in it and that the Library and its use are
covered by this License.
b) Accompany the object code with a copy of the GNU GPL and this license
document.
4. Combined Works.
You may convey a Combined Work under terms of your choice that,
taken together, effectively do not restrict modification of the
portions of the Library contained in the Combined Work and reverse
engineering for debugging such modifications, if you also do each of
the following:
a) Give prominent notice with each copy of the Combined Work that
the Library is used in it and that the Library and its use are
covered by this License.
b) Accompany the Combined Work with a copy of the GNU GPL and this license
document.
c) For a Combined Work that displays copyright notices during
execution, include the copyright notice for the Library among
these notices, as well as a reference directing the user to the
copies of the GNU GPL and this license document.
d) Do one of the following:
0) Convey the Minimal Corresponding Source under the terms of this
License, and the Corresponding Application Code in a form
suitable for, and under terms that permit, the user to
recombine or relink the Application with a modified version of
the Linked Version to produce a modified Combined Work, in the
manner specified by section 6 of the GNU GPL for conveying
Corresponding Source.
1) Use a suitable shared library mechanism for linking with the
Library. A suitable mechanism is one that (a) uses at run time
a copy of the Library already present on the user's computer
system, and (b) will operate properly with a modified version
of the Library that is interface-compatible with the Linked
Version.
e) Provide Installation Information, but only if you would otherwise
be required to provide such information under section 6 of the
GNU GPL, and only to the extent that such information is
necessary to install and execute a modified version of the
Combined Work produced by recombining or relinking the
Application with a modified version of the Linked Version. (If
you use option 4d0, the Installation Information must accompany
the Minimal Corresponding Source and Corresponding Application
Code. If you use option 4d1, you must provide the Installation
Information in the manner specified by section 6 of the GNU GPL
for conveying Corresponding Source.)
5. Combined Libraries.
You may place library facilities that are a work based on the
Library side by side in a single library together with other library
facilities that are not Applications and are not covered by this
License, and convey such a combined library under terms of your
choice, if you do both of the following:
a) Accompany the combined library with a copy of the same work based
on the Library, uncombined with any other library facilities,
conveyed under the terms of this License.
b) Give prominent notice with the combined library that part of it
is a work based on the Library, and explaining where to find the
accompanying uncombined form of the same work.
6. Revised Versions of the GNU Lesser General Public License.
The Free Software Foundation may publish revised and/or new versions
of the GNU Lesser General Public License from time to time. Such new
versions will be similar in spirit to the present version, but may
differ in detail to address new problems or concerns.
Each version is given a distinguishing version number. If the
Library as you received it specifies that a certain numbered version
of the GNU Lesser General Public License "or any later version"
applies to it, you have the option of following the terms and
conditions either of that published version or of any later version
published by the Free Software Foundation. If the Library as you
received it does not specify a version number of the GNU Lesser
General Public License, you may choose any version of the GNU Lesser
General Public License ever published by the Free Software Foundation.
If the Library as you received it specifies that a proxy can decide
whether future versions of the GNU Lesser General Public License shall
apply, that proxy's public statement of acceptance of any version is
permanent authorization for you to choose that version for the
Library.
......@@ -50,6 +50,28 @@ clang:
CC=clang CXX=clang++ \
BUILDDIR="build-$@"
.PHONY: clang-release
clang-release:
rm -f build
$(MAKE) build \
CC=clang CXX=clang++ \
BUILDTYPE=release \
BUILDDIR="build-$@"
.PHONY: gcc-%
gcc-%: GCC_VER=$(subst gcc-,,$@)
gcc-%:
rm -f build
$(MAKE) build \
CC=gcc-$(GCC_VER) CXX=g++-$(GCC_VER) \
BUILDDIR="build-$@"
.PHONY: test-%
test-%: TEST_BUILD=$(subst test-,,$@)
test-%:
$(MAKE) $(TEST_BUILD)
meson test -C build-$(TEST_BUILD)
.PHONY: fibril-locked
fibril-locked:
rm -f build
......@@ -75,6 +97,35 @@ stats:
EMPER_STATS=true \
BUILDDIR="build-$@"
.PHONY: lto
lto:
rm -f build
$(MAKE) build \
BUILDTYPE=release \
EMPER_B_LTO=true \
BUILDDIR="build-$@"
.PHONY: asan
asan:
rm -f build
$(MAKE) build \
EMPER_LOG_LEVEL="Info" \
EMPER_B_SANITIZE=address \
BUILDDIR="build-$@"
.PHONY: asan-test
asan-test: asan
meson test -C build-asan
.PHONY: waitfd
waitfd:
rm -f build
$(MAKE) build \
BUILDTYPE=release \
BUILDDIR="build-$@" \
EMPER_WORKER_SLEEP_STRATEGY=waitfd
.PHONY: fast-static-analysis
fast-static-analysis: all check-format check-license doc
......@@ -140,7 +191,7 @@ stresstest: test
# e.g. test-gcc.
.PHONY: gitlab-runner
gitlab-runner:
gitlab-runner exec docker smoke-test
gitlab-ci-local smoke-test-suite
.PHONY: subprojects
subprojects:
......
# EMPER
The Extensible Massive-Parallelism Execution Realm (EMPER) is a concurrency platform to develop and execute parallel applications.
The Efficient Massive-Parallelism Execution Realm (EMPER) is a concurrency platform to develop and execute parallel applications.
EMPER's primary objective is to support the research of different aspects of parallel execution of a potentially massive amount of concurrent strands of execution on current and future many-core systems.
Those aspects include, for example, scheduling strategies, synchronization primitives, and ultimately the overall coordination of concurrent strands of execution concerning optimal resource usage, including locality and energy efficiency.
......@@ -24,11 +24,11 @@ emper_fibril auto fib(int n) -> int {
Fibril fibril;
int a, b;
fibril.fork(&a, fib, n - 1);
fibril.spawn(&a, fib, n - 1);
b = fib(n - 2);
fibril.join();
fibril.sync();
return a + b;
}
......@@ -75,4 +75,36 @@ url: https://www4.cs.fau.de/~flow/papers/schmaus2021nowa.pdf
[pfeiffer2020cactus]
Pfeiffer, Nicolas. A Wait-Free Cactus Stack Implementation for a Microparalelism
Runtime. Master's thesis. MA-I4-2020-02. Mar. 2, 2020.
url: https://www4.cs.fau.de/~flow/papers/pfeiffer2020cactus.pdf
url: https://www4.cs.fau.de/~flow/papers/pfeiffer2020cactus.pdf
# Literature
> The dwarf sees farther than the giant, when he has the giant's shoulder to mount on.
- Samuel Taylor Coleridge, The Friend (1828)
EMPER uses concepts, ideas and algorithms from the following
publications. You will find the key of a publication, e.g.,
[chase2005dynamic] sometimes mentioned in EMPER's source code.
[chase2005dynamic]
Chase, David and Yossi Lev. “Dynamic Circular Work-Stealing Deque”. In: Pro-
ceedings of the Seventeenth Annual ACM Symposium on Parallelism in Algorithms
and Architectures. SPAA ’05. Las Vegas, Nevada, USA: Association
for Computing Machinery, 2005, pp. 21–28. isbn: 1581139861. doi: [10.1145/1073970.1073974](https://doi.org/10.1145/1073970.1073974).
[le2013correct]
Lê, Nhat Minh, Antoniu Pop, Albert Cohen, and Francesco Zappa Nardelli.
“Correct and Efficient Work-Stealing for Weak Memory Models”. In: Proceedings
of the 18th ACM SIGPLAN Symposium on Principles and Practice of
Parallel Programming. PPoPP ’13. Shenzhen, China: Association for Computing
Machinery, 2013, pp. 69–80. isbn: 9781450319225. doi: 10.1145/2442516.2442524.
url: https://hal.inria.fr/hal-00802885/document
[norris2013cdschecker]
Norris, Brian and Brian Demsky. “CDSchecker: Checking Concurrent Data Structures
Written with C/C++ Atomics”. In: Proceedings of the 2013 ACM SIGPLAN
International Conference on Object Oriented Programming Systems
Languages Applications. OOPSLA ’13. Indianapolis, Indiana, USA: Association
for Computing Machinery, 2013, pp. 131–150. isbn: 9781450323741.
doi: 10.1145/2509136.2509514.
url: http://plrg.eecs.uci.edu/publications/c11modelcheck.pdf
......@@ -5,6 +5,7 @@
#include <array>
#include <atomic>
#include <cstdlib>
#include <functional>
#include <iostream>
#include <mutex>
#include <string>
......
......@@ -7,6 +7,7 @@
#include <netinet/tcp.h>
#include <sys/socket.h> // for shutdown, socket, AF_INET
#include <sys/stat.h>
#include <sys/types.h>
#include <unistd.h>
#include <algorithm> // for find
......@@ -20,7 +21,8 @@
#include <cstring> // for memcmp
#include <iomanip>
#include <iostream> // for operator<<, basic_ostream, endl
#include <string> // for allocator, string, char_traits
#include <sstream>
#include <string> // for allocator, string, char_traits
#include <thread>
#include <utility>
......@@ -102,7 +104,7 @@ struct TimeStamps {
class Client {
using IterationResult = std::pair<int, std::string>;
enum class ClientState {
enum class ClientState : std::uint8_t {
unknown,
connecting,
sending,
......@@ -229,9 +231,9 @@ class Client {
}
}
enum class CollectTimeStamps { yes, no };
enum class CollectTimeStamps : std::uint8_t { yes, no };
enum class LinkedFutures { yes, no };
enum class LinkedFutures : std::uint8_t { yes, no };
template <CollectTimeStamps collectTimeStampsSwitch, LinkedFutures linkedFuturesSwitch>
void _run() {
......@@ -251,7 +253,8 @@ class Client {
RecvFuture recvFuture(sock, inBuf, size, MSG_WAITALL);
// prepare output buf
sprintf(outBuf, "%lu:%lu", id, iteration);
int res = sprintf(outBuf, "%lu:%lu", id, iteration);
if (res < 0) DIE_MSG("sprintf failed");
echoStart = high_resolution_clock::now();
if constexpr (collectTimeStamps) {
......@@ -402,6 +405,7 @@ static auto getOption(int argc, char** argv, const std::string& option) -> char*
char** end = argv + argc;
char** itr = std::find(argv, end, option);
// NOLINTNEXTLINE(bugprone-inc-dec-in-conditions)
if (itr != end && ++itr != end) {
return *itr;
}
......@@ -628,7 +632,7 @@ auto main(int argc, char* argv[]) -> int {
}
auto connect_duration = duration_cast<nanoseconds>(echo_start - connect_start).count();
uint64_t echoDurationUntilTermination;
uint64_t echoDurationUntilTermination = 0;
if (execution_seconds) {
echoDurationUntilTermination =
duration_cast<nanoseconds>(echoTerminationTime - echo_start).count();
......
// SPDX-License-Identifier: LGPL-3.0-or-later
// Copyright © 2020-2021 Florian Fischer
#include <sys/socket.h>
#include <sys/types.h>
#include <atomic>
#include <cerrno>
#include <chrono>
#include <cstdlib>
#include <cstring>
#include <functional>
#include <iostream>
#include <random>
#include <string>
#include <vector>
#include "Common.hpp"
#include "Debug.hpp"
......@@ -27,12 +30,15 @@ static const std::string HOST = "::";
static const std::string PORT = "12345";
static const int BACKLOG = 1024;
static const size_t BUF_SIZE = 1024;
static unsigned int computations_us = 0;
static unsigned int max_computations_us = 0;
static float max_computations_probability = -1;
static std::atomic<bool> quit = false;
// NOLINTNEXTLINE(cert-msc32-c,cert-msc51-cpp)
static thread_local std::mt19937 randGenerator;
static auto getComputation() -> unsigned {
// fixed computation is computations_us
......@@ -98,7 +104,7 @@ auto main(int argc, char* argv[]) -> int {
auto serverFunc = [](int socket) {
// NOLINTNEXTLINE(modernize-avoid-c-arrays)
char buf[1024];
char buf[BUF_SIZE];
while (!quit.load(std::memory_order_consume)) {
ssize_t bytes_recv = emper::io::recvAndWait(socket, buf, sizeof(buf), 0);
if (unlikely(bytes_recv <= 0)) {
......
......@@ -3,11 +3,14 @@
#include <sys/socket.h>
#include <array>
#include <atomic>
#include <cstdint>
#include <cstdlib>
#include <cstring>
#include <functional>
#include <iostream>
#include <string>
#include <vector>
#include "Common.hpp"
#include "Debug.hpp"
......@@ -20,67 +23,70 @@ using RecvFuture = emper::io::RecvFuture;
const std::string HOST = "::";
const std::string PORT = "12345";
static const int BACKLOG = 1024;
const size_t BUF_SIZE = 1024;
static std::atomic<bool> quit = false;
class Client {
public:
int sockfd;
size_t bytes_recv;
size_t bytes_send;
std::array<char, BUF_SIZE> buf;
Client(int socket) : sockfd(socket), bytes_recv(0), bytes_send(0) {}
void terminate() {
emper::io::closeAndForget(sockfd);
delete this;
}
void submitSend() {
SendFuture sf(sockfd, &buf[bytes_send], bytes_recv - bytes_send, MSG_NOSIGNAL);
sf.setCallback([this](int32_t bytes_send) { this->onSend(bytes_send); });
void submitSend(int32_t bytes_recv) {
SendFuture sf(sockfd, buf.data(), bytes_recv, MSG_NOSIGNAL);
sf.setCallback(
[this, bytes_recv](int32_t bytes_send) { this->onSend(bytes_send, bytes_recv); });
sf.submit();
}
void onSend(int32_t res) {
if (unlikely(res < 0)) {
LOGE("server send failed: " << strerror(-res));
emper::io::closeAndForget(sockfd);
void onSend(int32_t bytes_send, int32_t bytes_recv) {
if (unlikely(bytes_send != bytes_recv)) {
LOGE("server send failed: " << strerror(-bytes_send));
this->terminate();
return;
}
bytes_send += res;
// Send again
if (bytes_send < bytes_recv) {
submitSend();
return;
if (!quit.load(std::memory_order_consume)) {
submitRecv();
} else {
this->terminate();
}
submitRecv();
}
void submitRecv() {
bytes_send = 0;
RecvFuture rf(sockfd, buf.data(), BUF_SIZE, 0);
rf.setCallback([this](int32_t bytes_recv) { this->onRecv(bytes_recv); });
rf.submit();
}
void onRecv(int32_t res) {
if (unlikely(res <= 0)) {
void onRecv(int32_t bytes_recv) {
if (unlikely(bytes_recv <= 0)) {
// socket was shutdown
if (res < 0) {
LOGE("server read failed:" << strerror(-res));
if (bytes_recv < 0) {
LOGE("server read failed:" << strerror(-bytes_recv));
}
emper::io::closeAndForget(sockfd);
this->terminate();
return;
}
bytes_recv = res;
if (unlikely(bytes_recv == 5 && strncmp("quit\n", buf.data(), bytes_recv) == 0)) {
exit(EXIT_SUCCESS);
quit = true;
Runtime::getRuntime()->initiateTermination();
this->terminate();
return;
}
submitSend();
submitSend(bytes_recv);
}
public:
Client(int socket) : sockfd(socket) {}
void submitRecv() {
RecvFuture rf(sockfd, buf.data(), BUF_SIZE, 0);
rf.setCallback([this](int32_t bytes_recv) { this->onRecv(bytes_recv); });
rf.submit();
}
};
......@@ -100,10 +106,12 @@ auto main(int argc, char* argv[]) -> int {
std::cout << "Echoserver listening on " << host << ":" << port << std::endl;
Runtime runtime;
auto* listener = emper::io::tcp_listener(host, port, [](int socket) {
auto* client = new Client(socket);
client->submitRecv();
});
auto* listener = emper::io::tcp_listener(host, port,
[](int socket) {
auto* client = new Client(socket);
client->submitRecv();
},
BACKLOG, {emper::io::SockOpt::ReusePort});
if (!listener) {
exit(EXIT_FAILURE);
......
// SPDX-License-Identifier: LGPL-3.0-or-later
// Copyright © 2022 Florian Schmaus
#include <cstdlib>
#include "Emper.hpp"
#include "emper-common.h"
auto main(UNUSED_ARG int argc, UNUSED_ARG char* argv[]) -> int {
emper::printInfo();
return EXIT_SUCCESS;
}
......@@ -3,7 +3,7 @@
#include <boost/program_options.hpp>
#include <cstdint>
#include <iostream> // for basic_ostream::operator<<
#include <memory>
#include <string>
#include <thread>
#include "BinaryPrivateSemaphore.hpp" // for BPS
......@@ -66,13 +66,13 @@ static void fib(void* voidParams) {
// NOLINTNEXTLINE(bugprone-exception-escape)
auto main(int argc, char* argv[]) -> int {
uint64_t fibNum = -1;
uint64_t fibNum = 12;
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")
("fibnum", po::value<uint64_t>(&fibNum)->default_value(fibNum), "The Fibonacci number to compute")
;
// clang-format on
......
// SPDX-License-Identifier: LGPL-3.0-or-later
// Copyright © 2024 Florian Schmaus
#include <array>
#include <boost/numeric/ublas/io.hpp>
#include <boost/numeric/ublas/matrix.hpp>
#include <boost/program_options.hpp>
#include <chrono>
#include <cstdint>
#include <cstdlib>
#include <exception>
#include <iostream>
#include <random>
#include <string>
#include <thread>
#include <type_traits>
#include <vector>
#include "Common.hpp"
#include "CountingPrivateSemaphore.hpp"
#include "Fiber.hpp"
#include "Runtime.hpp"
#include "Semaphore.hpp"
#include "emper.hpp"
namespace po = boost::program_options;
template <class T>
using matrix = boost::numeric::ublas::matrix<T>;
static auto sequentialMatMul(matrix<double> &a, matrix<double> &b) -> matrix<double> {
const auto m = a.size1(); // number of rows of a
const auto n = a.size2(); // number of columns of a
if (n != b.size1()) DIE_MSG("Invalid argument");
const auto l = b.size2(); // number of rows of b
matrix<double> res(m, l);
for (unsigned int i = 0; i < m; ++i) {
for (unsigned int j = 0; j < l; ++j) {
res(i, j) = 0;
for (unsigned int k = 0; k < n; ++k) {
res(i, j) = res(i, j) + a(i, k) * b(k, j);
}
}
}
return res;
}
static auto naiveParallelMatMul(matrix<double> &a, matrix<double> &b) -> matrix<double> {
const auto m = a.size1(); // number of rows of a
const auto n = a.size2(); // number of columns of a
if (n != b.size1()) DIE_MSG("Invalid argument");
const auto l = b.size2(); // number of rows of b
matrix<double> res(m, l);
CPS cps;
for (unsigned int i = 0; i < m; ++i) {
for (unsigned int j = 0; j < l; ++j) {
spawn(
[i, j, n, &a, &b, &res] {
res(i, j) = 0;
for (unsigned int k = 0; k < n; ++k) {
res(i, j) = res(i, j) + a(i, k) * b(k, j);
}
},
cps);
}
}
cps.wait();
return res;
}
static auto stupidParallelMatMul(matrix<double> &a, matrix<double> &b) -> matrix<double> {
const auto m = a.size1(); // number of rows of a
const auto n = a.size2(); // number of columns of a
if (n != b.size1()) DIE_MSG("Invalid argument");
const auto l = b.size2(); // number of rows of b
matrix<double> res(m, l);
CPS outerCps;
for (unsigned int i = 0; i < m; ++i) {
for (unsigned int j = 0; j < l; ++j) {
outerCps.incrementCounterByOne();
auto *innerCps = new CPS();
auto *sem = new emper::Semaphore(1);
auto *scalprod = new double;
for (unsigned int k = 0; k < n; ++k) {
spawn(
[i, j, k, sem, scalprod, &a, &b] {
double product = a(i, k) * b(k, j);
sem->acquire();
*scalprod += product;
sem->release();
},
*innerCps);
}
async([i, j, innerCps, sem, scalprod, &res, &outerCps] {
innerCps->wait();
res(i, j) = *scalprod;
outerCps.signal();
delete innerCps;
delete sem;
delete scalprod;
});
}
}
outerCps.wait();
return res;
}
template <class G>
static auto createRandomMatrix(unsigned int m_dim, unsigned int n_dim, float zero_probability, G &g)
-> matrix<double> {
double min = 0;
double max = 1'000'000'000'000'000;
std::uniform_real_distribution<> value_distribution(min, max);
std::bernoulli_distribution zero_distribution(zero_probability);
matrix<double> res(m_dim, n_dim);
for (unsigned int m = 0; m < m_dim; ++m) {
for (unsigned int n = 0; n < n_dim; ++n) {
double value;
if (zero_distribution(g))
value = 0;
else
value = value_distribution(g);
res(m, n) = value;
}
}
return res;
}
using ParMatMul = struct {
std::string name;
matrix<double> (*mul)(matrix<double> &a, matrix<double> &b);
};
namespace chrn = std::chrono;
using Clock = std::chrono::high_resolution_clock;
static auto matmul(const po::variables_map &vm) -> int {
const auto nthreads = vm["nthreads"].as<unsigned int>();
const auto seed = vm["seed"].as<std::uint_fast64_t>();
const auto m = vm["m"].as<unsigned int>();
const auto n = vm["n"].as<unsigned int>();
const auto l = vm["l"].as<unsigned int>();
const auto par_mat_muls = vm["parMatMuls"].as<unsigned int>();
const auto iters = vm["iters"].as<unsigned int>();
const auto zero_probability = vm["zeroProb"].as<float>();
const auto verify = vm["verify"].as<bool>();
Runtime runtime(nthreads);
std::mt19937_64 rng(seed);
std::vector<matrix<double>> a_mtxs, b_mtxs, seq_results;
for (unsigned int i = 0; i < par_mat_muls; ++i) {
auto a = createRandomMatrix(m, n, zero_probability, rng);
a_mtxs.push_back(a);
auto b = createRandomMatrix(n, l, zero_probability, rng);
b_mtxs.push_back(b);
auto seq_res = sequentialMatMul(a_mtxs[i], b_mtxs[i]);
seq_results.push_back(seq_res);
}
auto par_mat_mul_impls = std::to_array<ParMatMul>({
{"naive", naiveParallelMatMul},
{"stupid", stupidParallelMatMul},
});
int exitStatus = EXIT_SUCCESS;
Fiber *alphaFiber = Fiber::from([&] {
for (auto impl : par_mat_mul_impls) {
std::vector<chrn::milliseconds> durations(iters);
std::cout << "Start " << impl.name << " with " << iters << " iterations: " << std::flush;
for (unsigned int iter = 0; iter < iters; ++iter) {
std::vector<matrix<double>> results(par_mat_muls);
CPS cps(par_mat_muls);
chrn::time_point<Clock> start = Clock::now();
for (unsigned int i = 0; i < par_mat_muls; ++i) {
async([i, &cps, &impl, &results, &a_mtxs, &b_mtxs] {
auto a = a_mtxs[i];
auto b = b_mtxs[i];
auto res = impl.mul(a, b);
results[i] = res;
cps.signal();
});
}
cps.wait();
chrn::time_point<Clock> end = Clock::now();
std::cout << "." << std::flush;
auto duration = chrn::duration_cast<chrn::milliseconds>(end - start);
durations[iter] = duration;
if (!verify) continue;
for (unsigned int i = 0; i < par_mat_muls; ++i) {
if (boost::numeric::ublas::detail::equals(seq_results[i], results[i], 1.e-6, 0.))
continue;
// clang-format off
std::cerr
<< std::endl
<< "ERROR: Matrix " << i << " produced by " << impl.name << " incorrect" << std::endl
<< "Expected matrix: " << std::endl << seq_results[i] << std::endl
<< "Provided matrix: " << std::endl << results[i] << std::endl
;
// clang-format on
exitStatus = EXIT_FAILURE;
runtime.initiateTermination();
return;
}
}
std::cout << std::endl << "Implementation '" << impl.name << "' took ";
for (unsigned int i = 0; i < iters; ++i) {
std::cout << durations[i];
if (i + 1 != iters) std::cout << ", ";
}
std::cout << ";" << std::endl;
}
runtime.initiateTermination();
});
runtime.scheduleFromAnywhere(*alphaFiber);
runtime.waitUntilFinished();
return exitStatus;
}
auto main(int argc, char *argv[]) -> int {
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")
("seed", po::value<std::uint_fast64_t>()->default_value(20180922), "Initial seed of the random number generator")
("m", po::value<unsigned int>()->default_value(10), "Number of rows of the first matrix and of the result matrix")
("n", po::value<unsigned int>()->default_value(10), "Number of columns of the first matrix and of rows of the second matrix")
("l", po::value<unsigned int>()->default_value(10), "Number of columns of the second matrix and of the result matrix")
("parMatMuls", po::value<unsigned int>()->default_value(5), "Number of matrix multiplications to perform in parallel")
("iters", po::value<unsigned int>()->default_value(3), "Number of benchmark iterations")
("zeroProb", po::value<float>()->default_value(0.01), "Probaility of generating a zero when initializing the matrices")
("verify", po::value<bool>()->default_value(true), "Verify the result of the matrix multiplication")
;
// clang-format on
auto parse_result = po::command_line_parser(argc, argv).options(desc).run();
po::variables_map vm;
po::store(parse_result, vm);
po::notify(vm);
if (vm.count("help")) {
std::cout << desc << std::endl;
return EXIT_SUCCESS;
}
try {
return matmul(vm);
} catch (std::exception &e) {
std::cerr << e.what() << std::endl;
return EXIT_FAILURE;
}
}
......@@ -3,7 +3,6 @@
#include <chrono> // for milliseconds, operator+, hig...
#include <cstdlib> // for exit, EXIT_SUCCESS
#include <iostream> // for operator<<, basic_ostream, endl
#include <ratio> // for ratio
#include <string>
#include "CountingPrivateSemaphore.hpp" // for CPS
......@@ -33,8 +32,7 @@ static void letsGetBusy(std::chrono::duration<Rep, Period> duration) {
// TODO: The suppressed linter error below may be a false positive
// reported by clang-tidy.
// NOLINTNEXTLINE(modernize-use-nullptr)
while (std::chrono::high_resolution_clock::now() < deadline)
;
while (std::chrono::high_resolution_clock::now() < deadline);
}
static void alphaFiber() {
......
// SPDX-License-Identifier: LGPL-3.0-or-later
// Copyright © 2021-2022 Florian Fischer, Florian Schmaus
#include <fcntl.h>
#include <sys/types.h>
#include <unistd.h>
#include <array>
#include <boost/program_options.hpp>
#include <climits>
#include <cstdlib>
#include <cstring>
#include <exception>
#include <filesystem>
#include <functional>
#include <iostream>
#include <sstream>
#include <string>
......@@ -20,57 +21,56 @@
#include "Semaphore.hpp"
#include "StealingMode.hpp"
#include "io.hpp"
#include "lib/ShardedFileBuffer.hpp"
namespace fs = std::filesystem;
namespace po = boost::program_options;
#define EMPER_RIPGREP_BUFSIZE 4096
static constexpr size_t EMPER_RIPGREP_BUFSIZE = 4096;
const char* needle;
size_t needle_len;
static const char* needle;
static size_t needle_len;
emper::Semaphore* max_running;
static emper::Semaphore* concurrent_open;
static emper::Semaphore* max_fibers;
static emper::Semaphore* max_searching;
static emper::Semaphore* max_walking;
static emper::lib::ShardedFileBuffer* outBuf;
static enum emper::StealingMode stealingMode;
void search(const std::string& path) {
if (max_running) {
max_running->acquire();
}
if (concurrent_open) concurrent_open->acquire();
int fd = emper::io::openAndWait(path.c_str(), O_RDONLY);
if (fd < 0) {
if (unlikely(fd < 0)) {
DIE_MSG_ERRNO("open of " << path << " failed");
}
if (concurrent_open) concurrent_open->release();
std::array<char, EMPER_RIPGREP_BUFSIZE> buf;
ssize_t bytes_read = emper::io::readFileAndWait(fd, buf.data(), buf.size(), 0);
while (bytes_read > 0) {
if (memmem(&buf[0], bytes_read, needle, needle_len)) {
std::array<char, PATH_MAX + 1> outBuf;
memcpy(outBuf.data(), path.c_str(), path.length());
outBuf[path.length()] = '\n';
emper::io::writeFileAndWait(STDOUT_FILENO, outBuf.data(), path.length() + 1, -1);
if (memmem(buf.data(), bytes_read, needle, needle_len)) {
outBuf->getStream() << path << std::endl;
goto out;
}
bytes_read = emper::io::readFileAndWait(fd, buf.data(), buf.size(), -1);
}
if (bytes_read < 0) {
if (unlikely(bytes_read < 0)) {
DIE_MSG_ERRNO("read of " << path << " failed");
}
out:
if (max_running) {
max_running->release();
}
emper::io::closeAndForget(fd);
}
void walk_dir() {
outBuf = new emper::lib::ShardedFileBuffer(*Runtime::getRuntime(), STDOUT_FILENO);
// Only search in regular files
auto filter = [](const fs::directory_entry& dirent) { return dirent.is_regular_file(); };
// Search the file
......@@ -78,13 +78,14 @@ void walk_dir() {
switch (stealingMode) {
case emper::StealingMode::child:
emper::io::recursive_directory_walk(".", filter, fn);
emper::io::recursive_directory_walk(".", filter, fn, max_searching, max_walking);
break;
case emper::StealingMode::continuation:
emper::io::fibril_recursive_directory_walk(".", filter, fn);
break;
}
delete outBuf;
Runtime::getRuntime()->initiateTermination();
}
......@@ -98,15 +99,35 @@ static auto fssearch(const po::variables_map& vm) -> int {
needle = needleStr.c_str();
needle_len = needleStr.length();
if (vm.count("concurrent-open")) {
unsigned int concurrentOpenCount = vm["concurrent-open"].as<unsigned int>();
concurrent_open = new emper::Semaphore(concurrentOpenCount);
}
if (vm.count("max-fibers")) {
unsigned int maxFibersCount = vm["max-fibers"].as<unsigned int>();
max_running = new emper::Semaphore(maxFibersCount);
max_fibers = max_searching = max_walking = new emper::Semaphore(maxFibersCount);
} else {
if (vm.count("max-searchers")) {
unsigned int maxSearchersCount = vm["max-searchers"].as<unsigned int>();
max_searching = new emper::Semaphore(maxSearchersCount);
}
if (vm.count("max-walkers")) {
unsigned int maxWalkersCount = vm["max-walkers"].as<unsigned int>();
max_walking = new emper::Semaphore(maxWalkersCount);
}
}
Runtime runtime;
std::cerr << "Starting fsearch with stealingMode=" << stealingMode;
if (max_running) std::cerr << " and " << max_running->getCount() << " file fibers";
if (max_fibers)
std::cerr << " and " << max_fibers->getCount() << " fibers";
else {
if (max_searching) std::cerr << ", " << max_searching->getCount() << " searching fibers";
if (max_walking) std::cerr << " and " << max_walking->getCount() << " walking fibers";
}
std::cerr << std::endl;
auto* dirWalker = Fiber::from(walk_dir);
......@@ -114,7 +135,13 @@ static auto fssearch(const po::variables_map& vm) -> int {
runtime.waitUntilFinished();
delete max_running;
delete concurrent_open;
if (max_searching == max_walking)
delete max_fibers;
else {
delete max_searching;
delete max_walking;
}
return EXIT_SUCCESS;
}
......@@ -125,7 +152,10 @@ auto main(int argc, char* argv[]) -> int {
desc.add_options()
("help", "Show help")
("needle", po::value<std::string>(), "The String to search for")
("max-fibers", po::value<unsigned int>(), "Maximum number of file processing fibers")
("max-fibers", po::value<unsigned int>(), "Maximum number of fibers")
("max-searchers", po::value<unsigned int>(), "Maximum number of file searching fibers")
("max-walkers", po::value<unsigned int>(), "Maximum number of directory walking fibers")
("concurrent-open", po::value<unsigned int>(), "Maximum number of fibers calling open")
("stealing-mode", po::value<enum emper::StealingMode>(&stealingMode)->default_value(emper::StealingMode::child), "Stealing mode to use, either 'child' or 'continuation'")
;
// clang-format on
......
......@@ -76,7 +76,7 @@ class FileSearcher {
DIE_MSG_ERRNO("read failed");
}
if (memmem(&buf[0], bytes_read, needle, needle_len)) {
if (memmem(buf.data(), bytes_read, needle, needle_len)) {
printf("%s\n", path.c_str());
delete this;
return;
......
......@@ -28,6 +28,12 @@ echoclient_exe = executable(
dependencies: emper_dep,
)
emper_info_exe = executable(
'emper-info',
'EmperInfo.cpp',
dependencies: emper_dep,
)
qsort = executable(
'qsort',
'qsort.cpp',
......@@ -48,12 +54,38 @@ cpp_can_link_with_boost_program_options = cpp_compiler.links(
dependencies: boost_program_options_dep,
)
if cpp_can_link_with_boost_program_options
boost_ublas_code = '''
#include <boost/numeric/ublas/matrix.hpp>
#include <boost/numeric/ublas/io.hpp>
int main (int argc, char* argv[]) {
using namespace boost::numeric::ublas;
matrix m (3, 3);
for (unsigned i = 0; i < m.size1 (); ++ i)
for (unsigned j = 0; j < m.size2 (); ++ j)
m (i, j) = 3 * i + j;
std::cout << m << std::endl;
}
'''
cpp_can_link_with_boost_ublas = cpp_compiler.links(
boost_ublas_code,
name: 'boost_ublas',
dependencies: boost_dep,
)
if (not automagic) or cpp_can_link_with_boost_program_options
fib_child_stealing_exe = executable(
'fib-child-stealing',
'FibChildStealing.cpp',
dependencies: [emper_dep, boost_program_options_dep],
)
if (not automagic) or cpp_can_link_with_boost_ublas
mat_mul_exe = executable(
'mat-mul',
'MatMul.cpp',
dependencies: [emper_dep, boost_dep, boost_program_options_dep],
)
endif
endif
subdir('fsearch')
......@@ -12,5 +12,6 @@ docker run \
--env USER_ID="${UID}" \
--env GROUP_ID="$(id -g ${USER})" \
--security-opt=seccomp:unconfined \
--entrypoint "${EMPER_ROOT}/tools/docker-prepare" \
"${IMAGE}" \
"${EMPER_ROOT}/tools/docker-prepare" "${EMPER_ROOT}" $@
"${EMPER_ROOT}" "$@"