From e44c76df139c25da5fe820a36d1601104f501ab2 Mon Sep 17 00:00:00 2001 From: FritzFlorian Date: Mon, 1 Apr 2019 10:41:01 +0200 Subject: [PATCH] Add high level header with all relevant APIs included. --- app/playground/main.cpp | 79 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++------- lib/pls/include/pls/library.h | 9 --------- lib/pls/include/pls/pls.h | 15 +++++++++++++++ lib/pls/src/library.cpp | 13 ------------- lib/pls/src/pls.cpp | 5 +++++ test/CMakeLists.txt | 1 - test/example_tests.cpp | 22 ---------------------- 7 files changed, 92 insertions(+), 52 deletions(-) delete mode 100644 lib/pls/include/pls/library.h create mode 100644 lib/pls/include/pls/pls.h delete mode 100644 lib/pls/src/library.cpp create mode 100644 lib/pls/src/pls.cpp delete mode 100644 test/example_tests.cpp diff --git a/app/playground/main.cpp b/app/playground/main.cpp index 758a413..e237a38 100644 --- a/app/playground/main.cpp +++ b/app/playground/main.cpp @@ -1,11 +1,76 @@ // Headers are available because we added the pls target -#include +#include +#include +#include +#include + +#include + +using namespace pls; + +// Example for static memory allocation (no malloc or free required) +static static_scheduler_memory<8, 2 << 12> my_scheduler_memory; + +class fib: public tbb_sub_task { + static constexpr int CUTOFF = 20; + + int num_; + int* result_; + +public: + fib(int num, int* result): num_{num}, result_{result} {} + +private: + static int fib_serial(int num) { + if (num == 0) { + return 0; + } + if (num == 1) { + return 1; + } + + return fib_serial(num - 1) + fib_serial(num - 2); + } + +protected: + void execute_internal() override { + if (num_ <= CUTOFF) { + *result_ = fib_serial(num_); + return; + } + + 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); + + wait_for_all(); + *result_ = left_result + right_result; + } +public: + void test() override { + std::cout << "Test Override" << std::endl; + } +}; + int main() { - // All interfaces are scoped in the pls namespace... - // ...explicitly name it... - pls::hello(); - // ...or use the namespace... - using namespace pls; - hello(); + scheduler my_scheduler{&my_scheduler_memory, 1}; + + 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}; + scheduler::execute_task(tbb_task); + + std::cout << "Result: " << result << std::endl; + }); + auto end = std::chrono::high_resolution_clock::now(); + long time = std::chrono::duration_cast(end - start).count(); + std::cout << "Startup time in us: " << time << std::endl; } diff --git a/lib/pls/include/pls/library.h b/lib/pls/include/pls/library.h deleted file mode 100644 index 6efc19f..0000000 --- a/lib/pls/include/pls/library.h +++ /dev/null @@ -1,9 +0,0 @@ -#ifndef PLS_LIBRARY_H -#define PLS_LIBRARY_H - -namespace pls { - void hello(); - int test_adder(int a, int b); -} - -#endif \ No newline at end of file diff --git a/lib/pls/include/pls/pls.h b/lib/pls/include/pls/pls.h new file mode 100644 index 0000000..992ce7f --- /dev/null +++ b/lib/pls/include/pls/pls.h @@ -0,0 +1,15 @@ +#ifndef PLS_LIBRARY_H +#define PLS_LIBRARY_H + +#include +#include + +namespace pls { + using internal::scheduling::scheduler; + using internal::scheduling::static_scheduler_memory; + + using internal::scheduling::tbb_sub_task; + using internal::scheduling::tbb_task; +} + +#endif diff --git a/lib/pls/src/library.cpp b/lib/pls/src/library.cpp deleted file mode 100644 index 6634af0..0000000 --- a/lib/pls/src/library.cpp +++ /dev/null @@ -1,13 +0,0 @@ -#include "pls/library.h" - -#include - -namespace pls { - void hello() { - std::cout << "Hello from PLS!" << std::endl; - } - - int test_adder(int a, int b) { - return a + b; - } -} \ No newline at end of file diff --git a/lib/pls/src/pls.cpp b/lib/pls/src/pls.cpp new file mode 100644 index 0000000..e27dca0 --- /dev/null +++ b/lib/pls/src/pls.cpp @@ -0,0 +1,5 @@ +#include "pls/pls.h" + +namespace pls { + +} diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt index 3532cbe..4c5fa7c 100644 --- a/test/CMakeLists.txt +++ b/test/CMakeLists.txt @@ -1,5 +1,4 @@ add_executable(tests main.cpp - example_tests.cpp base_tests.cpp) target_link_libraries(tests catch2 pls) diff --git a/test/example_tests.cpp b/test/example_tests.cpp deleted file mode 100644 index 7774ebf..0000000 --- a/test/example_tests.cpp +++ /dev/null @@ -1,22 +0,0 @@ -#include -#include - -// BDD style -SCENARIO( "the test_adder works", "[library]" ) { - GIVEN ("two numbers") { - WHEN ( "they are positive") { - THEN ( "the result is positive") { - REQUIRE(pls::test_adder(1, 2) >= 0); - } - THEN ( "the result is the sum of both") { - REQUIRE(pls::test_adder(1, 4) == 5); - } - } - } -} - - -// Normal Style -TEST_CASE( "the test_adder can sumup", "[libray]") { - -} \ No newline at end of file -- libgit2 0.26.0