diff --git a/CMakeLists.txt b/CMakeLists.txt index 8a73c46..21d054d 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -54,6 +54,7 @@ option(BUILD_EXAMPLES "Specify whether examples should be built" OFF) option(USE_EXCEPTIONS "Specify whether exceptions should be activated in C++" ON) option(INSTALL_DOCS "Specify whether Doxygen docs should be installed" ON) option(WARNINGS_ARE_ERRORS "Specify whether warnings should be treated as errors" OFF) +option(USE_AUTOMATIC_INITIALIZATION "Specify whether the MTAPI C++ interface, algorithms and dataflow should automatically intialize the MTAPI node if no explicit initialization is present" ON) ## LOCAL INSTALLATION OF SUBPROJECT BINARIES # diff --git a/README.md b/README.md index 6669a48..c30af40 100644 --- a/README.md +++ b/README.md @@ -172,6 +172,9 @@ EMB² can be built with and without C++ exception handling, which has to be specified on build file generation. When exceptions are turned off, an error message is emitted and the program aborts in case of an exception within EMB². To disable exceptions, add the option -DUSE_EXCEPTIONS=OFF. +Similarly, automatic initialization of the task scheduler by the MTAPI C++ +interface can be disabled with -DUSE_AUTOMATIC_INITIALIZATION=OFF. This way, +unexpected delays after startup can be avoided, e.g. for timing measurements. The tutorial of EMB² comes with example source files in doc/examples/. These can be built with the other source files using CMake option -DBUILD_EXAMPLES=ON @@ -184,6 +187,10 @@ For a Linux Debug build with exception handling, type cmake -G "Unix Makefiles" .. -DCMAKE_BUILD_TYPE=Debug +For a default Linux build without automatic MTAPI C++ initialization, type + + cmake .. -DUSE_AUTOMATIC_INITIALIZATION=OFF + For a Windows build (VS 2013, x86) without exception handling, type cmake -G "Visual Studio 12" .. -DUSE_EXCEPTIONS=OFF diff --git a/algorithms_cpp/CMakeLists.txt b/algorithms_cpp/CMakeLists.txt index b5ce17f..bf9f799 100644 --- a/algorithms_cpp/CMakeLists.txt +++ b/algorithms_cpp/CMakeLists.txt @@ -17,7 +17,8 @@ include_directories(${EMBB_ALGORITHMS_CPP_INCLUDE_DIRS} ${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_cpp/include) + ${CMAKE_CURRENT_SOURCE_DIR}/../mtapi_cpp/include + ${CMAKE_CURRENT_BINARY_DIR}/../mtapi_cpp/include) add_library(embb_algorithms_cpp ${EMBB_ALGORITHMS_CPP_SOURCES} ${EMBB_ALGORITHMS_CPP_HEADERS}) diff --git a/algorithms_cpp/test/main.cc b/algorithms_cpp/test/main.cc index be4167a..4b5bf5e 100644 --- a/algorithms_cpp/test/main.cc +++ b/algorithms_cpp/test/main.cc @@ -67,6 +67,7 @@ int compute1_() { PT_MAIN("Algorithms") { embb::mtapi::Node::Initialize(THIS_DOMAIN_ID, THIS_NODE_ID); + PT_RUN(PartitionerTest); PT_RUN(ForEachTest); PT_RUN(ReduceTest); diff --git a/dataflow_cpp/CMakeLists.txt b/dataflow_cpp/CMakeLists.txt index 6c5d4e6..0ad76a0 100644 --- a/dataflow_cpp/CMakeLists.txt +++ b/dataflow_cpp/CMakeLists.txt @@ -17,8 +17,8 @@ include_directories(${EMBB_DATAFLOW_CPP_INCLUDE_DIRS} ${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_cpp/include - ) + ${CMAKE_CURRENT_SOURCE_DIR}/../mtapi_cpp/include + ${CMAKE_CURRENT_BINARY_DIR}/../mtapi_cpp/include) add_library (embb_dataflow_cpp ${EMBB_DATAFLOW_CPP_SOURCES} ${EMBB_DATAFLOW_CPP_HEADERS}) target_link_libraries(embb_dataflow_cpp embb_mtapi_cpp embb_base_cpp embb_mtapi_c embb_base_c) diff --git a/doc/examples/CMakeLists.txt b/doc/examples/CMakeLists.txt index cff5224..9393c95 100644 --- a/doc/examples/CMakeLists.txt +++ b/doc/examples/CMakeLists.txt @@ -11,6 +11,7 @@ include_directories( ${CMAKE_CURRENT_BINARY_DIR}/../../base_cpp/include ${CMAKE_CURRENT_SOURCE_DIR}/../../mtapi_c/include ${CMAKE_CURRENT_SOURCE_DIR}/../../mtapi_cpp/include + ${CMAKE_CURRENT_BINARY_DIR}/../../mtapi_cpp/include ${CMAKE_CURRENT_SOURCE_DIR}/../../containers_cpp/include ${CMAKE_CURRENT_SOURCE_DIR}/../../algorithms_cpp/include ${CMAKE_CURRENT_SOURCE_DIR}/../../dataflow_cpp/include diff --git a/mtapi_cpp/CMakeLists.txt b/mtapi_cpp/CMakeLists.txt index 301766c..19a6353 100644 --- a/mtapi_cpp/CMakeLists.txt +++ b/mtapi_cpp/CMakeLists.txt @@ -4,6 +4,18 @@ file(GLOB_RECURSE EMBB_MTAPI_CPP_SOURCES "src/*.cc" "src/*.h") file(GLOB_RECURSE EMBB_MTAPI_CPP_HEADERS "include/*.h") file(GLOB_RECURSE EMBB_MTAPI_CPP_TEST_SOURCES "test/*.cc" "test/*.h") +if (USE_AUTOMATIC_INITIALIZATION STREQUAL ON) + message("-- Automatic initialization enabled (default)") + set(MTAPI_CPP_AUTOMATIC_INITIALIZE 1) +else() + set(MTAPI_CPP_AUTOMATIC_INITIALIZE 0) + message("-- Automatic initialization disabled") +endif() +message(" (set with command line option -DUSE_AUTOMATIC_INITIALIZATION=ON/OFF)") + +configure_file("include/embb/mtapi/internal/cmake_config.h.in" + "include/embb/mtapi/internal/cmake_config.h") + # Execute the GroupSources macro include(${CMAKE_SOURCE_DIR}/CMakeCommon/GroupSourcesMSVC.cmake) GroupSourcesMSVC(include) @@ -12,12 +24,12 @@ GroupSourcesMSVC(test) set (EMBB_MTAPI_CPP_INCLUDE_DIRS "include" "src" "test") include_directories(${EMBB_MTAPI_CPP_INCLUDE_DIRS} + ${CMAKE_CURRENT_BINARY_DIR}/include ${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/include) add_library (embb_mtapi_cpp ${EMBB_MTAPI_CPP_SOURCES} ${EMBB_MTAPI_CPP_HEADERS}) target_link_libraries(embb_mtapi_cpp embb_mtapi_c) @@ -32,4 +44,6 @@ endif() install(DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/include/ DESTINATION include FILES_MATCHING PATTERN "*.h") +install(DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/include/ + DESTINATION include FILES_MATCHING PATTERN "*.h") install(TARGETS embb_mtapi_cpp DESTINATION lib) diff --git a/mtapi_cpp/include/embb/mtapi/internal/cmake_config.h.in b/mtapi_cpp/include/embb/mtapi/internal/cmake_config.h.in new file mode 100644 index 0000000..32af64c --- /dev/null +++ b/mtapi_cpp/include/embb/mtapi/internal/cmake_config.h.in @@ -0,0 +1,41 @@ +/* + * 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. + */ + +#ifndef EMBB_MTAPI_INTERNAL_CMAKE_CONFIG_H_ +#define EMBB_MTAPI_INTERNAL_CMAKE_CONFIG_H_ + +/* This file is used as input for CMake. CMake creates a file cmake_config.h in + its current build directory under the path builddir/embb/mtapi/internal/. From + there, the cmake_config.h can be included as usual using + #include + */ + +/** + * Is used to enable automatic initialization of the MTAPI node + */ +#define MTAPI_CPP_AUTOMATIC_INITIALIZE ${MTAPI_CPP_AUTOMATIC_INITIALIZE} + +#endif // EMBB_MTAPI_INTERNAL_CMAKE_CONFIG_H_ diff --git a/mtapi_cpp/include/embb/mtapi/mtapi.h b/mtapi_cpp/include/embb/mtapi/mtapi.h index 2e138bc..4c83834 100644 --- a/mtapi_cpp/include/embb/mtapi/mtapi.h +++ b/mtapi_cpp/include/embb/mtapi/mtapi.h @@ -35,8 +35,9 @@ * \ingroup CPP */ +#include + #define MTAPI_CPP_TASK_JOB 1 -#define MTAPI_CPP_AUTOMATIC_INITIALIZE 1 #if MTAPI_CPP_AUTOMATIC_INITIALIZE #define MTAPI_CPP_AUTOMATIC_DOMAIN_ID 1 #define MTAPI_CPP_AUTOMATIC_NODE_ID 1 diff --git a/mtapi_cpp/src/node.cc b/mtapi_cpp/src/node.cc index e8986e8..0deb322 100644 --- a/mtapi_cpp/src/node.cc +++ b/mtapi_cpp/src/node.cc @@ -39,7 +39,9 @@ namespace { static embb::mtapi::Node * node_instance = NULL; +#if MTAPI_CPP_AUTOMATIC_INITIALIZE static embb::base::Mutex init_mutex; +#endif }