From 65d91329c659d964d791f72f3d65f74663e281ee Mon Sep 17 00:00:00 2001 From: FritzFlorian Date: Thu, 11 Apr 2019 10:43:02 +0200 Subject: [PATCH] Allow the library instalation without building all targets. --- README.md | 64 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ lib/pls/CMakeLists.txt | 7 +++++++ 2 files changed, 71 insertions(+) diff --git a/README.md b/README.md index d62f410..8ec38b4 100644 --- a/README.md +++ b/README.md @@ -3,6 +3,70 @@ [![pipeline status](http://lab.las3.de/gitlab/las3/development/scheduling/predictable_parallel_patterns/badges/master/pipeline.svg)](http://lab.las3.de/gitlab/las3/development/scheduling/predictable_parallel_patterns/commits/master) +## Getting Started + +This section will give a brief introduction on how to get a minimal +project setup that uses the PLS library. + +### Installation + +Clone the repository and open a terminal session in its folder. +Create a build folder using `mkdir cmake-build-release` +and switch into it `cd cmake-build-release`. +Setup the cmake project using `cmake ../ -DCMAKE_BUILD_TYPE=RELEASE`, +then install it as a system wide dependency using `sudo make install.pls`. + +At this point the library is installed on your system. +To use it simply add it to your existing cmake project using +`find_package(pls REQUIRED)` and then link it to your project +using `target_link_libraries(your_target pls::pls)`. + +### Basic Usage + +```c++ +#include +#include + +long fib(long n); + +int main() { + // All memory needed by the scheduler can be allocated in advance either on stack or using malloc. + const unsigned int num_threads = 8; + const unsigned int memory_per_thread = 2 << 14; + static pls::static_scheduler_memory memory; + + // Create the scheduler instance (starts a thread pool). + pls::scheduler scheduler{&memory, num_threads}; + + // Wake up the thread pool and perform work. + scheduler.perform_work([&] { + long result = fib(20); + std::cout << "fib(20)=" << result << std::endl; + }); + // At this point the thread pool sleeps. + // This can for example be used for periodic work. +} + +long fib(long n) { + if (n == 0) { + return 0; + } + if (n == 1) { + return 1; + } + + // Example for the high level API. + // Will run both functions in parallel as seperate tasks. + int left, right; + pls::invoke_parallel( + [&] { left = fib(n - 1); }, + [&] { right = fib(n - 2); } + ); + return left + right; +} + +``` + ## Project Structure diff --git a/lib/pls/CMakeLists.txt b/lib/pls/CMakeLists.txt index 7eb497f..346ad9f 100644 --- a/lib/pls/CMakeLists.txt +++ b/lib/pls/CMakeLists.txt @@ -70,6 +70,13 @@ INSTALl( FILES pls-config.cmake DESTINATION lib/pls ) +# ...add a custom target that will only build the library when istalling. +# This can allow us to speed up the installation on embedded devices. +ADD_CUSTOM_TARGET(install.pls + ${CMAKE_COMMAND} + -DBUILD_TYPE=${CMAKE_BUILD_TYPE} + -P ${CMAKE_BINARY_DIR}/cmake_install.cmake) +ADD_DEPENDENCIES(install.pls pls) # Enable warnings/tidy code checking from our compiler target_compile_options(pls PRIVATE -- libgit2 0.26.0