From 595bafb96f9d71c280263460632169d500bb3e7a Mon Sep 17 00:00:00 2001 From: Christian Kern Date: Mon, 29 Jun 2015 16:27:20 +0200 Subject: [PATCH] Revert "Move examples to examples_raw, updated tex and build files" This reverts commit 40624201275a363559f08e00151df8066c5a2f82. --- CMakeLists.txt | 2 +- doc/examples/CMakeLists.txt | 53 +++++++++++++++++++++++++++++++++++++++++++++++++++++ doc/examples/algorithms/counting/count-snippet.h | 3 +++ doc/examples/algorithms/counting/count_if-snippet.h | 3 +++ doc/examples/algorithms/counting/counting-fragmented.cc | 42 ++++++++++++++++++++++++++++++++++++++++++ doc/examples/algorithms/counting/setup-snippet.h | 1 + doc/examples/algorithms/for_each/doubling-snippet.h | 3 +++ doc/examples/algorithms/for_each/doubling_zip-snippet.h | 7 +++++++ doc/examples/algorithms/for_each/for_each-fragmented.cc | 53 +++++++++++++++++++++++++++++++++++++++++++++++++++++ doc/examples/algorithms/for_each/setup_zip-snippet.h | 5 +++++ doc/examples/algorithms/invoke/invocation-snippet.h | 2 ++ doc/examples/algorithms/invoke/invoke-fragmented.cc | 99 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ doc/examples/algorithms/invoke/packages-snippet.h | 3 +++ doc/examples/algorithms/invoke/parallel_quick_sort-snippet.h | 7 +++++++ doc/examples/algorithms/invoke/quick_sort-snippet.h | 6 ++++++ doc/examples/algorithms/reduce/dot_product-snippet.h | 9 +++++++++ doc/examples/algorithms/reduce/parallel-snippet.h | 2 ++ doc/examples/algorithms/reduce/range_init-snippet.h | 4 ++++ doc/examples/algorithms/reduce/reduce-fragmented.cc | 50 ++++++++++++++++++++++++++++++++++++++++++++++++++ doc/examples/algorithms/reduce/second_range_init-snippet.h | 4 ++++ doc/examples/algorithms/reduce/sequential-snippet.h | 4 ++++ doc/examples/algorithms/scan/prefix_sum-snippet.h | 3 +++ doc/examples/algorithms/scan/scan-fragmented.cc | 55 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ doc/examples/algorithms/scan/sequential_prefix_sum-snippet.h | 5 +++++ doc/examples/algorithms/scan/setup-snippet.h | 5 +++++ doc/examples/algorithms/sorting/merge_sort_preallocated-snippet.h | 3 +++ doc/examples/algorithms/sorting/quick_sort-snippet.h | 2 ++ doc/examples/algorithms/sorting/quick_sort_custom_compare-snippet.h | 1 + doc/examples/algorithms/sorting/range_define-snippet.h | 1 + doc/examples/algorithms/sorting/sorting-fragmented.cc | 60 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ doc/examples/containers/object_pool-fragmented.cc | 46 ++++++++++++++++++++++++++++++++++++++++++++++ doc/examples/containers/object_pool-snippet.h | 11 +++++++++++ doc/examples/containers/object_pool_2-snippet.h | 2 ++ doc/examples/containers/queues-fragmented.cc | 40 ++++++++++++++++++++++++++++++++++++++++ doc/examples/containers/queues-snippet.h | 15 +++++++++++++++ doc/examples/containers/stack-fragmented.cc | 37 +++++++++++++++++++++++++++++++++++++ doc/examples/containers/stack-snippet.h | 15 +++++++++++++++ doc/examples/dataflow/dataflow_add-snippet.h | 1 + doc/examples/dataflow/dataflow_comparator-snippet.h | 8 ++++++++ doc/examples/dataflow/dataflow_connect-snippet.h | 2 ++ doc/examples/dataflow/dataflow_consumer-snippet.h | 9 +++++++++ doc/examples/dataflow/dataflow_declare_add_sources-snippet.h | 20 ++++++++++++++++++++ doc/examples/dataflow/dataflow_declare_replace-snippet.h | 5 +++++ doc/examples/dataflow/dataflow_declare_sink-snippet.h | 3 +++ doc/examples/dataflow/dataflow_declare_source-snippet.h | 3 +++ doc/examples/dataflow/dataflow_include-snippet.h | 1 + doc/examples/dataflow/dataflow_linear-fragmented.cc | 61 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ doc/examples/dataflow/dataflow_network-snippet.h | 2 ++ doc/examples/dataflow/dataflow_nonlinear-fragmented.cc | 87 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ doc/examples/dataflow/dataflow_producer-snippet.h | 15 +++++++++++++++ doc/examples/dataflow/dataflow_replace_function-snippet.h | 4 ++++ doc/examples/dataflow/dataflow_run-snippet.h | 1 + doc/examples/dataflow/dataflow_sink_function-snippet.h | 3 +++ doc/examples/dataflow/dataflow_source_function-snippet.h | 4 ++++ doc/examples/insert_snippets.py | 51 +++++++++++++++++++++++++++++++++++++++++++++++++++ doc/examples/main.cc | 134 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ doc/examples/mtapi/mtapi_c-fragmented.cc | 66 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ doc/examples/mtapi/mtapi_c_action_signature-snippet.h | 9 +++++++++ doc/examples/mtapi/mtapi_c_calc_direct-snippet.h | 7 +++++++ doc/examples/mtapi/mtapi_c_calc_task-snippet.h | 15 +++++++++++++++ doc/examples/mtapi/mtapi_c_domain_node_id-snippet.h | 5 +++++ doc/examples/mtapi/mtapi_c_finalize-snippet.h | 7 +++++++ doc/examples/mtapi/mtapi_c_initialize-snippet.h | 25 +++++++++++++++++++++++++ doc/examples/mtapi/mtapi_c_network-fragmented.cc | 102 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ doc/examples/mtapi/mtapi_c_opencl-fragmented.cc | 98 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ doc/examples/mtapi/mtapi_c_plugin-fragmented.cc | 83 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ doc/examples/mtapi/mtapi_c_plugin_action_create-snippet.h | 10 ++++++++++ doc/examples/mtapi/mtapi_c_plugin_action_finalize_cb-snippet.h | 8 ++++++++ doc/examples/mtapi/mtapi_c_plugin_get_job-snippet.h | 4 ++++ doc/examples/mtapi/mtapi_c_plugin_task_cancel_cb-snippet.h | 8 ++++++++ doc/examples/mtapi/mtapi_c_plugin_task_schedule-snippet.h | 11 +++++++++++ doc/examples/mtapi/mtapi_c_plugin_task_start-snippet.h | 8 ++++++++ doc/examples/mtapi/mtapi_c_plugin_task_start_cb-snippet.h | 31 +++++++++++++++++++++++++++++++ doc/examples/mtapi/mtapi_c_register_action-snippet.h | 17 +++++++++++++++++ doc/examples/mtapi/mtapi_c_start_task-snippet.h | 15 +++++++++++++++ doc/examples/mtapi/mtapi_c_validate_arguments-snippet.h | 12 ++++++++++++ doc/examples/mtapi/mtapi_c_validate_result_buffer-snippet.h | 21 +++++++++++++++++++++ doc/examples/mtapi/mtapi_c_wait_task-snippet.h | 2 ++ doc/examples/mtapi/mtapi_check_status-snippet.h | 8 ++++++++ doc/examples/mtapi/mtapi_cpp-fragmented.cc | 67 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ doc/examples/mtapi/mtapi_cpp_calc_task-snippet.h | 3 +++ doc/examples/mtapi/mtapi_cpp_domain_node_id-snippet.h | 5 +++++ doc/examples/mtapi/mtapi_cpp_finalize-snippet.h | 2 ++ doc/examples/mtapi/mtapi_cpp_get_node-snippet.h | 1 + doc/examples/mtapi/mtapi_cpp_initialize-snippet.h | 2 ++ doc/examples/mtapi/mtapi_cpp_main-snippet.h | 6 ++++++ doc/examples/mtapi/mtapi_cpp_register_action-snippet.h | 9 +++++++++ doc/examples/mtapi/mtapi_cpp_start_task-snippet.h | 2 ++ doc/examples/mtapi/mtapi_cpp_wait_task-snippet.h | 5 +++++ doc/examples/mtapi/mtapi_network_c_action_function-snippet.h | 20 ++++++++++++++++++++ doc/examples/mtapi/mtapi_network_c_header-snippet.h | 1 + doc/examples/mtapi/mtapi_network_c_local_action_create-snippet.h | 6 ++++++ doc/examples/mtapi/mtapi_network_c_plugin_finalize-snippet.h | 1 + doc/examples/mtapi/mtapi_network_c_plugin_initialize-snippet.h | 2 ++ doc/examples/mtapi/mtapi_network_c_remote_action_create-snippet.h | 7 +++++++ doc/examples/mtapi/mtapi_opencl_c_action_create-snippet.h | 6 ++++++ doc/examples/mtapi/mtapi_opencl_c_header-snippet.h | 1 + doc/examples/mtapi/mtapi_opencl_c_kernel-snippet.h | 18 ++++++++++++++++++ doc/examples/mtapi/mtapi_opencl_c_plugin_finalize-snippet.h | 1 + doc/examples/mtapi/mtapi_opencl_c_plugin_initialize-snippet.h | 1 + doc/examples/mtapi/mtapi_terminating_condition-snippet.h | 3 +++ doc/examples/mtapi/mtapi_write_back-snippet.h | 3 +++ doc/examples/stl_for_each/function-snippet.h | 1 + doc/examples/stl_for_each/function_define-snippet.h | 3 +++ doc/examples/stl_for_each/functor-snippet.h | 1 + doc/examples/stl_for_each/functor_define-snippet.h | 5 +++++ doc/examples/stl_for_each/lambda-snippet.h | 2 ++ doc/examples/stl_for_each/manual-snippet.h | 3 +++ doc/examples/stl_for_each/setup-snippet.h | 4 ++++ doc/examples/stl_for_each/stl_for_each-fragmented.cc | 75 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ doc/examples/tasks/tasks_cpp-fragmented.cc | 64 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ doc/examples/tasks/tasks_cpp_action_signature-snippet.h | 5 +++++ doc/examples/tasks/tasks_cpp_calc_direct-snippet.h | 6 ++++++ doc/examples/tasks/tasks_cpp_calc_task-snippet.h | 10 ++++++++++ doc/examples/tasks/tasks_cpp_get_node-snippet.h | 1 + doc/examples/tasks/tasks_cpp_start_task-snippet.h | 9 +++++++++ doc/examples/tasks/tasks_cpp_wait_task-snippet.h | 2 ++ doc/examples_raw/CMakeLists.txt | 53 ----------------------------------------------------- doc/examples_raw/algorithms/counting/count-snippet.h | 3 --- doc/examples_raw/algorithms/counting/count_if-snippet.h | 3 --- doc/examples_raw/algorithms/counting/counting-fragmented.cc | 42 ------------------------------------------ doc/examples_raw/algorithms/counting/setup-snippet.h | 1 - doc/examples_raw/algorithms/for_each/doubling-snippet.h | 3 --- doc/examples_raw/algorithms/for_each/doubling_zip-snippet.h | 7 ------- doc/examples_raw/algorithms/for_each/for_each-fragmented.cc | 53 ----------------------------------------------------- doc/examples_raw/algorithms/for_each/setup_zip-snippet.h | 5 ----- doc/examples_raw/algorithms/invoke/invocation-snippet.h | 2 -- doc/examples_raw/algorithms/invoke/invoke-fragmented.cc | 99 --------------------------------------------------------------------------------------------------- doc/examples_raw/algorithms/invoke/packages-snippet.h | 3 --- doc/examples_raw/algorithms/invoke/parallel_quick_sort-snippet.h | 7 ------- doc/examples_raw/algorithms/invoke/quick_sort-snippet.h | 6 ------ doc/examples_raw/algorithms/reduce/dot_product-snippet.h | 9 --------- doc/examples_raw/algorithms/reduce/parallel-snippet.h | 2 -- doc/examples_raw/algorithms/reduce/range_init-snippet.h | 4 ---- doc/examples_raw/algorithms/reduce/reduce-fragmented.cc | 50 -------------------------------------------------- doc/examples_raw/algorithms/reduce/second_range_init-snippet.h | 4 ---- doc/examples_raw/algorithms/reduce/sequential-snippet.h | 4 ---- doc/examples_raw/algorithms/scan/prefix_sum-snippet.h | 3 --- doc/examples_raw/algorithms/scan/scan-fragmented.cc | 55 ------------------------------------------------------- doc/examples_raw/algorithms/scan/sequential_prefix_sum-snippet.h | 5 ----- doc/examples_raw/algorithms/scan/setup-snippet.h | 5 ----- doc/examples_raw/algorithms/sorting/merge_sort_preallocated-snippet.h | 3 --- doc/examples_raw/algorithms/sorting/quick_sort-snippet.h | 2 -- doc/examples_raw/algorithms/sorting/quick_sort_custom_compare-snippet.h | 1 - doc/examples_raw/algorithms/sorting/range_define-snippet.h | 1 - doc/examples_raw/algorithms/sorting/sorting-fragmented.cc | 60 ------------------------------------------------------------ doc/examples_raw/containers/object_pool-fragmented.cc | 46 ---------------------------------------------- doc/examples_raw/containers/object_pool-snippet.h | 11 ----------- doc/examples_raw/containers/object_pool_2-snippet.h | 2 -- doc/examples_raw/containers/queues-fragmented.cc | 40 ---------------------------------------- doc/examples_raw/containers/queues-snippet.h | 15 --------------- doc/examples_raw/containers/stack-fragmented.cc | 37 ------------------------------------- doc/examples_raw/containers/stack-snippet.h | 15 --------------- doc/examples_raw/dataflow/dataflow_add-snippet.h | 1 - doc/examples_raw/dataflow/dataflow_comparator-snippet.h | 8 -------- doc/examples_raw/dataflow/dataflow_connect-snippet.h | 2 -- doc/examples_raw/dataflow/dataflow_consumer-snippet.h | 9 --------- doc/examples_raw/dataflow/dataflow_declare_add_sources-snippet.h | 20 -------------------- doc/examples_raw/dataflow/dataflow_declare_replace-snippet.h | 5 ----- doc/examples_raw/dataflow/dataflow_declare_sink-snippet.h | 3 --- doc/examples_raw/dataflow/dataflow_declare_source-snippet.h | 3 --- doc/examples_raw/dataflow/dataflow_include-snippet.h | 1 - doc/examples_raw/dataflow/dataflow_linear-fragmented.cc | 61 ------------------------------------------------------------- doc/examples_raw/dataflow/dataflow_network-snippet.h | 2 -- doc/examples_raw/dataflow/dataflow_nonlinear-fragmented.cc | 87 --------------------------------------------------------------------------------------- doc/examples_raw/dataflow/dataflow_producer-snippet.h | 15 --------------- doc/examples_raw/dataflow/dataflow_replace_function-snippet.h | 4 ---- doc/examples_raw/dataflow/dataflow_run-snippet.h | 1 - doc/examples_raw/dataflow/dataflow_sink_function-snippet.h | 3 --- doc/examples_raw/dataflow/dataflow_source_function-snippet.h | 4 ---- doc/examples_raw/insert_snippets.py | 51 --------------------------------------------------- doc/examples_raw/main.cc | 134 -------------------------------------------------------------------------------------------------------------------------------------- doc/examples_raw/mtapi/mtapi_c-fragmented.cc | 66 ------------------------------------------------------------------ doc/examples_raw/mtapi/mtapi_c_action_signature-snippet.h | 9 --------- doc/examples_raw/mtapi/mtapi_c_calc_direct-snippet.h | 7 ------- doc/examples_raw/mtapi/mtapi_c_calc_task-snippet.h | 15 --------------- doc/examples_raw/mtapi/mtapi_c_domain_node_id-snippet.h | 5 ----- doc/examples_raw/mtapi/mtapi_c_finalize-snippet.h | 7 ------- doc/examples_raw/mtapi/mtapi_c_initialize-snippet.h | 25 ------------------------- doc/examples_raw/mtapi/mtapi_c_network-fragmented.cc | 102 ------------------------------------------------------------------------------------------------------ doc/examples_raw/mtapi/mtapi_c_opencl-fragmented.cc | 98 -------------------------------------------------------------------------------------------------- doc/examples_raw/mtapi/mtapi_c_plugin-fragmented.cc | 83 ----------------------------------------------------------------------------------- doc/examples_raw/mtapi/mtapi_c_plugin_action_create-snippet.h | 10 ---------- doc/examples_raw/mtapi/mtapi_c_plugin_action_finalize_cb-snippet.h | 8 -------- doc/examples_raw/mtapi/mtapi_c_plugin_get_job-snippet.h | 4 ---- doc/examples_raw/mtapi/mtapi_c_plugin_task_cancel_cb-snippet.h | 8 -------- doc/examples_raw/mtapi/mtapi_c_plugin_task_schedule-snippet.h | 11 ----------- doc/examples_raw/mtapi/mtapi_c_plugin_task_start-snippet.h | 8 -------- doc/examples_raw/mtapi/mtapi_c_plugin_task_start_cb-snippet.h | 31 ------------------------------- doc/examples_raw/mtapi/mtapi_c_register_action-snippet.h | 17 ----------------- doc/examples_raw/mtapi/mtapi_c_start_task-snippet.h | 15 --------------- doc/examples_raw/mtapi/mtapi_c_validate_arguments-snippet.h | 12 ------------ doc/examples_raw/mtapi/mtapi_c_validate_result_buffer-snippet.h | 21 --------------------- doc/examples_raw/mtapi/mtapi_c_wait_task-snippet.h | 2 -- doc/examples_raw/mtapi/mtapi_check_status-snippet.h | 8 -------- doc/examples_raw/mtapi/mtapi_cpp-fragmented.cc | 67 ------------------------------------------------------------------- doc/examples_raw/mtapi/mtapi_cpp_calc_task-snippet.h | 3 --- doc/examples_raw/mtapi/mtapi_cpp_domain_node_id-snippet.h | 5 ----- doc/examples_raw/mtapi/mtapi_cpp_finalize-snippet.h | 2 -- doc/examples_raw/mtapi/mtapi_cpp_get_node-snippet.h | 1 - doc/examples_raw/mtapi/mtapi_cpp_initialize-snippet.h | 2 -- doc/examples_raw/mtapi/mtapi_cpp_main-snippet.h | 6 ------ doc/examples_raw/mtapi/mtapi_cpp_register_action-snippet.h | 9 --------- doc/examples_raw/mtapi/mtapi_cpp_start_task-snippet.h | 2 -- doc/examples_raw/mtapi/mtapi_cpp_wait_task-snippet.h | 5 ----- doc/examples_raw/mtapi/mtapi_network_c_action_function-snippet.h | 20 -------------------- doc/examples_raw/mtapi/mtapi_network_c_header-snippet.h | 1 - doc/examples_raw/mtapi/mtapi_network_c_local_action_create-snippet.h | 6 ------ doc/examples_raw/mtapi/mtapi_network_c_plugin_finalize-snippet.h | 1 - doc/examples_raw/mtapi/mtapi_network_c_plugin_initialize-snippet.h | 2 -- doc/examples_raw/mtapi/mtapi_network_c_remote_action_create-snippet.h | 7 ------- doc/examples_raw/mtapi/mtapi_opencl_c_action_create-snippet.h | 6 ------ doc/examples_raw/mtapi/mtapi_opencl_c_header-snippet.h | 1 - doc/examples_raw/mtapi/mtapi_opencl_c_kernel-snippet.h | 18 ------------------ doc/examples_raw/mtapi/mtapi_opencl_c_plugin_finalize-snippet.h | 1 - doc/examples_raw/mtapi/mtapi_opencl_c_plugin_initialize-snippet.h | 1 - doc/examples_raw/mtapi/mtapi_terminating_condition-snippet.h | 3 --- doc/examples_raw/mtapi/mtapi_write_back-snippet.h | 3 --- doc/examples_raw/stl_for_each/function-snippet.h | 1 - doc/examples_raw/stl_for_each/function_define-snippet.h | 3 --- doc/examples_raw/stl_for_each/functor-snippet.h | 1 - doc/examples_raw/stl_for_each/functor_define-snippet.h | 5 ----- doc/examples_raw/stl_for_each/lambda-snippet.h | 2 -- doc/examples_raw/stl_for_each/manual-snippet.h | 3 --- doc/examples_raw/stl_for_each/setup-snippet.h | 4 ---- doc/examples_raw/stl_for_each/stl_for_each-fragmented.cc | 75 --------------------------------------------------------------------------- doc/examples_raw/tasks/tasks_cpp-fragmented.cc | 64 ---------------------------------------------------------------- doc/examples_raw/tasks/tasks_cpp_action_signature-snippet.h | 5 ----- doc/examples_raw/tasks/tasks_cpp_calc_direct-snippet.h | 6 ------ doc/examples_raw/tasks/tasks_cpp_calc_task-snippet.h | 10 ---------- doc/examples_raw/tasks/tasks_cpp_get_node-snippet.h | 1 - doc/examples_raw/tasks/tasks_cpp_start_task-snippet.h | 9 --------- doc/examples_raw/tasks/tasks_cpp_wait_task-snippet.h | 2 -- doc/tutorial/content/algorithms.tex | 44 ++++++++++++++++++++++---------------------- doc/tutorial/content/containers.tex | 8 ++++---- doc/tutorial/content/dataflow.tex | 30 +++++++++++++++--------------- doc/tutorial/content/introduction.tex | 14 +++++++------- doc/tutorial/content/mtapi.tex | 84 ++++++++++++++++++++++++++++++++++++++++++------------------------------------------ doc/tutorial/content/tasks.tex | 18 +++++++++--------- 239 files changed, 2110 insertions(+), 2110 deletions(-) create mode 100644 doc/examples/CMakeLists.txt create mode 100644 doc/examples/algorithms/counting/count-snippet.h create mode 100644 doc/examples/algorithms/counting/count_if-snippet.h create mode 100644 doc/examples/algorithms/counting/counting-fragmented.cc create mode 100644 doc/examples/algorithms/counting/setup-snippet.h create mode 100644 doc/examples/algorithms/for_each/doubling-snippet.h create mode 100644 doc/examples/algorithms/for_each/doubling_zip-snippet.h create mode 100644 doc/examples/algorithms/for_each/for_each-fragmented.cc create mode 100644 doc/examples/algorithms/for_each/setup_zip-snippet.h create mode 100644 doc/examples/algorithms/invoke/invocation-snippet.h create mode 100644 doc/examples/algorithms/invoke/invoke-fragmented.cc create mode 100644 doc/examples/algorithms/invoke/packages-snippet.h create mode 100644 doc/examples/algorithms/invoke/parallel_quick_sort-snippet.h create mode 100644 doc/examples/algorithms/invoke/quick_sort-snippet.h create mode 100644 doc/examples/algorithms/reduce/dot_product-snippet.h create mode 100644 doc/examples/algorithms/reduce/parallel-snippet.h create mode 100644 doc/examples/algorithms/reduce/range_init-snippet.h create mode 100644 doc/examples/algorithms/reduce/reduce-fragmented.cc create mode 100644 doc/examples/algorithms/reduce/second_range_init-snippet.h create mode 100644 doc/examples/algorithms/reduce/sequential-snippet.h create mode 100644 doc/examples/algorithms/scan/prefix_sum-snippet.h create mode 100644 doc/examples/algorithms/scan/scan-fragmented.cc create mode 100644 doc/examples/algorithms/scan/sequential_prefix_sum-snippet.h create mode 100644 doc/examples/algorithms/scan/setup-snippet.h create mode 100644 doc/examples/algorithms/sorting/merge_sort_preallocated-snippet.h create mode 100644 doc/examples/algorithms/sorting/quick_sort-snippet.h create mode 100644 doc/examples/algorithms/sorting/quick_sort_custom_compare-snippet.h create mode 100644 doc/examples/algorithms/sorting/range_define-snippet.h create mode 100644 doc/examples/algorithms/sorting/sorting-fragmented.cc create mode 100644 doc/examples/containers/object_pool-fragmented.cc create mode 100644 doc/examples/containers/object_pool-snippet.h create mode 100644 doc/examples/containers/object_pool_2-snippet.h create mode 100644 doc/examples/containers/queues-fragmented.cc create mode 100644 doc/examples/containers/queues-snippet.h create mode 100644 doc/examples/containers/stack-fragmented.cc create mode 100644 doc/examples/containers/stack-snippet.h create mode 100644 doc/examples/dataflow/dataflow_add-snippet.h create mode 100644 doc/examples/dataflow/dataflow_comparator-snippet.h create mode 100644 doc/examples/dataflow/dataflow_connect-snippet.h create mode 100644 doc/examples/dataflow/dataflow_consumer-snippet.h create mode 100644 doc/examples/dataflow/dataflow_declare_add_sources-snippet.h create mode 100644 doc/examples/dataflow/dataflow_declare_replace-snippet.h create mode 100644 doc/examples/dataflow/dataflow_declare_sink-snippet.h create mode 100644 doc/examples/dataflow/dataflow_declare_source-snippet.h create mode 100644 doc/examples/dataflow/dataflow_include-snippet.h create mode 100644 doc/examples/dataflow/dataflow_linear-fragmented.cc create mode 100644 doc/examples/dataflow/dataflow_network-snippet.h create mode 100644 doc/examples/dataflow/dataflow_nonlinear-fragmented.cc create mode 100644 doc/examples/dataflow/dataflow_producer-snippet.h create mode 100644 doc/examples/dataflow/dataflow_replace_function-snippet.h create mode 100644 doc/examples/dataflow/dataflow_run-snippet.h create mode 100644 doc/examples/dataflow/dataflow_sink_function-snippet.h create mode 100644 doc/examples/dataflow/dataflow_source_function-snippet.h create mode 100644 doc/examples/insert_snippets.py create mode 100644 doc/examples/main.cc create mode 100644 doc/examples/mtapi/mtapi_c-fragmented.cc create mode 100644 doc/examples/mtapi/mtapi_c_action_signature-snippet.h create mode 100644 doc/examples/mtapi/mtapi_c_calc_direct-snippet.h create mode 100644 doc/examples/mtapi/mtapi_c_calc_task-snippet.h create mode 100644 doc/examples/mtapi/mtapi_c_domain_node_id-snippet.h create mode 100644 doc/examples/mtapi/mtapi_c_finalize-snippet.h create mode 100644 doc/examples/mtapi/mtapi_c_initialize-snippet.h create mode 100644 doc/examples/mtapi/mtapi_c_network-fragmented.cc create mode 100644 doc/examples/mtapi/mtapi_c_opencl-fragmented.cc create mode 100644 doc/examples/mtapi/mtapi_c_plugin-fragmented.cc create mode 100644 doc/examples/mtapi/mtapi_c_plugin_action_create-snippet.h create mode 100644 doc/examples/mtapi/mtapi_c_plugin_action_finalize_cb-snippet.h create mode 100644 doc/examples/mtapi/mtapi_c_plugin_get_job-snippet.h create mode 100644 doc/examples/mtapi/mtapi_c_plugin_task_cancel_cb-snippet.h create mode 100644 doc/examples/mtapi/mtapi_c_plugin_task_schedule-snippet.h create mode 100644 doc/examples/mtapi/mtapi_c_plugin_task_start-snippet.h create mode 100644 doc/examples/mtapi/mtapi_c_plugin_task_start_cb-snippet.h create mode 100644 doc/examples/mtapi/mtapi_c_register_action-snippet.h create mode 100644 doc/examples/mtapi/mtapi_c_start_task-snippet.h create mode 100644 doc/examples/mtapi/mtapi_c_validate_arguments-snippet.h create mode 100644 doc/examples/mtapi/mtapi_c_validate_result_buffer-snippet.h create mode 100644 doc/examples/mtapi/mtapi_c_wait_task-snippet.h create mode 100644 doc/examples/mtapi/mtapi_check_status-snippet.h create mode 100644 doc/examples/mtapi/mtapi_cpp-fragmented.cc create mode 100644 doc/examples/mtapi/mtapi_cpp_calc_task-snippet.h create mode 100644 doc/examples/mtapi/mtapi_cpp_domain_node_id-snippet.h create mode 100644 doc/examples/mtapi/mtapi_cpp_finalize-snippet.h create mode 100644 doc/examples/mtapi/mtapi_cpp_get_node-snippet.h create mode 100644 doc/examples/mtapi/mtapi_cpp_initialize-snippet.h create mode 100644 doc/examples/mtapi/mtapi_cpp_main-snippet.h create mode 100644 doc/examples/mtapi/mtapi_cpp_register_action-snippet.h create mode 100644 doc/examples/mtapi/mtapi_cpp_start_task-snippet.h create mode 100644 doc/examples/mtapi/mtapi_cpp_wait_task-snippet.h create mode 100644 doc/examples/mtapi/mtapi_network_c_action_function-snippet.h create mode 100644 doc/examples/mtapi/mtapi_network_c_header-snippet.h create mode 100644 doc/examples/mtapi/mtapi_network_c_local_action_create-snippet.h create mode 100644 doc/examples/mtapi/mtapi_network_c_plugin_finalize-snippet.h create mode 100644 doc/examples/mtapi/mtapi_network_c_plugin_initialize-snippet.h create mode 100644 doc/examples/mtapi/mtapi_network_c_remote_action_create-snippet.h create mode 100644 doc/examples/mtapi/mtapi_opencl_c_action_create-snippet.h create mode 100644 doc/examples/mtapi/mtapi_opencl_c_header-snippet.h create mode 100644 doc/examples/mtapi/mtapi_opencl_c_kernel-snippet.h create mode 100644 doc/examples/mtapi/mtapi_opencl_c_plugin_finalize-snippet.h create mode 100644 doc/examples/mtapi/mtapi_opencl_c_plugin_initialize-snippet.h create mode 100644 doc/examples/mtapi/mtapi_terminating_condition-snippet.h create mode 100644 doc/examples/mtapi/mtapi_write_back-snippet.h create mode 100644 doc/examples/stl_for_each/function-snippet.h create mode 100644 doc/examples/stl_for_each/function_define-snippet.h create mode 100644 doc/examples/stl_for_each/functor-snippet.h create mode 100644 doc/examples/stl_for_each/functor_define-snippet.h create mode 100644 doc/examples/stl_for_each/lambda-snippet.h create mode 100644 doc/examples/stl_for_each/manual-snippet.h create mode 100644 doc/examples/stl_for_each/setup-snippet.h create mode 100644 doc/examples/stl_for_each/stl_for_each-fragmented.cc create mode 100644 doc/examples/tasks/tasks_cpp-fragmented.cc create mode 100644 doc/examples/tasks/tasks_cpp_action_signature-snippet.h create mode 100644 doc/examples/tasks/tasks_cpp_calc_direct-snippet.h create mode 100644 doc/examples/tasks/tasks_cpp_calc_task-snippet.h create mode 100644 doc/examples/tasks/tasks_cpp_get_node-snippet.h create mode 100644 doc/examples/tasks/tasks_cpp_start_task-snippet.h create mode 100644 doc/examples/tasks/tasks_cpp_wait_task-snippet.h delete mode 100644 doc/examples_raw/CMakeLists.txt delete mode 100644 doc/examples_raw/algorithms/counting/count-snippet.h delete mode 100644 doc/examples_raw/algorithms/counting/count_if-snippet.h delete mode 100644 doc/examples_raw/algorithms/counting/counting-fragmented.cc delete mode 100644 doc/examples_raw/algorithms/counting/setup-snippet.h delete mode 100644 doc/examples_raw/algorithms/for_each/doubling-snippet.h delete mode 100644 doc/examples_raw/algorithms/for_each/doubling_zip-snippet.h delete mode 100644 doc/examples_raw/algorithms/for_each/for_each-fragmented.cc delete mode 100644 doc/examples_raw/algorithms/for_each/setup_zip-snippet.h delete mode 100644 doc/examples_raw/algorithms/invoke/invocation-snippet.h delete mode 100644 doc/examples_raw/algorithms/invoke/invoke-fragmented.cc delete mode 100644 doc/examples_raw/algorithms/invoke/packages-snippet.h delete mode 100644 doc/examples_raw/algorithms/invoke/parallel_quick_sort-snippet.h delete mode 100644 doc/examples_raw/algorithms/invoke/quick_sort-snippet.h delete mode 100644 doc/examples_raw/algorithms/reduce/dot_product-snippet.h delete mode 100644 doc/examples_raw/algorithms/reduce/parallel-snippet.h delete mode 100644 doc/examples_raw/algorithms/reduce/range_init-snippet.h delete mode 100644 doc/examples_raw/algorithms/reduce/reduce-fragmented.cc delete mode 100644 doc/examples_raw/algorithms/reduce/second_range_init-snippet.h delete mode 100644 doc/examples_raw/algorithms/reduce/sequential-snippet.h delete mode 100644 doc/examples_raw/algorithms/scan/prefix_sum-snippet.h delete mode 100644 doc/examples_raw/algorithms/scan/scan-fragmented.cc delete mode 100644 doc/examples_raw/algorithms/scan/sequential_prefix_sum-snippet.h delete mode 100644 doc/examples_raw/algorithms/scan/setup-snippet.h delete mode 100644 doc/examples_raw/algorithms/sorting/merge_sort_preallocated-snippet.h delete mode 100644 doc/examples_raw/algorithms/sorting/quick_sort-snippet.h delete mode 100644 doc/examples_raw/algorithms/sorting/quick_sort_custom_compare-snippet.h delete mode 100644 doc/examples_raw/algorithms/sorting/range_define-snippet.h delete mode 100644 doc/examples_raw/algorithms/sorting/sorting-fragmented.cc delete mode 100644 doc/examples_raw/containers/object_pool-fragmented.cc delete mode 100644 doc/examples_raw/containers/object_pool-snippet.h delete mode 100644 doc/examples_raw/containers/object_pool_2-snippet.h delete mode 100644 doc/examples_raw/containers/queues-fragmented.cc delete mode 100644 doc/examples_raw/containers/queues-snippet.h delete mode 100644 doc/examples_raw/containers/stack-fragmented.cc delete mode 100644 doc/examples_raw/containers/stack-snippet.h delete mode 100644 doc/examples_raw/dataflow/dataflow_add-snippet.h delete mode 100644 doc/examples_raw/dataflow/dataflow_comparator-snippet.h delete mode 100644 doc/examples_raw/dataflow/dataflow_connect-snippet.h delete mode 100644 doc/examples_raw/dataflow/dataflow_consumer-snippet.h delete mode 100644 doc/examples_raw/dataflow/dataflow_declare_add_sources-snippet.h delete mode 100644 doc/examples_raw/dataflow/dataflow_declare_replace-snippet.h delete mode 100644 doc/examples_raw/dataflow/dataflow_declare_sink-snippet.h delete mode 100644 doc/examples_raw/dataflow/dataflow_declare_source-snippet.h delete mode 100644 doc/examples_raw/dataflow/dataflow_include-snippet.h delete mode 100644 doc/examples_raw/dataflow/dataflow_linear-fragmented.cc delete mode 100644 doc/examples_raw/dataflow/dataflow_network-snippet.h delete mode 100644 doc/examples_raw/dataflow/dataflow_nonlinear-fragmented.cc delete mode 100644 doc/examples_raw/dataflow/dataflow_producer-snippet.h delete mode 100644 doc/examples_raw/dataflow/dataflow_replace_function-snippet.h delete mode 100644 doc/examples_raw/dataflow/dataflow_run-snippet.h delete mode 100644 doc/examples_raw/dataflow/dataflow_sink_function-snippet.h delete mode 100644 doc/examples_raw/dataflow/dataflow_source_function-snippet.h delete mode 100644 doc/examples_raw/insert_snippets.py delete mode 100644 doc/examples_raw/main.cc delete mode 100644 doc/examples_raw/mtapi/mtapi_c-fragmented.cc delete mode 100644 doc/examples_raw/mtapi/mtapi_c_action_signature-snippet.h delete mode 100644 doc/examples_raw/mtapi/mtapi_c_calc_direct-snippet.h delete mode 100644 doc/examples_raw/mtapi/mtapi_c_calc_task-snippet.h delete mode 100644 doc/examples_raw/mtapi/mtapi_c_domain_node_id-snippet.h delete mode 100644 doc/examples_raw/mtapi/mtapi_c_finalize-snippet.h delete mode 100644 doc/examples_raw/mtapi/mtapi_c_initialize-snippet.h delete mode 100644 doc/examples_raw/mtapi/mtapi_c_network-fragmented.cc delete mode 100644 doc/examples_raw/mtapi/mtapi_c_opencl-fragmented.cc delete mode 100644 doc/examples_raw/mtapi/mtapi_c_plugin-fragmented.cc delete mode 100644 doc/examples_raw/mtapi/mtapi_c_plugin_action_create-snippet.h delete mode 100644 doc/examples_raw/mtapi/mtapi_c_plugin_action_finalize_cb-snippet.h delete mode 100644 doc/examples_raw/mtapi/mtapi_c_plugin_get_job-snippet.h delete mode 100644 doc/examples_raw/mtapi/mtapi_c_plugin_task_cancel_cb-snippet.h delete mode 100644 doc/examples_raw/mtapi/mtapi_c_plugin_task_schedule-snippet.h delete mode 100644 doc/examples_raw/mtapi/mtapi_c_plugin_task_start-snippet.h delete mode 100644 doc/examples_raw/mtapi/mtapi_c_plugin_task_start_cb-snippet.h delete mode 100644 doc/examples_raw/mtapi/mtapi_c_register_action-snippet.h delete mode 100644 doc/examples_raw/mtapi/mtapi_c_start_task-snippet.h delete mode 100644 doc/examples_raw/mtapi/mtapi_c_validate_arguments-snippet.h delete mode 100644 doc/examples_raw/mtapi/mtapi_c_validate_result_buffer-snippet.h delete mode 100644 doc/examples_raw/mtapi/mtapi_c_wait_task-snippet.h delete mode 100644 doc/examples_raw/mtapi/mtapi_check_status-snippet.h delete mode 100644 doc/examples_raw/mtapi/mtapi_cpp-fragmented.cc delete mode 100644 doc/examples_raw/mtapi/mtapi_cpp_calc_task-snippet.h delete mode 100644 doc/examples_raw/mtapi/mtapi_cpp_domain_node_id-snippet.h delete mode 100644 doc/examples_raw/mtapi/mtapi_cpp_finalize-snippet.h delete mode 100644 doc/examples_raw/mtapi/mtapi_cpp_get_node-snippet.h delete mode 100644 doc/examples_raw/mtapi/mtapi_cpp_initialize-snippet.h delete mode 100644 doc/examples_raw/mtapi/mtapi_cpp_main-snippet.h delete mode 100644 doc/examples_raw/mtapi/mtapi_cpp_register_action-snippet.h delete mode 100644 doc/examples_raw/mtapi/mtapi_cpp_start_task-snippet.h delete mode 100644 doc/examples_raw/mtapi/mtapi_cpp_wait_task-snippet.h delete mode 100644 doc/examples_raw/mtapi/mtapi_network_c_action_function-snippet.h delete mode 100644 doc/examples_raw/mtapi/mtapi_network_c_header-snippet.h delete mode 100644 doc/examples_raw/mtapi/mtapi_network_c_local_action_create-snippet.h delete mode 100644 doc/examples_raw/mtapi/mtapi_network_c_plugin_finalize-snippet.h delete mode 100644 doc/examples_raw/mtapi/mtapi_network_c_plugin_initialize-snippet.h delete mode 100644 doc/examples_raw/mtapi/mtapi_network_c_remote_action_create-snippet.h delete mode 100644 doc/examples_raw/mtapi/mtapi_opencl_c_action_create-snippet.h delete mode 100644 doc/examples_raw/mtapi/mtapi_opencl_c_header-snippet.h delete mode 100644 doc/examples_raw/mtapi/mtapi_opencl_c_kernel-snippet.h delete mode 100644 doc/examples_raw/mtapi/mtapi_opencl_c_plugin_finalize-snippet.h delete mode 100644 doc/examples_raw/mtapi/mtapi_opencl_c_plugin_initialize-snippet.h delete mode 100644 doc/examples_raw/mtapi/mtapi_terminating_condition-snippet.h delete mode 100644 doc/examples_raw/mtapi/mtapi_write_back-snippet.h delete mode 100644 doc/examples_raw/stl_for_each/function-snippet.h delete mode 100644 doc/examples_raw/stl_for_each/function_define-snippet.h delete mode 100644 doc/examples_raw/stl_for_each/functor-snippet.h delete mode 100644 doc/examples_raw/stl_for_each/functor_define-snippet.h delete mode 100644 doc/examples_raw/stl_for_each/lambda-snippet.h delete mode 100644 doc/examples_raw/stl_for_each/manual-snippet.h delete mode 100644 doc/examples_raw/stl_for_each/setup-snippet.h delete mode 100644 doc/examples_raw/stl_for_each/stl_for_each-fragmented.cc delete mode 100644 doc/examples_raw/tasks/tasks_cpp-fragmented.cc delete mode 100644 doc/examples_raw/tasks/tasks_cpp_action_signature-snippet.h delete mode 100644 doc/examples_raw/tasks/tasks_cpp_calc_direct-snippet.h delete mode 100644 doc/examples_raw/tasks/tasks_cpp_calc_task-snippet.h delete mode 100644 doc/examples_raw/tasks/tasks_cpp_get_node-snippet.h delete mode 100644 doc/examples_raw/tasks/tasks_cpp_start_task-snippet.h delete mode 100644 doc/examples_raw/tasks/tasks_cpp_wait_task-snippet.h diff --git a/CMakeLists.txt b/CMakeLists.txt index 9f8a001..a2c580d 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -190,7 +190,7 @@ add_subdirectory(algorithms_cpp) add_subdirectory(dataflow_cpp) if (BUILD_EXAMPLES STREQUAL ON) message("-- Building examples enabled") - add_subdirectory(doc/examples_raw) + add_subdirectory(doc/examples) else() message("-- Building examples disabled (default)") endif() diff --git a/doc/examples/CMakeLists.txt b/doc/examples/CMakeLists.txt new file mode 100644 index 0000000..d68a8a3 --- /dev/null +++ b/doc/examples/CMakeLists.txt @@ -0,0 +1,53 @@ +project (project_embb_tutorials) + +file(GLOB_RECURSE EXAMPLES_SOURCES "*.cc" "*.h") + + +include_directories( + ${CMAKE_CURRENT_SOURCE_DIR}/ + ${CMAKE_CURRENT_BINARY_DIR}/ + ${CMAKE_CURRENT_SOURCE_DIR}/../../base_c/include + ${CMAKE_CURRENT_BINARY_DIR}/../../base_c/include + ${CMAKE_CURRENT_SOURCE_DIR}/../../base_cpp/include + ${CMAKE_CURRENT_BINARY_DIR}/../../base_cpp/include + ${CMAKE_CURRENT_SOURCE_DIR}/../../mtapi_c/include + ${CMAKE_CURRENT_SOURCE_DIR}/../../mtapi_c/src + ${CMAKE_CURRENT_SOURCE_DIR}/../../mtapi_network_c/include + ${CMAKE_CURRENT_SOURCE_DIR}/../../mtapi_cpp/include + ${CMAKE_CURRENT_SOURCE_DIR}/../../tasks_cpp/include + ${CMAKE_CURRENT_BINARY_DIR}/../../tasks_cpp/include + ${CMAKE_CURRENT_SOURCE_DIR}/../../containers_cpp/include + ${CMAKE_CURRENT_SOURCE_DIR}/../../algorithms_cpp/include + ${CMAKE_CURRENT_SOURCE_DIR}/../../dataflow_cpp/include + ) + +if(OpenCL_FOUND) + # used in source code, to include opencl code + add_definitions(-DEMBB_WITH_OPENCL) + # add opencl includes + include_directories( + ${CMAKE_CURRENT_SOURCE_DIR}/../../mtapi_opencl_c/include + ) + # later used, to link opencl to target... + set (EMBB_MTAPI_OPENCL_C_CONDITIONAL "embb_mtapi_opencl_c") +else() + # remove opencl examples from sources (should not be build) + file(GLOB_RECURSE EXAMPLES_SOURCES_OPENCL_TO_REMOVE "*opencl*" ) + list(REMOVE_ITEM EXAMPLES_SOURCES ${EXAMPLES_SOURCES_OPENCL_TO_REMOVE}) +endif() + +if(CMAKE_COMPILER_IS_GNUCXX) + set(CMAKE_CXX_FLAGS "-std=c++11") + set (EXTRA_LIBS dl) +endif() + +IF(MSVC) + set (EXTRA_LIBS ws2_32) +ENDIF() + +add_executable(examples ${EXAMPLES_SOURCES}) +target_link_libraries(examples embb_dataflow_cpp embb_algorithms_cpp embb_tasks_cpp embb_mtapi_cpp + embb_mtapi_network_c ${EMBB_MTAPI_OPENCL_C_CONDITIONAL} embb_mtapi_c + embb_base_cpp embb_base_c embb_containers_cpp + ${EXTRA_LIBS} ${compiler_libs}) +CopyBin(BIN examples DEST ${local_install_dir}) diff --git a/doc/examples/algorithms/counting/count-snippet.h b/doc/examples/algorithms/counting/count-snippet.h new file mode 100644 index 0000000..9b3191d --- /dev/null +++ b/doc/examples/algorithms/counting/count-snippet.h @@ -0,0 +1,3 @@ +std::iterator_traits::difference_type count; +using embb::algorithms::Count; +count = Count(range, range + 8, 1); diff --git a/doc/examples/algorithms/counting/count_if-snippet.h b/doc/examples/algorithms/counting/count_if-snippet.h new file mode 100644 index 0000000..68806e8 --- /dev/null +++ b/doc/examples/algorithms/counting/count_if-snippet.h @@ -0,0 +1,3 @@ +using embb::algorithms::CountIf; +count = CountIf(range, range + 8, + [](const int& value) -> bool { return value > 0; }); diff --git a/doc/examples/algorithms/counting/counting-fragmented.cc b/doc/examples/algorithms/counting/counting-fragmented.cc new file mode 100644 index 0000000..a621d8b --- /dev/null +++ b/doc/examples/algorithms/counting/counting-fragmented.cc @@ -0,0 +1,42 @@ +/* + * Copyright (c) 2014-2015, Siemens AG. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +#include + +/** + * Example using embb::algorithms::Count and CountIf. + * + * Counting elements of a range that fulfill certain properties. + */ +void RunCounting() { + #include "algorithms/counting/setup-snippet.h" + + #include "algorithms/counting/count-snippet.h" + assert(count == 2); + + #include "algorithms/counting/count_if-snippet.h" + assert(count == 6); +} diff --git a/doc/examples/algorithms/counting/setup-snippet.h b/doc/examples/algorithms/counting/setup-snippet.h new file mode 100644 index 0000000..f488cbd --- /dev/null +++ b/doc/examples/algorithms/counting/setup-snippet.h @@ -0,0 +1 @@ +int range[] = {0, 3, 2, 0, 1, 1, 3, 2}; diff --git a/doc/examples/algorithms/for_each/doubling-snippet.h b/doc/examples/algorithms/for_each/doubling-snippet.h new file mode 100644 index 0000000..9d16397 --- /dev/null +++ b/doc/examples/algorithms/for_each/doubling-snippet.h @@ -0,0 +1,3 @@ +using embb::algorithms::ForEach; +ForEach(range.begin(), range.end(), + [] (int& to_double) { to_double *= 2; }); diff --git a/doc/examples/algorithms/for_each/doubling_zip-snippet.h b/doc/examples/algorithms/for_each/doubling_zip-snippet.h new file mode 100644 index 0000000..0e5ccc4 --- /dev/null +++ b/doc/examples/algorithms/for_each/doubling_zip-snippet.h @@ -0,0 +1,7 @@ +using embb::algorithms::Zip; +using embb::algorithms::ZipPair; +ForEach(Zip(input_range.begin(), output_range.begin()), + Zip(input_range.end(), output_range.end()), + [] (ZipPair pair) { + pair.Second() = pair.First() * 2; + }); diff --git a/doc/examples/algorithms/for_each/for_each-fragmented.cc b/doc/examples/algorithms/for_each/for_each-fragmented.cc new file mode 100644 index 0000000..ab80a0c --- /dev/null +++ b/doc/examples/algorithms/for_each/for_each-fragmented.cc @@ -0,0 +1,53 @@ +/* + * Copyright (c) 2014-2015, Siemens AG. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +#include +#include +#include + +static void CheckResults(const std::vector& range) { + int i = 1; + for (const int& value : range) { + assert(value == i * 2); + EMBB_UNUSED_IN_RELEASE(value); + i++; + } +} + +/** + * Example using embb::algorithms::ForEach. + * + * Traversing and modifying a sequence with a for-each loop. + */ +void RunForEach() { + #include "stl_for_each/setup-snippet.h" + #include "algorithms/for_each/doubling-snippet.h" + CheckResults(range); + + #include "algorithms/for_each/setup_zip-snippet.h" + #include "algorithms/for_each/doubling_zip-snippet.h" + CheckResults(output_range); +} diff --git a/doc/examples/algorithms/for_each/setup_zip-snippet.h b/doc/examples/algorithms/for_each/setup_zip-snippet.h new file mode 100644 index 0000000..311fb4b --- /dev/null +++ b/doc/examples/algorithms/for_each/setup_zip-snippet.h @@ -0,0 +1,5 @@ +std::vector input_range(5); +for (size_t i=0; i < input_range.size(); i++) { + input_range[i] = static_cast(i) + 1; +} +std::vector output_range(5); diff --git a/doc/examples/algorithms/invoke/invocation-snippet.h b/doc/examples/algorithms/invoke/invocation-snippet.h new file mode 100644 index 0000000..2b27930 --- /dev/null +++ b/doc/examples/algorithms/invoke/invocation-snippet.h @@ -0,0 +1,2 @@ +using embb::algorithms::Invoke; +Invoke(WorkPackageA, WorkPackageB, WorkPackageC); diff --git a/doc/examples/algorithms/invoke/invoke-fragmented.cc b/doc/examples/algorithms/invoke/invoke-fragmented.cc new file mode 100644 index 0000000..94cddd2 --- /dev/null +++ b/doc/examples/algorithms/invoke/invoke-fragmented.cc @@ -0,0 +1,99 @@ +/* + * Copyright (c) 2014-2015, Siemens AG. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +#include +#include + +#include "algorithms/invoke/packages-snippet.h" + +static int a = 0, b = 0, c = 0; + +void WorkPackageA() { + a++; +} + +void WorkPackageB() { + b++; +} + +void WorkPackageC() { + c++; +} + +int* Partition(int* first, int* last) { + int* pivot = last - 1; + while (first != last) { + while (*first < *pivot) { + ++first; + if (first == last) return first; + } + do { + --last; + if (first == last) return first; + } while (*pivot < *last); + std::swap(*first, *last); + if(pivot == first) { + pivot = last; + } else if (pivot == last) { + pivot = first; + } + ++first; + } + return first; +} + +#include "algorithms/invoke/quick_sort-snippet.h" + +#include "algorithms/invoke/parallel_quick_sort-snippet.h" + +/** + * Example using embb::algorithms::ParallelInvoke() to execute work packages in + * parallel. + */ +void RunInvoke() { + #include "algorithms/invoke/invocation-snippet.h" + assert(a == 1); + assert(b == 1); + assert(c == 1); + + { + int range[] = {2, 5, 3, 1, 4}; + QuickSort(range, range + 5); + for (size_t i = 0; i < 5; i++) { + assert(range[i] == static_cast(i) + 1); + } + } + { + int range[] = {2, 5, 3, 1, 4}; + ParallelQuickSort(range, range + 5); + for (size_t i = 0; i < 5; i++) { + assert(range[i] == static_cast(i) + 1); + } + } +} + + + diff --git a/doc/examples/algorithms/invoke/packages-snippet.h b/doc/examples/algorithms/invoke/packages-snippet.h new file mode 100644 index 0000000..743db1d --- /dev/null +++ b/doc/examples/algorithms/invoke/packages-snippet.h @@ -0,0 +1,3 @@ +void WorkPackageA(); +void WorkPackageB(); +void WorkPackageC(); diff --git a/doc/examples/algorithms/invoke/parallel_quick_sort-snippet.h b/doc/examples/algorithms/invoke/parallel_quick_sort-snippet.h new file mode 100644 index 0000000..f518853 --- /dev/null +++ b/doc/examples/algorithms/invoke/parallel_quick_sort-snippet.h @@ -0,0 +1,7 @@ +void ParallelQuickSort(int* first, int* last) { + if (last - first <= 1) return; + int* mid = Partition(first, last); + using embb::algorithms::Invoke; + Invoke([=](){ParallelQuickSort(first, mid);}, + [=](){ParallelQuickSort(mid, last);}); +} diff --git a/doc/examples/algorithms/invoke/quick_sort-snippet.h b/doc/examples/algorithms/invoke/quick_sort-snippet.h new file mode 100644 index 0000000..9d33c89 --- /dev/null +++ b/doc/examples/algorithms/invoke/quick_sort-snippet.h @@ -0,0 +1,6 @@ +void QuickSort(int* first, int* last) { + if (last - first <= 1) return; + int* mid = Partition(first, last); + QuickSort(first, mid); + QuickSort(mid, last); +} diff --git a/doc/examples/algorithms/reduce/dot_product-snippet.h b/doc/examples/algorithms/reduce/dot_product-snippet.h new file mode 100644 index 0000000..8d6bbf2 --- /dev/null +++ b/doc/examples/algorithms/reduce/dot_product-snippet.h @@ -0,0 +1,9 @@ +using embb::algorithms::Zip; +using embb::algorithms::ZipPair; +int dot_product = Reduce(Zip(range.begin(), second_range.begin()), + Zip(range.end(), second_range.end()), + 0, + std::plus(), + [](const ZipPair& pair) { + return pair.First() * pair.Second(); + }); diff --git a/doc/examples/algorithms/reduce/parallel-snippet.h b/doc/examples/algorithms/reduce/parallel-snippet.h new file mode 100644 index 0000000..b28ad55 --- /dev/null +++ b/doc/examples/algorithms/reduce/parallel-snippet.h @@ -0,0 +1,2 @@ +using embb::algorithms::Reduce; +sum = Reduce(range.begin(), range.end(), 0, std::plus()); diff --git a/doc/examples/algorithms/reduce/range_init-snippet.h b/doc/examples/algorithms/reduce/range_init-snippet.h new file mode 100644 index 0000000..e3a3ee3 --- /dev/null +++ b/doc/examples/algorithms/reduce/range_init-snippet.h @@ -0,0 +1,4 @@ +std::vector range(5); +for (size_t i = 0; i < range.size(); i++) { + range[i] = static_cast(i) + 1; +} diff --git a/doc/examples/algorithms/reduce/reduce-fragmented.cc b/doc/examples/algorithms/reduce/reduce-fragmented.cc new file mode 100644 index 0000000..4c9f1df --- /dev/null +++ b/doc/examples/algorithms/reduce/reduce-fragmented.cc @@ -0,0 +1,50 @@ +/* + * Copyright (c) 2014-2015, Siemens AG. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +#include +#include +#include +#include + +/** + * Example using embb::algorithms::Reduce. + * + * Summing up a range of values and more. + */ +void RunReduce() { + #include "algorithms/reduce/range_init-snippet.h" + + #include "algorithms/reduce/sequential-snippet.h" + assert(sum == 1 + 2 + 3 + 4 + 5); + + #include "algorithms/reduce/parallel-snippet.h" + assert(sum == 1 + 2 + 3 + 4 + 5); + + #include "algorithms/reduce/second_range_init-snippet.h" + #include "algorithms/reduce/dot_product-snippet.h" + assert(dot_product == 1*5 + 2*6 + 3*7 + 4*8 + 5*9); + EMBB_UNUSED_IN_RELEASE(dot_product); +} diff --git a/doc/examples/algorithms/reduce/second_range_init-snippet.h b/doc/examples/algorithms/reduce/second_range_init-snippet.h new file mode 100644 index 0000000..0c1f44e --- /dev/null +++ b/doc/examples/algorithms/reduce/second_range_init-snippet.h @@ -0,0 +1,4 @@ +std::vector second_range(5); +for (size_t i = 0; i < range.size(); i++) { + second_range[i] = static_cast(i) + 5; +} diff --git a/doc/examples/algorithms/reduce/sequential-snippet.h b/doc/examples/algorithms/reduce/sequential-snippet.h new file mode 100644 index 0000000..c5cca02 --- /dev/null +++ b/doc/examples/algorithms/reduce/sequential-snippet.h @@ -0,0 +1,4 @@ +int sum = 0; +for (size_t i = 0; i < range.size(); i++) { + sum += range[i]; +} diff --git a/doc/examples/algorithms/scan/prefix_sum-snippet.h b/doc/examples/algorithms/scan/prefix_sum-snippet.h new file mode 100644 index 0000000..38fae7d --- /dev/null +++ b/doc/examples/algorithms/scan/prefix_sum-snippet.h @@ -0,0 +1,3 @@ +using embb::algorithms::Scan; +Scan(input_range.begin(), input_range.end(), output_range.begin(), + 0, std::plus()); diff --git a/doc/examples/algorithms/scan/scan-fragmented.cc b/doc/examples/algorithms/scan/scan-fragmented.cc new file mode 100644 index 0000000..3a9c1d3 --- /dev/null +++ b/doc/examples/algorithms/scan/scan-fragmented.cc @@ -0,0 +1,55 @@ +/* + * Copyright (c) 2014-2015, Siemens AG. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +#include +#include +#include + +void CheckResults(const std::vector& results) { + assert(results.size() == 5); + assert(results[0] == 1); + assert(results[1] == 3); + assert(results[2] == 6); + assert(results[3] == 10); + assert(results[4] == 15); + EMBB_UNUSED_IN_RELEASE(results); +} + +/** + * Example using embb::algorithms::Scan. + * + * + */ +void RunScan() { + #include "algorithms/scan/setup-snippet.h" + + #include "algorithms/scan/sequential_prefix_sum-snippet.h" + CheckResults(output_range); + + for (size_t i = 0; i < output_range.size(); i++) output_range[i] = 0; + #include "algorithms/scan/prefix_sum-snippet.h" + CheckResults(output_range); +} diff --git a/doc/examples/algorithms/scan/sequential_prefix_sum-snippet.h b/doc/examples/algorithms/scan/sequential_prefix_sum-snippet.h new file mode 100644 index 0000000..4f42a55 --- /dev/null +++ b/doc/examples/algorithms/scan/sequential_prefix_sum-snippet.h @@ -0,0 +1,5 @@ +std::vector output_range(input_range.size()); +output_range[0] = input_range[0]; +for(size_t i = 1; i < input_range.size(); i++) { + output_range[i] = output_range[i-1] + input_range[i]; +} diff --git a/doc/examples/algorithms/scan/setup-snippet.h b/doc/examples/algorithms/scan/setup-snippet.h new file mode 100644 index 0000000..56c9517 --- /dev/null +++ b/doc/examples/algorithms/scan/setup-snippet.h @@ -0,0 +1,5 @@ +std::vector input_range(5); +for (size_t i = 0; i < input_range.size(); i++) { + input_range[i] = static_cast(i) + 1; +} + diff --git a/doc/examples/algorithms/sorting/merge_sort_preallocated-snippet.h b/doc/examples/algorithms/sorting/merge_sort_preallocated-snippet.h new file mode 100644 index 0000000..7f12c05 --- /dev/null +++ b/doc/examples/algorithms/sorting/merge_sort_preallocated-snippet.h @@ -0,0 +1,3 @@ +using embb::algorithms::MergeSort; +std::vector temporary_range(range.size()); +MergeSort(range.begin(), range.end(), temporary_range.begin()); diff --git a/doc/examples/algorithms/sorting/quick_sort-snippet.h b/doc/examples/algorithms/sorting/quick_sort-snippet.h new file mode 100644 index 0000000..a8eeb9b --- /dev/null +++ b/doc/examples/algorithms/sorting/quick_sort-snippet.h @@ -0,0 +1,2 @@ +using embb::algorithms::QuickSort; +QuickSort(range.begin(), range.end()); diff --git a/doc/examples/algorithms/sorting/quick_sort_custom_compare-snippet.h b/doc/examples/algorithms/sorting/quick_sort_custom_compare-snippet.h new file mode 100644 index 0000000..d33307d --- /dev/null +++ b/doc/examples/algorithms/sorting/quick_sort_custom_compare-snippet.h @@ -0,0 +1 @@ +QuickSort(range.begin(), range.end(), std::greater()); diff --git a/doc/examples/algorithms/sorting/range_define-snippet.h b/doc/examples/algorithms/sorting/range_define-snippet.h new file mode 100644 index 0000000..f9eb29e --- /dev/null +++ b/doc/examples/algorithms/sorting/range_define-snippet.h @@ -0,0 +1 @@ +std::vector range; diff --git a/doc/examples/algorithms/sorting/sorting-fragmented.cc b/doc/examples/algorithms/sorting/sorting-fragmented.cc new file mode 100644 index 0000000..36cb1ed --- /dev/null +++ b/doc/examples/algorithms/sorting/sorting-fragmented.cc @@ -0,0 +1,60 @@ +/* + * Copyright (c) 2014-2015, Siemens AG. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +#include +#include + +/** + * Example using embb::algorithms::QuickSort and MergeSort. + * + * Sorting a range of values. + */ +void RunSorting() { + #include "algorithms/sorting/range_define-snippet.h" + range.push_back(4); + range.push_back(2); + range.push_back(3); + range.push_back(5); + range.push_back(1); + + #include "algorithms/sorting/quick_sort-snippet.h" + for (size_t i = 0; i < range.size(); i++) { + assert(range[i] == static_cast(i) + 1); + } + + #include "algorithms/sorting/quick_sort_custom_compare-snippet.h" + for (size_t i = 0; i < range.size(); i++) { + assert(range[i] == static_cast(range.size() - i)); + } + + #include "algorithms/sorting/merge_sort_preallocated-snippet.h" + for (size_t i = 0; i < range.size(); i++) { + assert(range[i] == static_cast(i) + 1); + } +} + + + diff --git a/doc/examples/containers/object_pool-fragmented.cc b/doc/examples/containers/object_pool-fragmented.cc new file mode 100644 index 0000000..fb7ee1b --- /dev/null +++ b/doc/examples/containers/object_pool-fragmented.cc @@ -0,0 +1,46 @@ +/* + * Copyright (c) 2014-2015, Siemens AG. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +#include +#include +#include + +void RunObjectPoolExample1() +{ + #include "containers/object_pool-snippet.h" +} + +void RunObjectPoolExample2() +{ + #include "containers/object_pool_2-snippet.h" +} + +void RunObjectPoolExamples() +{ + RunObjectPoolExample1(); + RunObjectPoolExample2(); + +} diff --git a/doc/examples/containers/object_pool-snippet.h b/doc/examples/containers/object_pool-snippet.h new file mode 100644 index 0000000..15fe2b0 --- /dev/null +++ b/doc/examples/containers/object_pool-snippet.h @@ -0,0 +1,11 @@ +embb::containers::ObjectPool objPool(5); //@\label{lst:object_pool_lst1:line_create}@ + +int* alloc[5]; + +for (int i = 0; i != 5; ++i) { + alloc[i] = objPool.Allocate(); //@\label{lst:object_pool_lst1:line_allocate}@ +} + +for (int i = 0; i != 5; ++i) { + objPool.Free(alloc[i]); //@\label{lst:object_pool_lst1:line_free}@ +} \ No newline at end of file diff --git a/doc/examples/containers/object_pool_2-snippet.h b/doc/examples/containers/object_pool_2-snippet.h new file mode 100644 index 0000000..db87c42 --- /dev/null +++ b/doc/examples/containers/object_pool_2-snippet.h @@ -0,0 +1,2 @@ +embb::containers::ObjectPool> objPool(5); //@\label{lst:object_pool_lst2:line_create}@ diff --git a/doc/examples/containers/queues-fragmented.cc b/doc/examples/containers/queues-fragmented.cc new file mode 100644 index 0000000..0b6eaff --- /dev/null +++ b/doc/examples/containers/queues-fragmented.cc @@ -0,0 +1,40 @@ +/* + * Copyright (c) 2014-2015, Siemens AG. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +#include +#include +#include + +void RunQueueExample1() +{ + #include "containers/queues-snippet.h" +} + + +void RunQueueExamples() +{ + RunQueueExample1(); +} diff --git a/doc/examples/containers/queues-snippet.h b/doc/examples/containers/queues-snippet.h new file mode 100644 index 0000000..951f5c3 --- /dev/null +++ b/doc/examples/containers/queues-snippet.h @@ -0,0 +1,15 @@ +embb::containers::LockFreeMPMCQueue queue(10); //@\label{lst:queue_lst1:line_create}@ + +int i, j; +bool result = queue.TryDequeue(i); //@\label{lst:queue_lst1:fail_pop}@ +assert(result == false); + +for (int i = 0; i <= 4; ++i) { //@\label{lst:queue_lst1:loop1}@ + result = queue.TryEnqueue(i); //@\label{lst:queue_lst1:push}@ + assert(result == true); +} + +for (int i = 0; i <= 4; ++i) { //@\label{lst:queue_lst1:loop2}@ + result = queue.TryDequeue(j); //@\label{lst:queue_lst1:pop}@ + assert(result == true && i == j); //@\label{lst:queue_lst1:assert}@ +} \ No newline at end of file diff --git a/doc/examples/containers/stack-fragmented.cc b/doc/examples/containers/stack-fragmented.cc new file mode 100644 index 0000000..31adda7 --- /dev/null +++ b/doc/examples/containers/stack-fragmented.cc @@ -0,0 +1,37 @@ +/* + * Copyright (c) 2014-2015, Siemens AG. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +#include +#include +void RunStackExample1() +{ + #include "containers/stack-snippet.h" +} + +void RunStackExamples() +{ + RunStackExample1(); +} diff --git a/doc/examples/containers/stack-snippet.h b/doc/examples/containers/stack-snippet.h new file mode 100644 index 0000000..dce744f --- /dev/null +++ b/doc/examples/containers/stack-snippet.h @@ -0,0 +1,15 @@ +embb::containers::LockFreeStack stack(10); //@\label{lst:stack_lst1:line_create}@ + +int i, j; +bool result = stack.TryPop(i); //@\label{lst:stack_lst1:fail_pop}@ +assert(result == false); + +for (int i = 0; i <= 4; ++i) {//@\label{lst:stack_lst1:loop1}@ + result = stack.TryPush(i); //@\label{lst:stack_lst1:push}@ + assert(result == true); +} + +for (int i = 4; i >= 0; --i) { //@\label{lst:stack_lst1:loop2}@ + result = stack.TryPop(j); //@\label{lst:stack_lst1:pop}@ + assert(result == true && i == j); //@\label{lst:stack_lst1:assert}@ +} \ No newline at end of file diff --git a/doc/examples/dataflow/dataflow_add-snippet.h b/doc/examples/dataflow/dataflow_add-snippet.h new file mode 100644 index 0000000..ce51ef8 --- /dev/null +++ b/doc/examples/dataflow/dataflow_add-snippet.h @@ -0,0 +1 @@ + nw.AddSource(read); diff --git a/doc/examples/dataflow/dataflow_comparator-snippet.h b/doc/examples/dataflow/dataflow_comparator-snippet.h new file mode 100644 index 0000000..3630f18 --- /dev/null +++ b/doc/examples/dataflow/dataflow_comparator-snippet.h @@ -0,0 +1,8 @@ +template +class Comparator { +public: + void Run(const T& a, const T& b, T& x, T& y) { + x = std::min(a,b); + y = std::max(a,b); + } +}; diff --git a/doc/examples/dataflow/dataflow_connect-snippet.h b/doc/examples/dataflow/dataflow_connect-snippet.h new file mode 100644 index 0000000..6660f53 --- /dev/null +++ b/doc/examples/dataflow/dataflow_connect-snippet.h @@ -0,0 +1,2 @@ + read >> replace; + replace >> write; diff --git a/doc/examples/dataflow/dataflow_consumer-snippet.h b/doc/examples/dataflow/dataflow_consumer-snippet.h new file mode 100644 index 0000000..eae4054 --- /dev/null +++ b/doc/examples/dataflow/dataflow_consumer-snippet.h @@ -0,0 +1,9 @@ +template +class Consumer { +public: + void Run(const T& x1, const T& x2, const T& x3, const T& x4) { + if (x1 <= x2 && x2 <= x3 && x3 <= x4) { + // consume values + } + } +}; diff --git a/doc/examples/dataflow/dataflow_declare_add_sources-snippet.h b/doc/examples/dataflow/dataflow_declare_add_sources-snippet.h new file mode 100644 index 0000000..f1cfcaa --- /dev/null +++ b/doc/examples/dataflow/dataflow_declare_add_sources-snippet.h @@ -0,0 +1,20 @@ + Producer + producer1(1), + producer2(2), + producer3(3), + producer4(4); + + Network::Source + source1( + embb::base::MakeFunction(producer1, &Producer::Run) ), + source2( + embb::base::MakeFunction(producer2, &Producer::Run) ), + source3( + embb::base::MakeFunction(producer3, &Producer::Run) ), + source4( + embb::base::MakeFunction(producer4, &Producer::Run) ); + + nw.AddSource(source1); + nw.AddSource(source2); + nw.AddSource(source3); + nw.AddSource(source4); diff --git a/doc/examples/dataflow/dataflow_declare_replace-snippet.h b/doc/examples/dataflow/dataflow_declare_replace-snippet.h new file mode 100644 index 0000000..e230807 --- /dev/null +++ b/doc/examples/dataflow/dataflow_declare_replace-snippet.h @@ -0,0 +1,5 @@ + Network::ParallelProcess< + Network::Inputs::Type, + Network::Outputs::Type> replace( + embb::base::MakeFunction(ReplaceFunction) + ); diff --git a/doc/examples/dataflow/dataflow_declare_sink-snippet.h b/doc/examples/dataflow/dataflow_declare_sink-snippet.h new file mode 100644 index 0000000..dfdd6b2 --- /dev/null +++ b/doc/examples/dataflow/dataflow_declare_sink-snippet.h @@ -0,0 +1,3 @@ + Network::Sink write( + embb::base::MakeFunction(SinkFunction) + ); diff --git a/doc/examples/dataflow/dataflow_declare_source-snippet.h b/doc/examples/dataflow/dataflow_declare_source-snippet.h new file mode 100644 index 0000000..470db74 --- /dev/null +++ b/doc/examples/dataflow/dataflow_declare_source-snippet.h @@ -0,0 +1,3 @@ + Network::Source read( + embb::base::MakeFunction(SourceFunction) + ); diff --git a/doc/examples/dataflow/dataflow_include-snippet.h b/doc/examples/dataflow/dataflow_include-snippet.h new file mode 100644 index 0000000..ca47769 --- /dev/null +++ b/doc/examples/dataflow/dataflow_include-snippet.h @@ -0,0 +1 @@ +#include diff --git a/doc/examples/dataflow/dataflow_linear-fragmented.cc b/doc/examples/dataflow/dataflow_linear-fragmented.cc new file mode 100644 index 0000000..25bdacd --- /dev/null +++ b/doc/examples/dataflow/dataflow_linear-fragmented.cc @@ -0,0 +1,61 @@ +/* + * Copyright (c) 2014-2015, Siemens AG. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +#include +#include +#include +#include + +// replace all occurrences of 'what' in 'str' with 'with' +void repl(std::string& str, const std::string &what, + const std::string& with) { + std::string::size_type pos = 0; + while ((pos = str.find(what, pos)) != std::string::npos) { + str.replace(pos, what.length(), with); + pos += with.length(); + } +} + +#include "dataflow/dataflow_include-snippet.h" + +std::stringstream file("hi world!\nhi there!\nhi hi!?\nhi!\n"); +std::string what("hi"); +std::string with("hello"); + +#include "dataflow/dataflow_network-snippet.h" + +#include "dataflow/dataflow_source_function-snippet.h" +#include "dataflow/dataflow_replace_function-snippet.h" +#include "dataflow/dataflow_sink_function-snippet.h" + +void RunDataflowLinear() { +#include "dataflow/dataflow_declare_source-snippet.h" +#include "dataflow/dataflow_declare_replace-snippet.h" +#include "dataflow/dataflow_declare_sink-snippet.h" +#include "dataflow/dataflow_connect-snippet.h" +#include "dataflow/dataflow_add-snippet.h" +#include "dataflow/dataflow_run-snippet.h" +} diff --git a/doc/examples/dataflow/dataflow_network-snippet.h b/doc/examples/dataflow/dataflow_network-snippet.h new file mode 100644 index 0000000..c13ebeb --- /dev/null +++ b/doc/examples/dataflow/dataflow_network-snippet.h @@ -0,0 +1,2 @@ +typedef embb::dataflow::Network<2> Network; +static Network nw; diff --git a/doc/examples/dataflow/dataflow_nonlinear-fragmented.cc b/doc/examples/dataflow/dataflow_nonlinear-fragmented.cc new file mode 100644 index 0000000..e7f419d --- /dev/null +++ b/doc/examples/dataflow/dataflow_nonlinear-fragmented.cc @@ -0,0 +1,87 @@ +/* + * Copyright (c) 2014-2015, Siemens AG. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +#include +#include + +#ifdef NDEBUG +#undef assert +#define assert(x) if(!x) std::cout << "assert failed." << std::endl +#endif + +static int SimpleRand(int & seed) { + const int a = 16807; + const int m = 2147483647; + seed = (a * seed) % m; + return seed % 100; +} + +#include "dataflow/dataflow_include-snippet.h" + +#include "dataflow/dataflow_producer-snippet.h" +#include "dataflow/dataflow_comparator-snippet.h" +#include "dataflow/dataflow_consumer-snippet.h" + +#include "dataflow/dataflow_network-snippet.h" + +void RunDataflowNonLinear() { +#include "dataflow/dataflow_declare_add_sources-snippet.h" + + Comparator comparator; + + Network::ParallelProcess< + Network::Inputs::Type, Network::Outputs::Type> + process1( embb::base::MakeFunction(comparator, &Comparator::Run) ), + process2( embb::base::MakeFunction(comparator, &Comparator::Run) ), + process3( embb::base::MakeFunction(comparator, &Comparator::Run) ), + process4( embb::base::MakeFunction(comparator, &Comparator::Run) ), + process5( embb::base::MakeFunction(comparator, &Comparator::Run) ); + + Consumer consumer; + + Network::Sink + sink1(embb::base::MakeFunction(consumer, &Consumer::Run)); + + source1.GetOutput<0>() >> process1.GetInput<0>(); + source2.GetOutput<0>() >> process2.GetInput<0>(); + source3.GetOutput<0>() >> process1.GetInput<1>(); + source4.GetOutput<0>() >> process2.GetInput<1>(); + + process1.GetOutput<0>() >> process3.GetInput<0>(); + process2.GetOutput<0>() >> process3.GetInput<1>(); + process1.GetOutput<1>() >> process4.GetInput<0>(); + process2.GetOutput<1>() >> process4.GetInput<1>(); + + process3.GetOutput<1>() >> process5.GetInput<0>(); + process4.GetOutput<0>() >> process5.GetInput<1>(); + + process3.GetOutput<0>() >> sink1.GetInput<0>(); + process5.GetOutput<0>() >> sink1.GetInput<1>(); + process5.GetOutput<1>() >> sink1.GetInput<2>(); + process4.GetOutput<1>() >> sink1.GetInput<3>(); + + nw(); +} diff --git a/doc/examples/dataflow/dataflow_producer-snippet.h b/doc/examples/dataflow/dataflow_producer-snippet.h new file mode 100644 index 0000000..ffaf79e --- /dev/null +++ b/doc/examples/dataflow/dataflow_producer-snippet.h @@ -0,0 +1,15 @@ +template +class Producer { + public: + explicit Producer(int seed) : seed_(seed), count_(4) {} + bool Run(T& x) { + // produce a new value x + x = SimpleRand(seed_); + count_--; + return count_ >= 0; + } + + private: + int seed_; + int count_; +}; diff --git a/doc/examples/dataflow/dataflow_replace_function-snippet.h b/doc/examples/dataflow/dataflow_replace_function-snippet.h new file mode 100644 index 0000000..21e71d9 --- /dev/null +++ b/doc/examples/dataflow/dataflow_replace_function-snippet.h @@ -0,0 +1,4 @@ +void ReplaceFunction(std::string const & istr, std::string & ostr) { + ostr = istr; + repl(ostr, what, with); +} diff --git a/doc/examples/dataflow/dataflow_run-snippet.h b/doc/examples/dataflow/dataflow_run-snippet.h new file mode 100644 index 0000000..ff4f083 --- /dev/null +++ b/doc/examples/dataflow/dataflow_run-snippet.h @@ -0,0 +1 @@ + nw(); diff --git a/doc/examples/dataflow/dataflow_sink_function-snippet.h b/doc/examples/dataflow/dataflow_sink_function-snippet.h new file mode 100644 index 0000000..66896ea --- /dev/null +++ b/doc/examples/dataflow/dataflow_sink_function-snippet.h @@ -0,0 +1,3 @@ +void SinkFunction(std::string const & str) { + std::cout << str << std::endl; +} diff --git a/doc/examples/dataflow/dataflow_source_function-snippet.h b/doc/examples/dataflow/dataflow_source_function-snippet.h new file mode 100644 index 0000000..6c1cdea --- /dev/null +++ b/doc/examples/dataflow/dataflow_source_function-snippet.h @@ -0,0 +1,4 @@ +bool SourceFunction(std::string & str) { + std::getline(file, str); + return !file.eof(); +} diff --git a/doc/examples/insert_snippets.py b/doc/examples/insert_snippets.py new file mode 100644 index 0000000..40d70bc --- /dev/null +++ b/doc/examples/insert_snippets.py @@ -0,0 +1,51 @@ +import os +import glob +import shutil +import sys +import string + +filenames = os.listdir(".") +# Work through all files and directories +for filename in filenames: + # If it is a directory, just add content to filenames + if os.path.isdir(filename): + nestedfiles = os.listdir(filename + "/") + for i in range(len(nestedfiles)): + nestedfiles[i] = filename + "/" + nestedfiles[i] + filenames.extend(nestedfiles) + # Otherwise look into file + else: + #sys.stdout.write("Looking at " + filename) + is_fragmented = string.find(filename, "-fragmented.cc") != -1 + if is_fragmented: + in_file = open(filename, 'r+') + out_filename = string.replace(filename, "-fragmented", "") + sys.stdout.write(filename + " -> " + out_filename + "\n") + out_file = open(out_filename, 'w') + for line in in_file: + stripped_line = string.lstrip(line) + # Check if first characters after whitespaces are include + is_include = string.find(stripped_line, "#include") == 0 + # Check if snippet keyword is contained in include + includes_snippet = string.find(line, "-snippet.") != -1 + if is_include and includes_snippet: + # Get number of whitespaces for indentation of snippet + num_whitespaces = len(line) - len(stripped_line) + # Create Whitespace-string for indentation + whitespaces = "" + for i in range(num_whitespaces): + whitespaces += " " + # Get include filename + first_quotes_pos = string.find(line, '"') + last_quotes_pos = string.rfind(line, '"') + snippet_filename = line[first_quotes_pos + 1 : last_quotes_pos] + sys.stdout.write(" + " + snippet_filename + "\n") + snippet_file = open(snippet_filename, 'r') + for snippet_line in snippet_file: + out_file.write(whitespaces + snippet_line) + snippet_file.close() + #out_file.write("\n") + else: + out_file.write(line) + in_file.close() + out_file.close() \ No newline at end of file diff --git a/doc/examples/main.cc b/doc/examples/main.cc new file mode 100644 index 0000000..7888d4b --- /dev/null +++ b/doc/examples/main.cc @@ -0,0 +1,134 @@ +/* + * Copyright (c) 2014-2015, Siemens AG. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +#include +#include + +void RunMTAPI_C(); +void RunMTAPI_C_Plugin(); +void RunMTAPI_C_Network(); +#ifdef EMBB_WITH_OPENCL +void RunMTAPI_C_OpenCL(); +#endif +void RunMTAPI_CPP(); +void RunTasks(); +void RunDataflowLinear(); +void RunDataflowNonLinear(); +void RunSTLForEach(); +void RunForEach(); +void RunInvoke(); +void RunSorting(); +void RunReduce(); +void RunCounting(); +void RunScan(); +void RunObjectPoolExamples(); +void RunStackExamples(); +void RunQueueExamples(); + +/** + * Runs all examples and tests their correctness. + */ +int main() { + embb_thread_set_max_count(1024); + + std::cout << "Running examples ..." << std::endl; + + std::cout << "RunMTAPI_C() ..." << std::endl; + RunMTAPI_C(); + std::cout << "RunMTAPI_C() ... done" << std::endl; + + std::cout << "RunMTAPI_C_Plugin() ..." << std::endl; + RunMTAPI_C_Plugin(); + std::cout << "RunMTAPI_C_Plugin() ... done" << std::endl; + + std::cout << "RunMTAPI_C_Network() ..." << std::endl; + RunMTAPI_C_Network(); + std::cout << "RunMTAPI_C_Network() ... done" << std::endl; + +#ifdef EMBB_WITH_OPENCL + std::cout << "RunMTAPI_C_OpenCL() ..." << std::endl; + RunMTAPI_C_OpenCL(); + std::cout << "RunMTAPI_C_OpenCL() ... done" << std::endl; +#endif + + std::cout << "RunMTAPI_CPP() ..." << std::endl; + RunMTAPI_CPP(); + std::cout << "RunMTAPI_CPP() ... done" << std::endl; + + std::cout << "RunTasks() ..." << std::endl; + RunTasks(); + std::cout << "RunTasks() ... done" << std::endl; + + std::cout << "RunDataflowLinear() ..." << std::endl; + RunDataflowLinear(); + std::cout << "RunDataflowLinear() ... done" << std::endl; + + std::cout << "RunDataflowNonLinear() ..." << std::endl; + RunDataflowNonLinear(); + std::cout << "RunDataflowNonLinear() ... done" << std::endl; + + std::cout << "RunSTLForEach() ..." << std::endl; + RunSTLForEach(); + std::cout << "RunSTLForEach() ... done" << std::endl; + + std::cout << "RunForEach() ..." << std::endl; + RunForEach(); + std::cout << "RunForEach() ... done" << std::endl; + + std::cout << "RunInvoke() ..." << std::endl; + RunInvoke(); + std::cout << "RunInvoke() ... done" << std::endl; + + std::cout << "RunSorting() ... " << std::endl; + RunSorting(); + std::cout << "RunSorting() ... done" << std::endl; + + std::cout << "RunReduce() ... " << std::endl; + RunReduce(); + std::cout << "RunReduce() ... done" << std::endl; + + std::cout << "RunCounting() ..." << std::endl; + RunCounting(); + std::cout << "RunCounting() ... done" << std::endl; + /* + std::cout << "RunScan() ..." << std::endl; + RunScan(); + std::cout << "RunScan() ... done" << std::endl; + */ + std::cout << "RunObjectPoolExamples() ..." << std::endl; + RunObjectPoolExamples(); + std::cout << "RunObjectPoolExamples() ... done" << std::endl; + + std::cout << "RunStackExamples() ..." << std::endl; + RunStackExamples(); + std::cout << "RunStackExamples() ... done" << std::endl; + + std::cout << "RunQueueExamples() ..." << std::endl; + RunQueueExamples(); + std::cout << "RunQueueExamples() ... done" << std::endl; + + std::cout << "Running examples ... done" << std::endl; +} diff --git a/doc/examples/mtapi/mtapi_c-fragmented.cc b/doc/examples/mtapi/mtapi_c-fragmented.cc new file mode 100644 index 0000000..d543e12 --- /dev/null +++ b/doc/examples/mtapi/mtapi_c-fragmented.cc @@ -0,0 +1,66 @@ +/* + * Copyright (c) 2014-2015, Siemens AG. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +#include +#include + +#include "mtapi/mtapi_check_status-snippet.h" +#include "mtapi/mtapi_c_domain_node_id-snippet.h" + +static +#include "mtapi/mtapi_c_action_signature-snippet.h" +#include "mtapi/mtapi_c_validate_arguments-snippet.h" +#include "mtapi/mtapi_c_validate_result_buffer-snippet.h" + /* calculate */ +#include "mtapi/mtapi_terminating_condition-snippet.h" + /* first recursive call spawned as task (x = fib(n - 1);) */ +#include "mtapi/mtapi_c_calc_task-snippet.h" + /* second recursive call can be called directly (y = fib(n - 2);) */ +#include "mtapi/mtapi_c_calc_direct-snippet.h" + /* wait for completion */ +#include "mtapi/mtapi_c_wait_task-snippet.h" + /* add the two preceeding numbers */ +#include "mtapi/mtapi_write_back-snippet.h" + +static int fibonacci(int n) { +#include "mtapi/mtapi_c_initialize-snippet.h" +#include "mtapi/mtapi_c_register_action-snippet.h" +#include "mtapi/mtapi_c_start_task-snippet.h" + /* wait for task completion */ + mtapi_task_wait(task, MTAPI_INFINITE, &status); + MTAPI_CHECK_STATUS(status); +#include "mtapi/mtapi_c_finalize-snippet.h" + return result; +} + +void RunMTAPI_C() { + /* run calculation */ + int result; + result = fibonacci(6); + + /* print result */ + printf("result: %i\n", result); +} diff --git a/doc/examples/mtapi/mtapi_c_action_signature-snippet.h b/doc/examples/mtapi/mtapi_c_action_signature-snippet.h new file mode 100644 index 0000000..80b8a4f --- /dev/null +++ b/doc/examples/mtapi/mtapi_c_action_signature-snippet.h @@ -0,0 +1,9 @@ +void fibonacciActionFunction( + const void* args, + mtapi_size_t arg_size, + void* result_buffer, + mtapi_size_t result_buffer_size, + const void* /*node_local_data*/, + mtapi_size_t /*node_local_data_size*/, + mtapi_task_context_t* task_context + ) { diff --git a/doc/examples/mtapi/mtapi_c_calc_direct-snippet.h b/doc/examples/mtapi/mtapi_c_calc_direct-snippet.h new file mode 100644 index 0000000..525f7be --- /dev/null +++ b/doc/examples/mtapi/mtapi_c_calc_direct-snippet.h @@ -0,0 +1,7 @@ + int b = n - 2; + int y; + fibonacciActionFunction( + &b, sizeof(int), + &y, sizeof(int), + MTAPI_NULL, 0, + task_context); diff --git a/doc/examples/mtapi/mtapi_c_calc_task-snippet.h b/doc/examples/mtapi/mtapi_c_calc_task-snippet.h new file mode 100644 index 0000000..62b352a --- /dev/null +++ b/doc/examples/mtapi/mtapi_c_calc_task-snippet.h @@ -0,0 +1,15 @@ + int a = n - 1; + int x; + mtapi_task_hndl_t task = mtapi_task_start( + MTAPI_TASK_ID_NONE, /* optional task ID */ + fibonacciJob, /* job */ + (void*)&a, /* arguments passed to action + functions */ + sizeof(int), /* size of arguments */ + (void*)&x, /* result buffer */ + sizeof(int), /* size of result buffer */ + MTAPI_DEFAULT_TASK_ATTRIBUTES, /* task attributes */ + MTAPI_GROUP_NONE, /* optional task group */ + &status /* status out - parameter */ + ); + MTAPI_CHECK_STATUS(status); diff --git a/doc/examples/mtapi/mtapi_c_domain_node_id-snippet.h b/doc/examples/mtapi/mtapi_c_domain_node_id-snippet.h new file mode 100644 index 0000000..b1850d0 --- /dev/null +++ b/doc/examples/mtapi/mtapi_c_domain_node_id-snippet.h @@ -0,0 +1,5 @@ +#define THIS_DOMAIN_ID 1 +#define THIS_NODE_ID 1 + +#define FIBONACCI_JOB 1 +static mtapi_job_hndl_t fibonacciJob; diff --git a/doc/examples/mtapi/mtapi_c_finalize-snippet.h b/doc/examples/mtapi/mtapi_c_finalize-snippet.h new file mode 100644 index 0000000..21c5bfa --- /dev/null +++ b/doc/examples/mtapi/mtapi_c_finalize-snippet.h @@ -0,0 +1,7 @@ + /* delete action */ + mtapi_action_delete(fibonacciAction, 100, &status); + MTAPI_CHECK_STATUS(status); + + /* finalize the node */ + mtapi_finalize(&status); + MTAPI_CHECK_STATUS(status); diff --git a/doc/examples/mtapi/mtapi_c_initialize-snippet.h b/doc/examples/mtapi/mtapi_c_initialize-snippet.h new file mode 100644 index 0000000..1269342 --- /dev/null +++ b/doc/examples/mtapi/mtapi_c_initialize-snippet.h @@ -0,0 +1,25 @@ + mtapi_status_t status; + + /* initialize node attributes to default values */ + mtapi_node_attributes_t node_attr; + mtapi_nodeattr_init(&node_attr, &status); + MTAPI_CHECK_STATUS(status); + + /* set node type to SMP */ + mtapi_nodeattr_set( + &node_attr, + MTAPI_NODE_TYPE, + MTAPI_ATTRIBUTE_VALUE(MTAPI_NODE_TYPE_SMP), + MTAPI_ATTRIBUTE_POINTER_AS_VALUE, + &status); + MTAPI_CHECK_STATUS(status); + + /* initialize the node */ + mtapi_info_t info; + mtapi_initialize( + THIS_DOMAIN_ID, + THIS_NODE_ID, + &node_attr, + &info, + &status); + MTAPI_CHECK_STATUS(status); diff --git a/doc/examples/mtapi/mtapi_c_network-fragmented.cc b/doc/examples/mtapi/mtapi_c_network-fragmented.cc new file mode 100644 index 0000000..777e74c --- /dev/null +++ b/doc/examples/mtapi/mtapi_c_network-fragmented.cc @@ -0,0 +1,102 @@ +/* + * Copyright (c) 2014-2015, Siemens AG. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +#include +#include "mtapi/mtapi_network_c_header-snippet.h" +#include + +#include "mtapi/mtapi_check_status-snippet.h" + +#define NETWORK_DOMAIN 1 +#define NETWORK_LOCAL_NODE 3 +#define NETWORK_LOCAL_JOB 3 +#define NETWORK_REMOTE_NODE 3 +#define NETWORK_REMOTE_JOB 4 + +#include "mtapi/mtapi_network_c_action_function-snippet.h" + +void RunMTAPI_C_Network() { + mtapi_status_t status; + mtapi_job_hndl_t job; + mtapi_task_hndl_t task; + mtapi_action_hndl_t network_action, local_action; + + const int kElements = 64; + float arguments[kElements * 2]; + float results[kElements]; + + for (int ii = 0; ii < kElements; ii++) { + arguments[ii] = static_cast(ii); + arguments[ii + kElements] = static_cast(ii); + } + + mtapi_initialize( + NETWORK_DOMAIN, + NETWORK_LOCAL_NODE, + MTAPI_DEFAULT_NODE_ATTRIBUTES, + MTAPI_NULL, + &status); + MTAPI_CHECK_STATUS(status); + +#include "mtapi/mtapi_network_c_plugin_initialize-snippet.h" + MTAPI_CHECK_STATUS(status); + +#include "mtapi/mtapi_network_c_remote_action_create-snippet.h" + MTAPI_CHECK_STATUS(status); + +#include "mtapi/mtapi_network_c_local_action_create-snippet.h" + MTAPI_CHECK_STATUS(status); + + job = mtapi_job_get(NETWORK_LOCAL_JOB, NETWORK_DOMAIN, &status); + MTAPI_CHECK_STATUS(status); + + task = mtapi_task_start( + MTAPI_TASK_ID_NONE, + job, + arguments, kElements * 2 * sizeof(float), + results, kElements*sizeof(float), + MTAPI_DEFAULT_TASK_ATTRIBUTES, + MTAPI_GROUP_NONE, + &status); + MTAPI_CHECK_STATUS(status); + + mtapi_task_wait(task, MTAPI_INFINITE, &status); + MTAPI_CHECK_STATUS(status); + + for (int ii = 0; ii < kElements; ii++) { + if (results[ii] != ii * 2 + 1) { + printf("result %d was expected to be %d but was %f.\n", + ii, ii * 2 + 1, results[ii]); + exit(MTAPI_ERR_UNKNOWN); + } + } + +#include "mtapi/mtapi_network_c_plugin_finalize-snippet.h" + MTAPI_CHECK_STATUS(status); + + mtapi_finalize(&status); + MTAPI_CHECK_STATUS(status); +} diff --git a/doc/examples/mtapi/mtapi_c_opencl-fragmented.cc b/doc/examples/mtapi/mtapi_c_opencl-fragmented.cc new file mode 100644 index 0000000..074744a --- /dev/null +++ b/doc/examples/mtapi/mtapi_c_opencl-fragmented.cc @@ -0,0 +1,98 @@ +/* + * Copyright (c) 2014-2015, Siemens AG. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +#include +#include "mtapi/mtapi_opencl_c_header-snippet.h" + +#include "mtapi/mtapi_check_status-snippet.h" + +#define OPENCL_DOMAIN 1 +#define OPENCL_NODE 2 +#define OPENCL_JOB 2 + +// OpenCL Kernel Function for element by element vector addition +#include "mtapi/mtapi_opencl_c_kernel-snippet.h" + +void RunMTAPI_C_OpenCL() { + mtapi_status_t status; + mtapi_job_hndl_t job; + mtapi_task_hndl_t task; + mtapi_action_hndl_t action; + + const int kElements = 64; + float arguments[kElements * 2]; + float results[kElements]; + + for (int ii = 0; ii < kElements; ii++) { + arguments[ii] = static_cast(ii); + arguments[ii + kElements] = static_cast(ii); + } + + mtapi_initialize( + OPENCL_DOMAIN, + OPENCL_NODE, + MTAPI_DEFAULT_NODE_ATTRIBUTES, + MTAPI_NULL, + &status); + MTAPI_CHECK_STATUS(status); + +#include "mtapi/mtapi_opencl_c_plugin_initialize-snippet.h" + MTAPI_CHECK_STATUS(status); + +#include "mtapi/mtapi_opencl_c_action_create-snippet.h" + MTAPI_CHECK_STATUS(status); + + status = MTAPI_ERR_UNKNOWN; + job = mtapi_job_get(OPENCL_JOB, OPENCL_DOMAIN, &status); + MTAPI_CHECK_STATUS(status); + + task = mtapi_task_start( + MTAPI_TASK_ID_NONE, + job, + arguments, kElements * 2 * sizeof(float), + results, kElements*sizeof(float), + MTAPI_DEFAULT_TASK_ATTRIBUTES, + MTAPI_GROUP_NONE, + &status); + MTAPI_CHECK_STATUS(status); + + mtapi_task_wait(task, MTAPI_INFINITE, &status); + MTAPI_CHECK_STATUS(status); + + for (int ii = 0; ii < kElements; ii++) { + if (results[ii] != ii * 2 + 1) { + printf("result %d was expected to be %d but was %f.\n", + ii, ii * 2 + 1, results[ii]); + exit(MTAPI_ERR_UNKNOWN); + } + } + +#include "mtapi/mtapi_opencl_c_plugin_finalize-snippet.h" + MTAPI_CHECK_STATUS(status); + + mtapi_finalize(&status); + MTAPI_CHECK_STATUS(status); +} diff --git a/doc/examples/mtapi/mtapi_c_plugin-fragmented.cc b/doc/examples/mtapi/mtapi_c_plugin-fragmented.cc new file mode 100644 index 0000000..b072164 --- /dev/null +++ b/doc/examples/mtapi/mtapi_c_plugin-fragmented.cc @@ -0,0 +1,83 @@ +/* + * Copyright (c) 2014-2015, Siemens AG. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +#include +#include + +#include +#include +#include + +#include + +#include +#include +#include +#include + +#define PLUGIN_DOMAIN_ID 1 +#define PLUGIN_NODE_ID 1 +#define PLUGIN_JOB_ID 1 + +#include "mtapi/mtapi_check_status-snippet.h" + +#include "mtapi/mtapi_c_plugin_task_schedule-snippet.h" + +#include "mtapi/mtapi_c_plugin_task_start_cb-snippet.h" + +#include "mtapi/mtapi_c_plugin_task_cancel_cb-snippet.h" + +#include "mtapi/mtapi_c_plugin_action_finalize_cb-snippet.h" + +void RunMTAPI_C_Plugin() { + mtapi_status_t status; + mtapi_job_hndl_t job; + mtapi_action_hndl_t action; + mtapi_task_hndl_t task; + + mtapi_initialize( + PLUGIN_DOMAIN_ID, + PLUGIN_NODE_ID, + MTAPI_DEFAULT_NODE_ATTRIBUTES, + MTAPI_NULL, + &status); + MTAPI_CHECK_STATUS(status); + +#include "mtapi/mtapi_c_plugin_action_create-snippet.h" + MTAPI_CHECK_STATUS(status); + +#include "mtapi/mtapi_c_plugin_get_job-snippet.h" + MTAPI_CHECK_STATUS(status); + +#include "mtapi/mtapi_c_plugin_task_start-snippet.h" + MTAPI_CHECK_STATUS(status); + + mtapi_task_wait(task, MTAPI_INFINITE, &status); + MTAPI_CHECK_STATUS(status); + + mtapi_finalize(&status); + MTAPI_CHECK_STATUS(status); +} diff --git a/doc/examples/mtapi/mtapi_c_plugin_action_create-snippet.h b/doc/examples/mtapi/mtapi_c_plugin_action_create-snippet.h new file mode 100644 index 0000000..2ec43dd --- /dev/null +++ b/doc/examples/mtapi/mtapi_c_plugin_action_create-snippet.h @@ -0,0 +1,10 @@ +action = mtapi_ext_plugin_action_create( + PLUGIN_JOB_ID, + plugin_task_start, + plugin_task_cancel, + plugin_action_finalize, + MTAPI_NULL, + MTAPI_NULL, + 0, + MTAPI_DEFAULT_ACTION_ATTRIBUTES, + &status); diff --git a/doc/examples/mtapi/mtapi_c_plugin_action_finalize_cb-snippet.h b/doc/examples/mtapi/mtapi_c_plugin_action_finalize_cb-snippet.h new file mode 100644 index 0000000..7c44e30 --- /dev/null +++ b/doc/examples/mtapi/mtapi_c_plugin_action_finalize_cb-snippet.h @@ -0,0 +1,8 @@ +void plugin_action_finalize( + MTAPI_IN mtapi_action_hndl_t action, + MTAPI_OUT mtapi_status_t* status + ) { + EMBB_UNUSED(action); + // nothing to do for tearing down the plugin action + mtapi_status_set(status, MTAPI_SUCCESS); +} diff --git a/doc/examples/mtapi/mtapi_c_plugin_get_job-snippet.h b/doc/examples/mtapi/mtapi_c_plugin_get_job-snippet.h new file mode 100644 index 0000000..9e97299 --- /dev/null +++ b/doc/examples/mtapi/mtapi_c_plugin_get_job-snippet.h @@ -0,0 +1,4 @@ + job = mtapi_job_get( + PLUGIN_JOB_ID, + PLUGIN_DOMAIN_ID, + &status); diff --git a/doc/examples/mtapi/mtapi_c_plugin_task_cancel_cb-snippet.h b/doc/examples/mtapi/mtapi_c_plugin_task_cancel_cb-snippet.h new file mode 100644 index 0000000..2a62c5d --- /dev/null +++ b/doc/examples/mtapi/mtapi_c_plugin_task_cancel_cb-snippet.h @@ -0,0 +1,8 @@ +void plugin_task_cancel( + MTAPI_IN mtapi_task_hndl_t task, + MTAPI_OUT mtapi_status_t* status + ) { + EMBB_UNUSED(task); + // nothing to cancel in this simple example + mtapi_status_set(status, MTAPI_SUCCESS); +} diff --git a/doc/examples/mtapi/mtapi_c_plugin_task_schedule-snippet.h b/doc/examples/mtapi/mtapi_c_plugin_task_schedule-snippet.h new file mode 100644 index 0000000..a180edc --- /dev/null +++ b/doc/examples/mtapi/mtapi_c_plugin_task_schedule-snippet.h @@ -0,0 +1,11 @@ +void plugin_task_schedule(embb_mtapi_task_t* local_task) { + // here the task might be dispatched to some hardware or separate thread + + // mark the task as running + embb_mtapi_task_set_state(local_task, MTAPI_TASK_RUNNING); + + // nothing to do to execute the no-op task + + // just mark the task as done + embb_mtapi_task_set_state(local_task, MTAPI_TASK_COMPLETED); +} diff --git a/doc/examples/mtapi/mtapi_c_plugin_task_start-snippet.h b/doc/examples/mtapi/mtapi_c_plugin_task_start-snippet.h new file mode 100644 index 0000000..344330a --- /dev/null +++ b/doc/examples/mtapi/mtapi_c_plugin_task_start-snippet.h @@ -0,0 +1,8 @@ + task = mtapi_task_start( + MTAPI_TASK_ID_NONE, + job, + MTAPI_NULL, 0, + MTAPI_NULL, 0, + MTAPI_DEFAULT_TASK_ATTRIBUTES, + MTAPI_GROUP_NONE, + &status); diff --git a/doc/examples/mtapi/mtapi_c_plugin_task_start_cb-snippet.h b/doc/examples/mtapi/mtapi_c_plugin_task_start_cb-snippet.h new file mode 100644 index 0000000..8e4d063 --- /dev/null +++ b/doc/examples/mtapi/mtapi_c_plugin_task_start_cb-snippet.h @@ -0,0 +1,31 @@ +void plugin_task_start( + MTAPI_IN mtapi_task_hndl_t task, + MTAPI_OUT mtapi_status_t* status) { + mtapi_status_t local_status = MTAPI_ERR_UNKNOWN; + + // do we have a node? + if (embb_mtapi_node_is_initialized()) { + // get the node instance + embb_mtapi_node_t * node = embb_mtapi_node_get_instance(); + + // is this a valid task? + if (embb_mtapi_task_pool_is_handle_valid(node->task_pool, task)) { + // get the tasks storage + embb_mtapi_task_t * local_task = + embb_mtapi_task_pool_get_storage_for_handle(node->task_pool, task); + + // dispatch the task + plugin_task_schedule(local_task); + + local_status = MTAPI_SUCCESS; + } + else { + local_status = MTAPI_ERR_TASK_INVALID; + } + } + else { + local_status = MTAPI_ERR_NODE_NOTINIT; + } + + mtapi_status_set(status, local_status); +} diff --git a/doc/examples/mtapi/mtapi_c_register_action-snippet.h b/doc/examples/mtapi/mtapi_c_register_action-snippet.h new file mode 100644 index 0000000..a05aaa7 --- /dev/null +++ b/doc/examples/mtapi/mtapi_c_register_action-snippet.h @@ -0,0 +1,17 @@ + /* create action */ + mtapi_action_hndl_t fibonacciAction; + fibonacciAction = mtapi_action_create( + FIBONACCI_JOB, /* action ID, defined by the + application */ + (fibonacciActionFunction), /* action function */ + MTAPI_NULL, /* no shared data */ + 0, /* length of shared data */ + MTAPI_DEFAULT_ACTION_ATTRIBUTES, /* action attributes */ + &status /* status out - parameter */ + ); + MTAPI_CHECK_STATUS(status); + + /* get job */ + mtapi_task_hndl_t task; + fibonacciJob = mtapi_job_get(FIBONACCI_JOB, THIS_DOMAIN_ID, &status); + MTAPI_CHECK_STATUS(status); diff --git a/doc/examples/mtapi/mtapi_c_start_task-snippet.h b/doc/examples/mtapi/mtapi_c_start_task-snippet.h new file mode 100644 index 0000000..79d005e --- /dev/null +++ b/doc/examples/mtapi/mtapi_c_start_task-snippet.h @@ -0,0 +1,15 @@ + /* start task */ + int result; + task = mtapi_task_start( + MTAPI_TASK_ID_NONE, /* optional task ID */ + fibonacciJob, /* job */ + (void*)&n, /* arguments passed to action + functions */ + sizeof(int), /* size of arguments */ + (void*)&result, /* result buffer */ + sizeof(int), /* size of result buffer */ + MTAPI_DEFAULT_TASK_ATTRIBUTES, /* task attributes */ + MTAPI_GROUP_NONE, /* optional task group */ + &status /* status out - parameter */ + ); + MTAPI_CHECK_STATUS(status); diff --git a/doc/examples/mtapi/mtapi_c_validate_arguments-snippet.h b/doc/examples/mtapi/mtapi_c_validate_arguments-snippet.h new file mode 100644 index 0000000..44246ab --- /dev/null +++ b/doc/examples/mtapi/mtapi_c_validate_arguments-snippet.h @@ -0,0 +1,12 @@ + /* check size of arguments (in this case we only expect one int + value)*/ + mtapi_status_t status; + if (arg_size != sizeof(int)) { + printf("wrong size of arguments\n"); + mtapi_context_status_set(task_context, MTAPI_ERR_ARG_SIZE, &status); + MTAPI_CHECK_STATUS(status); + return; + } + + /* cast arguments to the desired type */ + int n = *(int*)args; diff --git a/doc/examples/mtapi/mtapi_c_validate_result_buffer-snippet.h b/doc/examples/mtapi/mtapi_c_validate_result_buffer-snippet.h new file mode 100644 index 0000000..24e7630 --- /dev/null +++ b/doc/examples/mtapi/mtapi_c_validate_result_buffer-snippet.h @@ -0,0 +1,21 @@ + /* if the caller is not interested in results, result_buffer may be + MTAPI_NULL. Of course, this depends on the application */ + int* result = MTAPI_NULL; + if (result_buffer == MTAPI_NULL) { + mtapi_context_status_set( + task_context, MTAPI_ERR_RESULT_SIZE, &status); + MTAPI_CHECK_STATUS(status); + } else { + /* if results are expected by the caller, check result buffer + size... */ + if (result_buffer_size == sizeof(int)) { + /* ... and cast the result buffer */ + result = (int*)result_buffer; + } else { + printf("wrong size of result buffer\n"); + mtapi_context_status_set( + task_context, MTAPI_ERR_RESULT_SIZE, &status); + MTAPI_CHECK_STATUS(status); + return; + } + } diff --git a/doc/examples/mtapi/mtapi_c_wait_task-snippet.h b/doc/examples/mtapi/mtapi_c_wait_task-snippet.h new file mode 100644 index 0000000..8c3e348 --- /dev/null +++ b/doc/examples/mtapi/mtapi_c_wait_task-snippet.h @@ -0,0 +1,2 @@ + mtapi_task_wait(task, MTAPI_INFINITE, &status); + MTAPI_CHECK_STATUS(status); diff --git a/doc/examples/mtapi/mtapi_check_status-snippet.h b/doc/examples/mtapi/mtapi_check_status-snippet.h new file mode 100644 index 0000000..bf1d1d3 --- /dev/null +++ b/doc/examples/mtapi/mtapi_check_status-snippet.h @@ -0,0 +1,8 @@ +#include +#include +#include +#define MTAPI_CHECK_STATUS(status) \ +if (MTAPI_SUCCESS != status) { \ + printf("...error %d\n\n", status); \ + exit(status); \ +} diff --git a/doc/examples/mtapi/mtapi_cpp-fragmented.cc b/doc/examples/mtapi/mtapi_cpp-fragmented.cc new file mode 100644 index 0000000..d211fd9 --- /dev/null +++ b/doc/examples/mtapi/mtapi_cpp-fragmented.cc @@ -0,0 +1,67 @@ +/* + * Copyright (c) 2014-2015, Siemens AG. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +#include + +#include + +#include "mtapi/mtapi_check_status-snippet.h" +#include "mtapi/mtapi_cpp_domain_node_id-snippet.h" + +static +#include "mtapi/mtapi_c_action_signature-snippet.h" +#include "mtapi/mtapi_c_validate_arguments-snippet.h" +#include "mtapi/mtapi_c_validate_result_buffer-snippet.h" + /* get the node instance */ +#include "mtapi/mtapi_cpp_get_node-snippet.h" + /* calculate */ +#include "mtapi/mtapi_terminating_condition-snippet.h" + /* first recursive call spawned as task (x = fib(n - 1);) */ +#include "mtapi/mtapi_cpp_calc_task-snippet.h" + /* second recursive call can be called directly (y = fib(n - 2);) */ +#include "mtapi/mtapi_c_calc_direct-snippet.h" + /* wait for completion */ +#include "mtapi/mtapi_cpp_wait_task-snippet.h" + /* add the two preceding numbers */ +#include "mtapi/mtapi_write_back-snippet.h" + +static +int fibonacci(int n) { +#include "mtapi/mtapi_cpp_initialize-snippet.h" +#include "mtapi/mtapi_cpp_register_action-snippet.h" +#include "mtapi/mtapi_cpp_get_node-snippet.h" + /* start calculation */ +#include "mtapi/mtapi_cpp_start_task-snippet.h" + /* wait for task completion */ + mtapi_status_t status = task.Wait(MTAPI_INFINITE); + MTAPI_CHECK_STATUS(status); +#include "mtapi/mtapi_cpp_finalize-snippet.h" + return result; +} + +void RunMTAPI_CPP() { +#include "mtapi/mtapi_cpp_main-snippet.h" +} diff --git a/doc/examples/mtapi/mtapi_cpp_calc_task-snippet.h b/doc/examples/mtapi/mtapi_cpp_calc_task-snippet.h new file mode 100644 index 0000000..aad4e1e --- /dev/null +++ b/doc/examples/mtapi/mtapi_cpp_calc_task-snippet.h @@ -0,0 +1,3 @@ + int a = n - 1; + int x; + embb::mtapi::Task task = node.Start(fibonacciJob, &a, &x); diff --git a/doc/examples/mtapi/mtapi_cpp_domain_node_id-snippet.h b/doc/examples/mtapi/mtapi_cpp_domain_node_id-snippet.h new file mode 100644 index 0000000..747609d --- /dev/null +++ b/doc/examples/mtapi/mtapi_cpp_domain_node_id-snippet.h @@ -0,0 +1,5 @@ +#define THIS_DOMAIN_ID 1 +#define THIS_NODE_ID 1 + +#define FIBONACCI_JOB 1 +static embb::mtapi::Job fibonacciJob; diff --git a/doc/examples/mtapi/mtapi_cpp_finalize-snippet.h b/doc/examples/mtapi/mtapi_cpp_finalize-snippet.h new file mode 100644 index 0000000..5061b36 --- /dev/null +++ b/doc/examples/mtapi/mtapi_cpp_finalize-snippet.h @@ -0,0 +1,2 @@ + /* finalize the node */ + embb::mtapi::Node::Finalize(); diff --git a/doc/examples/mtapi/mtapi_cpp_get_node-snippet.h b/doc/examples/mtapi/mtapi_cpp_get_node-snippet.h new file mode 100644 index 0000000..b91d187 --- /dev/null +++ b/doc/examples/mtapi/mtapi_cpp_get_node-snippet.h @@ -0,0 +1 @@ + embb::mtapi::Node& node = embb::mtapi::Node::GetInstance(); diff --git a/doc/examples/mtapi/mtapi_cpp_initialize-snippet.h b/doc/examples/mtapi/mtapi_cpp_initialize-snippet.h new file mode 100644 index 0000000..859b55a --- /dev/null +++ b/doc/examples/mtapi/mtapi_cpp_initialize-snippet.h @@ -0,0 +1,2 @@ + /* initialize the node with default attributes */ + embb::mtapi::Node::Initialize(THIS_DOMAIN_ID, THIS_NODE_ID); diff --git a/doc/examples/mtapi/mtapi_cpp_main-snippet.h b/doc/examples/mtapi/mtapi_cpp_main-snippet.h new file mode 100644 index 0000000..582850a --- /dev/null +++ b/doc/examples/mtapi/mtapi_cpp_main-snippet.h @@ -0,0 +1,6 @@ + EMBB_TRY { + int result = fibonacci(6); + std::cout << "result: " << result << std::endl; + } EMBB_CATCH(embb::mtapi::StatusException &) { + std::cout << "MTAPI error occured." << std::endl; + } diff --git a/doc/examples/mtapi/mtapi_cpp_register_action-snippet.h b/doc/examples/mtapi/mtapi_cpp_register_action-snippet.h new file mode 100644 index 0000000..beeea5a --- /dev/null +++ b/doc/examples/mtapi/mtapi_cpp_register_action-snippet.h @@ -0,0 +1,9 @@ + /* create action */ + embb::mtapi::Action fibonacciAction( + FIBONACCI_JOB, /* action ID, defined by the + application */ + (fibonacciActionFunction) /* action function */ + ); + + /* get job */ + fibonacciJob = embb::mtapi::Job(FIBONACCI_JOB, THIS_DOMAIN_ID); diff --git a/doc/examples/mtapi/mtapi_cpp_start_task-snippet.h b/doc/examples/mtapi/mtapi_cpp_start_task-snippet.h new file mode 100644 index 0000000..cf1f908 --- /dev/null +++ b/doc/examples/mtapi/mtapi_cpp_start_task-snippet.h @@ -0,0 +1,2 @@ + int result; + embb::mtapi::Task task = node.Start(fibonacciJob, &n, &result); diff --git a/doc/examples/mtapi/mtapi_cpp_wait_task-snippet.h b/doc/examples/mtapi/mtapi_cpp_wait_task-snippet.h new file mode 100644 index 0000000..9f1f9d7 --- /dev/null +++ b/doc/examples/mtapi/mtapi_cpp_wait_task-snippet.h @@ -0,0 +1,5 @@ + mtapi_status_t status = task.Wait(MTAPI_INFINITE); + if (status != MTAPI_SUCCESS) { + printf("task failed with error: %d\n\n", status); + exit(status); + } diff --git a/doc/examples/mtapi/mtapi_network_c_action_function-snippet.h b/doc/examples/mtapi/mtapi_network_c_action_function-snippet.h new file mode 100644 index 0000000..9f56102 --- /dev/null +++ b/doc/examples/mtapi/mtapi_network_c_action_function-snippet.h @@ -0,0 +1,20 @@ +static void AddVectorAction( + void const * arguments, + mtapi_size_t arguments_size, + void * result_buffer, + mtapi_size_t result_buffer_size, + void const * node_local_data, + mtapi_size_t node_local_data_size, + mtapi_task_context_t * context) { + EMBB_UNUSED(context); + EMBB_UNUSED(result_buffer_size); + EMBB_UNUSED(node_local_data_size); + int elements = static_cast(arguments_size / sizeof(float) / 2); + float const * a = reinterpret_cast(arguments); + float const * b = reinterpret_cast(arguments)+elements; + float * c = reinterpret_cast(result_buffer); + float const * d = reinterpret_cast(node_local_data); + for (int ii = 0; ii < elements; ii++) { + c[ii] = a[ii] + b[ii] + d[0]; + } +} diff --git a/doc/examples/mtapi/mtapi_network_c_header-snippet.h b/doc/examples/mtapi/mtapi_network_c_header-snippet.h new file mode 100644 index 0000000..c052390 --- /dev/null +++ b/doc/examples/mtapi/mtapi_network_c_header-snippet.h @@ -0,0 +1 @@ +#include diff --git a/doc/examples/mtapi/mtapi_network_c_local_action_create-snippet.h b/doc/examples/mtapi/mtapi_network_c_local_action_create-snippet.h new file mode 100644 index 0000000..c057151 --- /dev/null +++ b/doc/examples/mtapi/mtapi_network_c_local_action_create-snippet.h @@ -0,0 +1,6 @@ + network_action = mtapi_network_action_create( + NETWORK_DOMAIN, + NETWORK_LOCAL_JOB, + NETWORK_REMOTE_JOB, + "127.0.0.1", 12345, + &status); diff --git a/doc/examples/mtapi/mtapi_network_c_plugin_finalize-snippet.h b/doc/examples/mtapi/mtapi_network_c_plugin_finalize-snippet.h new file mode 100644 index 0000000..74d49f3 --- /dev/null +++ b/doc/examples/mtapi/mtapi_network_c_plugin_finalize-snippet.h @@ -0,0 +1 @@ + mtapi_network_plugin_finalize(&status); diff --git a/doc/examples/mtapi/mtapi_network_c_plugin_initialize-snippet.h b/doc/examples/mtapi/mtapi_network_c_plugin_initialize-snippet.h new file mode 100644 index 0000000..b7cc83b --- /dev/null +++ b/doc/examples/mtapi/mtapi_network_c_plugin_initialize-snippet.h @@ -0,0 +1,2 @@ + mtapi_network_plugin_initialize("127.0.0.1", 12345, 5, + kElements * 4 * 3 + 32, &status); diff --git a/doc/examples/mtapi/mtapi_network_c_remote_action_create-snippet.h b/doc/examples/mtapi/mtapi_network_c_remote_action_create-snippet.h new file mode 100644 index 0000000..31fa6ac --- /dev/null +++ b/doc/examples/mtapi/mtapi_network_c_remote_action_create-snippet.h @@ -0,0 +1,7 @@ + float node_remote = 1.0f; + local_action = mtapi_action_create( + NETWORK_REMOTE_JOB, + AddVectorAction, + &node_remote, sizeof(float), + MTAPI_DEFAULT_ACTION_ATTRIBUTES, + &status); diff --git a/doc/examples/mtapi/mtapi_opencl_c_action_create-snippet.h b/doc/examples/mtapi/mtapi_opencl_c_action_create-snippet.h new file mode 100644 index 0000000..c3927a4 --- /dev/null +++ b/doc/examples/mtapi/mtapi_opencl_c_action_create-snippet.h @@ -0,0 +1,6 @@ + float node_local = 1.0f; + action = mtapi_opencl_action_create( + OPENCL_JOB, + kernel, "AddVector", 32, 4, + &node_local, sizeof(float), + &status); diff --git a/doc/examples/mtapi/mtapi_opencl_c_header-snippet.h b/doc/examples/mtapi/mtapi_opencl_c_header-snippet.h new file mode 100644 index 0000000..1d3a916 --- /dev/null +++ b/doc/examples/mtapi/mtapi_opencl_c_header-snippet.h @@ -0,0 +1 @@ +#include diff --git a/doc/examples/mtapi/mtapi_opencl_c_kernel-snippet.h b/doc/examples/mtapi/mtapi_opencl_c_kernel-snippet.h new file mode 100644 index 0000000..cfd3e99 --- /dev/null +++ b/doc/examples/mtapi/mtapi_opencl_c_kernel-snippet.h @@ -0,0 +1,18 @@ +const char * kernel = +"__kernel void AddVector(\n" +" __global void* arguments,\n" +" int arguments_size,\n" +" __global void* result_buffer,\n" +" int result_buffer_size,\n" +" __global void* node_local_data,\n" +" int node_local_data_size) {\n" +" int ii = get_global_id(0);\n" +" int elements = arguments_size / sizeof(float) / 2;\n" +" if (ii >= elements)" +" return;" +" __global float* a = (__global float*)arguments;\n" +" __global float* b = ((__global float*)arguments) + elements;\n" +" __global float* c = (__global float*)result_buffer;\n" +" __global float* d = (__global float*)node_local_data;\n" +" c[ii] = a[ii] + b[ii] + d[0];\n" +"}\n"; diff --git a/doc/examples/mtapi/mtapi_opencl_c_plugin_finalize-snippet.h b/doc/examples/mtapi/mtapi_opencl_c_plugin_finalize-snippet.h new file mode 100644 index 0000000..8689937 --- /dev/null +++ b/doc/examples/mtapi/mtapi_opencl_c_plugin_finalize-snippet.h @@ -0,0 +1 @@ + mtapi_opencl_plugin_finalize(&status); diff --git a/doc/examples/mtapi/mtapi_opencl_c_plugin_initialize-snippet.h b/doc/examples/mtapi/mtapi_opencl_c_plugin_initialize-snippet.h new file mode 100644 index 0000000..c8106fc --- /dev/null +++ b/doc/examples/mtapi/mtapi_opencl_c_plugin_initialize-snippet.h @@ -0,0 +1 @@ + mtapi_opencl_plugin_initialize(&status); diff --git a/doc/examples/mtapi/mtapi_terminating_condition-snippet.h b/doc/examples/mtapi/mtapi_terminating_condition-snippet.h new file mode 100644 index 0000000..7112b48 --- /dev/null +++ b/doc/examples/mtapi/mtapi_terminating_condition-snippet.h @@ -0,0 +1,3 @@ + if (n < 2) { + *result = n; + } else { diff --git a/doc/examples/mtapi/mtapi_write_back-snippet.h b/doc/examples/mtapi/mtapi_write_back-snippet.h new file mode 100644 index 0000000..bca08c7 --- /dev/null +++ b/doc/examples/mtapi/mtapi_write_back-snippet.h @@ -0,0 +1,3 @@ + *result = x + y; + } +} diff --git a/doc/examples/stl_for_each/function-snippet.h b/doc/examples/stl_for_each/function-snippet.h new file mode 100644 index 0000000..d870d31 --- /dev/null +++ b/doc/examples/stl_for_each/function-snippet.h @@ -0,0 +1 @@ +std::for_each(range.begin(), range.end(), &DoubleFunction); diff --git a/doc/examples/stl_for_each/function_define-snippet.h b/doc/examples/stl_for_each/function_define-snippet.h new file mode 100644 index 0000000..0bb8d2b --- /dev/null +++ b/doc/examples/stl_for_each/function_define-snippet.h @@ -0,0 +1,3 @@ +void DoubleFunction(int& to_double) { + to_double *= 2; +} diff --git a/doc/examples/stl_for_each/functor-snippet.h b/doc/examples/stl_for_each/functor-snippet.h new file mode 100644 index 0000000..e282b10 --- /dev/null +++ b/doc/examples/stl_for_each/functor-snippet.h @@ -0,0 +1 @@ +std::for_each(range.begin(), range.end(), DoubleFunctor()); diff --git a/doc/examples/stl_for_each/functor_define-snippet.h b/doc/examples/stl_for_each/functor_define-snippet.h new file mode 100644 index 0000000..d5e34d1 --- /dev/null +++ b/doc/examples/stl_for_each/functor_define-snippet.h @@ -0,0 +1,5 @@ +struct DoubleFunctor { + void operator()(int& to_double) { + to_double *= 2; + } +}; diff --git a/doc/examples/stl_for_each/lambda-snippet.h b/doc/examples/stl_for_each/lambda-snippet.h new file mode 100644 index 0000000..e8c545a --- /dev/null +++ b/doc/examples/stl_for_each/lambda-snippet.h @@ -0,0 +1,2 @@ +std::for_each(range.begin(), range.end(), + [] (int& to_double) { to_double *= 2; }); diff --git a/doc/examples/stl_for_each/manual-snippet.h b/doc/examples/stl_for_each/manual-snippet.h new file mode 100644 index 0000000..22b72cc --- /dev/null +++ b/doc/examples/stl_for_each/manual-snippet.h @@ -0,0 +1,3 @@ +for (size_t i=0; i < range.size(); i++) { + range[i] *= 2; +} diff --git a/doc/examples/stl_for_each/setup-snippet.h b/doc/examples/stl_for_each/setup-snippet.h new file mode 100644 index 0000000..0e78cc8 --- /dev/null +++ b/doc/examples/stl_for_each/setup-snippet.h @@ -0,0 +1,4 @@ +std::vector range(5); +for (size_t i=0; i < range.size(); i++) { + range[i] = static_cast(i) + 1; +} diff --git a/doc/examples/stl_for_each/stl_for_each-fragmented.cc b/doc/examples/stl_for_each/stl_for_each-fragmented.cc new file mode 100644 index 0000000..ecff00b --- /dev/null +++ b/doc/examples/stl_for_each/stl_for_each-fragmented.cc @@ -0,0 +1,75 @@ +/* + * Copyright (c) 2014-2015, Siemens AG. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +#include +#include +#include +#include + +#include "stl_for_each/function_define-snippet.h" + +#include "stl_for_each/functor_define-snippet.h" + +static void CheckResults(const std::vector& range) { + int i = 1; + for (const int& value : range) { + assert(value == i * 2); + EMBB_UNUSED_IN_RELEASE(value); + i++; + } +} + +/** + * Example using embb::patterns::ForEach. + * + * Traversing and modifying a sequence with a for-each loop. + */ + +void RunSTLForEach() { + { + #include "stl_for_each/setup-snippet.h" + #include "stl_for_each/manual-snippet.h" + CheckResults(range); + } + + { + #include "stl_for_each/setup-snippet.h" + #include "stl_for_each/function-snippet.h" + CheckResults(range); + } + + { + #include "stl_for_each/setup-snippet.h" + #include "stl_for_each/functor-snippet.h" + CheckResults(range); + } + + { + #include "stl_for_each/setup-snippet.h" + #include "stl_for_each/lambda-snippet.h" + CheckResults(range); + } +} diff --git a/doc/examples/tasks/tasks_cpp-fragmented.cc b/doc/examples/tasks/tasks_cpp-fragmented.cc new file mode 100644 index 0000000..4e13885 --- /dev/null +++ b/doc/examples/tasks/tasks_cpp-fragmented.cc @@ -0,0 +1,64 @@ +/* + * Copyright (c) 2014-2015, Siemens AG. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +#include + +#include + +#include "mtapi/mtapi_check_status-snippet.h" + +static +#include "tasks/tasks_cpp_action_signature-snippet.h" + /* get the node instance */ +#include "tasks/tasks_cpp_get_node-snippet.h" + /* calculate */ +#include "mtapi/mtapi_terminating_condition-snippet.h" + /* first recursive call spawned as task (x = fib(n - 1);) */ +#include "tasks/tasks_cpp_calc_task-snippet.h" + /* second recursive call can be called directly (y = fib(n - 2);) */ +#include "tasks/tasks_cpp_calc_direct-snippet.h" + /* wait for completion */ +#include "tasks/tasks_cpp_wait_task-snippet.h" + /* add the two preceeding numbers */ +#include "mtapi/mtapi_write_back-snippet.h" + +static +int fibonacci(int n) { + /* get the node instance, the node is initialized automatically */ + embb::tasks::Node& node = embb::tasks::Node::GetInstance(); + /* start calculation */ +#include "tasks/tasks_cpp_start_task-snippet.h" + /* wait for task completion */ + mtapi_status_t status = task.Wait(MTAPI_INFINITE); + MTAPI_CHECK_STATUS(status); + + return result; +} + +void RunTasks() { + int result = fibonacci(6); + std::cout << "result: " << result << std::endl; +} diff --git a/doc/examples/tasks/tasks_cpp_action_signature-snippet.h b/doc/examples/tasks/tasks_cpp_action_signature-snippet.h new file mode 100644 index 0000000..24aa989 --- /dev/null +++ b/doc/examples/tasks/tasks_cpp_action_signature-snippet.h @@ -0,0 +1,5 @@ +void fibonacciActionFunction( + int n, + int* result, + embb::tasks::TaskContext & task_context + ) { diff --git a/doc/examples/tasks/tasks_cpp_calc_direct-snippet.h b/doc/examples/tasks/tasks_cpp_calc_direct-snippet.h new file mode 100644 index 0000000..eb08e75 --- /dev/null +++ b/doc/examples/tasks/tasks_cpp_calc_direct-snippet.h @@ -0,0 +1,6 @@ + int b = n - 2; + int y; + fibonacciActionFunction( + b, + &y, + task_context); diff --git a/doc/examples/tasks/tasks_cpp_calc_task-snippet.h b/doc/examples/tasks/tasks_cpp_calc_task-snippet.h new file mode 100644 index 0000000..cfe5664 --- /dev/null +++ b/doc/examples/tasks/tasks_cpp_calc_task-snippet.h @@ -0,0 +1,10 @@ + int a = n - 1; + int x; + embb::tasks::Task task = node.Spawn( + embb::base::Bind( + embb::base::MakeFunction(fibonacciActionFunction), + a, /* argument */ + &x, /* result */ + embb::base::Placeholder::_1 + ) + ); diff --git a/doc/examples/tasks/tasks_cpp_get_node-snippet.h b/doc/examples/tasks/tasks_cpp_get_node-snippet.h new file mode 100644 index 0000000..f644ec5 --- /dev/null +++ b/doc/examples/tasks/tasks_cpp_get_node-snippet.h @@ -0,0 +1 @@ + embb::tasks::Node& node = embb::tasks::Node::GetInstance(); diff --git a/doc/examples/tasks/tasks_cpp_start_task-snippet.h b/doc/examples/tasks/tasks_cpp_start_task-snippet.h new file mode 100644 index 0000000..507e634 --- /dev/null +++ b/doc/examples/tasks/tasks_cpp_start_task-snippet.h @@ -0,0 +1,9 @@ + int result; + embb::tasks::Task task = node.Spawn( + embb::base::Bind( + embb::base::MakeFunction(fibonacciActionFunction), + n, + &result, + embb::base::Placeholder::_1 + ) + ); diff --git a/doc/examples/tasks/tasks_cpp_wait_task-snippet.h b/doc/examples/tasks/tasks_cpp_wait_task-snippet.h new file mode 100644 index 0000000..21637fd --- /dev/null +++ b/doc/examples/tasks/tasks_cpp_wait_task-snippet.h @@ -0,0 +1,2 @@ + mtapi_status_t status = task.Wait(MTAPI_INFINITE); + MTAPI_CHECK_STATUS(status); diff --git a/doc/examples_raw/CMakeLists.txt b/doc/examples_raw/CMakeLists.txt deleted file mode 100644 index d68a8a3..0000000 --- a/doc/examples_raw/CMakeLists.txt +++ /dev/null @@ -1,53 +0,0 @@ -project (project_embb_tutorials) - -file(GLOB_RECURSE EXAMPLES_SOURCES "*.cc" "*.h") - - -include_directories( - ${CMAKE_CURRENT_SOURCE_DIR}/ - ${CMAKE_CURRENT_BINARY_DIR}/ - ${CMAKE_CURRENT_SOURCE_DIR}/../../base_c/include - ${CMAKE_CURRENT_BINARY_DIR}/../../base_c/include - ${CMAKE_CURRENT_SOURCE_DIR}/../../base_cpp/include - ${CMAKE_CURRENT_BINARY_DIR}/../../base_cpp/include - ${CMAKE_CURRENT_SOURCE_DIR}/../../mtapi_c/include - ${CMAKE_CURRENT_SOURCE_DIR}/../../mtapi_c/src - ${CMAKE_CURRENT_SOURCE_DIR}/../../mtapi_network_c/include - ${CMAKE_CURRENT_SOURCE_DIR}/../../mtapi_cpp/include - ${CMAKE_CURRENT_SOURCE_DIR}/../../tasks_cpp/include - ${CMAKE_CURRENT_BINARY_DIR}/../../tasks_cpp/include - ${CMAKE_CURRENT_SOURCE_DIR}/../../containers_cpp/include - ${CMAKE_CURRENT_SOURCE_DIR}/../../algorithms_cpp/include - ${CMAKE_CURRENT_SOURCE_DIR}/../../dataflow_cpp/include - ) - -if(OpenCL_FOUND) - # used in source code, to include opencl code - add_definitions(-DEMBB_WITH_OPENCL) - # add opencl includes - include_directories( - ${CMAKE_CURRENT_SOURCE_DIR}/../../mtapi_opencl_c/include - ) - # later used, to link opencl to target... - set (EMBB_MTAPI_OPENCL_C_CONDITIONAL "embb_mtapi_opencl_c") -else() - # remove opencl examples from sources (should not be build) - file(GLOB_RECURSE EXAMPLES_SOURCES_OPENCL_TO_REMOVE "*opencl*" ) - list(REMOVE_ITEM EXAMPLES_SOURCES ${EXAMPLES_SOURCES_OPENCL_TO_REMOVE}) -endif() - -if(CMAKE_COMPILER_IS_GNUCXX) - set(CMAKE_CXX_FLAGS "-std=c++11") - set (EXTRA_LIBS dl) -endif() - -IF(MSVC) - set (EXTRA_LIBS ws2_32) -ENDIF() - -add_executable(examples ${EXAMPLES_SOURCES}) -target_link_libraries(examples embb_dataflow_cpp embb_algorithms_cpp embb_tasks_cpp embb_mtapi_cpp - embb_mtapi_network_c ${EMBB_MTAPI_OPENCL_C_CONDITIONAL} embb_mtapi_c - embb_base_cpp embb_base_c embb_containers_cpp - ${EXTRA_LIBS} ${compiler_libs}) -CopyBin(BIN examples DEST ${local_install_dir}) diff --git a/doc/examples_raw/algorithms/counting/count-snippet.h b/doc/examples_raw/algorithms/counting/count-snippet.h deleted file mode 100644 index 9b3191d..0000000 --- a/doc/examples_raw/algorithms/counting/count-snippet.h +++ /dev/null @@ -1,3 +0,0 @@ -std::iterator_traits::difference_type count; -using embb::algorithms::Count; -count = Count(range, range + 8, 1); diff --git a/doc/examples_raw/algorithms/counting/count_if-snippet.h b/doc/examples_raw/algorithms/counting/count_if-snippet.h deleted file mode 100644 index 68806e8..0000000 --- a/doc/examples_raw/algorithms/counting/count_if-snippet.h +++ /dev/null @@ -1,3 +0,0 @@ -using embb::algorithms::CountIf; -count = CountIf(range, range + 8, - [](const int& value) -> bool { return value > 0; }); diff --git a/doc/examples_raw/algorithms/counting/counting-fragmented.cc b/doc/examples_raw/algorithms/counting/counting-fragmented.cc deleted file mode 100644 index a621d8b..0000000 --- a/doc/examples_raw/algorithms/counting/counting-fragmented.cc +++ /dev/null @@ -1,42 +0,0 @@ -/* - * Copyright (c) 2014-2015, Siemens AG. All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are met: - * - * 1. Redistributions of source code must retain the above copyright notice, - * this list of conditions and the following disclaimer. - * - * 2. Redistributions in binary form must reproduce the above copyright notice, - * this list of conditions and the following disclaimer in the documentation - * and/or other materials provided with the distribution. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" - * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE - * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR - * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF - * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS - * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN - * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) - * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE - * POSSIBILITY OF SUCH DAMAGE. - */ - -#include - -/** - * Example using embb::algorithms::Count and CountIf. - * - * Counting elements of a range that fulfill certain properties. - */ -void RunCounting() { - #include "algorithms/counting/setup-snippet.h" - - #include "algorithms/counting/count-snippet.h" - assert(count == 2); - - #include "algorithms/counting/count_if-snippet.h" - assert(count == 6); -} diff --git a/doc/examples_raw/algorithms/counting/setup-snippet.h b/doc/examples_raw/algorithms/counting/setup-snippet.h deleted file mode 100644 index f488cbd..0000000 --- a/doc/examples_raw/algorithms/counting/setup-snippet.h +++ /dev/null @@ -1 +0,0 @@ -int range[] = {0, 3, 2, 0, 1, 1, 3, 2}; diff --git a/doc/examples_raw/algorithms/for_each/doubling-snippet.h b/doc/examples_raw/algorithms/for_each/doubling-snippet.h deleted file mode 100644 index 9d16397..0000000 --- a/doc/examples_raw/algorithms/for_each/doubling-snippet.h +++ /dev/null @@ -1,3 +0,0 @@ -using embb::algorithms::ForEach; -ForEach(range.begin(), range.end(), - [] (int& to_double) { to_double *= 2; }); diff --git a/doc/examples_raw/algorithms/for_each/doubling_zip-snippet.h b/doc/examples_raw/algorithms/for_each/doubling_zip-snippet.h deleted file mode 100644 index 0e5ccc4..0000000 --- a/doc/examples_raw/algorithms/for_each/doubling_zip-snippet.h +++ /dev/null @@ -1,7 +0,0 @@ -using embb::algorithms::Zip; -using embb::algorithms::ZipPair; -ForEach(Zip(input_range.begin(), output_range.begin()), - Zip(input_range.end(), output_range.end()), - [] (ZipPair pair) { - pair.Second() = pair.First() * 2; - }); diff --git a/doc/examples_raw/algorithms/for_each/for_each-fragmented.cc b/doc/examples_raw/algorithms/for_each/for_each-fragmented.cc deleted file mode 100644 index ab80a0c..0000000 --- a/doc/examples_raw/algorithms/for_each/for_each-fragmented.cc +++ /dev/null @@ -1,53 +0,0 @@ -/* - * Copyright (c) 2014-2015, Siemens AG. All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are met: - * - * 1. Redistributions of source code must retain the above copyright notice, - * this list of conditions and the following disclaimer. - * - * 2. Redistributions in binary form must reproduce the above copyright notice, - * this list of conditions and the following disclaimer in the documentation - * and/or other materials provided with the distribution. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" - * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE - * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR - * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF - * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS - * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN - * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) - * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE - * POSSIBILITY OF SUCH DAMAGE. - */ - -#include -#include -#include - -static void CheckResults(const std::vector& range) { - int i = 1; - for (const int& value : range) { - assert(value == i * 2); - EMBB_UNUSED_IN_RELEASE(value); - i++; - } -} - -/** - * Example using embb::algorithms::ForEach. - * - * Traversing and modifying a sequence with a for-each loop. - */ -void RunForEach() { - #include "stl_for_each/setup-snippet.h" - #include "algorithms/for_each/doubling-snippet.h" - CheckResults(range); - - #include "algorithms/for_each/setup_zip-snippet.h" - #include "algorithms/for_each/doubling_zip-snippet.h" - CheckResults(output_range); -} diff --git a/doc/examples_raw/algorithms/for_each/setup_zip-snippet.h b/doc/examples_raw/algorithms/for_each/setup_zip-snippet.h deleted file mode 100644 index 311fb4b..0000000 --- a/doc/examples_raw/algorithms/for_each/setup_zip-snippet.h +++ /dev/null @@ -1,5 +0,0 @@ -std::vector input_range(5); -for (size_t i=0; i < input_range.size(); i++) { - input_range[i] = static_cast(i) + 1; -} -std::vector output_range(5); diff --git a/doc/examples_raw/algorithms/invoke/invocation-snippet.h b/doc/examples_raw/algorithms/invoke/invocation-snippet.h deleted file mode 100644 index 2b27930..0000000 --- a/doc/examples_raw/algorithms/invoke/invocation-snippet.h +++ /dev/null @@ -1,2 +0,0 @@ -using embb::algorithms::Invoke; -Invoke(WorkPackageA, WorkPackageB, WorkPackageC); diff --git a/doc/examples_raw/algorithms/invoke/invoke-fragmented.cc b/doc/examples_raw/algorithms/invoke/invoke-fragmented.cc deleted file mode 100644 index 94cddd2..0000000 --- a/doc/examples_raw/algorithms/invoke/invoke-fragmented.cc +++ /dev/null @@ -1,99 +0,0 @@ -/* - * Copyright (c) 2014-2015, Siemens AG. All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are met: - * - * 1. Redistributions of source code must retain the above copyright notice, - * this list of conditions and the following disclaimer. - * - * 2. Redistributions in binary form must reproduce the above copyright notice, - * this list of conditions and the following disclaimer in the documentation - * and/or other materials provided with the distribution. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" - * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE - * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR - * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF - * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS - * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN - * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) - * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE - * POSSIBILITY OF SUCH DAMAGE. - */ - -#include -#include - -#include "algorithms/invoke/packages-snippet.h" - -static int a = 0, b = 0, c = 0; - -void WorkPackageA() { - a++; -} - -void WorkPackageB() { - b++; -} - -void WorkPackageC() { - c++; -} - -int* Partition(int* first, int* last) { - int* pivot = last - 1; - while (first != last) { - while (*first < *pivot) { - ++first; - if (first == last) return first; - } - do { - --last; - if (first == last) return first; - } while (*pivot < *last); - std::swap(*first, *last); - if(pivot == first) { - pivot = last; - } else if (pivot == last) { - pivot = first; - } - ++first; - } - return first; -} - -#include "algorithms/invoke/quick_sort-snippet.h" - -#include "algorithms/invoke/parallel_quick_sort-snippet.h" - -/** - * Example using embb::algorithms::ParallelInvoke() to execute work packages in - * parallel. - */ -void RunInvoke() { - #include "algorithms/invoke/invocation-snippet.h" - assert(a == 1); - assert(b == 1); - assert(c == 1); - - { - int range[] = {2, 5, 3, 1, 4}; - QuickSort(range, range + 5); - for (size_t i = 0; i < 5; i++) { - assert(range[i] == static_cast(i) + 1); - } - } - { - int range[] = {2, 5, 3, 1, 4}; - ParallelQuickSort(range, range + 5); - for (size_t i = 0; i < 5; i++) { - assert(range[i] == static_cast(i) + 1); - } - } -} - - - diff --git a/doc/examples_raw/algorithms/invoke/packages-snippet.h b/doc/examples_raw/algorithms/invoke/packages-snippet.h deleted file mode 100644 index 743db1d..0000000 --- a/doc/examples_raw/algorithms/invoke/packages-snippet.h +++ /dev/null @@ -1,3 +0,0 @@ -void WorkPackageA(); -void WorkPackageB(); -void WorkPackageC(); diff --git a/doc/examples_raw/algorithms/invoke/parallel_quick_sort-snippet.h b/doc/examples_raw/algorithms/invoke/parallel_quick_sort-snippet.h deleted file mode 100644 index f518853..0000000 --- a/doc/examples_raw/algorithms/invoke/parallel_quick_sort-snippet.h +++ /dev/null @@ -1,7 +0,0 @@ -void ParallelQuickSort(int* first, int* last) { - if (last - first <= 1) return; - int* mid = Partition(first, last); - using embb::algorithms::Invoke; - Invoke([=](){ParallelQuickSort(first, mid);}, - [=](){ParallelQuickSort(mid, last);}); -} diff --git a/doc/examples_raw/algorithms/invoke/quick_sort-snippet.h b/doc/examples_raw/algorithms/invoke/quick_sort-snippet.h deleted file mode 100644 index 9d33c89..0000000 --- a/doc/examples_raw/algorithms/invoke/quick_sort-snippet.h +++ /dev/null @@ -1,6 +0,0 @@ -void QuickSort(int* first, int* last) { - if (last - first <= 1) return; - int* mid = Partition(first, last); - QuickSort(first, mid); - QuickSort(mid, last); -} diff --git a/doc/examples_raw/algorithms/reduce/dot_product-snippet.h b/doc/examples_raw/algorithms/reduce/dot_product-snippet.h deleted file mode 100644 index 8d6bbf2..0000000 --- a/doc/examples_raw/algorithms/reduce/dot_product-snippet.h +++ /dev/null @@ -1,9 +0,0 @@ -using embb::algorithms::Zip; -using embb::algorithms::ZipPair; -int dot_product = Reduce(Zip(range.begin(), second_range.begin()), - Zip(range.end(), second_range.end()), - 0, - std::plus(), - [](const ZipPair& pair) { - return pair.First() * pair.Second(); - }); diff --git a/doc/examples_raw/algorithms/reduce/parallel-snippet.h b/doc/examples_raw/algorithms/reduce/parallel-snippet.h deleted file mode 100644 index b28ad55..0000000 --- a/doc/examples_raw/algorithms/reduce/parallel-snippet.h +++ /dev/null @@ -1,2 +0,0 @@ -using embb::algorithms::Reduce; -sum = Reduce(range.begin(), range.end(), 0, std::plus()); diff --git a/doc/examples_raw/algorithms/reduce/range_init-snippet.h b/doc/examples_raw/algorithms/reduce/range_init-snippet.h deleted file mode 100644 index e3a3ee3..0000000 --- a/doc/examples_raw/algorithms/reduce/range_init-snippet.h +++ /dev/null @@ -1,4 +0,0 @@ -std::vector range(5); -for (size_t i = 0; i < range.size(); i++) { - range[i] = static_cast(i) + 1; -} diff --git a/doc/examples_raw/algorithms/reduce/reduce-fragmented.cc b/doc/examples_raw/algorithms/reduce/reduce-fragmented.cc deleted file mode 100644 index 4c9f1df..0000000 --- a/doc/examples_raw/algorithms/reduce/reduce-fragmented.cc +++ /dev/null @@ -1,50 +0,0 @@ -/* - * Copyright (c) 2014-2015, Siemens AG. All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are met: - * - * 1. Redistributions of source code must retain the above copyright notice, - * this list of conditions and the following disclaimer. - * - * 2. Redistributions in binary form must reproduce the above copyright notice, - * this list of conditions and the following disclaimer in the documentation - * and/or other materials provided with the distribution. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" - * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE - * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR - * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF - * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS - * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN - * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) - * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE - * POSSIBILITY OF SUCH DAMAGE. - */ - -#include -#include -#include -#include - -/** - * Example using embb::algorithms::Reduce. - * - * Summing up a range of values and more. - */ -void RunReduce() { - #include "algorithms/reduce/range_init-snippet.h" - - #include "algorithms/reduce/sequential-snippet.h" - assert(sum == 1 + 2 + 3 + 4 + 5); - - #include "algorithms/reduce/parallel-snippet.h" - assert(sum == 1 + 2 + 3 + 4 + 5); - - #include "algorithms/reduce/second_range_init-snippet.h" - #include "algorithms/reduce/dot_product-snippet.h" - assert(dot_product == 1*5 + 2*6 + 3*7 + 4*8 + 5*9); - EMBB_UNUSED_IN_RELEASE(dot_product); -} diff --git a/doc/examples_raw/algorithms/reduce/second_range_init-snippet.h b/doc/examples_raw/algorithms/reduce/second_range_init-snippet.h deleted file mode 100644 index 0c1f44e..0000000 --- a/doc/examples_raw/algorithms/reduce/second_range_init-snippet.h +++ /dev/null @@ -1,4 +0,0 @@ -std::vector second_range(5); -for (size_t i = 0; i < range.size(); i++) { - second_range[i] = static_cast(i) + 5; -} diff --git a/doc/examples_raw/algorithms/reduce/sequential-snippet.h b/doc/examples_raw/algorithms/reduce/sequential-snippet.h deleted file mode 100644 index c5cca02..0000000 --- a/doc/examples_raw/algorithms/reduce/sequential-snippet.h +++ /dev/null @@ -1,4 +0,0 @@ -int sum = 0; -for (size_t i = 0; i < range.size(); i++) { - sum += range[i]; -} diff --git a/doc/examples_raw/algorithms/scan/prefix_sum-snippet.h b/doc/examples_raw/algorithms/scan/prefix_sum-snippet.h deleted file mode 100644 index 38fae7d..0000000 --- a/doc/examples_raw/algorithms/scan/prefix_sum-snippet.h +++ /dev/null @@ -1,3 +0,0 @@ -using embb::algorithms::Scan; -Scan(input_range.begin(), input_range.end(), output_range.begin(), - 0, std::plus()); diff --git a/doc/examples_raw/algorithms/scan/scan-fragmented.cc b/doc/examples_raw/algorithms/scan/scan-fragmented.cc deleted file mode 100644 index 3a9c1d3..0000000 --- a/doc/examples_raw/algorithms/scan/scan-fragmented.cc +++ /dev/null @@ -1,55 +0,0 @@ -/* - * Copyright (c) 2014-2015, Siemens AG. All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are met: - * - * 1. Redistributions of source code must retain the above copyright notice, - * this list of conditions and the following disclaimer. - * - * 2. Redistributions in binary form must reproduce the above copyright notice, - * this list of conditions and the following disclaimer in the documentation - * and/or other materials provided with the distribution. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" - * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE - * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR - * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF - * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS - * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN - * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) - * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE - * POSSIBILITY OF SUCH DAMAGE. - */ - -#include -#include -#include - -void CheckResults(const std::vector& results) { - assert(results.size() == 5); - assert(results[0] == 1); - assert(results[1] == 3); - assert(results[2] == 6); - assert(results[3] == 10); - assert(results[4] == 15); - EMBB_UNUSED_IN_RELEASE(results); -} - -/** - * Example using embb::algorithms::Scan. - * - * - */ -void RunScan() { - #include "algorithms/scan/setup-snippet.h" - - #include "algorithms/scan/sequential_prefix_sum-snippet.h" - CheckResults(output_range); - - for (size_t i = 0; i < output_range.size(); i++) output_range[i] = 0; - #include "algorithms/scan/prefix_sum-snippet.h" - CheckResults(output_range); -} diff --git a/doc/examples_raw/algorithms/scan/sequential_prefix_sum-snippet.h b/doc/examples_raw/algorithms/scan/sequential_prefix_sum-snippet.h deleted file mode 100644 index 4f42a55..0000000 --- a/doc/examples_raw/algorithms/scan/sequential_prefix_sum-snippet.h +++ /dev/null @@ -1,5 +0,0 @@ -std::vector output_range(input_range.size()); -output_range[0] = input_range[0]; -for(size_t i = 1; i < input_range.size(); i++) { - output_range[i] = output_range[i-1] + input_range[i]; -} diff --git a/doc/examples_raw/algorithms/scan/setup-snippet.h b/doc/examples_raw/algorithms/scan/setup-snippet.h deleted file mode 100644 index 56c9517..0000000 --- a/doc/examples_raw/algorithms/scan/setup-snippet.h +++ /dev/null @@ -1,5 +0,0 @@ -std::vector input_range(5); -for (size_t i = 0; i < input_range.size(); i++) { - input_range[i] = static_cast(i) + 1; -} - diff --git a/doc/examples_raw/algorithms/sorting/merge_sort_preallocated-snippet.h b/doc/examples_raw/algorithms/sorting/merge_sort_preallocated-snippet.h deleted file mode 100644 index 7f12c05..0000000 --- a/doc/examples_raw/algorithms/sorting/merge_sort_preallocated-snippet.h +++ /dev/null @@ -1,3 +0,0 @@ -using embb::algorithms::MergeSort; -std::vector temporary_range(range.size()); -MergeSort(range.begin(), range.end(), temporary_range.begin()); diff --git a/doc/examples_raw/algorithms/sorting/quick_sort-snippet.h b/doc/examples_raw/algorithms/sorting/quick_sort-snippet.h deleted file mode 100644 index a8eeb9b..0000000 --- a/doc/examples_raw/algorithms/sorting/quick_sort-snippet.h +++ /dev/null @@ -1,2 +0,0 @@ -using embb::algorithms::QuickSort; -QuickSort(range.begin(), range.end()); diff --git a/doc/examples_raw/algorithms/sorting/quick_sort_custom_compare-snippet.h b/doc/examples_raw/algorithms/sorting/quick_sort_custom_compare-snippet.h deleted file mode 100644 index d33307d..0000000 --- a/doc/examples_raw/algorithms/sorting/quick_sort_custom_compare-snippet.h +++ /dev/null @@ -1 +0,0 @@ -QuickSort(range.begin(), range.end(), std::greater()); diff --git a/doc/examples_raw/algorithms/sorting/range_define-snippet.h b/doc/examples_raw/algorithms/sorting/range_define-snippet.h deleted file mode 100644 index f9eb29e..0000000 --- a/doc/examples_raw/algorithms/sorting/range_define-snippet.h +++ /dev/null @@ -1 +0,0 @@ -std::vector range; diff --git a/doc/examples_raw/algorithms/sorting/sorting-fragmented.cc b/doc/examples_raw/algorithms/sorting/sorting-fragmented.cc deleted file mode 100644 index 36cb1ed..0000000 --- a/doc/examples_raw/algorithms/sorting/sorting-fragmented.cc +++ /dev/null @@ -1,60 +0,0 @@ -/* - * Copyright (c) 2014-2015, Siemens AG. All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are met: - * - * 1. Redistributions of source code must retain the above copyright notice, - * this list of conditions and the following disclaimer. - * - * 2. Redistributions in binary form must reproduce the above copyright notice, - * this list of conditions and the following disclaimer in the documentation - * and/or other materials provided with the distribution. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" - * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE - * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR - * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF - * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS - * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN - * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) - * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE - * POSSIBILITY OF SUCH DAMAGE. - */ - -#include -#include - -/** - * Example using embb::algorithms::QuickSort and MergeSort. - * - * Sorting a range of values. - */ -void RunSorting() { - #include "algorithms/sorting/range_define-snippet.h" - range.push_back(4); - range.push_back(2); - range.push_back(3); - range.push_back(5); - range.push_back(1); - - #include "algorithms/sorting/quick_sort-snippet.h" - for (size_t i = 0; i < range.size(); i++) { - assert(range[i] == static_cast(i) + 1); - } - - #include "algorithms/sorting/quick_sort_custom_compare-snippet.h" - for (size_t i = 0; i < range.size(); i++) { - assert(range[i] == static_cast(range.size() - i)); - } - - #include "algorithms/sorting/merge_sort_preallocated-snippet.h" - for (size_t i = 0; i < range.size(); i++) { - assert(range[i] == static_cast(i) + 1); - } -} - - - diff --git a/doc/examples_raw/containers/object_pool-fragmented.cc b/doc/examples_raw/containers/object_pool-fragmented.cc deleted file mode 100644 index fb7ee1b..0000000 --- a/doc/examples_raw/containers/object_pool-fragmented.cc +++ /dev/null @@ -1,46 +0,0 @@ -/* - * Copyright (c) 2014-2015, Siemens AG. All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are met: - * - * 1. Redistributions of source code must retain the above copyright notice, - * this list of conditions and the following disclaimer. - * - * 2. Redistributions in binary form must reproduce the above copyright notice, - * this list of conditions and the following disclaimer in the documentation - * and/or other materials provided with the distribution. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" - * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE - * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR - * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF - * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS - * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN - * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) - * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE - * POSSIBILITY OF SUCH DAMAGE. - */ - -#include -#include -#include - -void RunObjectPoolExample1() -{ - #include "containers/object_pool-snippet.h" -} - -void RunObjectPoolExample2() -{ - #include "containers/object_pool_2-snippet.h" -} - -void RunObjectPoolExamples() -{ - RunObjectPoolExample1(); - RunObjectPoolExample2(); - -} diff --git a/doc/examples_raw/containers/object_pool-snippet.h b/doc/examples_raw/containers/object_pool-snippet.h deleted file mode 100644 index 15fe2b0..0000000 --- a/doc/examples_raw/containers/object_pool-snippet.h +++ /dev/null @@ -1,11 +0,0 @@ -embb::containers::ObjectPool objPool(5); //@\label{lst:object_pool_lst1:line_create}@ - -int* alloc[5]; - -for (int i = 0; i != 5; ++i) { - alloc[i] = objPool.Allocate(); //@\label{lst:object_pool_lst1:line_allocate}@ -} - -for (int i = 0; i != 5; ++i) { - objPool.Free(alloc[i]); //@\label{lst:object_pool_lst1:line_free}@ -} \ No newline at end of file diff --git a/doc/examples_raw/containers/object_pool_2-snippet.h b/doc/examples_raw/containers/object_pool_2-snippet.h deleted file mode 100644 index db87c42..0000000 --- a/doc/examples_raw/containers/object_pool_2-snippet.h +++ /dev/null @@ -1,2 +0,0 @@ -embb::containers::ObjectPool> objPool(5); //@\label{lst:object_pool_lst2:line_create}@ diff --git a/doc/examples_raw/containers/queues-fragmented.cc b/doc/examples_raw/containers/queues-fragmented.cc deleted file mode 100644 index 0b6eaff..0000000 --- a/doc/examples_raw/containers/queues-fragmented.cc +++ /dev/null @@ -1,40 +0,0 @@ -/* - * Copyright (c) 2014-2015, Siemens AG. All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are met: - * - * 1. Redistributions of source code must retain the above copyright notice, - * this list of conditions and the following disclaimer. - * - * 2. Redistributions in binary form must reproduce the above copyright notice, - * this list of conditions and the following disclaimer in the documentation - * and/or other materials provided with the distribution. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" - * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE - * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR - * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF - * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS - * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN - * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) - * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE - * POSSIBILITY OF SUCH DAMAGE. - */ - -#include -#include -#include - -void RunQueueExample1() -{ - #include "containers/queues-snippet.h" -} - - -void RunQueueExamples() -{ - RunQueueExample1(); -} diff --git a/doc/examples_raw/containers/queues-snippet.h b/doc/examples_raw/containers/queues-snippet.h deleted file mode 100644 index 951f5c3..0000000 --- a/doc/examples_raw/containers/queues-snippet.h +++ /dev/null @@ -1,15 +0,0 @@ -embb::containers::LockFreeMPMCQueue queue(10); //@\label{lst:queue_lst1:line_create}@ - -int i, j; -bool result = queue.TryDequeue(i); //@\label{lst:queue_lst1:fail_pop}@ -assert(result == false); - -for (int i = 0; i <= 4; ++i) { //@\label{lst:queue_lst1:loop1}@ - result = queue.TryEnqueue(i); //@\label{lst:queue_lst1:push}@ - assert(result == true); -} - -for (int i = 0; i <= 4; ++i) { //@\label{lst:queue_lst1:loop2}@ - result = queue.TryDequeue(j); //@\label{lst:queue_lst1:pop}@ - assert(result == true && i == j); //@\label{lst:queue_lst1:assert}@ -} \ No newline at end of file diff --git a/doc/examples_raw/containers/stack-fragmented.cc b/doc/examples_raw/containers/stack-fragmented.cc deleted file mode 100644 index 31adda7..0000000 --- a/doc/examples_raw/containers/stack-fragmented.cc +++ /dev/null @@ -1,37 +0,0 @@ -/* - * Copyright (c) 2014-2015, Siemens AG. All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are met: - * - * 1. Redistributions of source code must retain the above copyright notice, - * this list of conditions and the following disclaimer. - * - * 2. Redistributions in binary form must reproduce the above copyright notice, - * this list of conditions and the following disclaimer in the documentation - * and/or other materials provided with the distribution. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" - * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE - * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR - * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF - * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS - * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN - * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) - * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE - * POSSIBILITY OF SUCH DAMAGE. - */ - -#include -#include -void RunStackExample1() -{ - #include "containers/stack-snippet.h" -} - -void RunStackExamples() -{ - RunStackExample1(); -} diff --git a/doc/examples_raw/containers/stack-snippet.h b/doc/examples_raw/containers/stack-snippet.h deleted file mode 100644 index dce744f..0000000 --- a/doc/examples_raw/containers/stack-snippet.h +++ /dev/null @@ -1,15 +0,0 @@ -embb::containers::LockFreeStack stack(10); //@\label{lst:stack_lst1:line_create}@ - -int i, j; -bool result = stack.TryPop(i); //@\label{lst:stack_lst1:fail_pop}@ -assert(result == false); - -for (int i = 0; i <= 4; ++i) {//@\label{lst:stack_lst1:loop1}@ - result = stack.TryPush(i); //@\label{lst:stack_lst1:push}@ - assert(result == true); -} - -for (int i = 4; i >= 0; --i) { //@\label{lst:stack_lst1:loop2}@ - result = stack.TryPop(j); //@\label{lst:stack_lst1:pop}@ - assert(result == true && i == j); //@\label{lst:stack_lst1:assert}@ -} \ No newline at end of file diff --git a/doc/examples_raw/dataflow/dataflow_add-snippet.h b/doc/examples_raw/dataflow/dataflow_add-snippet.h deleted file mode 100644 index ce51ef8..0000000 --- a/doc/examples_raw/dataflow/dataflow_add-snippet.h +++ /dev/null @@ -1 +0,0 @@ - nw.AddSource(read); diff --git a/doc/examples_raw/dataflow/dataflow_comparator-snippet.h b/doc/examples_raw/dataflow/dataflow_comparator-snippet.h deleted file mode 100644 index 3630f18..0000000 --- a/doc/examples_raw/dataflow/dataflow_comparator-snippet.h +++ /dev/null @@ -1,8 +0,0 @@ -template -class Comparator { -public: - void Run(const T& a, const T& b, T& x, T& y) { - x = std::min(a,b); - y = std::max(a,b); - } -}; diff --git a/doc/examples_raw/dataflow/dataflow_connect-snippet.h b/doc/examples_raw/dataflow/dataflow_connect-snippet.h deleted file mode 100644 index 6660f53..0000000 --- a/doc/examples_raw/dataflow/dataflow_connect-snippet.h +++ /dev/null @@ -1,2 +0,0 @@ - read >> replace; - replace >> write; diff --git a/doc/examples_raw/dataflow/dataflow_consumer-snippet.h b/doc/examples_raw/dataflow/dataflow_consumer-snippet.h deleted file mode 100644 index eae4054..0000000 --- a/doc/examples_raw/dataflow/dataflow_consumer-snippet.h +++ /dev/null @@ -1,9 +0,0 @@ -template -class Consumer { -public: - void Run(const T& x1, const T& x2, const T& x3, const T& x4) { - if (x1 <= x2 && x2 <= x3 && x3 <= x4) { - // consume values - } - } -}; diff --git a/doc/examples_raw/dataflow/dataflow_declare_add_sources-snippet.h b/doc/examples_raw/dataflow/dataflow_declare_add_sources-snippet.h deleted file mode 100644 index f1cfcaa..0000000 --- a/doc/examples_raw/dataflow/dataflow_declare_add_sources-snippet.h +++ /dev/null @@ -1,20 +0,0 @@ - Producer - producer1(1), - producer2(2), - producer3(3), - producer4(4); - - Network::Source - source1( - embb::base::MakeFunction(producer1, &Producer::Run) ), - source2( - embb::base::MakeFunction(producer2, &Producer::Run) ), - source3( - embb::base::MakeFunction(producer3, &Producer::Run) ), - source4( - embb::base::MakeFunction(producer4, &Producer::Run) ); - - nw.AddSource(source1); - nw.AddSource(source2); - nw.AddSource(source3); - nw.AddSource(source4); diff --git a/doc/examples_raw/dataflow/dataflow_declare_replace-snippet.h b/doc/examples_raw/dataflow/dataflow_declare_replace-snippet.h deleted file mode 100644 index e230807..0000000 --- a/doc/examples_raw/dataflow/dataflow_declare_replace-snippet.h +++ /dev/null @@ -1,5 +0,0 @@ - Network::ParallelProcess< - Network::Inputs::Type, - Network::Outputs::Type> replace( - embb::base::MakeFunction(ReplaceFunction) - ); diff --git a/doc/examples_raw/dataflow/dataflow_declare_sink-snippet.h b/doc/examples_raw/dataflow/dataflow_declare_sink-snippet.h deleted file mode 100644 index dfdd6b2..0000000 --- a/doc/examples_raw/dataflow/dataflow_declare_sink-snippet.h +++ /dev/null @@ -1,3 +0,0 @@ - Network::Sink write( - embb::base::MakeFunction(SinkFunction) - ); diff --git a/doc/examples_raw/dataflow/dataflow_declare_source-snippet.h b/doc/examples_raw/dataflow/dataflow_declare_source-snippet.h deleted file mode 100644 index 470db74..0000000 --- a/doc/examples_raw/dataflow/dataflow_declare_source-snippet.h +++ /dev/null @@ -1,3 +0,0 @@ - Network::Source read( - embb::base::MakeFunction(SourceFunction) - ); diff --git a/doc/examples_raw/dataflow/dataflow_include-snippet.h b/doc/examples_raw/dataflow/dataflow_include-snippet.h deleted file mode 100644 index ca47769..0000000 --- a/doc/examples_raw/dataflow/dataflow_include-snippet.h +++ /dev/null @@ -1 +0,0 @@ -#include diff --git a/doc/examples_raw/dataflow/dataflow_linear-fragmented.cc b/doc/examples_raw/dataflow/dataflow_linear-fragmented.cc deleted file mode 100644 index 25bdacd..0000000 --- a/doc/examples_raw/dataflow/dataflow_linear-fragmented.cc +++ /dev/null @@ -1,61 +0,0 @@ -/* - * Copyright (c) 2014-2015, Siemens AG. All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are met: - * - * 1. Redistributions of source code must retain the above copyright notice, - * this list of conditions and the following disclaimer. - * - * 2. Redistributions in binary form must reproduce the above copyright notice, - * this list of conditions and the following disclaimer in the documentation - * and/or other materials provided with the distribution. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" - * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE - * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR - * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF - * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS - * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN - * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) - * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE - * POSSIBILITY OF SUCH DAMAGE. - */ - -#include -#include -#include -#include - -// replace all occurrences of 'what' in 'str' with 'with' -void repl(std::string& str, const std::string &what, - const std::string& with) { - std::string::size_type pos = 0; - while ((pos = str.find(what, pos)) != std::string::npos) { - str.replace(pos, what.length(), with); - pos += with.length(); - } -} - -#include "dataflow/dataflow_include-snippet.h" - -std::stringstream file("hi world!\nhi there!\nhi hi!?\nhi!\n"); -std::string what("hi"); -std::string with("hello"); - -#include "dataflow/dataflow_network-snippet.h" - -#include "dataflow/dataflow_source_function-snippet.h" -#include "dataflow/dataflow_replace_function-snippet.h" -#include "dataflow/dataflow_sink_function-snippet.h" - -void RunDataflowLinear() { -#include "dataflow/dataflow_declare_source-snippet.h" -#include "dataflow/dataflow_declare_replace-snippet.h" -#include "dataflow/dataflow_declare_sink-snippet.h" -#include "dataflow/dataflow_connect-snippet.h" -#include "dataflow/dataflow_add-snippet.h" -#include "dataflow/dataflow_run-snippet.h" -} diff --git a/doc/examples_raw/dataflow/dataflow_network-snippet.h b/doc/examples_raw/dataflow/dataflow_network-snippet.h deleted file mode 100644 index c13ebeb..0000000 --- a/doc/examples_raw/dataflow/dataflow_network-snippet.h +++ /dev/null @@ -1,2 +0,0 @@ -typedef embb::dataflow::Network<2> Network; -static Network nw; diff --git a/doc/examples_raw/dataflow/dataflow_nonlinear-fragmented.cc b/doc/examples_raw/dataflow/dataflow_nonlinear-fragmented.cc deleted file mode 100644 index e7f419d..0000000 --- a/doc/examples_raw/dataflow/dataflow_nonlinear-fragmented.cc +++ /dev/null @@ -1,87 +0,0 @@ -/* - * Copyright (c) 2014-2015, Siemens AG. All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are met: - * - * 1. Redistributions of source code must retain the above copyright notice, - * this list of conditions and the following disclaimer. - * - * 2. Redistributions in binary form must reproduce the above copyright notice, - * this list of conditions and the following disclaimer in the documentation - * and/or other materials provided with the distribution. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" - * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE - * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR - * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF - * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS - * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN - * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) - * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE - * POSSIBILITY OF SUCH DAMAGE. - */ - -#include -#include - -#ifdef NDEBUG -#undef assert -#define assert(x) if(!x) std::cout << "assert failed." << std::endl -#endif - -static int SimpleRand(int & seed) { - const int a = 16807; - const int m = 2147483647; - seed = (a * seed) % m; - return seed % 100; -} - -#include "dataflow/dataflow_include-snippet.h" - -#include "dataflow/dataflow_producer-snippet.h" -#include "dataflow/dataflow_comparator-snippet.h" -#include "dataflow/dataflow_consumer-snippet.h" - -#include "dataflow/dataflow_network-snippet.h" - -void RunDataflowNonLinear() { -#include "dataflow/dataflow_declare_add_sources-snippet.h" - - Comparator comparator; - - Network::ParallelProcess< - Network::Inputs::Type, Network::Outputs::Type> - process1( embb::base::MakeFunction(comparator, &Comparator::Run) ), - process2( embb::base::MakeFunction(comparator, &Comparator::Run) ), - process3( embb::base::MakeFunction(comparator, &Comparator::Run) ), - process4( embb::base::MakeFunction(comparator, &Comparator::Run) ), - process5( embb::base::MakeFunction(comparator, &Comparator::Run) ); - - Consumer consumer; - - Network::Sink - sink1(embb::base::MakeFunction(consumer, &Consumer::Run)); - - source1.GetOutput<0>() >> process1.GetInput<0>(); - source2.GetOutput<0>() >> process2.GetInput<0>(); - source3.GetOutput<0>() >> process1.GetInput<1>(); - source4.GetOutput<0>() >> process2.GetInput<1>(); - - process1.GetOutput<0>() >> process3.GetInput<0>(); - process2.GetOutput<0>() >> process3.GetInput<1>(); - process1.GetOutput<1>() >> process4.GetInput<0>(); - process2.GetOutput<1>() >> process4.GetInput<1>(); - - process3.GetOutput<1>() >> process5.GetInput<0>(); - process4.GetOutput<0>() >> process5.GetInput<1>(); - - process3.GetOutput<0>() >> sink1.GetInput<0>(); - process5.GetOutput<0>() >> sink1.GetInput<1>(); - process5.GetOutput<1>() >> sink1.GetInput<2>(); - process4.GetOutput<1>() >> sink1.GetInput<3>(); - - nw(); -} diff --git a/doc/examples_raw/dataflow/dataflow_producer-snippet.h b/doc/examples_raw/dataflow/dataflow_producer-snippet.h deleted file mode 100644 index ffaf79e..0000000 --- a/doc/examples_raw/dataflow/dataflow_producer-snippet.h +++ /dev/null @@ -1,15 +0,0 @@ -template -class Producer { - public: - explicit Producer(int seed) : seed_(seed), count_(4) {} - bool Run(T& x) { - // produce a new value x - x = SimpleRand(seed_); - count_--; - return count_ >= 0; - } - - private: - int seed_; - int count_; -}; diff --git a/doc/examples_raw/dataflow/dataflow_replace_function-snippet.h b/doc/examples_raw/dataflow/dataflow_replace_function-snippet.h deleted file mode 100644 index 21e71d9..0000000 --- a/doc/examples_raw/dataflow/dataflow_replace_function-snippet.h +++ /dev/null @@ -1,4 +0,0 @@ -void ReplaceFunction(std::string const & istr, std::string & ostr) { - ostr = istr; - repl(ostr, what, with); -} diff --git a/doc/examples_raw/dataflow/dataflow_run-snippet.h b/doc/examples_raw/dataflow/dataflow_run-snippet.h deleted file mode 100644 index ff4f083..0000000 --- a/doc/examples_raw/dataflow/dataflow_run-snippet.h +++ /dev/null @@ -1 +0,0 @@ - nw(); diff --git a/doc/examples_raw/dataflow/dataflow_sink_function-snippet.h b/doc/examples_raw/dataflow/dataflow_sink_function-snippet.h deleted file mode 100644 index 66896ea..0000000 --- a/doc/examples_raw/dataflow/dataflow_sink_function-snippet.h +++ /dev/null @@ -1,3 +0,0 @@ -void SinkFunction(std::string const & str) { - std::cout << str << std::endl; -} diff --git a/doc/examples_raw/dataflow/dataflow_source_function-snippet.h b/doc/examples_raw/dataflow/dataflow_source_function-snippet.h deleted file mode 100644 index 6c1cdea..0000000 --- a/doc/examples_raw/dataflow/dataflow_source_function-snippet.h +++ /dev/null @@ -1,4 +0,0 @@ -bool SourceFunction(std::string & str) { - std::getline(file, str); - return !file.eof(); -} diff --git a/doc/examples_raw/insert_snippets.py b/doc/examples_raw/insert_snippets.py deleted file mode 100644 index 40d70bc..0000000 --- a/doc/examples_raw/insert_snippets.py +++ /dev/null @@ -1,51 +0,0 @@ -import os -import glob -import shutil -import sys -import string - -filenames = os.listdir(".") -# Work through all files and directories -for filename in filenames: - # If it is a directory, just add content to filenames - if os.path.isdir(filename): - nestedfiles = os.listdir(filename + "/") - for i in range(len(nestedfiles)): - nestedfiles[i] = filename + "/" + nestedfiles[i] - filenames.extend(nestedfiles) - # Otherwise look into file - else: - #sys.stdout.write("Looking at " + filename) - is_fragmented = string.find(filename, "-fragmented.cc") != -1 - if is_fragmented: - in_file = open(filename, 'r+') - out_filename = string.replace(filename, "-fragmented", "") - sys.stdout.write(filename + " -> " + out_filename + "\n") - out_file = open(out_filename, 'w') - for line in in_file: - stripped_line = string.lstrip(line) - # Check if first characters after whitespaces are include - is_include = string.find(stripped_line, "#include") == 0 - # Check if snippet keyword is contained in include - includes_snippet = string.find(line, "-snippet.") != -1 - if is_include and includes_snippet: - # Get number of whitespaces for indentation of snippet - num_whitespaces = len(line) - len(stripped_line) - # Create Whitespace-string for indentation - whitespaces = "" - for i in range(num_whitespaces): - whitespaces += " " - # Get include filename - first_quotes_pos = string.find(line, '"') - last_quotes_pos = string.rfind(line, '"') - snippet_filename = line[first_quotes_pos + 1 : last_quotes_pos] - sys.stdout.write(" + " + snippet_filename + "\n") - snippet_file = open(snippet_filename, 'r') - for snippet_line in snippet_file: - out_file.write(whitespaces + snippet_line) - snippet_file.close() - #out_file.write("\n") - else: - out_file.write(line) - in_file.close() - out_file.close() \ No newline at end of file diff --git a/doc/examples_raw/main.cc b/doc/examples_raw/main.cc deleted file mode 100644 index 7888d4b..0000000 --- a/doc/examples_raw/main.cc +++ /dev/null @@ -1,134 +0,0 @@ -/* - * Copyright (c) 2014-2015, Siemens AG. All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are met: - * - * 1. Redistributions of source code must retain the above copyright notice, - * this list of conditions and the following disclaimer. - * - * 2. Redistributions in binary form must reproduce the above copyright notice, - * this list of conditions and the following disclaimer in the documentation - * and/or other materials provided with the distribution. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" - * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE - * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR - * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF - * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS - * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN - * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) - * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE - * POSSIBILITY OF SUCH DAMAGE. - */ - -#include -#include - -void RunMTAPI_C(); -void RunMTAPI_C_Plugin(); -void RunMTAPI_C_Network(); -#ifdef EMBB_WITH_OPENCL -void RunMTAPI_C_OpenCL(); -#endif -void RunMTAPI_CPP(); -void RunTasks(); -void RunDataflowLinear(); -void RunDataflowNonLinear(); -void RunSTLForEach(); -void RunForEach(); -void RunInvoke(); -void RunSorting(); -void RunReduce(); -void RunCounting(); -void RunScan(); -void RunObjectPoolExamples(); -void RunStackExamples(); -void RunQueueExamples(); - -/** - * Runs all examples and tests their correctness. - */ -int main() { - embb_thread_set_max_count(1024); - - std::cout << "Running examples ..." << std::endl; - - std::cout << "RunMTAPI_C() ..." << std::endl; - RunMTAPI_C(); - std::cout << "RunMTAPI_C() ... done" << std::endl; - - std::cout << "RunMTAPI_C_Plugin() ..." << std::endl; - RunMTAPI_C_Plugin(); - std::cout << "RunMTAPI_C_Plugin() ... done" << std::endl; - - std::cout << "RunMTAPI_C_Network() ..." << std::endl; - RunMTAPI_C_Network(); - std::cout << "RunMTAPI_C_Network() ... done" << std::endl; - -#ifdef EMBB_WITH_OPENCL - std::cout << "RunMTAPI_C_OpenCL() ..." << std::endl; - RunMTAPI_C_OpenCL(); - std::cout << "RunMTAPI_C_OpenCL() ... done" << std::endl; -#endif - - std::cout << "RunMTAPI_CPP() ..." << std::endl; - RunMTAPI_CPP(); - std::cout << "RunMTAPI_CPP() ... done" << std::endl; - - std::cout << "RunTasks() ..." << std::endl; - RunTasks(); - std::cout << "RunTasks() ... done" << std::endl; - - std::cout << "RunDataflowLinear() ..." << std::endl; - RunDataflowLinear(); - std::cout << "RunDataflowLinear() ... done" << std::endl; - - std::cout << "RunDataflowNonLinear() ..." << std::endl; - RunDataflowNonLinear(); - std::cout << "RunDataflowNonLinear() ... done" << std::endl; - - std::cout << "RunSTLForEach() ..." << std::endl; - RunSTLForEach(); - std::cout << "RunSTLForEach() ... done" << std::endl; - - std::cout << "RunForEach() ..." << std::endl; - RunForEach(); - std::cout << "RunForEach() ... done" << std::endl; - - std::cout << "RunInvoke() ..." << std::endl; - RunInvoke(); - std::cout << "RunInvoke() ... done" << std::endl; - - std::cout << "RunSorting() ... " << std::endl; - RunSorting(); - std::cout << "RunSorting() ... done" << std::endl; - - std::cout << "RunReduce() ... " << std::endl; - RunReduce(); - std::cout << "RunReduce() ... done" << std::endl; - - std::cout << "RunCounting() ..." << std::endl; - RunCounting(); - std::cout << "RunCounting() ... done" << std::endl; - /* - std::cout << "RunScan() ..." << std::endl; - RunScan(); - std::cout << "RunScan() ... done" << std::endl; - */ - std::cout << "RunObjectPoolExamples() ..." << std::endl; - RunObjectPoolExamples(); - std::cout << "RunObjectPoolExamples() ... done" << std::endl; - - std::cout << "RunStackExamples() ..." << std::endl; - RunStackExamples(); - std::cout << "RunStackExamples() ... done" << std::endl; - - std::cout << "RunQueueExamples() ..." << std::endl; - RunQueueExamples(); - std::cout << "RunQueueExamples() ... done" << std::endl; - - std::cout << "Running examples ... done" << std::endl; -} diff --git a/doc/examples_raw/mtapi/mtapi_c-fragmented.cc b/doc/examples_raw/mtapi/mtapi_c-fragmented.cc deleted file mode 100644 index d543e12..0000000 --- a/doc/examples_raw/mtapi/mtapi_c-fragmented.cc +++ /dev/null @@ -1,66 +0,0 @@ -/* - * Copyright (c) 2014-2015, Siemens AG. All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are met: - * - * 1. Redistributions of source code must retain the above copyright notice, - * this list of conditions and the following disclaimer. - * - * 2. Redistributions in binary form must reproduce the above copyright notice, - * this list of conditions and the following disclaimer in the documentation - * and/or other materials provided with the distribution. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" - * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE - * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR - * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF - * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS - * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN - * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) - * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE - * POSSIBILITY OF SUCH DAMAGE. - */ - -#include -#include - -#include "mtapi/mtapi_check_status-snippet.h" -#include "mtapi/mtapi_c_domain_node_id-snippet.h" - -static -#include "mtapi/mtapi_c_action_signature-snippet.h" -#include "mtapi/mtapi_c_validate_arguments-snippet.h" -#include "mtapi/mtapi_c_validate_result_buffer-snippet.h" - /* calculate */ -#include "mtapi/mtapi_terminating_condition-snippet.h" - /* first recursive call spawned as task (x = fib(n - 1);) */ -#include "mtapi/mtapi_c_calc_task-snippet.h" - /* second recursive call can be called directly (y = fib(n - 2);) */ -#include "mtapi/mtapi_c_calc_direct-snippet.h" - /* wait for completion */ -#include "mtapi/mtapi_c_wait_task-snippet.h" - /* add the two preceeding numbers */ -#include "mtapi/mtapi_write_back-snippet.h" - -static int fibonacci(int n) { -#include "mtapi/mtapi_c_initialize-snippet.h" -#include "mtapi/mtapi_c_register_action-snippet.h" -#include "mtapi/mtapi_c_start_task-snippet.h" - /* wait for task completion */ - mtapi_task_wait(task, MTAPI_INFINITE, &status); - MTAPI_CHECK_STATUS(status); -#include "mtapi/mtapi_c_finalize-snippet.h" - return result; -} - -void RunMTAPI_C() { - /* run calculation */ - int result; - result = fibonacci(6); - - /* print result */ - printf("result: %i\n", result); -} diff --git a/doc/examples_raw/mtapi/mtapi_c_action_signature-snippet.h b/doc/examples_raw/mtapi/mtapi_c_action_signature-snippet.h deleted file mode 100644 index 80b8a4f..0000000 --- a/doc/examples_raw/mtapi/mtapi_c_action_signature-snippet.h +++ /dev/null @@ -1,9 +0,0 @@ -void fibonacciActionFunction( - const void* args, - mtapi_size_t arg_size, - void* result_buffer, - mtapi_size_t result_buffer_size, - const void* /*node_local_data*/, - mtapi_size_t /*node_local_data_size*/, - mtapi_task_context_t* task_context - ) { diff --git a/doc/examples_raw/mtapi/mtapi_c_calc_direct-snippet.h b/doc/examples_raw/mtapi/mtapi_c_calc_direct-snippet.h deleted file mode 100644 index 525f7be..0000000 --- a/doc/examples_raw/mtapi/mtapi_c_calc_direct-snippet.h +++ /dev/null @@ -1,7 +0,0 @@ - int b = n - 2; - int y; - fibonacciActionFunction( - &b, sizeof(int), - &y, sizeof(int), - MTAPI_NULL, 0, - task_context); diff --git a/doc/examples_raw/mtapi/mtapi_c_calc_task-snippet.h b/doc/examples_raw/mtapi/mtapi_c_calc_task-snippet.h deleted file mode 100644 index 62b352a..0000000 --- a/doc/examples_raw/mtapi/mtapi_c_calc_task-snippet.h +++ /dev/null @@ -1,15 +0,0 @@ - int a = n - 1; - int x; - mtapi_task_hndl_t task = mtapi_task_start( - MTAPI_TASK_ID_NONE, /* optional task ID */ - fibonacciJob, /* job */ - (void*)&a, /* arguments passed to action - functions */ - sizeof(int), /* size of arguments */ - (void*)&x, /* result buffer */ - sizeof(int), /* size of result buffer */ - MTAPI_DEFAULT_TASK_ATTRIBUTES, /* task attributes */ - MTAPI_GROUP_NONE, /* optional task group */ - &status /* status out - parameter */ - ); - MTAPI_CHECK_STATUS(status); diff --git a/doc/examples_raw/mtapi/mtapi_c_domain_node_id-snippet.h b/doc/examples_raw/mtapi/mtapi_c_domain_node_id-snippet.h deleted file mode 100644 index b1850d0..0000000 --- a/doc/examples_raw/mtapi/mtapi_c_domain_node_id-snippet.h +++ /dev/null @@ -1,5 +0,0 @@ -#define THIS_DOMAIN_ID 1 -#define THIS_NODE_ID 1 - -#define FIBONACCI_JOB 1 -static mtapi_job_hndl_t fibonacciJob; diff --git a/doc/examples_raw/mtapi/mtapi_c_finalize-snippet.h b/doc/examples_raw/mtapi/mtapi_c_finalize-snippet.h deleted file mode 100644 index 21c5bfa..0000000 --- a/doc/examples_raw/mtapi/mtapi_c_finalize-snippet.h +++ /dev/null @@ -1,7 +0,0 @@ - /* delete action */ - mtapi_action_delete(fibonacciAction, 100, &status); - MTAPI_CHECK_STATUS(status); - - /* finalize the node */ - mtapi_finalize(&status); - MTAPI_CHECK_STATUS(status); diff --git a/doc/examples_raw/mtapi/mtapi_c_initialize-snippet.h b/doc/examples_raw/mtapi/mtapi_c_initialize-snippet.h deleted file mode 100644 index 1269342..0000000 --- a/doc/examples_raw/mtapi/mtapi_c_initialize-snippet.h +++ /dev/null @@ -1,25 +0,0 @@ - mtapi_status_t status; - - /* initialize node attributes to default values */ - mtapi_node_attributes_t node_attr; - mtapi_nodeattr_init(&node_attr, &status); - MTAPI_CHECK_STATUS(status); - - /* set node type to SMP */ - mtapi_nodeattr_set( - &node_attr, - MTAPI_NODE_TYPE, - MTAPI_ATTRIBUTE_VALUE(MTAPI_NODE_TYPE_SMP), - MTAPI_ATTRIBUTE_POINTER_AS_VALUE, - &status); - MTAPI_CHECK_STATUS(status); - - /* initialize the node */ - mtapi_info_t info; - mtapi_initialize( - THIS_DOMAIN_ID, - THIS_NODE_ID, - &node_attr, - &info, - &status); - MTAPI_CHECK_STATUS(status); diff --git a/doc/examples_raw/mtapi/mtapi_c_network-fragmented.cc b/doc/examples_raw/mtapi/mtapi_c_network-fragmented.cc deleted file mode 100644 index 777e74c..0000000 --- a/doc/examples_raw/mtapi/mtapi_c_network-fragmented.cc +++ /dev/null @@ -1,102 +0,0 @@ -/* - * Copyright (c) 2014-2015, Siemens AG. All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are met: - * - * 1. Redistributions of source code must retain the above copyright notice, - * this list of conditions and the following disclaimer. - * - * 2. Redistributions in binary form must reproduce the above copyright notice, - * this list of conditions and the following disclaimer in the documentation - * and/or other materials provided with the distribution. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" - * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE - * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR - * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF - * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS - * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN - * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) - * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE - * POSSIBILITY OF SUCH DAMAGE. - */ - -#include -#include "mtapi/mtapi_network_c_header-snippet.h" -#include - -#include "mtapi/mtapi_check_status-snippet.h" - -#define NETWORK_DOMAIN 1 -#define NETWORK_LOCAL_NODE 3 -#define NETWORK_LOCAL_JOB 3 -#define NETWORK_REMOTE_NODE 3 -#define NETWORK_REMOTE_JOB 4 - -#include "mtapi/mtapi_network_c_action_function-snippet.h" - -void RunMTAPI_C_Network() { - mtapi_status_t status; - mtapi_job_hndl_t job; - mtapi_task_hndl_t task; - mtapi_action_hndl_t network_action, local_action; - - const int kElements = 64; - float arguments[kElements * 2]; - float results[kElements]; - - for (int ii = 0; ii < kElements; ii++) { - arguments[ii] = static_cast(ii); - arguments[ii + kElements] = static_cast(ii); - } - - mtapi_initialize( - NETWORK_DOMAIN, - NETWORK_LOCAL_NODE, - MTAPI_DEFAULT_NODE_ATTRIBUTES, - MTAPI_NULL, - &status); - MTAPI_CHECK_STATUS(status); - -#include "mtapi/mtapi_network_c_plugin_initialize-snippet.h" - MTAPI_CHECK_STATUS(status); - -#include "mtapi/mtapi_network_c_remote_action_create-snippet.h" - MTAPI_CHECK_STATUS(status); - -#include "mtapi/mtapi_network_c_local_action_create-snippet.h" - MTAPI_CHECK_STATUS(status); - - job = mtapi_job_get(NETWORK_LOCAL_JOB, NETWORK_DOMAIN, &status); - MTAPI_CHECK_STATUS(status); - - task = mtapi_task_start( - MTAPI_TASK_ID_NONE, - job, - arguments, kElements * 2 * sizeof(float), - results, kElements*sizeof(float), - MTAPI_DEFAULT_TASK_ATTRIBUTES, - MTAPI_GROUP_NONE, - &status); - MTAPI_CHECK_STATUS(status); - - mtapi_task_wait(task, MTAPI_INFINITE, &status); - MTAPI_CHECK_STATUS(status); - - for (int ii = 0; ii < kElements; ii++) { - if (results[ii] != ii * 2 + 1) { - printf("result %d was expected to be %d but was %f.\n", - ii, ii * 2 + 1, results[ii]); - exit(MTAPI_ERR_UNKNOWN); - } - } - -#include "mtapi/mtapi_network_c_plugin_finalize-snippet.h" - MTAPI_CHECK_STATUS(status); - - mtapi_finalize(&status); - MTAPI_CHECK_STATUS(status); -} diff --git a/doc/examples_raw/mtapi/mtapi_c_opencl-fragmented.cc b/doc/examples_raw/mtapi/mtapi_c_opencl-fragmented.cc deleted file mode 100644 index 074744a..0000000 --- a/doc/examples_raw/mtapi/mtapi_c_opencl-fragmented.cc +++ /dev/null @@ -1,98 +0,0 @@ -/* - * Copyright (c) 2014-2015, Siemens AG. All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are met: - * - * 1. Redistributions of source code must retain the above copyright notice, - * this list of conditions and the following disclaimer. - * - * 2. Redistributions in binary form must reproduce the above copyright notice, - * this list of conditions and the following disclaimer in the documentation - * and/or other materials provided with the distribution. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" - * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE - * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR - * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF - * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS - * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN - * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) - * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE - * POSSIBILITY OF SUCH DAMAGE. - */ - -#include -#include "mtapi/mtapi_opencl_c_header-snippet.h" - -#include "mtapi/mtapi_check_status-snippet.h" - -#define OPENCL_DOMAIN 1 -#define OPENCL_NODE 2 -#define OPENCL_JOB 2 - -// OpenCL Kernel Function for element by element vector addition -#include "mtapi/mtapi_opencl_c_kernel-snippet.h" - -void RunMTAPI_C_OpenCL() { - mtapi_status_t status; - mtapi_job_hndl_t job; - mtapi_task_hndl_t task; - mtapi_action_hndl_t action; - - const int kElements = 64; - float arguments[kElements * 2]; - float results[kElements]; - - for (int ii = 0; ii < kElements; ii++) { - arguments[ii] = static_cast(ii); - arguments[ii + kElements] = static_cast(ii); - } - - mtapi_initialize( - OPENCL_DOMAIN, - OPENCL_NODE, - MTAPI_DEFAULT_NODE_ATTRIBUTES, - MTAPI_NULL, - &status); - MTAPI_CHECK_STATUS(status); - -#include "mtapi/mtapi_opencl_c_plugin_initialize-snippet.h" - MTAPI_CHECK_STATUS(status); - -#include "mtapi/mtapi_opencl_c_action_create-snippet.h" - MTAPI_CHECK_STATUS(status); - - status = MTAPI_ERR_UNKNOWN; - job = mtapi_job_get(OPENCL_JOB, OPENCL_DOMAIN, &status); - MTAPI_CHECK_STATUS(status); - - task = mtapi_task_start( - MTAPI_TASK_ID_NONE, - job, - arguments, kElements * 2 * sizeof(float), - results, kElements*sizeof(float), - MTAPI_DEFAULT_TASK_ATTRIBUTES, - MTAPI_GROUP_NONE, - &status); - MTAPI_CHECK_STATUS(status); - - mtapi_task_wait(task, MTAPI_INFINITE, &status); - MTAPI_CHECK_STATUS(status); - - for (int ii = 0; ii < kElements; ii++) { - if (results[ii] != ii * 2 + 1) { - printf("result %d was expected to be %d but was %f.\n", - ii, ii * 2 + 1, results[ii]); - exit(MTAPI_ERR_UNKNOWN); - } - } - -#include "mtapi/mtapi_opencl_c_plugin_finalize-snippet.h" - MTAPI_CHECK_STATUS(status); - - mtapi_finalize(&status); - MTAPI_CHECK_STATUS(status); -} diff --git a/doc/examples_raw/mtapi/mtapi_c_plugin-fragmented.cc b/doc/examples_raw/mtapi/mtapi_c_plugin-fragmented.cc deleted file mode 100644 index b072164..0000000 --- a/doc/examples_raw/mtapi/mtapi_c_plugin-fragmented.cc +++ /dev/null @@ -1,83 +0,0 @@ -/* - * Copyright (c) 2014-2015, Siemens AG. All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are met: - * - * 1. Redistributions of source code must retain the above copyright notice, - * this list of conditions and the following disclaimer. - * - * 2. Redistributions in binary form must reproduce the above copyright notice, - * this list of conditions and the following disclaimer in the documentation - * and/or other materials provided with the distribution. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" - * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE - * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR - * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF - * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS - * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN - * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) - * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE - * POSSIBILITY OF SUCH DAMAGE. - */ - -#include -#include - -#include -#include -#include - -#include - -#include -#include -#include -#include - -#define PLUGIN_DOMAIN_ID 1 -#define PLUGIN_NODE_ID 1 -#define PLUGIN_JOB_ID 1 - -#include "mtapi/mtapi_check_status-snippet.h" - -#include "mtapi/mtapi_c_plugin_task_schedule-snippet.h" - -#include "mtapi/mtapi_c_plugin_task_start_cb-snippet.h" - -#include "mtapi/mtapi_c_plugin_task_cancel_cb-snippet.h" - -#include "mtapi/mtapi_c_plugin_action_finalize_cb-snippet.h" - -void RunMTAPI_C_Plugin() { - mtapi_status_t status; - mtapi_job_hndl_t job; - mtapi_action_hndl_t action; - mtapi_task_hndl_t task; - - mtapi_initialize( - PLUGIN_DOMAIN_ID, - PLUGIN_NODE_ID, - MTAPI_DEFAULT_NODE_ATTRIBUTES, - MTAPI_NULL, - &status); - MTAPI_CHECK_STATUS(status); - -#include "mtapi/mtapi_c_plugin_action_create-snippet.h" - MTAPI_CHECK_STATUS(status); - -#include "mtapi/mtapi_c_plugin_get_job-snippet.h" - MTAPI_CHECK_STATUS(status); - -#include "mtapi/mtapi_c_plugin_task_start-snippet.h" - MTAPI_CHECK_STATUS(status); - - mtapi_task_wait(task, MTAPI_INFINITE, &status); - MTAPI_CHECK_STATUS(status); - - mtapi_finalize(&status); - MTAPI_CHECK_STATUS(status); -} diff --git a/doc/examples_raw/mtapi/mtapi_c_plugin_action_create-snippet.h b/doc/examples_raw/mtapi/mtapi_c_plugin_action_create-snippet.h deleted file mode 100644 index 2ec43dd..0000000 --- a/doc/examples_raw/mtapi/mtapi_c_plugin_action_create-snippet.h +++ /dev/null @@ -1,10 +0,0 @@ -action = mtapi_ext_plugin_action_create( - PLUGIN_JOB_ID, - plugin_task_start, - plugin_task_cancel, - plugin_action_finalize, - MTAPI_NULL, - MTAPI_NULL, - 0, - MTAPI_DEFAULT_ACTION_ATTRIBUTES, - &status); diff --git a/doc/examples_raw/mtapi/mtapi_c_plugin_action_finalize_cb-snippet.h b/doc/examples_raw/mtapi/mtapi_c_plugin_action_finalize_cb-snippet.h deleted file mode 100644 index 7c44e30..0000000 --- a/doc/examples_raw/mtapi/mtapi_c_plugin_action_finalize_cb-snippet.h +++ /dev/null @@ -1,8 +0,0 @@ -void plugin_action_finalize( - MTAPI_IN mtapi_action_hndl_t action, - MTAPI_OUT mtapi_status_t* status - ) { - EMBB_UNUSED(action); - // nothing to do for tearing down the plugin action - mtapi_status_set(status, MTAPI_SUCCESS); -} diff --git a/doc/examples_raw/mtapi/mtapi_c_plugin_get_job-snippet.h b/doc/examples_raw/mtapi/mtapi_c_plugin_get_job-snippet.h deleted file mode 100644 index 9e97299..0000000 --- a/doc/examples_raw/mtapi/mtapi_c_plugin_get_job-snippet.h +++ /dev/null @@ -1,4 +0,0 @@ - job = mtapi_job_get( - PLUGIN_JOB_ID, - PLUGIN_DOMAIN_ID, - &status); diff --git a/doc/examples_raw/mtapi/mtapi_c_plugin_task_cancel_cb-snippet.h b/doc/examples_raw/mtapi/mtapi_c_plugin_task_cancel_cb-snippet.h deleted file mode 100644 index 2a62c5d..0000000 --- a/doc/examples_raw/mtapi/mtapi_c_plugin_task_cancel_cb-snippet.h +++ /dev/null @@ -1,8 +0,0 @@ -void plugin_task_cancel( - MTAPI_IN mtapi_task_hndl_t task, - MTAPI_OUT mtapi_status_t* status - ) { - EMBB_UNUSED(task); - // nothing to cancel in this simple example - mtapi_status_set(status, MTAPI_SUCCESS); -} diff --git a/doc/examples_raw/mtapi/mtapi_c_plugin_task_schedule-snippet.h b/doc/examples_raw/mtapi/mtapi_c_plugin_task_schedule-snippet.h deleted file mode 100644 index a180edc..0000000 --- a/doc/examples_raw/mtapi/mtapi_c_plugin_task_schedule-snippet.h +++ /dev/null @@ -1,11 +0,0 @@ -void plugin_task_schedule(embb_mtapi_task_t* local_task) { - // here the task might be dispatched to some hardware or separate thread - - // mark the task as running - embb_mtapi_task_set_state(local_task, MTAPI_TASK_RUNNING); - - // nothing to do to execute the no-op task - - // just mark the task as done - embb_mtapi_task_set_state(local_task, MTAPI_TASK_COMPLETED); -} diff --git a/doc/examples_raw/mtapi/mtapi_c_plugin_task_start-snippet.h b/doc/examples_raw/mtapi/mtapi_c_plugin_task_start-snippet.h deleted file mode 100644 index 344330a..0000000 --- a/doc/examples_raw/mtapi/mtapi_c_plugin_task_start-snippet.h +++ /dev/null @@ -1,8 +0,0 @@ - task = mtapi_task_start( - MTAPI_TASK_ID_NONE, - job, - MTAPI_NULL, 0, - MTAPI_NULL, 0, - MTAPI_DEFAULT_TASK_ATTRIBUTES, - MTAPI_GROUP_NONE, - &status); diff --git a/doc/examples_raw/mtapi/mtapi_c_plugin_task_start_cb-snippet.h b/doc/examples_raw/mtapi/mtapi_c_plugin_task_start_cb-snippet.h deleted file mode 100644 index 8e4d063..0000000 --- a/doc/examples_raw/mtapi/mtapi_c_plugin_task_start_cb-snippet.h +++ /dev/null @@ -1,31 +0,0 @@ -void plugin_task_start( - MTAPI_IN mtapi_task_hndl_t task, - MTAPI_OUT mtapi_status_t* status) { - mtapi_status_t local_status = MTAPI_ERR_UNKNOWN; - - // do we have a node? - if (embb_mtapi_node_is_initialized()) { - // get the node instance - embb_mtapi_node_t * node = embb_mtapi_node_get_instance(); - - // is this a valid task? - if (embb_mtapi_task_pool_is_handle_valid(node->task_pool, task)) { - // get the tasks storage - embb_mtapi_task_t * local_task = - embb_mtapi_task_pool_get_storage_for_handle(node->task_pool, task); - - // dispatch the task - plugin_task_schedule(local_task); - - local_status = MTAPI_SUCCESS; - } - else { - local_status = MTAPI_ERR_TASK_INVALID; - } - } - else { - local_status = MTAPI_ERR_NODE_NOTINIT; - } - - mtapi_status_set(status, local_status); -} diff --git a/doc/examples_raw/mtapi/mtapi_c_register_action-snippet.h b/doc/examples_raw/mtapi/mtapi_c_register_action-snippet.h deleted file mode 100644 index a05aaa7..0000000 --- a/doc/examples_raw/mtapi/mtapi_c_register_action-snippet.h +++ /dev/null @@ -1,17 +0,0 @@ - /* create action */ - mtapi_action_hndl_t fibonacciAction; - fibonacciAction = mtapi_action_create( - FIBONACCI_JOB, /* action ID, defined by the - application */ - (fibonacciActionFunction), /* action function */ - MTAPI_NULL, /* no shared data */ - 0, /* length of shared data */ - MTAPI_DEFAULT_ACTION_ATTRIBUTES, /* action attributes */ - &status /* status out - parameter */ - ); - MTAPI_CHECK_STATUS(status); - - /* get job */ - mtapi_task_hndl_t task; - fibonacciJob = mtapi_job_get(FIBONACCI_JOB, THIS_DOMAIN_ID, &status); - MTAPI_CHECK_STATUS(status); diff --git a/doc/examples_raw/mtapi/mtapi_c_start_task-snippet.h b/doc/examples_raw/mtapi/mtapi_c_start_task-snippet.h deleted file mode 100644 index 79d005e..0000000 --- a/doc/examples_raw/mtapi/mtapi_c_start_task-snippet.h +++ /dev/null @@ -1,15 +0,0 @@ - /* start task */ - int result; - task = mtapi_task_start( - MTAPI_TASK_ID_NONE, /* optional task ID */ - fibonacciJob, /* job */ - (void*)&n, /* arguments passed to action - functions */ - sizeof(int), /* size of arguments */ - (void*)&result, /* result buffer */ - sizeof(int), /* size of result buffer */ - MTAPI_DEFAULT_TASK_ATTRIBUTES, /* task attributes */ - MTAPI_GROUP_NONE, /* optional task group */ - &status /* status out - parameter */ - ); - MTAPI_CHECK_STATUS(status); diff --git a/doc/examples_raw/mtapi/mtapi_c_validate_arguments-snippet.h b/doc/examples_raw/mtapi/mtapi_c_validate_arguments-snippet.h deleted file mode 100644 index 44246ab..0000000 --- a/doc/examples_raw/mtapi/mtapi_c_validate_arguments-snippet.h +++ /dev/null @@ -1,12 +0,0 @@ - /* check size of arguments (in this case we only expect one int - value)*/ - mtapi_status_t status; - if (arg_size != sizeof(int)) { - printf("wrong size of arguments\n"); - mtapi_context_status_set(task_context, MTAPI_ERR_ARG_SIZE, &status); - MTAPI_CHECK_STATUS(status); - return; - } - - /* cast arguments to the desired type */ - int n = *(int*)args; diff --git a/doc/examples_raw/mtapi/mtapi_c_validate_result_buffer-snippet.h b/doc/examples_raw/mtapi/mtapi_c_validate_result_buffer-snippet.h deleted file mode 100644 index 24e7630..0000000 --- a/doc/examples_raw/mtapi/mtapi_c_validate_result_buffer-snippet.h +++ /dev/null @@ -1,21 +0,0 @@ - /* if the caller is not interested in results, result_buffer may be - MTAPI_NULL. Of course, this depends on the application */ - int* result = MTAPI_NULL; - if (result_buffer == MTAPI_NULL) { - mtapi_context_status_set( - task_context, MTAPI_ERR_RESULT_SIZE, &status); - MTAPI_CHECK_STATUS(status); - } else { - /* if results are expected by the caller, check result buffer - size... */ - if (result_buffer_size == sizeof(int)) { - /* ... and cast the result buffer */ - result = (int*)result_buffer; - } else { - printf("wrong size of result buffer\n"); - mtapi_context_status_set( - task_context, MTAPI_ERR_RESULT_SIZE, &status); - MTAPI_CHECK_STATUS(status); - return; - } - } diff --git a/doc/examples_raw/mtapi/mtapi_c_wait_task-snippet.h b/doc/examples_raw/mtapi/mtapi_c_wait_task-snippet.h deleted file mode 100644 index 8c3e348..0000000 --- a/doc/examples_raw/mtapi/mtapi_c_wait_task-snippet.h +++ /dev/null @@ -1,2 +0,0 @@ - mtapi_task_wait(task, MTAPI_INFINITE, &status); - MTAPI_CHECK_STATUS(status); diff --git a/doc/examples_raw/mtapi/mtapi_check_status-snippet.h b/doc/examples_raw/mtapi/mtapi_check_status-snippet.h deleted file mode 100644 index bf1d1d3..0000000 --- a/doc/examples_raw/mtapi/mtapi_check_status-snippet.h +++ /dev/null @@ -1,8 +0,0 @@ -#include -#include -#include -#define MTAPI_CHECK_STATUS(status) \ -if (MTAPI_SUCCESS != status) { \ - printf("...error %d\n\n", status); \ - exit(status); \ -} diff --git a/doc/examples_raw/mtapi/mtapi_cpp-fragmented.cc b/doc/examples_raw/mtapi/mtapi_cpp-fragmented.cc deleted file mode 100644 index d211fd9..0000000 --- a/doc/examples_raw/mtapi/mtapi_cpp-fragmented.cc +++ /dev/null @@ -1,67 +0,0 @@ -/* - * Copyright (c) 2014-2015, Siemens AG. All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are met: - * - * 1. Redistributions of source code must retain the above copyright notice, - * this list of conditions and the following disclaimer. - * - * 2. Redistributions in binary form must reproduce the above copyright notice, - * this list of conditions and the following disclaimer in the documentation - * and/or other materials provided with the distribution. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" - * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE - * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR - * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF - * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS - * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN - * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) - * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE - * POSSIBILITY OF SUCH DAMAGE. - */ - -#include - -#include - -#include "mtapi/mtapi_check_status-snippet.h" -#include "mtapi/mtapi_cpp_domain_node_id-snippet.h" - -static -#include "mtapi/mtapi_c_action_signature-snippet.h" -#include "mtapi/mtapi_c_validate_arguments-snippet.h" -#include "mtapi/mtapi_c_validate_result_buffer-snippet.h" - /* get the node instance */ -#include "mtapi/mtapi_cpp_get_node-snippet.h" - /* calculate */ -#include "mtapi/mtapi_terminating_condition-snippet.h" - /* first recursive call spawned as task (x = fib(n - 1);) */ -#include "mtapi/mtapi_cpp_calc_task-snippet.h" - /* second recursive call can be called directly (y = fib(n - 2);) */ -#include "mtapi/mtapi_c_calc_direct-snippet.h" - /* wait for completion */ -#include "mtapi/mtapi_cpp_wait_task-snippet.h" - /* add the two preceding numbers */ -#include "mtapi/mtapi_write_back-snippet.h" - -static -int fibonacci(int n) { -#include "mtapi/mtapi_cpp_initialize-snippet.h" -#include "mtapi/mtapi_cpp_register_action-snippet.h" -#include "mtapi/mtapi_cpp_get_node-snippet.h" - /* start calculation */ -#include "mtapi/mtapi_cpp_start_task-snippet.h" - /* wait for task completion */ - mtapi_status_t status = task.Wait(MTAPI_INFINITE); - MTAPI_CHECK_STATUS(status); -#include "mtapi/mtapi_cpp_finalize-snippet.h" - return result; -} - -void RunMTAPI_CPP() { -#include "mtapi/mtapi_cpp_main-snippet.h" -} diff --git a/doc/examples_raw/mtapi/mtapi_cpp_calc_task-snippet.h b/doc/examples_raw/mtapi/mtapi_cpp_calc_task-snippet.h deleted file mode 100644 index aad4e1e..0000000 --- a/doc/examples_raw/mtapi/mtapi_cpp_calc_task-snippet.h +++ /dev/null @@ -1,3 +0,0 @@ - int a = n - 1; - int x; - embb::mtapi::Task task = node.Start(fibonacciJob, &a, &x); diff --git a/doc/examples_raw/mtapi/mtapi_cpp_domain_node_id-snippet.h b/doc/examples_raw/mtapi/mtapi_cpp_domain_node_id-snippet.h deleted file mode 100644 index 747609d..0000000 --- a/doc/examples_raw/mtapi/mtapi_cpp_domain_node_id-snippet.h +++ /dev/null @@ -1,5 +0,0 @@ -#define THIS_DOMAIN_ID 1 -#define THIS_NODE_ID 1 - -#define FIBONACCI_JOB 1 -static embb::mtapi::Job fibonacciJob; diff --git a/doc/examples_raw/mtapi/mtapi_cpp_finalize-snippet.h b/doc/examples_raw/mtapi/mtapi_cpp_finalize-snippet.h deleted file mode 100644 index 5061b36..0000000 --- a/doc/examples_raw/mtapi/mtapi_cpp_finalize-snippet.h +++ /dev/null @@ -1,2 +0,0 @@ - /* finalize the node */ - embb::mtapi::Node::Finalize(); diff --git a/doc/examples_raw/mtapi/mtapi_cpp_get_node-snippet.h b/doc/examples_raw/mtapi/mtapi_cpp_get_node-snippet.h deleted file mode 100644 index b91d187..0000000 --- a/doc/examples_raw/mtapi/mtapi_cpp_get_node-snippet.h +++ /dev/null @@ -1 +0,0 @@ - embb::mtapi::Node& node = embb::mtapi::Node::GetInstance(); diff --git a/doc/examples_raw/mtapi/mtapi_cpp_initialize-snippet.h b/doc/examples_raw/mtapi/mtapi_cpp_initialize-snippet.h deleted file mode 100644 index 859b55a..0000000 --- a/doc/examples_raw/mtapi/mtapi_cpp_initialize-snippet.h +++ /dev/null @@ -1,2 +0,0 @@ - /* initialize the node with default attributes */ - embb::mtapi::Node::Initialize(THIS_DOMAIN_ID, THIS_NODE_ID); diff --git a/doc/examples_raw/mtapi/mtapi_cpp_main-snippet.h b/doc/examples_raw/mtapi/mtapi_cpp_main-snippet.h deleted file mode 100644 index 582850a..0000000 --- a/doc/examples_raw/mtapi/mtapi_cpp_main-snippet.h +++ /dev/null @@ -1,6 +0,0 @@ - EMBB_TRY { - int result = fibonacci(6); - std::cout << "result: " << result << std::endl; - } EMBB_CATCH(embb::mtapi::StatusException &) { - std::cout << "MTAPI error occured." << std::endl; - } diff --git a/doc/examples_raw/mtapi/mtapi_cpp_register_action-snippet.h b/doc/examples_raw/mtapi/mtapi_cpp_register_action-snippet.h deleted file mode 100644 index beeea5a..0000000 --- a/doc/examples_raw/mtapi/mtapi_cpp_register_action-snippet.h +++ /dev/null @@ -1,9 +0,0 @@ - /* create action */ - embb::mtapi::Action fibonacciAction( - FIBONACCI_JOB, /* action ID, defined by the - application */ - (fibonacciActionFunction) /* action function */ - ); - - /* get job */ - fibonacciJob = embb::mtapi::Job(FIBONACCI_JOB, THIS_DOMAIN_ID); diff --git a/doc/examples_raw/mtapi/mtapi_cpp_start_task-snippet.h b/doc/examples_raw/mtapi/mtapi_cpp_start_task-snippet.h deleted file mode 100644 index cf1f908..0000000 --- a/doc/examples_raw/mtapi/mtapi_cpp_start_task-snippet.h +++ /dev/null @@ -1,2 +0,0 @@ - int result; - embb::mtapi::Task task = node.Start(fibonacciJob, &n, &result); diff --git a/doc/examples_raw/mtapi/mtapi_cpp_wait_task-snippet.h b/doc/examples_raw/mtapi/mtapi_cpp_wait_task-snippet.h deleted file mode 100644 index 9f1f9d7..0000000 --- a/doc/examples_raw/mtapi/mtapi_cpp_wait_task-snippet.h +++ /dev/null @@ -1,5 +0,0 @@ - mtapi_status_t status = task.Wait(MTAPI_INFINITE); - if (status != MTAPI_SUCCESS) { - printf("task failed with error: %d\n\n", status); - exit(status); - } diff --git a/doc/examples_raw/mtapi/mtapi_network_c_action_function-snippet.h b/doc/examples_raw/mtapi/mtapi_network_c_action_function-snippet.h deleted file mode 100644 index 9f56102..0000000 --- a/doc/examples_raw/mtapi/mtapi_network_c_action_function-snippet.h +++ /dev/null @@ -1,20 +0,0 @@ -static void AddVectorAction( - void const * arguments, - mtapi_size_t arguments_size, - void * result_buffer, - mtapi_size_t result_buffer_size, - void const * node_local_data, - mtapi_size_t node_local_data_size, - mtapi_task_context_t * context) { - EMBB_UNUSED(context); - EMBB_UNUSED(result_buffer_size); - EMBB_UNUSED(node_local_data_size); - int elements = static_cast(arguments_size / sizeof(float) / 2); - float const * a = reinterpret_cast(arguments); - float const * b = reinterpret_cast(arguments)+elements; - float * c = reinterpret_cast(result_buffer); - float const * d = reinterpret_cast(node_local_data); - for (int ii = 0; ii < elements; ii++) { - c[ii] = a[ii] + b[ii] + d[0]; - } -} diff --git a/doc/examples_raw/mtapi/mtapi_network_c_header-snippet.h b/doc/examples_raw/mtapi/mtapi_network_c_header-snippet.h deleted file mode 100644 index c052390..0000000 --- a/doc/examples_raw/mtapi/mtapi_network_c_header-snippet.h +++ /dev/null @@ -1 +0,0 @@ -#include diff --git a/doc/examples_raw/mtapi/mtapi_network_c_local_action_create-snippet.h b/doc/examples_raw/mtapi/mtapi_network_c_local_action_create-snippet.h deleted file mode 100644 index c057151..0000000 --- a/doc/examples_raw/mtapi/mtapi_network_c_local_action_create-snippet.h +++ /dev/null @@ -1,6 +0,0 @@ - network_action = mtapi_network_action_create( - NETWORK_DOMAIN, - NETWORK_LOCAL_JOB, - NETWORK_REMOTE_JOB, - "127.0.0.1", 12345, - &status); diff --git a/doc/examples_raw/mtapi/mtapi_network_c_plugin_finalize-snippet.h b/doc/examples_raw/mtapi/mtapi_network_c_plugin_finalize-snippet.h deleted file mode 100644 index 74d49f3..0000000 --- a/doc/examples_raw/mtapi/mtapi_network_c_plugin_finalize-snippet.h +++ /dev/null @@ -1 +0,0 @@ - mtapi_network_plugin_finalize(&status); diff --git a/doc/examples_raw/mtapi/mtapi_network_c_plugin_initialize-snippet.h b/doc/examples_raw/mtapi/mtapi_network_c_plugin_initialize-snippet.h deleted file mode 100644 index b7cc83b..0000000 --- a/doc/examples_raw/mtapi/mtapi_network_c_plugin_initialize-snippet.h +++ /dev/null @@ -1,2 +0,0 @@ - mtapi_network_plugin_initialize("127.0.0.1", 12345, 5, - kElements * 4 * 3 + 32, &status); diff --git a/doc/examples_raw/mtapi/mtapi_network_c_remote_action_create-snippet.h b/doc/examples_raw/mtapi/mtapi_network_c_remote_action_create-snippet.h deleted file mode 100644 index 31fa6ac..0000000 --- a/doc/examples_raw/mtapi/mtapi_network_c_remote_action_create-snippet.h +++ /dev/null @@ -1,7 +0,0 @@ - float node_remote = 1.0f; - local_action = mtapi_action_create( - NETWORK_REMOTE_JOB, - AddVectorAction, - &node_remote, sizeof(float), - MTAPI_DEFAULT_ACTION_ATTRIBUTES, - &status); diff --git a/doc/examples_raw/mtapi/mtapi_opencl_c_action_create-snippet.h b/doc/examples_raw/mtapi/mtapi_opencl_c_action_create-snippet.h deleted file mode 100644 index c3927a4..0000000 --- a/doc/examples_raw/mtapi/mtapi_opencl_c_action_create-snippet.h +++ /dev/null @@ -1,6 +0,0 @@ - float node_local = 1.0f; - action = mtapi_opencl_action_create( - OPENCL_JOB, - kernel, "AddVector", 32, 4, - &node_local, sizeof(float), - &status); diff --git a/doc/examples_raw/mtapi/mtapi_opencl_c_header-snippet.h b/doc/examples_raw/mtapi/mtapi_opencl_c_header-snippet.h deleted file mode 100644 index 1d3a916..0000000 --- a/doc/examples_raw/mtapi/mtapi_opencl_c_header-snippet.h +++ /dev/null @@ -1 +0,0 @@ -#include diff --git a/doc/examples_raw/mtapi/mtapi_opencl_c_kernel-snippet.h b/doc/examples_raw/mtapi/mtapi_opencl_c_kernel-snippet.h deleted file mode 100644 index cfd3e99..0000000 --- a/doc/examples_raw/mtapi/mtapi_opencl_c_kernel-snippet.h +++ /dev/null @@ -1,18 +0,0 @@ -const char * kernel = -"__kernel void AddVector(\n" -" __global void* arguments,\n" -" int arguments_size,\n" -" __global void* result_buffer,\n" -" int result_buffer_size,\n" -" __global void* node_local_data,\n" -" int node_local_data_size) {\n" -" int ii = get_global_id(0);\n" -" int elements = arguments_size / sizeof(float) / 2;\n" -" if (ii >= elements)" -" return;" -" __global float* a = (__global float*)arguments;\n" -" __global float* b = ((__global float*)arguments) + elements;\n" -" __global float* c = (__global float*)result_buffer;\n" -" __global float* d = (__global float*)node_local_data;\n" -" c[ii] = a[ii] + b[ii] + d[0];\n" -"}\n"; diff --git a/doc/examples_raw/mtapi/mtapi_opencl_c_plugin_finalize-snippet.h b/doc/examples_raw/mtapi/mtapi_opencl_c_plugin_finalize-snippet.h deleted file mode 100644 index 8689937..0000000 --- a/doc/examples_raw/mtapi/mtapi_opencl_c_plugin_finalize-snippet.h +++ /dev/null @@ -1 +0,0 @@ - mtapi_opencl_plugin_finalize(&status); diff --git a/doc/examples_raw/mtapi/mtapi_opencl_c_plugin_initialize-snippet.h b/doc/examples_raw/mtapi/mtapi_opencl_c_plugin_initialize-snippet.h deleted file mode 100644 index c8106fc..0000000 --- a/doc/examples_raw/mtapi/mtapi_opencl_c_plugin_initialize-snippet.h +++ /dev/null @@ -1 +0,0 @@ - mtapi_opencl_plugin_initialize(&status); diff --git a/doc/examples_raw/mtapi/mtapi_terminating_condition-snippet.h b/doc/examples_raw/mtapi/mtapi_terminating_condition-snippet.h deleted file mode 100644 index 7112b48..0000000 --- a/doc/examples_raw/mtapi/mtapi_terminating_condition-snippet.h +++ /dev/null @@ -1,3 +0,0 @@ - if (n < 2) { - *result = n; - } else { diff --git a/doc/examples_raw/mtapi/mtapi_write_back-snippet.h b/doc/examples_raw/mtapi/mtapi_write_back-snippet.h deleted file mode 100644 index bca08c7..0000000 --- a/doc/examples_raw/mtapi/mtapi_write_back-snippet.h +++ /dev/null @@ -1,3 +0,0 @@ - *result = x + y; - } -} diff --git a/doc/examples_raw/stl_for_each/function-snippet.h b/doc/examples_raw/stl_for_each/function-snippet.h deleted file mode 100644 index d870d31..0000000 --- a/doc/examples_raw/stl_for_each/function-snippet.h +++ /dev/null @@ -1 +0,0 @@ -std::for_each(range.begin(), range.end(), &DoubleFunction); diff --git a/doc/examples_raw/stl_for_each/function_define-snippet.h b/doc/examples_raw/stl_for_each/function_define-snippet.h deleted file mode 100644 index 0bb8d2b..0000000 --- a/doc/examples_raw/stl_for_each/function_define-snippet.h +++ /dev/null @@ -1,3 +0,0 @@ -void DoubleFunction(int& to_double) { - to_double *= 2; -} diff --git a/doc/examples_raw/stl_for_each/functor-snippet.h b/doc/examples_raw/stl_for_each/functor-snippet.h deleted file mode 100644 index e282b10..0000000 --- a/doc/examples_raw/stl_for_each/functor-snippet.h +++ /dev/null @@ -1 +0,0 @@ -std::for_each(range.begin(), range.end(), DoubleFunctor()); diff --git a/doc/examples_raw/stl_for_each/functor_define-snippet.h b/doc/examples_raw/stl_for_each/functor_define-snippet.h deleted file mode 100644 index d5e34d1..0000000 --- a/doc/examples_raw/stl_for_each/functor_define-snippet.h +++ /dev/null @@ -1,5 +0,0 @@ -struct DoubleFunctor { - void operator()(int& to_double) { - to_double *= 2; - } -}; diff --git a/doc/examples_raw/stl_for_each/lambda-snippet.h b/doc/examples_raw/stl_for_each/lambda-snippet.h deleted file mode 100644 index e8c545a..0000000 --- a/doc/examples_raw/stl_for_each/lambda-snippet.h +++ /dev/null @@ -1,2 +0,0 @@ -std::for_each(range.begin(), range.end(), - [] (int& to_double) { to_double *= 2; }); diff --git a/doc/examples_raw/stl_for_each/manual-snippet.h b/doc/examples_raw/stl_for_each/manual-snippet.h deleted file mode 100644 index 22b72cc..0000000 --- a/doc/examples_raw/stl_for_each/manual-snippet.h +++ /dev/null @@ -1,3 +0,0 @@ -for (size_t i=0; i < range.size(); i++) { - range[i] *= 2; -} diff --git a/doc/examples_raw/stl_for_each/setup-snippet.h b/doc/examples_raw/stl_for_each/setup-snippet.h deleted file mode 100644 index 0e78cc8..0000000 --- a/doc/examples_raw/stl_for_each/setup-snippet.h +++ /dev/null @@ -1,4 +0,0 @@ -std::vector range(5); -for (size_t i=0; i < range.size(); i++) { - range[i] = static_cast(i) + 1; -} diff --git a/doc/examples_raw/stl_for_each/stl_for_each-fragmented.cc b/doc/examples_raw/stl_for_each/stl_for_each-fragmented.cc deleted file mode 100644 index ecff00b..0000000 --- a/doc/examples_raw/stl_for_each/stl_for_each-fragmented.cc +++ /dev/null @@ -1,75 +0,0 @@ -/* - * Copyright (c) 2014-2015, Siemens AG. All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are met: - * - * 1. Redistributions of source code must retain the above copyright notice, - * this list of conditions and the following disclaimer. - * - * 2. Redistributions in binary form must reproduce the above copyright notice, - * this list of conditions and the following disclaimer in the documentation - * and/or other materials provided with the distribution. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" - * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE - * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR - * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF - * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS - * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN - * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) - * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE - * POSSIBILITY OF SUCH DAMAGE. - */ - -#include -#include -#include -#include - -#include "stl_for_each/function_define-snippet.h" - -#include "stl_for_each/functor_define-snippet.h" - -static void CheckResults(const std::vector& range) { - int i = 1; - for (const int& value : range) { - assert(value == i * 2); - EMBB_UNUSED_IN_RELEASE(value); - i++; - } -} - -/** - * Example using embb::patterns::ForEach. - * - * Traversing and modifying a sequence with a for-each loop. - */ - -void RunSTLForEach() { - { - #include "stl_for_each/setup-snippet.h" - #include "stl_for_each/manual-snippet.h" - CheckResults(range); - } - - { - #include "stl_for_each/setup-snippet.h" - #include "stl_for_each/function-snippet.h" - CheckResults(range); - } - - { - #include "stl_for_each/setup-snippet.h" - #include "stl_for_each/functor-snippet.h" - CheckResults(range); - } - - { - #include "stl_for_each/setup-snippet.h" - #include "stl_for_each/lambda-snippet.h" - CheckResults(range); - } -} diff --git a/doc/examples_raw/tasks/tasks_cpp-fragmented.cc b/doc/examples_raw/tasks/tasks_cpp-fragmented.cc deleted file mode 100644 index 4e13885..0000000 --- a/doc/examples_raw/tasks/tasks_cpp-fragmented.cc +++ /dev/null @@ -1,64 +0,0 @@ -/* - * Copyright (c) 2014-2015, Siemens AG. All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are met: - * - * 1. Redistributions of source code must retain the above copyright notice, - * this list of conditions and the following disclaimer. - * - * 2. Redistributions in binary form must reproduce the above copyright notice, - * this list of conditions and the following disclaimer in the documentation - * and/or other materials provided with the distribution. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" - * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE - * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR - * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF - * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS - * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN - * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) - * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE - * POSSIBILITY OF SUCH DAMAGE. - */ - -#include - -#include - -#include "mtapi/mtapi_check_status-snippet.h" - -static -#include "tasks/tasks_cpp_action_signature-snippet.h" - /* get the node instance */ -#include "tasks/tasks_cpp_get_node-snippet.h" - /* calculate */ -#include "mtapi/mtapi_terminating_condition-snippet.h" - /* first recursive call spawned as task (x = fib(n - 1);) */ -#include "tasks/tasks_cpp_calc_task-snippet.h" - /* second recursive call can be called directly (y = fib(n - 2);) */ -#include "tasks/tasks_cpp_calc_direct-snippet.h" - /* wait for completion */ -#include "tasks/tasks_cpp_wait_task-snippet.h" - /* add the two preceeding numbers */ -#include "mtapi/mtapi_write_back-snippet.h" - -static -int fibonacci(int n) { - /* get the node instance, the node is initialized automatically */ - embb::tasks::Node& node = embb::tasks::Node::GetInstance(); - /* start calculation */ -#include "tasks/tasks_cpp_start_task-snippet.h" - /* wait for task completion */ - mtapi_status_t status = task.Wait(MTAPI_INFINITE); - MTAPI_CHECK_STATUS(status); - - return result; -} - -void RunTasks() { - int result = fibonacci(6); - std::cout << "result: " << result << std::endl; -} diff --git a/doc/examples_raw/tasks/tasks_cpp_action_signature-snippet.h b/doc/examples_raw/tasks/tasks_cpp_action_signature-snippet.h deleted file mode 100644 index 24aa989..0000000 --- a/doc/examples_raw/tasks/tasks_cpp_action_signature-snippet.h +++ /dev/null @@ -1,5 +0,0 @@ -void fibonacciActionFunction( - int n, - int* result, - embb::tasks::TaskContext & task_context - ) { diff --git a/doc/examples_raw/tasks/tasks_cpp_calc_direct-snippet.h b/doc/examples_raw/tasks/tasks_cpp_calc_direct-snippet.h deleted file mode 100644 index eb08e75..0000000 --- a/doc/examples_raw/tasks/tasks_cpp_calc_direct-snippet.h +++ /dev/null @@ -1,6 +0,0 @@ - int b = n - 2; - int y; - fibonacciActionFunction( - b, - &y, - task_context); diff --git a/doc/examples_raw/tasks/tasks_cpp_calc_task-snippet.h b/doc/examples_raw/tasks/tasks_cpp_calc_task-snippet.h deleted file mode 100644 index cfe5664..0000000 --- a/doc/examples_raw/tasks/tasks_cpp_calc_task-snippet.h +++ /dev/null @@ -1,10 +0,0 @@ - int a = n - 1; - int x; - embb::tasks::Task task = node.Spawn( - embb::base::Bind( - embb::base::MakeFunction(fibonacciActionFunction), - a, /* argument */ - &x, /* result */ - embb::base::Placeholder::_1 - ) - ); diff --git a/doc/examples_raw/tasks/tasks_cpp_get_node-snippet.h b/doc/examples_raw/tasks/tasks_cpp_get_node-snippet.h deleted file mode 100644 index f644ec5..0000000 --- a/doc/examples_raw/tasks/tasks_cpp_get_node-snippet.h +++ /dev/null @@ -1 +0,0 @@ - embb::tasks::Node& node = embb::tasks::Node::GetInstance(); diff --git a/doc/examples_raw/tasks/tasks_cpp_start_task-snippet.h b/doc/examples_raw/tasks/tasks_cpp_start_task-snippet.h deleted file mode 100644 index 507e634..0000000 --- a/doc/examples_raw/tasks/tasks_cpp_start_task-snippet.h +++ /dev/null @@ -1,9 +0,0 @@ - int result; - embb::tasks::Task task = node.Spawn( - embb::base::Bind( - embb::base::MakeFunction(fibonacciActionFunction), - n, - &result, - embb::base::Placeholder::_1 - ) - ); diff --git a/doc/examples_raw/tasks/tasks_cpp_wait_task-snippet.h b/doc/examples_raw/tasks/tasks_cpp_wait_task-snippet.h deleted file mode 100644 index 21637fd..0000000 --- a/doc/examples_raw/tasks/tasks_cpp_wait_task-snippet.h +++ /dev/null @@ -1,2 +0,0 @@ - mtapi_status_t status = task.Wait(MTAPI_INFINITE); - MTAPI_CHECK_STATUS(status); diff --git a/doc/tutorial/content/algorithms.tex b/doc/tutorial/content/algorithms.tex index 64eec17..14bff9f 100644 --- a/doc/tutorial/content/algorithms.tex +++ b/doc/tutorial/content/algorithms.tex @@ -13,21 +13,21 @@ In the following, we look at parallel function invocation (Section~\ref{sec:algo %In the previous section, we have considered data parallelism, that is, parallel execution of the same operation on a range of elements. Next, we consider parallel execution of several work packages encapsulated in functions. Let us start with the parallel execution of several work packages encapsulated in functions. Suppose that the following functions operate on different data sets, and thus are independent of each other: % -\\\inputlisting{../examples_raw/algorithms/invoke/packages-snippet.h} +\\\inputlisting{../examples/algorithms/invoke/packages-snippet.h} % The functions can be executed in parallel using the \lstinline|ParallelInvoke| construct provided by {\embb}: % -\\\inputlisting{../examples_raw/algorithms/invoke/invocation-snippet.h} +\\\inputlisting{../examples/algorithms/invoke/invocation-snippet.h} % Note that \lstinline|ParallelInvoke| waits until all its arguments have finished execution. Next, let us consider a more elaborate example. The following piece of code shows a serial quick sort algorithm which we want to parallelize (do not care about the details of the \lstinline|Partition| function for the moment): % -\\\inputlisting{../examples_raw/algorithms/invoke/quick_sort-snippet.h} +\\\inputlisting{../examples/algorithms/invoke/quick_sort-snippet.h} % A straightforward approach to parallelize this algorithm is to execute the recursive calls to \lstinline|Quicksort| in parallel. With \lstinline|ParallelInvoke| and lambdas, it is as simple as that: % -\\\inputlisting{../examples_raw/algorithms/invoke/parallel_quick_sort-snippet.h} +\\\inputlisting{../examples/algorithms/invoke/parallel_quick_sort-snippet.h} % The lambdas capture the \lstinline|first|, \lstinline|mid|, and \lstinline|last| pointers to the range to be sorted and forward them to the recursive calls of quick sort. These are executed in parallel, where \lstinline|Invoke| does not return before both have finished execution. The above implementation of parallel quick sort is of course not yet optimal. In particular, the creation of new tasks should be stopped when a certain lower bound on the size of the subranges has been reached. The subranges can then be sorted sequentially in order to reduce the overhead for task creation and management. Fortunately, {\embb} already provides solutions for parallel sorting, which will be covered in the following section. @@ -37,19 +37,19 @@ The lambdas capture the \lstinline|first|, \lstinline|mid|, and \lstinline|last| %As sorting is a prominent problem that can benefit from multicore processors, {\embb} provides ready-to-use algorithms for parallel sorting. For systems with constraints on memory consumption, the quick sort algorithm provided by \embb is usually the best choice, since it works in-place which means that it does not require additional memory. Considering real-time systems, however, its worst-case runtime of $O(N^2)$, where $N$ is the number of elements to be sorted, can be a problem. For this reason, {\embb} also provides a parallel merge sort algorithm. Merge sort does not work in-place, but has a predictable runtime complexity of $\Theta(N \log N)$. Assume we want to sort a vector of integers: % -\\\inputlisting{../examples_raw/algorithms/sorting/range_define-snippet.h} +\\\inputlisting{../examples/algorithms/sorting/range_define-snippet.h} % Using quick sort, we simply write: % -\\\inputlisting{../examples_raw/algorithms/sorting/quick_sort-snippet.h} +\\\inputlisting{../examples/algorithms/sorting/quick_sort-snippet.h} % The default invocation of \lstinline|QuickSort| uses \lstinline|std::less| with the iterators' \lstinline|value_type| as comparison operation. As a result, the range is sorted in ascending order. It is possible to provide a custom comparison operation, for example \lstinline|std::greater|, by passing it as a function object to the algorithm. Sorting the elements in descending can be accomplished as follows: % -\\\inputlisting{../examples_raw/algorithms/sorting/quick_sort_custom_compare-snippet.h} +\\\inputlisting{../examples/algorithms/sorting/quick_sort_custom_compare-snippet.h} The merge sort algorithm comes in two versions. The first version automatically allocates dynamic memory for temporary values when the algorithm is called. Its name is \lstinline|MergeSortAllocate| and it has the same parameters as \lstinline|QuickSort|. To enable the use of merge sort in environments that forbid dynamic memory allocation after initialization, the second version can be called with a pre-allocated temporary range of values: % -\\\inputlisting{../examples_raw/algorithms/sorting/merge_sort_preallocated-snippet.h} +\\\inputlisting{../examples/algorithms/sorting/merge_sort_preallocated-snippet.h} % The temporary range can be allocated at any time, e.g., during the initialization phase of the system. @@ -59,33 +59,33 @@ The temporary range can be allocated at any time, e.g., during the initializatio %Related to the above described summation reductions are the so-called counting operations. \embb also provides functions for counting the number of elements in a range. Consider a range of integers from 0 to 3: % -\\\inputlisting{../examples_raw/algorithms/counting/setup-snippet.h} +\\\inputlisting{../examples/algorithms/counting/setup-snippet.h} % To determine how often a specific value appears within the range, we could simply iterate over it and compare each element with the specified one. The \lstinline|Count| function does this in parallel, where the first two arguments specify the range and the third one the element to be counted: %have to go through each of them, perform a comparison, and count the elements that compare equal. As in the reduction, the problem here is that a global counter is involved. The counting with equal comparison can be realized using the \lstinline|Count| function as % -\\\inputlisting{../examples_raw/algorithms/counting/count-snippet.h} +\\\inputlisting{../examples/algorithms/counting/count-snippet.h} % For the range given above, we have \lstinline|count == 2|. In case the comparison operation is not equality, we can employ the \lstinline|CountIf| function. Here, the third argument is a unary predicate which evaluates to \lstinline|true| for each element to be counted. The following example shows how to count the number of values greater than 0: % -\\\inputlisting{../examples_raw/algorithms/counting/count_if-snippet.h} +\\\inputlisting{../examples/algorithms/counting/count_if-snippet.h} \section{Foreach Loops} \label{sec:algorithms_foreach} A frequently encountered task in parallel programming is to apply some operation on a range of values, as illustrated in the example of Section~\ref{sec:introduction_function_objects}. In principle, one could apply the operation to all elements in parallel provided that there are no data dependencies. However, this results in unnecessary overhead if the number of elements is greater than the number of available processor cores $p$. A better solution is to partition the range into $p$ blocks and to process the elements of a block sequentially. With the \lstinline|ForEach| construct provided by \embb, users do not have to care about the partitioning, since this is done automatically. Similar to the Standard Library's \lstinline|for_each| function, it is sufficient to pass the operation in form of a function object. The following piece of code shows how to implement the example of Section~\ref{sec:introduction_function_objects} using \embb: % -\\\inputlisting{../examples_raw/algorithms/for_each/doubling-snippet.h} +\\\inputlisting{../examples/algorithms/for_each/doubling-snippet.h} In the above code snippet, the results of the computation overwrite the input. If the input has to be left unchanged, the results must be written to a separate output range. Thus, the operation requires two ranges. {\embb} supports such scenarios by the \lstinline|ZipIterator|, which wraps two iterators into one. Consider the following revised example for doubling the elements of a vector: % -\\\inputlisting{../examples_raw/algorithms/for_each/setup_zip-snippet.h} +\\\inputlisting{../examples/algorithms/for_each/setup_zip-snippet.h} % Using the \lstinline|Zip| function as convenient way to create a zip iterator, the doubling can be performed as follows: % -\\\inputlisting{../examples_raw/algorithms/for_each/doubling_zip-snippet.h} +\\\inputlisting{../examples/algorithms/for_each/doubling_zip-snippet.h} % The argument to the lambda function is a \lstinline|ZipPair| with the iterators' reference value as template parameters. The elements pointed to by the zip iterator can be accessed via \lstinline|First()| and \lstinline|Second()|, similar to \lstinline|std::pair|. @@ -94,25 +94,25 @@ The argument to the lambda function is a \lstinline|ZipPair| with the iterators' As mentioned in the previous section, the \lstinline|ForEach| construct requires the loop iterations do be independent of each other. However, this is not always the case. Imagine we want to sum up the values of a range, e.g., a vector of integers: % -\\\inputlisting{../examples_raw/algorithms/reduce/range_init-snippet.h} +\\\inputlisting{../examples/algorithms/reduce/range_init-snippet.h} % Sequentially, this can be done by a simple loop: % -\\\inputlisting{../examples_raw/algorithms/reduce/sequential-snippet.h} +\\\inputlisting{../examples/algorithms/reduce/sequential-snippet.h} % One might be tempted to sum up the elements in parallel using a foreach loop. The problem is that parallel accesses to \lstinline|sum| must be synchronized to avoid race conditions, which in fact sequentializes the loop. A more efficient approach is to compute intermediate sums for each block of the range and to sum them up at the end. For such purposes, {\embb} provides the function \lstinline|Reduce|: % -\\\inputlisting{../examples_raw/algorithms/reduce/parallel-snippet.h} +\\\inputlisting{../examples/algorithms/reduce/parallel-snippet.h} % The third argument to \lstinline|Reduce| is the neutral element of the reduction operation, i.e., the element that does not change the result. In case of addition (\lstinline|std::plus|), the neutral element is 0. If we wanted to compute the product of the vector elements, the neutral element would be 1. Next, let us consider the parallel computation of a dot product. Given two input ranges, we want to multiply each pair of input elements and sum up the products. The second input range is given as follows: % -\\\inputlisting{../examples_raw/algorithms/reduce/second_range_init-snippet.h} +\\\inputlisting{../examples/algorithms/reduce/second_range_init-snippet.h} % The reduction consists of two steps: First, the input ranges are transformed and then, the reduction is performed on the transformed range. For that purpose, the \lstinline|Reduce| function allows to specify a transformation function object. By default, this is the identity functor which does not modify the input range. To implement the dot product, we can use the \lstinline|Zip| function (see Section~\ref{sec:algorithms_foreach}) and a lambda function for computing the transformed range: % -\\\inputlisting{../examples_raw/algorithms/reduce/dot_product-snippet.h} +\\\inputlisting{../examples/algorithms/reduce/dot_product-snippet.h} \section{Prefix Computations} \label{sec:algorithms_prefix} @@ -128,14 +128,14 @@ y_n &=& y_{n-1} \cdot x_n \end{eqnarray*} where $id$ is the identity (neutral element) with respect to the operation $(\cdot): X \times X \rightarrow Y$. As an example, consider the following range: % -\\\inputlisting{../examples_raw/algorithms/scan/setup-snippet.h} +\\\inputlisting{../examples/algorithms/scan/setup-snippet.h} % Computing the prefix sums of \lstinline|input_range| sequentially is easy: % -\\\inputlisting{../examples_raw/algorithms/scan/sequential_prefix_sum-snippet.h} +\\\inputlisting{../examples/algorithms/scan/sequential_prefix_sum-snippet.h} % Note the dependency on loop iteration $i-1$ to compute the result in iteration $i$. A special two-pass algorithm is used in the {\embb} function \lstinline|Scan| to perform prefix computations in parallel. Using \lstinline|Scan| to compute the prefix sums, we get: % -\\\inputlisting{../examples_raw/algorithms/scan/prefix_sum-snippet.h} +\\\inputlisting{../examples/algorithms/scan/prefix_sum-snippet.h} % As in the case of reductions, the neutral element has to be given explicitly. Also, a transformation function can be passed as additional argument to \lstinline|Scan|. The elements of the input range are then transformed before given to the prefix operation. \ No newline at end of file diff --git a/doc/tutorial/content/containers.tex b/doc/tutorial/content/containers.tex index 7ecb36e..5cdc0ce 100644 --- a/doc/tutorial/content/containers.tex +++ b/doc/tutorial/content/containers.tex @@ -15,12 +15,12 @@ An object pool allocates a fixed number of objects at construction. Objects can Listing~\ref{lst:object_pool_lst1} shows an example, where we create in Line~\ref{lst:object_pool_lst1:line_create} an object pool with five objects of type \lstinline|int|. If nothing else is specified, the object-pool uses a wait-free implementation. Then, we allocate five objects from the object pool and store the obtained pointers in a temporary array. The actual allocation takes place in Line~\ref{lst:object_pool_lst1:line_allocate}. After that, we deallocate them in the second loop be calling \lstinline|FreeObject| on each pointer (see Line~\ref{lst:object_pool_lst1:line_free}). \lstinputlisting[caption={Object pool -- initialization, allocation and -deallocation},label={lst:object_pool_lst1}]{../examples_raw/containers/object_pool-snippet.h} +deallocation},label={lst:object_pool_lst1}]{../examples/containers/object_pool-snippet.h} For actually allocating and deallocating objects, the object pool's implementation relies on a value pool which keeps track of the objects in use. If the value pool is implemented in a lock-free manner, the object pool is lock-free as well (analogously for wait-free pools). Currently, \embb provides two value pools: \lstinline|WaitFreeArrayValuePool| and \lstinline|LockFreeTreeValuePool|. Normally (if nothing is specified), the wait-free pool is used. For having a lock-free object pool instead, one has to specify the corresponding value pool to use as additional template parameter. If we replace Line~\ref{lst:object_pool_lst1:line_create} of the previous example with the following lines, the object pool is not wait-free anymore but lock-free (the values are of type \lstinline|int| and initialized to \lstinline|0|): % -\lstinputlisting{../examples_raw/containers/object_pool_2-snippet.h} +\lstinputlisting{../examples/containers/object_pool_2-snippet.h} % This will result in a speed-up for most applications, but progress guarantees are weaker. @@ -30,7 +30,7 @@ This will result in a speed-up for most applications, but progress guarantees ar As the name indicates, the class template \lstinline|LockFreeStack| implements a lock-free stack which stores elements according to the LIFO (Last-In, First-Out) principle. Listing~\ref{lst:stack_lst1} shows a simple example. In Line~\ref{lst:stack_lst1:line_create}, we create a stack of integers with a capacity of 10 elements.\footnote{Due to the necessary over-provisioning of memory in thread-safe memory management, the stack might be able to hold more than 10 elements, but is guaranteed to be able to hold at least 10 elements.} The stack provides two methods, \lstinline|TryPush| and \lstinline|TryPop|, both returning a Boolean value indicating success of the operation: \lstinline|TryPop| returns \lstinline|false| if the stack is empty, and \lstinline|TryPush| returns false if the stack is full. \lstinline|TryPop| returns the element removed from the stack via reference. \lstinputlisting[caption={Stack -- initialization, push and -pop},label={lst:stack_lst1}]{../examples_raw/containers/stack-snippet.h} +pop},label={lst:stack_lst1}]{../examples/containers/stack-snippet.h} In Line~\ref{lst:stack_lst1:fail_pop} of Listing~\ref{lst:stack_lst1}, we try to pop an element from the empty stack, which has to fail. In the for-loop in Line \ref{lst:stack_lst1:loop1}, we fill the stack with \lstinline|int| values 0 $\ldots$ 4. Afterwards, in the loop in Line~\ref{lst:stack_lst1:loop2}, we pop five values (Line~\ref{lst:stack_lst1:pop}) from the stack into variable \lstinline|j|. According to the LIFO semantics, the values are popped in reverse order, i.e., we get the sequence 4 $\ldots$ 0. This is checked by the assertion in Line~\ref{lst:stack_lst1:assert}. @@ -41,6 +41,6 @@ There are two FIFO (First-In, First-Out) queue implementations in \embb, \lstinl Listing~\ref{lst:queue_lst1} shows an example for the \lstinline|LockFreeMPMCQueue|. In Line~\ref{lst:queue_lst1:line_create}, we create a queue with element type \lstinline|int| and a capacity of 10 elements.\footnote{As in case of stacks, the queue may actually hold more than 10 elements.} The Boolean return value of the methods \lstinline|TryEnqueue| and \lstinline|TryDequeue| indicates success (\lstinline|false| if the queue is full or empty, respectively). -\lstinputlisting[caption={Queue -- initialization, enqueue and dequeue},label={lst:queue_lst1}]{../examples_raw/containers/queues-snippet.h} +\lstinputlisting[caption={Queue -- initialization, enqueue and dequeue},label={lst:queue_lst1}]{../examples/containers/queues-snippet.h} In Line~\ref{lst:queue_lst1:fail_pop} of Listing~\ref{lst:queue_lst1}, we try to dequeue an element from the empty queue, which has to fail. In the for-loop in Line~\ref{lst:queue_lst1:loop1}, we fill the queue with \lstinline|int| values 0 $\ldots$ 4. Afterwards, in the loop in Line~\ref{lst:queue_lst1:loop2}, we dequeue five values (Line~\ref{lst:queue_lst1:pop}) from the queue into variable \lstinline|j|. According to the FIFO semantics, the values are dequeued in the same order as they were enqueued, i.e., we get the sequence 0 $\ldots$ 4. This is checked by the assertion in Line~\ref{lst:queue_lst1:assert}. diff --git a/doc/tutorial/content/dataflow.tex b/doc/tutorial/content/dataflow.tex index 626ffaa..e7a07a1 100644 --- a/doc/tutorial/content/dataflow.tex +++ b/doc/tutorial/content/dataflow.tex @@ -100,21 +100,21 @@ To run this program on a multicore processor, we may execute the above steps in This pipeline can be easily implemented using the Dataflow building block. As the first step, we have to include the \lstinline|dataflow.h| header file: % -\\\inputlisting{../examples_raw/dataflow/dataflow_include-snippet.h} +\\\inputlisting{../examples/dataflow/dataflow_include-snippet.h} % Then, we have to construct a \emph{network}. A network consists of a set of processes that are connected by communication channels. %\footnote{Pipelines belong to the most simple networks, where the processes are connected in string-like (linear) fashion.} \embb provides a class template \lstinline|Network| that can be customized to your needs. For the moment, we are using 2 as a template argument: % -\\\inputlisting{../examples_raw/dataflow/dataflow_network-snippet.h} +\\\inputlisting{../examples/dataflow/dataflow_network-snippet.h} % As the next step, we have to construct the processes shown in Figure~\ref{fig:replace_par}. The easiest way to construct a process is to wrap the user-defined code in a lambda function and to pass it to the network. The network constructs an object for that process and executes the lambda function whenever new data is available. There are several methods for constructing processes depending on their type. The process \textbf{read} is a \emph{source} process, since it produces data (by reading it from the specified file) but does not consume any data. Source processes are constructed from a function object % -\\\inputlisting{../examples_raw/dataflow/dataflow_source_function-snippet.h} +\\\inputlisting{../examples/dataflow/dataflow_source_function-snippet.h} % like this: % -\\\inputlisting{../examples_raw/dataflow/dataflow_declare_source-snippet.h} +\\\inputlisting{../examples/dataflow/dataflow_declare_source-snippet.h} % %There are a couple of things to mention here. Firstly, Note the template argument \lstinline|string| to \lstinline|Source|. This tells \embb that the process has exactly one \emph{port} of type \lstinline|string| and that this port is used to transmit data to other processes. The user-defined code can access the ports via the parameters of the function. Thus, each parameter corresponds to exactly one port. In our example, the result of the process is stored in a variable \lstinline|str|, which is passed by reference. @@ -122,21 +122,21 @@ Note the template argument \lstinline|string| to \lstinline|Source|. This tells The replacement of the strings can be done by a \emph{parallel} process, which means that multiple invocations of the process may be executed simultaneously. In general, processes that neither have any side effects nor maintain a state can safely be executed in parallel. This helps to avoid bottlenecks that arise when some processes are faster than others. Suppose, for example, that \textbf{replace} requires up to 50 ms to execute, whereas \textbf{read} and \textbf{write} each requires 10 ms to execute. If only one invocation of \textbf{replace} could be executed at a time, the throughput would be at most 20 elements per second. Since \textbf{replace} is a parallel process, however, the network may start a new invocation every 10 ms. Hence, up to five invocations may be executed in parallel, yielding a throughput of 100 elements per second. To compensate for variations in the runtime of parallel stages, \embb may execute them \emph{out-of-order}. As a result, the order in which the elements of a stream enter and leave parallel stages is not necessarily preserved. In our example, the runtime of \textbf{replace} may vary significantly due to the fact that not all lines have the same length and that the number of replacements depends on the content. However, let us now return to our example. The \textbf{replace} process is constructed from the function % -\\\inputlisting{../examples_raw/dataflow/dataflow_replace_function-snippet.h} +\\\inputlisting{../examples/dataflow/dataflow_replace_function-snippet.h} % like this: % -\\\inputlisting{../examples_raw/dataflow/dataflow_declare_replace-snippet.h} +\\\inputlisting{../examples/dataflow/dataflow_declare_replace-snippet.h} % The template parameter \lstinline|Network::Inputs| specifies that the process has one port serving as input. Analogously, \lstinline|Network::Outputs| specifies that there is one port serving as output. Since the last process (\textbf{write}) does not have any outputs, we make it a \emph{Sink}. Unlike parallel processes, sinks are always executed \emph{in-order}. \embb takes care that the elements are automatically reordered according to their original order in the stream. In this way, the externally visible behavior is preserved even if some parallel stages may be executed out-of-order. The function % -\\\inputlisting{../examples_raw/dataflow/dataflow_sink_function-snippet.h} +\\\inputlisting{../examples/dataflow/dataflow_sink_function-snippet.h} % is used to construct the sink: % -\\\inputlisting{../examples_raw/dataflow/dataflow_declare_sink-snippet.h} +\\\inputlisting{../examples/dataflow/dataflow_declare_sink-snippet.h} % %In order to avoid that the received string is overwritten accidentally, the parameter \lstinline|str| corresponding to the input port of \lstinline|write| must be constant.\\ @@ -144,16 +144,16 @@ is used to construct the sink: The network needs to know about the source declared above, so we add it to our network: % -\\\inputlisting{../examples_raw/dataflow/dataflow_add-snippet.h} +\\\inputlisting{../examples/dataflow/dataflow_add-snippet.h} % As the last step, we have to connect the processes (ports). This is straightforward using the C++ stream operator: % -\\\inputlisting{../examples_raw/dataflow/dataflow_connect-snippet.h} +\\\inputlisting{../examples/dataflow/dataflow_connect-snippet.h} % Once all connections have been established, we can start the network: % -\\\inputlisting{../examples_raw/dataflow/dataflow_run-snippet.h} +\\\inputlisting{../examples/dataflow/dataflow_run-snippet.h} % The integer given as a template parameter to the network specifies the maximum number of elements that can be in the network at a time. The number of elements is limited to avoid that the network is flooded with new elements before the previous elements have been processed. In a linear pipeline, for example, this may happen if the source is faster than the sink. In our example, at most four elements may be processed simultaneously: one in the source, one in the sink, and two in the middle stage (see above). Finding an optimal value depends on the application and usually requires some experimentation. In general, large values boost the throughput but also increase the latency. Conversely, small values reduce the latency but may lead to a drop of performance in terms of throughput. @@ -295,7 +295,7 @@ Let us now consider the implementation of the sorting network using \embb. As in The following Listing shows the implementation of the source processes using classes instead of functions.\footnote{For the sake of brevity, we omit the functionality. A complete implementation can be found in the examples directory.} % -\\\inputlisting{../examples_raw/dataflow/dataflow_producer-snippet.h} +\\\inputlisting{../examples/dataflow/dataflow_producer-snippet.h} % %In order to use an instance of a class as a process, it must be derived from one of the predfined base classes. The class-based approach has several advantages besides the use of templates: Firstly, the creation of multiple processes is straightforward. Secondly, one can derive other processes from a given base class such as \lstinline|Producer|. Thirdly, it eases migration of existing code. For example, if you want to use an object of an existing class \lstinline|foo| as a process, you might derive a class \lstinline|bar| from \lstinline|foo|. The function operator of \lstinline|bar| then has access to the members provided by \lstinline|foo|. @@ -305,13 +305,13 @@ Each instance of the class \lstinline|Network| maintains a list of source proces % When you create a source process using \lstinline|MakeSource|, it is automatically added to this list. Otherwise, you must explicitly add it by a call to \lstinline|Add|. For example, if we want to feed our sorting network \lstinline|nw| with streams of integer values, we may write: You must explicitly add all sources to the network by a call to \lstinline|AddSource|. For example, if we want to feed our sorting network \lstinline|nw| with four streams of integer values, we may write: % -\\\inputlisting{../examples_raw/dataflow/dataflow_declare_add_sources-snippet.h} +\\\inputlisting{../examples/dataflow/dataflow_declare_add_sources-snippet.h} % This is only necessary for source processes. All other processes are automatically found via a depth-first search starting from the source processes. The code for the comparators looks like this: % -\\\inputlisting{../examples_raw/dataflow/dataflow_comparator-snippet.h} +\\\inputlisting{../examples/dataflow/dataflow_comparator-snippet.h} % Since the comparators neither have any side effects nor maintain a state, we allow multiple invocations to be executed in parallel. % by deriving the class \lstinline|comparator| from the base class \lstinline|network<>::parallel|. @@ -331,6 +331,6 @@ Since the comparators neither have any side effects nor maintain a state, we all To check whether the resulting values are sorted, we use a single sink with four inputs: % -\\\inputlisting{../examples_raw/dataflow/dataflow_consumer-snippet.h} +\\\inputlisting{../examples/dataflow/dataflow_consumer-snippet.h} % In general, however, we could also have a sink for each output of the sorting network. There is no restriction on the number of sources and sinks a network may have. diff --git a/doc/tutorial/content/introduction.tex b/doc/tutorial/content/introduction.tex index 3130802..b98aaca 100644 --- a/doc/tutorial/content/introduction.tex +++ b/doc/tutorial/content/introduction.tex @@ -32,30 +32,30 @@ Throughout this tutorial, we will encounter C++ types which model the C++ concep Consider, for example, the transformation of an iterable range of data values. Specifically, consider a vector of integers initialized as follows: % -\\\inputlisting{../examples_raw/stl_for_each/setup-snippet.h} +\\\inputlisting{../examples/stl_for_each/setup-snippet.h} % The range consists of the values (\lstinline|1, 2, 3, 4, 5|) and we now want to double each of them. We could simply get an iterator from the container holding the range, iterate over every element, and multiply it by two: % -\\\inputlisting{../examples_raw/stl_for_each/manual-snippet.h} +\\\inputlisting{../examples/stl_for_each/manual-snippet.h} % The range then contains the values (\lstinline|2, 4, 6, 8, 10|). In order to demonstrate the concept of function objects, we are now going to use the \lstinline|std::for_each| function defined in the \lstinline|algorithm| header of the C++ Standard Library. This function accepts as argument a \lstinline|UnaryFunction|, that is, a function object which takes only one argument. In case of \lstinline|std::for_each|, the argument has to have the same type as the elements in the range, as these are passed to the unary function. In our example, the unary function's task is to double the incoming value. We could define a function for that purpose: % -\\\inputlisting{../examples_raw/stl_for_each/function_define-snippet.h} +\\\inputlisting{../examples/stl_for_each/function_define-snippet.h} % Since a function pointer models the concept of function objects, we can simply pass \lstinline|&DoubleFunction| to \lstinline|std::for_each|: % -\\\inputlisting{../examples_raw/stl_for_each/function-snippet.h} +\\\inputlisting{../examples/stl_for_each/function-snippet.h} % Another possibility is to define a functor % -\\\inputlisting{../examples_raw/stl_for_each/functor_define-snippet.h} +\\\inputlisting{../examples/stl_for_each/functor_define-snippet.h} % and to pass an instance of this class to \lstinline|std::for_each|: % -\\\inputlisting{../examples_raw/stl_for_each/functor-snippet.h} +\\\inputlisting{../examples/stl_for_each/functor-snippet.h} % Functors as well as the function pointers separate the actual implementation from its place of usage which can be useful if the functionality is needed at different places. In many cases, however, it is advantageous to have the implementation of the function object at the same place as it is used. C++11 provides lambda expressions for that purpose which make our example more concise: % -\\\inputlisting{../examples_raw/stl_for_each/lambda-snippet.h} +\\\inputlisting{../examples/stl_for_each/lambda-snippet.h} % Of course, this example is too simple to really benefit from function objects and the algorithms contained in the C++ Standard Library. However, in combination with the parallelization features provided by \embb, function objects are a helpful mechanism to boost productivity. Within this document, whenever a function object or one of its subtypes is required, one can use a function pointer, a functor, or a lambda. For simplicity, we will restrict ourselves to lambdas in subsequent examples, as they are most suitable for this kind of tutorial. diff --git a/doc/tutorial/content/mtapi.tex b/doc/tutorial/content/mtapi.tex index 67192a1..4b940ce 100644 --- a/doc/tutorial/content/mtapi.tex +++ b/doc/tutorial/content/mtapi.tex @@ -100,53 +100,53 @@ void main(void) { This algorithm can be parallelized by spawning a task for one of the recursive calls (\lstinline|fib(n - 1)|, for example). When doing this with MTAPI, an action function that represents \lstinline|fib(int n)| is needed. It has the following signature: % -\\\inputlisting{../examples_raw/mtapi/mtapi_c_action_signature-snippet.h} +\\\inputlisting{../examples/mtapi/mtapi_c_action_signature-snippet.h} % Within the action function, the arguments should be checked, since the user might supply a buffer that is too small: % -\\\inputlisting{../examples_raw/mtapi/mtapi_c_validate_arguments-snippet.h} +\\\inputlisting{../examples/mtapi/mtapi_c_validate_arguments-snippet.h} % Here, \lstinline|mtapi_context_status_set()| is used to report errors. The error code will be returned by \lstinline|mtapi_task_wait()|. Also, care has to be taken when using the result buffer. The user might not want to use the result and supply a NULL pointer or accidentally a buffer that is too small: % -\\\inputlisting{../examples_raw/mtapi/mtapi_c_validate_result_buffer-snippet.h} +\\\inputlisting{../examples/mtapi/mtapi_c_validate_result_buffer-snippet.h} % At this point, calculation of the result can commence. First, the terminating condition of the recursion is checked: % -\\\inputlisting{../examples_raw/mtapi/mtapi_terminating_condition-snippet.h} +\\\inputlisting{../examples/mtapi/mtapi_terminating_condition-snippet.h} % After that, the first part of the computation is launched as a task using \lstinline|mtapi_task_start()| (the action function is registered with the job \lstinline|FIBONACCI_JOB| in the \lstinline|fibonacci()| function and the resulting handle is stored in the global variable \lstinline|mtapi_job_hndl_t fibonacciJob|): % -\\\inputlisting{../examples_raw/mtapi/mtapi_c_calc_task-snippet.h} +\\\inputlisting{../examples/mtapi/mtapi_c_calc_task-snippet.h} % The second part can be executed directly: % -\\\inputlisting{../examples_raw/mtapi/mtapi_c_calc_direct-snippet.h} +\\\inputlisting{../examples/mtapi/mtapi_c_calc_direct-snippet.h} % Then, completion of the MTAPI task has to be waited for by calling \lstinline|mtapi_task_wait()|: % -\\\inputlisting{../examples_raw/mtapi/mtapi_c_wait_task-snippet.h} +\\\inputlisting{../examples/mtapi/mtapi_c_wait_task-snippet.h} % Finally, the results can be added and written into the result buffer: % -\\\inputlisting{../examples_raw/mtapi/mtapi_write_back-snippet.h} +\\\inputlisting{../examples/mtapi/mtapi_write_back-snippet.h} % The \lstinline|fibonacci()| function gets a bit more complicated now. The MTAPI runtime has to be initialized first by (optionally) initializing node attributes and then calling \lstinline|mtapi_initialize()|: % -\\\inputlisting{../examples_raw/mtapi/mtapi_c_initialize-snippet.h} +\\\inputlisting{../examples/mtapi/mtapi_c_initialize-snippet.h} % Then, the action function needs to be associated to a job. By calling \lstinline|mtapi_action_create()|, the action function is registered with the job \lstinline|FIBONACCI_JOB|. The job handle of this job is stored in the global variable \lstinline|mtapi_job_hndl_t fibonacciJob| so that it can be accessed by the action function later on: % -\\\inputlisting{../examples_raw/mtapi/mtapi_c_register_action-snippet.h} +\\\inputlisting{../examples/mtapi/mtapi_c_register_action-snippet.h} % Now that the action is registered with a job, the root task can be started with \lstinline|mtapi_task_start()|: % -\\\inputlisting{../examples_raw/mtapi/mtapi_c_start_task-snippet.h} +\\\inputlisting{../examples/mtapi/mtapi_c_start_task-snippet.h} % %The started task has to be waited for before the result can be returned. After everything is done, the action is deleted (\lstinline|mtapi_action_delete()|) and the runtime is shut down (\lstinline|mtapi_finalize()|): % -\\\inputlisting{../examples_raw/mtapi/mtapi_c_finalize-snippet.h} +\\\inputlisting{../examples/mtapi/mtapi_c_finalize-snippet.h} % \section{C++ Interface} @@ -154,54 +154,54 @@ After everything is done, the action is deleted (\lstinline|mtapi_action_delete( \embb provides C++ wrappers for the MTAPI C interface. The signature of the action function for the C++ interface is the same as in the C interface: % -\\\inputlisting{../examples_raw/mtapi/mtapi_c_action_signature-snippet.h} +\\\inputlisting{../examples/mtapi/mtapi_c_action_signature-snippet.h} % Checking argument and result buffer sizes is the same as in the C example. Also, the terminating condition of the recursion still needs to be checked: % -\\\inputlisting{../examples_raw/mtapi/mtapi_terminating_condition-snippet.h} +\\\inputlisting{../examples/mtapi/mtapi_terminating_condition-snippet.h} % After that, the first part of the computation is launched as an MTAPI task using \lstinline|embb::mtapi::Node::Start()| (the action function is registered with the job \lstinline|FIBONACCI_JOB| in the \lstinline|fibonacci()| function and the resulting handle is stored in the global variable \lstinline|embb::mtapi::Job fibonacciJob|): % -\\\inputlisting{../examples_raw/mtapi/mtapi_cpp_calc_task-snippet.h} +\\\inputlisting{../examples/mtapi/mtapi_cpp_calc_task-snippet.h} % The second part can be executed directly: % -\\\inputlisting{../examples_raw/mtapi/mtapi_c_calc_direct-snippet.h} +\\\inputlisting{../examples/mtapi/mtapi_c_calc_direct-snippet.h} % Then, completion of the MTAPI task has to be waited for using \lstinline|embb::mtapi::Task::Wait()|: % -\\\inputlisting{../examples_raw/mtapi/mtapi_cpp_wait_task-snippet.h} +\\\inputlisting{../examples/mtapi/mtapi_cpp_wait_task-snippet.h} % Finally, the two parts can be added and written into the result buffer: % -\\\inputlisting{../examples_raw/mtapi/mtapi_write_back-snippet.h} +\\\inputlisting{../examples/mtapi/mtapi_write_back-snippet.h} % Note that there is no need to do error checking everywhere, since errors are reported as exceptions. In this example there is only a single try/catch block in the main function: % -\\\inputlisting{../examples_raw/mtapi/mtapi_cpp_main-snippet.h} +\\\inputlisting{../examples/mtapi/mtapi_cpp_main-snippet.h} % The \lstinline|fibonacci()| function is about the same as in the C version. The MTAPI runtime needs to be initialized first: % -\\\inputlisting{../examples_raw/mtapi/mtapi_cpp_initialize-snippet.h} +\\\inputlisting{../examples/mtapi/mtapi_cpp_initialize-snippet.h} % Then the node instance can to be fetched: % -\\\inputlisting{../examples_raw/mtapi/mtapi_cpp_get_node-snippet.h} +\\\inputlisting{../examples/mtapi/mtapi_cpp_get_node-snippet.h} % After that, the action function needs to be associated to a job. By instancing an \lstinline|embb::mtap::Action| object, the action function is registered with the job \lstinline|FIBONACCI_JOB|. The job is stored in the global variable \lstinline|embb::mtapi::Job fibonacciJob| so that it can be accessed by the action function later on: % -\\\inputlisting{../examples_raw/mtapi/mtapi_cpp_register_action-snippet.h} +\\\inputlisting{../examples/mtapi/mtapi_cpp_register_action-snippet.h} % Not that the action is registered and the job is initialized, the root task can be started: % -\\\inputlisting{../examples_raw/mtapi/mtapi_cpp_start_task-snippet.h} +\\\inputlisting{../examples/mtapi/mtapi_cpp_start_task-snippet.h} % Again, the started task has to be waited for (using \lstinline|embb::mtapi::Task::Wait()|) before the result can be returned. The registered action will be unregistered when it goes out of scope. The runtime needs to be shut down by calling: -\\\inputlisting{../examples_raw/mtapi/mtapi_cpp_finalize-snippet.h} +\\\inputlisting{../examples/mtapi/mtapi_cpp_finalize-snippet.h} \section{Plugins} @@ -234,32 +234,32 @@ The plugin action is implemented through 3 callbacks, task start, task cancel an For illustration our example plugin will provide a no-op action. The task start callback in that case looks like this: % -\\\inputlisting{../examples_raw/mtapi/mtapi_c_plugin_task_start_cb-snippet.h} +\\\inputlisting{../examples/mtapi/mtapi_c_plugin_task_start_cb-snippet.h} % The scheduling operation is responsible for bringing the task to execution, this might involve instructing some hardware to execute the task or pushing the task into a queue for execution by a separate worker thread. Here however, the task is executed directly: % -\\\inputlisting{../examples_raw/mtapi/mtapi_c_plugin_task_schedule-snippet.h} +\\\inputlisting{../examples/mtapi/mtapi_c_plugin_task_schedule-snippet.h} % Since the task gets executed right away, it cannot be canceled and the task cancel callback implementation is empty: % -\\\inputlisting{../examples_raw/mtapi/mtapi_c_plugin_task_cancel_cb-snippet.h} +\\\inputlisting{../examples/mtapi/mtapi_c_plugin_task_cancel_cb-snippet.h} % The plugin action did not acquire any resources so the action finalize callback is empty as well: % -\\\inputlisting{../examples_raw/mtapi/mtapi_c_plugin_action_finalize_cb-snippet.h} +\\\inputlisting{../examples/mtapi/mtapi_c_plugin_action_finalize_cb-snippet.h} % Now that the callbacks are in place, the action can be registered with a job after the node was initialized using \lstinline|mtapi_initialize()|: % -\\\inputlisting{../examples_raw/mtapi/mtapi_c_plugin_action_create-snippet.h} +\\\inputlisting{../examples/mtapi/mtapi_c_plugin_action_create-snippet.h} % The job handle can now be obtained the normal MTAPI way. The fact that there is a plugin working behind the scenes is transparent by now: % -\\\inputlisting{../examples_raw/mtapi/mtapi_c_plugin_get_job-snippet.h} +\\\inputlisting{../examples/mtapi/mtapi_c_plugin_get_job-snippet.h} % Using the job handle tasks can be started like normal MTAPI tasks: % -\\\inputlisting{../examples_raw/mtapi/mtapi_c_plugin_task_start-snippet.h} +\\\inputlisting{../examples/mtapi/mtapi_c_plugin_task_start-snippet.h} % This call will lead to the invocation of then \lstinline|plugin_task_start| callback function, where the plugin implementor is responsible for bringing the task to execution. @@ -267,33 +267,33 @@ This call will lead to the invocation of then \lstinline|plugin_task_start| call The MTAPI network plugin provides a means to distribute tasks over a TCP/IP network. As an example the following vector addition action is used: % -\\\inputlisting{../examples_raw/mtapi/mtapi_network_c_action_function-snippet.h} +\\\inputlisting{../examples/mtapi/mtapi_network_c_action_function-snippet.h} % It adds two float vectors and a float from node local data and writes the result into the result float vector. In the example code the vectors will hold \lstinline|kElements| floats each. To use the network plugin, its header file needs to be included first: % -\\\inputlisting{../examples_raw/mtapi/mtapi_network_c_header-snippet.h} +\\\inputlisting{../examples/mtapi/mtapi_network_c_header-snippet.h} % After initializing the node using \lstinline|mtapi_initialize()|, the plugin itself needs to be initialized: % -\\\inputlisting{../examples_raw/mtapi/mtapi_network_c_plugin_initialize-snippet.h} +\\\inputlisting{../examples/mtapi/mtapi_network_c_plugin_initialize-snippet.h} % This will set up a listening socket on the localhost interface (127.0.0.1) at port 12345. The socket will allow a maximum of 5 connections and have a maximum transfer buffer size of \lstinline|kElements * 4 * 3 + 32|. This buffer size needs to be big enough to fit at least the argument and result buffer sizes at once. The example uses 3 vectors of \lstinline|kElements| floats using \lstinline|kElements * sizeof(float) * 3| bytes. Since the example connects to itself on localhost, the "remote" action needs to be registered with the \lstinline|NETWORK_REMOTE_JOB|: % -\\\inputlisting{../examples_raw/mtapi/mtapi_network_c_remote_action_create-snippet.h} +\\\inputlisting{../examples/mtapi/mtapi_network_c_remote_action_create-snippet.h} % After that, the local network action is created, that maps \lstinline|NETWORK_LOCAL_JOB| to \lstinline|NETWORK_REMOTE_JOB| through the network: % -\\\inputlisting{../examples_raw/mtapi/mtapi_network_c_local_action_create-snippet.h} +\\\inputlisting{../examples/mtapi/mtapi_network_c_local_action_create-snippet.h} % Now, \lstinline|NETWORK_LOCAL_JOB| can be used to execute tasks by simply calling \lstinline|mtapi_task_start()|. Their parameters will be transmitted through a socket connection and are consumed by the network plugin worker thread. The thread will start a task using the \lstinline|NETWORK_REMOTE_JOB|. When this task is finished, the results will be collected and sent back through the network. Again the network plugin thread will receive the results, provide them to the \lstinline|NETWORK_LOCAL_JOB| task and mark that task as finished. When all work is done, the plugin needs to be finalized. This will stop the plugin worker thread and close the sockets: % -\\\inputlisting{../examples_raw/mtapi/mtapi_network_c_plugin_finalize-snippet.h} +\\\inputlisting{../examples/mtapi/mtapi_network_c_plugin_finalize-snippet.h} % Then the node may be finalized by calling \lstinline|mtapi_finalize()|. @@ -303,19 +303,19 @@ The MTAPI OpenCL plugin allows the user to incorporate the computational power o The vector addition example from the network plugin is used again. However, the action function is an OpenCL kernel now: % -\\\inputlisting{../examples_raw/mtapi/mtapi_opencl_c_kernel-snippet.h} +\\\inputlisting{../examples/mtapi/mtapi_opencl_c_kernel-snippet.h} % The OpenCL plugin header file needs to be included first: % -\\\inputlisting{../examples_raw/mtapi/mtapi_opencl_c_header-snippet.h} +\\\inputlisting{../examples/mtapi/mtapi_opencl_c_header-snippet.h} % As with the network plugin, the OpenCL plugin needs to be initialized after the node has been initialized: % -\\\inputlisting{../examples_raw/mtapi/mtapi_opencl_c_plugin_initialize-snippet.h} +\\\inputlisting{../examples/mtapi/mtapi_opencl_c_plugin_initialize-snippet.h} % Then the plugin action can be registered with the \lstinline|OPENCL_JOB|: % -\\\inputlisting{../examples_raw/mtapi/mtapi_opencl_c_action_create-snippet.h} +\\\inputlisting{../examples/mtapi/mtapi_opencl_c_action_create-snippet.h} % The kernel source and the name of the kernel to use (AddVector) need to be specified while creating the action. The kernel will be compiled using the OpenCL runtime and the provided node local data transferred to accelerator memory. The local work size is the number of threads that will share OpenCL local memory, in this case 32. The element size instructs the OpenCL plugin how many bytes a single element in the result buffer consumes, in this case 4, as a single result is a single float. The OpenCL plugin will launch \lstinline|result_buffer_size/element_size| OpenCL threads to calculate the result. @@ -323,5 +323,5 @@ Now the \lstinline|OPENCL_JOB| can be used like a normal MTAPI job to start task After all work is done, the plugin needs to be finalized. This will free all memory on the accelerator and delete the corresponding OpenCL context: % -\\\inputlisting{../examples_raw/mtapi/mtapi_opencl_c_plugin_finalize-snippet.h} +\\\inputlisting{../examples/mtapi/mtapi_opencl_c_plugin_finalize-snippet.h} % diff --git a/doc/tutorial/content/tasks.tex b/doc/tutorial/content/tasks.tex index cb91713..45770bc 100644 --- a/doc/tutorial/content/tasks.tex +++ b/doc/tutorial/content/tasks.tex @@ -3,42 +3,42 @@ \embb provides a simple task management wrapper for the MTAPI interface. Using the example from the previous section, the signature of the action function for the tasks interface looks like this: % -\\\inputlisting{../examples_raw/tasks/tasks_cpp_action_signature-snippet.h} +\\\inputlisting{../examples/tasks/tasks_cpp_action_signature-snippet.h} % First, the node instance needs to be obtained. If the node is not initialized yet, this function will do it. % -\\\inputlisting{../examples_raw/tasks/tasks_cpp_get_node-snippet.h} +\\\inputlisting{../examples/tasks/tasks_cpp_get_node-snippet.h} % \emph{\textbf{Note:} Automatic initialization allows for easy usage of the \emph{Algorithms} and \emph{Dataflow} building blocks. For performance measurements however, explicit initialization by calling \lstinline|embb::tasks::Node::Initialize| is imperative since the measurements will otherwise include the initialization time of MTAPI.} Checking the arguments and the result buffer is not necessary, since everything is safely typed. However, the terminating condition of the recursion still needs to be checked: % -\\\inputlisting{../examples_raw/mtapi/mtapi_terminating_condition-snippet.h} +\\\inputlisting{../examples/mtapi/mtapi_terminating_condition-snippet.h} % After that, the first part of the computation is launched as an MTAPI task using \lstinline|embb::tasks::Node::Spawn()| (registering an action function with a job is done automatically): % -\\\inputlisting{../examples_raw/tasks/tasks_cpp_calc_task-snippet.h} +\\\inputlisting{../examples/tasks/tasks_cpp_calc_task-snippet.h} % The second part can be executed directly: % -\\\inputlisting{../examples_raw/tasks/tasks_cpp_calc_direct-snippet.h} +\\\inputlisting{../examples/tasks/tasks_cpp_calc_direct-snippet.h} % Then, completion of the MTAPI task has to be waited for using \lstinline|embb::tasks::Task::Wait()|: % -\\\inputlisting{../examples_raw/tasks/tasks_cpp_wait_task-snippet.h} +\\\inputlisting{../examples/tasks/tasks_cpp_wait_task-snippet.h} % Finally, the two parts can be added and written into the result buffer: % -\\\inputlisting{../examples_raw/mtapi/mtapi_write_back-snippet.h} +\\\inputlisting{../examples/mtapi/mtapi_write_back-snippet.h} % The \lstinline|fibonacci()| function also gets simpler compared to the C version. The MTAPI runtime is initialized automatically, only the node instance has to be fetched: % -\\\inputlisting{../examples_raw/tasks/tasks_cpp_get_node-snippet.h} +\\\inputlisting{../examples/tasks/tasks_cpp_get_node-snippet.h} % The root task can be started using \lstinline|embb::tasks::Node::Spawn()| directly, registering with a job is done automatically: % -\\\inputlisting{../examples_raw/tasks/tasks_cpp_start_task-snippet.h} +\\\inputlisting{../examples/tasks/tasks_cpp_start_task-snippet.h} % Again, the started task has to be waited for (using \lstinline|embb::tasks::Task::Wait()|) before the result can be returned. The runtime is shut down automatically in an \lstinline|atexit()| handler. -- libgit2 0.26.0