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/pls.h similarity index 55% rename from lib/pls/include/pls/library.h rename to lib/pls/include/pls/pls.h index 6efc19f..992ce7f 100644 --- a/lib/pls/include/pls/library.h +++ b/lib/pls/include/pls/pls.h @@ -1,9 +1,15 @@ #ifndef PLS_LIBRARY_H #define PLS_LIBRARY_H +#include +#include + namespace pls { - void hello(); - int test_adder(int a, int b); + using internal::scheduling::scheduler; + using internal::scheduling::static_scheduler_memory; + + using internal::scheduling::tbb_sub_task; + using internal::scheduling::tbb_task; } -#endif \ No newline at end of file +#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