From 5f7d4bd88ddf02c29572996062fe0b9303f5b253 Mon Sep 17 00:00:00 2001 From: Clement Jamin Date: Tue, 22 Jan 2013 14:42:13 +0100 Subject: [PATCH 01/17] Original FindTBB.cmake file --- Installation/cmake/modules/FindTBB.cmake | 283 +++++++++++++++++++++++ 1 file changed, 283 insertions(+) create mode 100644 Installation/cmake/modules/FindTBB.cmake diff --git a/Installation/cmake/modules/FindTBB.cmake b/Installation/cmake/modules/FindTBB.cmake new file mode 100644 index 00000000000..e5ca1003912 --- /dev/null +++ b/Installation/cmake/modules/FindTBB.cmake @@ -0,0 +1,283 @@ +# Locate Intel Threading Building Blocks include paths and libraries +# FindTBB.cmake can be found at https://code.google.com/p/findtbb/ +# Written by Hannes Hofmann +# Improvements by Gino van den Bergen , +# Florian Uhlig , +# Jiri Marsik + +# The MIT License +# +# Copyright (c) 2011 Hannes Hofmann +# +# Permission is hereby granted, free of charge, to any person obtaining a copy +# of this software and associated documentation files (the "Software"), to deal +# in the Software without restriction, including without limitation the rights +# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +# copies of the Software, and to permit persons to whom the Software is +# furnished to do so, subject to the following conditions: +# +# The above copyright notice and this permission notice shall be included in +# all copies or substantial portions of the Software. +# +# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +# THE SOFTWARE. + +# GvdB: This module uses the environment variable TBB_ARCH_PLATFORM which defines architecture and compiler. +# e.g. "ia32/vc8" or "em64t/cc4.1.0_libc2.4_kernel2.6.16.21" +# TBB_ARCH_PLATFORM is set by the build script tbbvars[.bat|.sh|.csh], which can be found +# in the TBB installation directory (TBB_INSTALL_DIR). +# +# GvdB: Mac OS X distribution places libraries directly in lib directory. +# +# For backwards compatibility, you may explicitely set the CMake variables TBB_ARCHITECTURE and TBB_COMPILER. +# TBB_ARCHITECTURE [ ia32 | em64t | itanium ] +# which architecture to use +# TBB_COMPILER e.g. vc9 or cc3.2.3_libc2.3.2_kernel2.4.21 or cc4.0.1_os10.4.9 +# which compiler to use (detected automatically on Windows) + +# This module respects +# TBB_INSTALL_DIR or $ENV{TBB21_INSTALL_DIR} or $ENV{TBB_INSTALL_DIR} + +# This module defines +# TBB_INCLUDE_DIRS, where to find task_scheduler_init.h, etc. +# TBB_LIBRARY_DIRS, where to find libtbb, libtbbmalloc +# TBB_DEBUG_LIBRARY_DIRS, where to find libtbb_debug, libtbbmalloc_debug +# TBB_INSTALL_DIR, the base TBB install directory +# TBB_LIBRARIES, the libraries to link against to use TBB. +# TBB_DEBUG_LIBRARIES, the libraries to link against to use TBB with debug symbols. +# TBB_FOUND, If false, don't try to use TBB. +# TBB_INTERFACE_VERSION, as defined in tbb/tbb_stddef.h + + +if (WIN32) + # has em64t/vc8 em64t/vc9 + # has ia32/vc7.1 ia32/vc8 ia32/vc9 + set(_TBB_DEFAULT_INSTALL_DIR "C:/Program Files/Intel/TBB" "C:/Program Files (x86)/Intel/TBB") + set(_TBB_LIB_NAME "tbb") + set(_TBB_LIB_MALLOC_NAME "${_TBB_LIB_NAME}malloc") + set(_TBB_LIB_DEBUG_NAME "${_TBB_LIB_NAME}_debug") + set(_TBB_LIB_MALLOC_DEBUG_NAME "${_TBB_LIB_MALLOC_NAME}_debug") + if (MSVC71) + set (_TBB_COMPILER "vc7.1") + endif(MSVC71) + if (MSVC80) + set(_TBB_COMPILER "vc8") + endif(MSVC80) + if (MSVC90) + set(_TBB_COMPILER "vc9") + endif(MSVC90) + if(MSVC10) + set(_TBB_COMPILER "vc10") + endif(MSVC10) + # Todo: add other Windows compilers such as ICL. + set(_TBB_ARCHITECTURE ${TBB_ARCHITECTURE}) +endif (WIN32) + +if (UNIX) + if (APPLE) + # MAC + set(_TBB_DEFAULT_INSTALL_DIR "/Library/Frameworks/Intel_TBB.framework/Versions") + # libs: libtbb.dylib, libtbbmalloc.dylib, *_debug + set(_TBB_LIB_NAME "tbb") + set(_TBB_LIB_MALLOC_NAME "${_TBB_LIB_NAME}malloc") + set(_TBB_LIB_DEBUG_NAME "${_TBB_LIB_NAME}_debug") + set(_TBB_LIB_MALLOC_DEBUG_NAME "${_TBB_LIB_MALLOC_NAME}_debug") + # default flavor on apple: ia32/cc4.0.1_os10.4.9 + # Jiri: There is no reason to presume there is only one flavor and + # that user's setting of variables should be ignored. + if(NOT TBB_COMPILER) + set(_TBB_COMPILER "cc4.0.1_os10.4.9") + elseif (NOT TBB_COMPILER) + set(_TBB_COMPILER ${TBB_COMPILER}) + endif(NOT TBB_COMPILER) + if(NOT TBB_ARCHITECTURE) + set(_TBB_ARCHITECTURE "ia32") + elseif(NOT TBB_ARCHITECTURE) + set(_TBB_ARCHITECTURE ${TBB_ARCHITECTURE}) + endif(NOT TBB_ARCHITECTURE) + else (APPLE) + # LINUX + set(_TBB_DEFAULT_INSTALL_DIR "/opt/intel/tbb" "/usr/local/include" "/usr/include") + set(_TBB_LIB_NAME "tbb") + set(_TBB_LIB_MALLOC_NAME "${_TBB_LIB_NAME}malloc") + set(_TBB_LIB_DEBUG_NAME "${_TBB_LIB_NAME}_debug") + set(_TBB_LIB_MALLOC_DEBUG_NAME "${_TBB_LIB_MALLOC_NAME}_debug") + # has em64t/cc3.2.3_libc2.3.2_kernel2.4.21 em64t/cc3.3.3_libc2.3.3_kernel2.6.5 em64t/cc3.4.3_libc2.3.4_kernel2.6.9 em64t/cc4.1.0_libc2.4_kernel2.6.16.21 + # has ia32/* + # has itanium/* + set(_TBB_COMPILER ${TBB_COMPILER}) + set(_TBB_ARCHITECTURE ${TBB_ARCHITECTURE}) + endif (APPLE) +endif (UNIX) + +if (CMAKE_SYSTEM MATCHES "SunOS.*") +# SUN +# not yet supported +# has em64t/cc3.4.3_kernel5.10 +# has ia32/* +endif (CMAKE_SYSTEM MATCHES "SunOS.*") + + +#-- Clear the public variables +set (TBB_FOUND "NO") + + +#-- Find TBB install dir and set ${_TBB_INSTALL_DIR} and cached ${TBB_INSTALL_DIR} +# first: use CMake variable TBB_INSTALL_DIR +if (TBB_INSTALL_DIR) + set (_TBB_INSTALL_DIR ${TBB_INSTALL_DIR}) +endif (TBB_INSTALL_DIR) +# second: use environment variable +if (NOT _TBB_INSTALL_DIR) + if (NOT "$ENV{TBB_INSTALL_DIR}" STREQUAL "") + set (_TBB_INSTALL_DIR $ENV{TBB_INSTALL_DIR}) + endif (NOT "$ENV{TBB_INSTALL_DIR}" STREQUAL "") + # Intel recommends setting TBB21_INSTALL_DIR + if (NOT "$ENV{TBB21_INSTALL_DIR}" STREQUAL "") + set (_TBB_INSTALL_DIR $ENV{TBB21_INSTALL_DIR}) + endif (NOT "$ENV{TBB21_INSTALL_DIR}" STREQUAL "") + if (NOT "$ENV{TBB22_INSTALL_DIR}" STREQUAL "") + set (_TBB_INSTALL_DIR $ENV{TBB22_INSTALL_DIR}) + endif (NOT "$ENV{TBB22_INSTALL_DIR}" STREQUAL "") + if (NOT "$ENV{TBB30_INSTALL_DIR}" STREQUAL "") + set (_TBB_INSTALL_DIR $ENV{TBB30_INSTALL_DIR}) + endif (NOT "$ENV{TBB30_INSTALL_DIR}" STREQUAL "") +endif (NOT _TBB_INSTALL_DIR) +# third: try to find path automatically +if (NOT _TBB_INSTALL_DIR) + if (_TBB_DEFAULT_INSTALL_DIR) + set (_TBB_INSTALL_DIR ${_TBB_DEFAULT_INSTALL_DIR}) + endif (_TBB_DEFAULT_INSTALL_DIR) +endif (NOT _TBB_INSTALL_DIR) +# sanity check +if (NOT _TBB_INSTALL_DIR) + message ("ERROR: Unable to find Intel TBB install directory. ${_TBB_INSTALL_DIR}") +else (NOT _TBB_INSTALL_DIR) +# finally: set the cached CMake variable TBB_INSTALL_DIR +if (NOT TBB_INSTALL_DIR) + set (TBB_INSTALL_DIR ${_TBB_INSTALL_DIR} CACHE PATH "Intel TBB install directory") + mark_as_advanced(TBB_INSTALL_DIR) +endif (NOT TBB_INSTALL_DIR) + + +#-- A macro to rewrite the paths of the library. This is necessary, because +# find_library() always found the em64t/vc9 version of the TBB libs +macro(TBB_CORRECT_LIB_DIR var_name) +# if (NOT "${_TBB_ARCHITECTURE}" STREQUAL "em64t") + string(REPLACE em64t "${_TBB_ARCHITECTURE}" ${var_name} ${${var_name}}) +# endif (NOT "${_TBB_ARCHITECTURE}" STREQUAL "em64t") + string(REPLACE ia32 "${_TBB_ARCHITECTURE}" ${var_name} ${${var_name}}) + string(REPLACE vc7.1 "${_TBB_COMPILER}" ${var_name} ${${var_name}}) + string(REPLACE vc8 "${_TBB_COMPILER}" ${var_name} ${${var_name}}) + string(REPLACE vc9 "${_TBB_COMPILER}" ${var_name} ${${var_name}}) + string(REPLACE vc10 "${_TBB_COMPILER}" ${var_name} ${${var_name}}) +endmacro(TBB_CORRECT_LIB_DIR var_content) + + +#-- Look for include directory and set ${TBB_INCLUDE_DIR} +set (TBB_INC_SEARCH_DIR ${_TBB_INSTALL_DIR}/include) +# Jiri: tbbvars now sets the CPATH environment variable to the directory +# containing the headers. +find_path(TBB_INCLUDE_DIR + tbb/task_scheduler_init.h + PATHS ${TBB_INC_SEARCH_DIR} ENV CPATH +) +mark_as_advanced(TBB_INCLUDE_DIR) + + +#-- Look for libraries +# GvdB: $ENV{TBB_ARCH_PLATFORM} is set by the build script tbbvars[.bat|.sh|.csh] +if (NOT $ENV{TBB_ARCH_PLATFORM} STREQUAL "") + set (_TBB_LIBRARY_DIR + ${_TBB_INSTALL_DIR}/lib/$ENV{TBB_ARCH_PLATFORM} + ${_TBB_INSTALL_DIR}/$ENV{TBB_ARCH_PLATFORM}/lib + ) +endif (NOT $ENV{TBB_ARCH_PLATFORM} STREQUAL "") +# Jiri: This block isn't mutually exclusive with the previous one +# (hence no else), instead I test if the user really specified +# the variables in question. +if ((NOT ${TBB_ARCHITECTURE} STREQUAL "") AND (NOT ${TBB_COMPILER} STREQUAL "")) + # HH: deprecated + message(STATUS "[Warning] FindTBB.cmake: The use of TBB_ARCHITECTURE and TBB_COMPILER is deprecated and may not be supported in future versions. Please set \$ENV{TBB_ARCH_PLATFORM} (using tbbvars.[bat|csh|sh]).") + # Jiri: It doesn't hurt to look in more places, so I store the hints from + # ENV{TBB_ARCH_PLATFORM} and the TBB_ARCHITECTURE and TBB_COMPILER + # variables and search them both. + set (_TBB_LIBRARY_DIR "${_TBB_INSTALL_DIR}/${_TBB_ARCHITECTURE}/${_TBB_COMPILER}/lib" ${_TBB_LIBRARY_DIR}) +endif ((NOT ${TBB_ARCHITECTURE} STREQUAL "") AND (NOT ${TBB_COMPILER} STREQUAL "")) + +# GvdB: Mac OS X distribution places libraries directly in lib directory. +list(APPEND _TBB_LIBRARY_DIR ${_TBB_INSTALL_DIR}/lib) + +# Jiri: No reason not to check the default paths. From recent versions, +# tbbvars has started exporting the LIBRARY_PATH and LD_LIBRARY_PATH +# variables, which now point to the directories of the lib files. +# It all makes more sense to use the ${_TBB_LIBRARY_DIR} as a HINTS +# argument instead of the implicit PATHS as it isn't hard-coded +# but computed by system introspection. Searching the LIBRARY_PATH +# and LD_LIBRARY_PATH environment variables is now even more important +# that tbbvars doesn't export TBB_ARCH_PLATFORM and it facilitates +# the use of TBB built from sources. +find_library(TBB_LIBRARY ${_TBB_LIB_NAME} HINTS ${_TBB_LIBRARY_DIR} + PATHS ENV LIBRARY_PATH ENV LD_LIBRARY_PATH) +find_library(TBB_MALLOC_LIBRARY ${_TBB_LIB_MALLOC_NAME} HINTS ${_TBB_LIBRARY_DIR} + PATHS ENV LIBRARY_PATH ENV LD_LIBRARY_PATH) + +#Extract path from TBB_LIBRARY name +get_filename_component(TBB_LIBRARY_DIR ${TBB_LIBRARY} PATH) + +#TBB_CORRECT_LIB_DIR(TBB_LIBRARY) +#TBB_CORRECT_LIB_DIR(TBB_MALLOC_LIBRARY) +mark_as_advanced(TBB_LIBRARY TBB_MALLOC_LIBRARY) + +#-- Look for debug libraries +# Jiri: Changed the same way as for the release libraries. +find_library(TBB_LIBRARY_DEBUG ${_TBB_LIB_DEBUG_NAME} HINTS ${_TBB_LIBRARY_DIR} + PATHS ENV LIBRARY_PATH ENV LD_LIBRARY_PATH) +find_library(TBB_MALLOC_LIBRARY_DEBUG ${_TBB_LIB_MALLOC_DEBUG_NAME} HINTS ${_TBB_LIBRARY_DIR} + PATHS ENV LIBRARY_PATH ENV LD_LIBRARY_PATH) + +# Jiri: Self-built TBB stores the debug libraries in a separate directory. +# Extract path from TBB_LIBRARY_DEBUG name +get_filename_component(TBB_LIBRARY_DEBUG_DIR ${TBB_LIBRARY_DEBUG} PATH) + +#TBB_CORRECT_LIB_DIR(TBB_LIBRARY_DEBUG) +#TBB_CORRECT_LIB_DIR(TBB_MALLOC_LIBRARY_DEBUG) +mark_as_advanced(TBB_LIBRARY_DEBUG TBB_MALLOC_LIBRARY_DEBUG) + + +if (TBB_INCLUDE_DIR) + if (TBB_LIBRARY) + set (TBB_FOUND "YES") + set (TBB_LIBRARIES ${TBB_LIBRARY} ${TBB_MALLOC_LIBRARY} ${TBB_LIBRARIES}) + set (TBB_DEBUG_LIBRARIES ${TBB_LIBRARY_DEBUG} ${TBB_MALLOC_LIBRARY_DEBUG} ${TBB_DEBUG_LIBRARIES}) + set (TBB_INCLUDE_DIRS ${TBB_INCLUDE_DIR} CACHE PATH "TBB include directory" FORCE) + set (TBB_LIBRARY_DIRS ${TBB_LIBRARY_DIR} CACHE PATH "TBB library directory" FORCE) + # Jiri: Self-built TBB stores the debug libraries in a separate directory. + set (TBB_DEBUG_LIBRARY_DIRS ${TBB_LIBRARY_DEBUG_DIR} CACHE PATH "TBB debug library directory" FORCE) + mark_as_advanced(TBB_INCLUDE_DIRS TBB_LIBRARY_DIRS TBB_DEBUG_LIBRARY_DIRS TBB_LIBRARIES TBB_DEBUG_LIBRARIES) + message(STATUS "Found Intel TBB") + endif (TBB_LIBRARY) +endif (TBB_INCLUDE_DIR) + +if (NOT TBB_FOUND) + message("ERROR: Intel TBB NOT found!") + message(STATUS "Looked for Threading Building Blocks in ${_TBB_INSTALL_DIR}") + # do only throw fatal, if this pkg is REQUIRED + if (TBB_FIND_REQUIRED) + message(FATAL_ERROR "Could NOT find TBB library.") + endif (TBB_FIND_REQUIRED) +endif (NOT TBB_FOUND) + +endif (NOT _TBB_INSTALL_DIR) + +if (TBB_FOUND) + set(TBB_INTERFACE_VERSION 0) + FILE(READ "${TBB_INCLUDE_DIRS}/tbb/tbb_stddef.h" _TBB_VERSION_CONTENTS) + STRING(REGEX REPLACE ".*#define TBB_INTERFACE_VERSION ([0-9]+).*" "\\1" TBB_INTERFACE_VERSION "${_TBB_VERSION_CONTENTS}") + set(TBB_INTERFACE_VERSION "${TBB_INTERFACE_VERSION}") +endif (TBB_FOUND) From 0fcd19db7ae540fc359f66472d364eef8612c3c1 Mon Sep 17 00:00:00 2001 From: Clement Jamin Date: Tue, 22 Jan 2013 14:50:01 +0100 Subject: [PATCH 02/17] Updated FindTBB so that it looks for the malloc proxy + better error messages --- Installation/cmake/modules/FindTBB.cmake | 26 +++++++++++++++++++----- 1 file changed, 21 insertions(+), 5 deletions(-) diff --git a/Installation/cmake/modules/FindTBB.cmake b/Installation/cmake/modules/FindTBB.cmake index e5ca1003912..47bb2daf6c8 100644 --- a/Installation/cmake/modules/FindTBB.cmake +++ b/Installation/cmake/modules/FindTBB.cmake @@ -60,8 +60,10 @@ if (WIN32) set(_TBB_DEFAULT_INSTALL_DIR "C:/Program Files/Intel/TBB" "C:/Program Files (x86)/Intel/TBB") set(_TBB_LIB_NAME "tbb") set(_TBB_LIB_MALLOC_NAME "${_TBB_LIB_NAME}malloc") + set(_TBB_LIB_MALLOCPROXY_NAME "${_TBB_LIB_NAME}malloc_proxy") set(_TBB_LIB_DEBUG_NAME "${_TBB_LIB_NAME}_debug") set(_TBB_LIB_MALLOC_DEBUG_NAME "${_TBB_LIB_MALLOC_NAME}_debug") + set(_TBB_LIB_MALLOCPROXY_DEBUG_NAME "${_TBB_LIB_MALLOCPROXY_NAME}_debug") if (MSVC71) set (_TBB_COMPILER "vc7.1") endif(MSVC71) @@ -85,8 +87,10 @@ if (UNIX) # libs: libtbb.dylib, libtbbmalloc.dylib, *_debug set(_TBB_LIB_NAME "tbb") set(_TBB_LIB_MALLOC_NAME "${_TBB_LIB_NAME}malloc") + set(_TBB_LIB_MALLOCPROXY_NAME "${_TBB_LIB_NAME}malloc_proxy") set(_TBB_LIB_DEBUG_NAME "${_TBB_LIB_NAME}_debug") set(_TBB_LIB_MALLOC_DEBUG_NAME "${_TBB_LIB_MALLOC_NAME}_debug") + set(_TBB_LIB_MALLOCPROXY_DEBUG_NAME "${_TBB_LIB_MALLOCPROXY_NAME}_debug") # default flavor on apple: ia32/cc4.0.1_os10.4.9 # Jiri: There is no reason to presume there is only one flavor and # that user's setting of variables should be ignored. @@ -105,8 +109,10 @@ if (UNIX) set(_TBB_DEFAULT_INSTALL_DIR "/opt/intel/tbb" "/usr/local/include" "/usr/include") set(_TBB_LIB_NAME "tbb") set(_TBB_LIB_MALLOC_NAME "${_TBB_LIB_NAME}malloc") + set(_TBB_LIB_MALLOCPROXY_NAME "${_TBB_LIB_NAME}malloc_proxy") set(_TBB_LIB_DEBUG_NAME "${_TBB_LIB_NAME}_debug") set(_TBB_LIB_MALLOC_DEBUG_NAME "${_TBB_LIB_MALLOC_NAME}_debug") + set(_TBB_LIB_MALLOCPROXY_DEBUG_NAME "${_TBB_LIB_MALLOCPROXY_NAME}_debug") # has em64t/cc3.2.3_libc2.3.2_kernel2.4.21 em64t/cc3.3.3_libc2.3.3_kernel2.6.5 em64t/cc3.4.3_libc2.3.4_kernel2.6.9 em64t/cc4.1.0_libc2.4_kernel2.6.16.21 # has ia32/* # has itanium/* @@ -134,6 +140,9 @@ if (TBB_INSTALL_DIR) endif (TBB_INSTALL_DIR) # second: use environment variable if (NOT _TBB_INSTALL_DIR) + if (NOT "$ENV{TBBROOT}" STREQUAL "") + set (_TBB_INSTALL_DIR $ENV{TBBROOT}) + endif (NOT "$ENV{TBBROOT}" STREQUAL "") if (NOT "$ENV{TBB_INSTALL_DIR}" STREQUAL "") set (_TBB_INSTALL_DIR $ENV{TBB_INSTALL_DIR}) endif (NOT "$ENV{TBB_INSTALL_DIR}" STREQUAL "") @@ -226,13 +235,16 @@ find_library(TBB_LIBRARY ${_TBB_LIB_NAME} HINTS ${_TBB_LIBRARY_DIR} PATHS ENV LIBRARY_PATH ENV LD_LIBRARY_PATH) find_library(TBB_MALLOC_LIBRARY ${_TBB_LIB_MALLOC_NAME} HINTS ${_TBB_LIBRARY_DIR} PATHS ENV LIBRARY_PATH ENV LD_LIBRARY_PATH) +find_library(TBB_MALLOCPROXY_LIBRARY ${_TBB_LIB_MALLOCPROXY_NAME} HINTS ${_TBB_LIBRARY_DIR} + PATHS ENV LIBRARY_PATH ENV LD_LIBRARY_PATH) #Extract path from TBB_LIBRARY name get_filename_component(TBB_LIBRARY_DIR ${TBB_LIBRARY} PATH) #TBB_CORRECT_LIB_DIR(TBB_LIBRARY) #TBB_CORRECT_LIB_DIR(TBB_MALLOC_LIBRARY) -mark_as_advanced(TBB_LIBRARY TBB_MALLOC_LIBRARY) +#TBB_CORRECT_LIB_DIR(TBB_MALLOCPROXY_LIBRARY) +mark_as_advanced(TBB_LIBRARY TBB_MALLOC_LIBRARY TBB_MALLOCPROXY_LIBRARY) #-- Look for debug libraries # Jiri: Changed the same way as for the release libraries. @@ -240,6 +252,8 @@ find_library(TBB_LIBRARY_DEBUG ${_TBB_LIB_DEBUG_NAME} HINTS ${_TBB_LIBRARY_DIR} PATHS ENV LIBRARY_PATH ENV LD_LIBRARY_PATH) find_library(TBB_MALLOC_LIBRARY_DEBUG ${_TBB_LIB_MALLOC_DEBUG_NAME} HINTS ${_TBB_LIBRARY_DIR} PATHS ENV LIBRARY_PATH ENV LD_LIBRARY_PATH) +find_library(TBB_MALLOCPROXY_LIBRARY_DEBUG ${_TBB_LIB_MALLOCPROXY_DEBUG_NAME} HINTS ${_TBB_LIBRARY_DIR} + PATHS ENV LIBRARY_PATH ENV LD_LIBRARY_PATH) # Jiri: Self-built TBB stores the debug libraries in a separate directory. # Extract path from TBB_LIBRARY_DEBUG name @@ -247,14 +261,15 @@ get_filename_component(TBB_LIBRARY_DEBUG_DIR ${TBB_LIBRARY_DEBUG} PATH) #TBB_CORRECT_LIB_DIR(TBB_LIBRARY_DEBUG) #TBB_CORRECT_LIB_DIR(TBB_MALLOC_LIBRARY_DEBUG) -mark_as_advanced(TBB_LIBRARY_DEBUG TBB_MALLOC_LIBRARY_DEBUG) +#TBB_CORRECT_LIB_DIR(TBB_MALLOCPROXY_LIBRARY_DEBUG) +mark_as_advanced(TBB_LIBRARY_DEBUG TBB_MALLOC_LIBRARY_DEBUG TBB_MALLOCPROXY_LIBRARY_DEBUG) if (TBB_INCLUDE_DIR) if (TBB_LIBRARY) set (TBB_FOUND "YES") - set (TBB_LIBRARIES ${TBB_LIBRARY} ${TBB_MALLOC_LIBRARY} ${TBB_LIBRARIES}) - set (TBB_DEBUG_LIBRARIES ${TBB_LIBRARY_DEBUG} ${TBB_MALLOC_LIBRARY_DEBUG} ${TBB_DEBUG_LIBRARIES}) + set (TBB_LIBRARIES ${TBB_LIBRARY} ${TBB_MALLOC_LIBRARY} ${TBB_MALLOCPROXY_LIBRARY} ${TBB_LIBRARIES}) + set (TBB_DEBUG_LIBRARIES ${TBB_LIBRARY_DEBUG} ${TBB_MALLOC_LIBRARY_DEBUG} ${TBB_MALLOCPROXY_LIBRARY_DEBUG} ${TBB_DEBUG_LIBRARIES}) set (TBB_INCLUDE_DIRS ${TBB_INCLUDE_DIR} CACHE PATH "TBB include directory" FORCE) set (TBB_LIBRARY_DIRS ${TBB_LIBRARY_DIR} CACHE PATH "TBB library directory" FORCE) # Jiri: Self-built TBB stores the debug libraries in a separate directory. @@ -265,8 +280,9 @@ if (TBB_INCLUDE_DIR) endif (TBB_INCLUDE_DIR) if (NOT TBB_FOUND) - message("ERROR: Intel TBB NOT found!") + message("ERROR: Intel TBB NOT found! Please define the TBBROOT and/or TBB_ARCH_PLATFORM environment variable.") message(STATUS "Looked for Threading Building Blocks in ${_TBB_INSTALL_DIR}") + SET(TBB_INSTALL_DIR "TBB_INSTALL_DIR_NOT_FOUND" CACHE STRING "Intel TBB install directory") # do only throw fatal, if this pkg is REQUIRED if (TBB_FIND_REQUIRED) message(FATAL_ERROR "Could NOT find TBB library.") From b4fae54565838560647e229fb99c1e9e4c835f12 Mon Sep 17 00:00:00 2001 From: Clement Jamin Date: Tue, 22 Jan 2013 15:44:34 +0100 Subject: [PATCH 03/17] New class for TBB configuration (num threads...) --- Installation/include/CGAL/tbb.h | 76 +++++++++++++++++++++++++++++++++ 1 file changed, 76 insertions(+) create mode 100644 Installation/include/CGAL/tbb.h diff --git a/Installation/include/CGAL/tbb.h b/Installation/include/CGAL/tbb.h new file mode 100644 index 00000000000..331879f0738 --- /dev/null +++ b/Installation/include/CGAL/tbb.h @@ -0,0 +1,76 @@ +// Copyright (c) 2013 +// INRIA Sophia-Antipolis (France). All rights reserved. +// +// This file is part of CGAL (www.cgal.org); you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public License as +// published by the Free Software Foundation; either version 3 of the License, +// or (at your option) any later version. +// +// Licensees holding a valid commercial license may use this file in +// accordance with the commercial license agreement provided with the software. +// +// This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE +// WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. +// +// $URL$ +// $Id$ +// +// +// Author(s) : Clement Jamin + +#ifndef CGAL_TBB_H +#define CGAL_TBB_H + +#ifdef CGAL_LINKED_WITH_TBB + +#include +#include + +namespace CGAL { + +/*! +\ingroup Installation + +\brief The class TBB_configuration provides control over TBB. +*/ +class TBB_configuration +{ +public: + /*! + \brief Set the maximum number of threads that TBB may create. + \details If max_num_threads <= 0, TBB will decide the number of threads, + which is typically the number of hardware threads. + */ + static void set_max_number_of_threads(int max_num_threads = -1) + { + static tbb::task_scheduler_init init(tbb::task_scheduler_init::deferred); + + if (init.is_active()) + init.terminate(); + + if (max_num_threads > 0) + init.initialize(max_num_threads); + else + init.initialize(); + } + + /*! + \brief Returns the number of threads TBB scheduler would create if initialized by + default. + \details This number is typically the number of hardware threads (logical + processors). + */ + static int get_default_number_of_threads() + { + return tbb::task_scheduler_init::default_num_threads(); + } + +protected: + // We don't want this class to be instantiated by an user + TBB_configuration() {} +}; + +} //namespace CGAL + +#endif // CGAL_LINKED_WITH_TBB +#endif // CGAL_TBB_H From fc26d6effc1bb21153a585ff9da7352f3f7b2883 Mon Sep 17 00:00:00 2001 From: Clement Jamin Date: Wed, 23 Jan 2013 11:03:35 +0100 Subject: [PATCH 04/17] Renamed header to be compliant with CGAL naming policy --- Installation/include/CGAL/{tbb.h => TBB_configuration.h} | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename Installation/include/CGAL/{tbb.h => TBB_configuration.h} (100%) diff --git a/Installation/include/CGAL/tbb.h b/Installation/include/CGAL/TBB_configuration.h similarity index 100% rename from Installation/include/CGAL/tbb.h rename to Installation/include/CGAL/TBB_configuration.h From 0a89951884001d0a734854f7d9435acdd363679d Mon Sep 17 00:00:00 2001 From: Clement Jamin Date: Wed, 23 Jan 2013 15:14:08 +0100 Subject: [PATCH 05/17] Updated FindTBB.cmake so that it uses the "optimized"/"debug" cmake keywords --- Installation/cmake/modules/FindTBB.cmake | 110 ++++++++++++----------- 1 file changed, 60 insertions(+), 50 deletions(-) diff --git a/Installation/cmake/modules/FindTBB.cmake b/Installation/cmake/modules/FindTBB.cmake index 47bb2daf6c8..7c772fa2531 100644 --- a/Installation/cmake/modules/FindTBB.cmake +++ b/Installation/cmake/modules/FindTBB.cmake @@ -45,11 +45,15 @@ # This module defines # TBB_INCLUDE_DIRS, where to find task_scheduler_init.h, etc. -# TBB_LIBRARY_DIRS, where to find libtbb, libtbbmalloc -# TBB_DEBUG_LIBRARY_DIRS, where to find libtbb_debug, libtbbmalloc_debug -# TBB_INSTALL_DIR, the base TBB install directory -# TBB_LIBRARIES, the libraries to link against to use TBB. -# TBB_DEBUG_LIBRARIES, the libraries to link against to use TBB with debug symbols. +# TBB_LIBRARY_DIRS, where to find TBB libraries (both release and debug versions, using "optimized" and "debug" CMake keywords). +# TBB_INSTALL_DIR, the base TBB install directory. +# TBB_LIBRARIES, all the TBB libraries (both release and debug versions, using "optimized" and "debug" CMake keywords). +# TBB_RELEASE_LIBRARY, the TBB release library +# TBB_MALLOC_RELEASE_LIBRARY, the TBB release malloc library +# TBB_MALLOCPROXY_RELEASE_LIBRARY, the TBB release malloc_proxy library +# TBB_DEBUG_LIBRARY, the TBB debug library +# TBB_MALLOC_DEBUG_LIBRARY, the TBB debug malloc library +# TBB_MALLOCPROXY_DEBUG_LIBRARY, the TBB debug malloc_proxy library # TBB_FOUND, If false, don't try to use TBB. # TBB_INTERFACE_VERSION, as defined in tbb/tbb_stddef.h @@ -58,12 +62,12 @@ if (WIN32) # has em64t/vc8 em64t/vc9 # has ia32/vc7.1 ia32/vc8 ia32/vc9 set(_TBB_DEFAULT_INSTALL_DIR "C:/Program Files/Intel/TBB" "C:/Program Files (x86)/Intel/TBB") - set(_TBB_LIB_NAME "tbb") - set(_TBB_LIB_MALLOC_NAME "${_TBB_LIB_NAME}malloc") - set(_TBB_LIB_MALLOCPROXY_NAME "${_TBB_LIB_NAME}malloc_proxy") - set(_TBB_LIB_DEBUG_NAME "${_TBB_LIB_NAME}_debug") - set(_TBB_LIB_MALLOC_DEBUG_NAME "${_TBB_LIB_MALLOC_NAME}_debug") - set(_TBB_LIB_MALLOCPROXY_DEBUG_NAME "${_TBB_LIB_MALLOCPROXY_NAME}_debug") + set(_TBB_LIB_RELEASE_NAME "tbb") + set(_TBB_LIB_MALLOC_RELEASE_NAME "${_TBB_LIB_RELEASE_NAME}malloc") + set(_TBB_LIB_MALLOCPROXY_RELEASE_NAME "${_TBB_LIB_RELEASE_NAME}malloc_proxy") + set(_TBB_LIB_DEBUG_NAME "${_TBB_LIB_RELEASE_NAME}_debug") + set(_TBB_LIB_MALLOC_DEBUG_NAME "${_TBB_LIB_MALLOC_RELEASE_NAME}_debug") + set(_TBB_LIB_MALLOCPROXY_DEBUG_NAME "${_TBB_LIB_MALLOCPROXY_RELEASE_NAME}_debug") if (MSVC71) set (_TBB_COMPILER "vc7.1") endif(MSVC71) @@ -76,6 +80,9 @@ if (WIN32) if(MSVC10) set(_TBB_COMPILER "vc10") endif(MSVC10) + if(MSVC11) + set(_TBB_COMPILER "vc11") + endif(MSVC11) # Todo: add other Windows compilers such as ICL. set(_TBB_ARCHITECTURE ${TBB_ARCHITECTURE}) endif (WIN32) @@ -85,12 +92,12 @@ if (UNIX) # MAC set(_TBB_DEFAULT_INSTALL_DIR "/Library/Frameworks/Intel_TBB.framework/Versions") # libs: libtbb.dylib, libtbbmalloc.dylib, *_debug - set(_TBB_LIB_NAME "tbb") - set(_TBB_LIB_MALLOC_NAME "${_TBB_LIB_NAME}malloc") - set(_TBB_LIB_MALLOCPROXY_NAME "${_TBB_LIB_NAME}malloc_proxy") - set(_TBB_LIB_DEBUG_NAME "${_TBB_LIB_NAME}_debug") - set(_TBB_LIB_MALLOC_DEBUG_NAME "${_TBB_LIB_MALLOC_NAME}_debug") - set(_TBB_LIB_MALLOCPROXY_DEBUG_NAME "${_TBB_LIB_MALLOCPROXY_NAME}_debug") + set(_TBB_LIB_RELEASE_NAME "tbb") + set(_TBB_LIB_MALLOC_RELEASE_NAME "${_TBB_LIB_RELEASE_NAME}malloc") + set(_TBB_LIB_MALLOCPROXY_RELEASE_NAME "${_TBB_LIB_RELEASE_NAME}malloc_proxy") + set(_TBB_LIB_DEBUG_NAME "${_TBB_LIB_RELEASE_NAME}_debug") + set(_TBB_LIB_MALLOC_DEBUG_NAME "${_TBB_LIB_MALLOC_RELEASE_NAME}_debug") + set(_TBB_LIB_MALLOCPROXY_DEBUG_NAME "${_TBB_LIB_MALLOCPROXY_RELEASE_NAME}_debug") # default flavor on apple: ia32/cc4.0.1_os10.4.9 # Jiri: There is no reason to presume there is only one flavor and # that user's setting of variables should be ignored. @@ -107,12 +114,12 @@ if (UNIX) else (APPLE) # LINUX set(_TBB_DEFAULT_INSTALL_DIR "/opt/intel/tbb" "/usr/local/include" "/usr/include") - set(_TBB_LIB_NAME "tbb") - set(_TBB_LIB_MALLOC_NAME "${_TBB_LIB_NAME}malloc") - set(_TBB_LIB_MALLOCPROXY_NAME "${_TBB_LIB_NAME}malloc_proxy") - set(_TBB_LIB_DEBUG_NAME "${_TBB_LIB_NAME}_debug") - set(_TBB_LIB_MALLOC_DEBUG_NAME "${_TBB_LIB_MALLOC_NAME}_debug") - set(_TBB_LIB_MALLOCPROXY_DEBUG_NAME "${_TBB_LIB_MALLOCPROXY_NAME}_debug") + set(_TBB_LIB_RELEASE_NAME "tbb") + set(_TBB_LIB_MALLOC_RELEASE_NAME "${_TBB_LIB_RELEASE_NAME}malloc") + set(_TBB_LIB_MALLOCPROXY_RELEASE_NAME "${_TBB_LIB_RELEASE_NAME}malloc_proxy") + set(_TBB_LIB_DEBUG_NAME "${_TBB_LIB_RELEASE_NAME}_debug") + set(_TBB_LIB_MALLOC_DEBUG_NAME "${_TBB_LIB_MALLOC_RELEASE_NAME}_debug") + set(_TBB_LIB_MALLOCPROXY_DEBUG_NAME "${_TBB_LIB_MALLOCPROXY_RELEASE_NAME}_debug") # has em64t/cc3.2.3_libc2.3.2_kernel2.4.21 em64t/cc3.3.3_libc2.3.3_kernel2.6.5 em64t/cc3.4.3_libc2.3.4_kernel2.6.9 em64t/cc4.1.0_libc2.4_kernel2.6.16.21 # has ia32/* # has itanium/* @@ -185,6 +192,7 @@ macro(TBB_CORRECT_LIB_DIR var_name) string(REPLACE vc8 "${_TBB_COMPILER}" ${var_name} ${${var_name}}) string(REPLACE vc9 "${_TBB_COMPILER}" ${var_name} ${${var_name}}) string(REPLACE vc10 "${_TBB_COMPILER}" ${var_name} ${${var_name}}) + string(REPLACE vc11 "${_TBB_COMPILER}" ${var_name} ${${var_name}}) endmacro(TBB_CORRECT_LIB_DIR var_content) @@ -231,56 +239,58 @@ list(APPEND _TBB_LIBRARY_DIR ${_TBB_INSTALL_DIR}/lib) # and LD_LIBRARY_PATH environment variables is now even more important # that tbbvars doesn't export TBB_ARCH_PLATFORM and it facilitates # the use of TBB built from sources. -find_library(TBB_LIBRARY ${_TBB_LIB_NAME} HINTS ${_TBB_LIBRARY_DIR} +find_library(TBB_RELEASE_LIBRARY ${_TBB_LIB_RELEASE_NAME} HINTS ${_TBB_LIBRARY_DIR} PATHS ENV LIBRARY_PATH ENV LD_LIBRARY_PATH) -find_library(TBB_MALLOC_LIBRARY ${_TBB_LIB_MALLOC_NAME} HINTS ${_TBB_LIBRARY_DIR} +find_library(TBB_MALLOC_RELEASE_LIBRARY ${_TBB_LIB_MALLOC_RELEASE_NAME} HINTS ${_TBB_LIBRARY_DIR} PATHS ENV LIBRARY_PATH ENV LD_LIBRARY_PATH) -find_library(TBB_MALLOCPROXY_LIBRARY ${_TBB_LIB_MALLOCPROXY_NAME} HINTS ${_TBB_LIBRARY_DIR} +find_library(TBB_MALLOCPROXY_RELEASE_LIBRARY ${_TBB_LIB_MALLOCPROXY_RELEASE_NAME} HINTS ${_TBB_LIBRARY_DIR} PATHS ENV LIBRARY_PATH ENV LD_LIBRARY_PATH) -#Extract path from TBB_LIBRARY name -get_filename_component(TBB_LIBRARY_DIR ${TBB_LIBRARY} PATH) +#Extract path from TBB_RELEASE_LIBRARY name +get_filename_component(TBB_RELEASE_LIBRARY_DIR ${TBB_RELEASE_LIBRARY} PATH) -#TBB_CORRECT_LIB_DIR(TBB_LIBRARY) -#TBB_CORRECT_LIB_DIR(TBB_MALLOC_LIBRARY) -#TBB_CORRECT_LIB_DIR(TBB_MALLOCPROXY_LIBRARY) -mark_as_advanced(TBB_LIBRARY TBB_MALLOC_LIBRARY TBB_MALLOCPROXY_LIBRARY) +#TBB_CORRECT_LIB_DIR(TBB_RELEASE_LIBRARY) +#TBB_CORRECT_LIB_DIR(TBB_MALLOC_RELEASE_LIBRARY) +#TBB_CORRECT_LIB_DIR(TBB_MALLOCPROXY_RELEASE_LIBRARY) +mark_as_advanced(TBB_RELEASE_LIBRARY TBB_MALLOC_RELEASE_LIBRARY TBB_MALLOCPROXY_RELEASE_LIBRARY) #-- Look for debug libraries # Jiri: Changed the same way as for the release libraries. -find_library(TBB_LIBRARY_DEBUG ${_TBB_LIB_DEBUG_NAME} HINTS ${_TBB_LIBRARY_DIR} +find_library(TBB_DEBUG_LIBRARY ${_TBB_LIB_DEBUG_NAME} HINTS ${_TBB_LIBRARY_DIR} PATHS ENV LIBRARY_PATH ENV LD_LIBRARY_PATH) -find_library(TBB_MALLOC_LIBRARY_DEBUG ${_TBB_LIB_MALLOC_DEBUG_NAME} HINTS ${_TBB_LIBRARY_DIR} +find_library(TBB_MALLOC_DEBUG_LIBRARY ${_TBB_LIB_MALLOC_DEBUG_NAME} HINTS ${_TBB_LIBRARY_DIR} PATHS ENV LIBRARY_PATH ENV LD_LIBRARY_PATH) -find_library(TBB_MALLOCPROXY_LIBRARY_DEBUG ${_TBB_LIB_MALLOCPROXY_DEBUG_NAME} HINTS ${_TBB_LIBRARY_DIR} +find_library(TBB_MALLOCPROXY_DEBUG_LIBRARY ${_TBB_LIB_MALLOCPROXY_DEBUG_NAME} HINTS ${_TBB_LIBRARY_DIR} PATHS ENV LIBRARY_PATH ENV LD_LIBRARY_PATH) # Jiri: Self-built TBB stores the debug libraries in a separate directory. -# Extract path from TBB_LIBRARY_DEBUG name -get_filename_component(TBB_LIBRARY_DEBUG_DIR ${TBB_LIBRARY_DEBUG} PATH) +# Extract path from TBB_DEBUG_LIBRARY name +get_filename_component(TBB_DEBUG_LIBRARY_DIR ${TBB_DEBUG_LIBRARY} PATH) -#TBB_CORRECT_LIB_DIR(TBB_LIBRARY_DEBUG) -#TBB_CORRECT_LIB_DIR(TBB_MALLOC_LIBRARY_DEBUG) -#TBB_CORRECT_LIB_DIR(TBB_MALLOCPROXY_LIBRARY_DEBUG) -mark_as_advanced(TBB_LIBRARY_DEBUG TBB_MALLOC_LIBRARY_DEBUG TBB_MALLOCPROXY_LIBRARY_DEBUG) +#TBB_CORRECT_LIB_DIR(TBB_DEBUG_LIBRARY) +#TBB_CORRECT_LIB_DIR(TBB_MALLOC_DEBUG_LIBRARY) +#TBB_CORRECT_LIB_DIR(TBB_MALLOCPROXY_DEBUG_LIBRARY) +mark_as_advanced(TBB_DEBUG_LIBRARY TBB_MALLOC_DEBUG_LIBRARY TBB_MALLOCPROXY_DEBUG_LIBRARY) if (TBB_INCLUDE_DIR) - if (TBB_LIBRARY) + if (TBB_RELEASE_LIBRARY) set (TBB_FOUND "YES") - set (TBB_LIBRARIES ${TBB_LIBRARY} ${TBB_MALLOC_LIBRARY} ${TBB_MALLOCPROXY_LIBRARY} ${TBB_LIBRARIES}) - set (TBB_DEBUG_LIBRARIES ${TBB_LIBRARY_DEBUG} ${TBB_MALLOC_LIBRARY_DEBUG} ${TBB_MALLOCPROXY_LIBRARY_DEBUG} ${TBB_DEBUG_LIBRARIES}) + set (TBB_LIBRARIES + optimized ${TBB_RELEASE_LIBRARY} optimized ${TBB_MALLOC_RELEASE_LIBRARY} optimized ${TBB_MALLOCPROXY_RELEASE_LIBRARY} + debug ${TBB_DEBUG_LIBRARY} debug ${TBB_MALLOC_DEBUG_LIBRARY} debug ${TBB_MALLOCPROXY_DEBUG_LIBRARY} + CACHE PATH "TBB libraries" FORCE) set (TBB_INCLUDE_DIRS ${TBB_INCLUDE_DIR} CACHE PATH "TBB include directory" FORCE) - set (TBB_LIBRARY_DIRS ${TBB_LIBRARY_DIR} CACHE PATH "TBB library directory" FORCE) - # Jiri: Self-built TBB stores the debug libraries in a separate directory. - set (TBB_DEBUG_LIBRARY_DIRS ${TBB_LIBRARY_DEBUG_DIR} CACHE PATH "TBB debug library directory" FORCE) - mark_as_advanced(TBB_INCLUDE_DIRS TBB_LIBRARY_DIRS TBB_DEBUG_LIBRARY_DIRS TBB_LIBRARIES TBB_DEBUG_LIBRARIES) + set (TBB_LIBRARY_DIRS + optimized ${TBB_RELEASE_LIBRARY_DIR} debug ${TBB_DEBUG_LIBRARY_DIR} + CACHE PATH "TBB library directories" FORCE) + mark_as_advanced(TBB_INCLUDE_DIRS TBB_LIBRARY_DIRS TBB_LIBRARIES) message(STATUS "Found Intel TBB") - endif (TBB_LIBRARY) + endif (TBB_RELEASE_LIBRARY) endif (TBB_INCLUDE_DIR) if (NOT TBB_FOUND) - message("ERROR: Intel TBB NOT found! Please define the TBBROOT and/or TBB_ARCH_PLATFORM environment variable.") + message("ERROR: Intel TBB NOT found! Please define the TBBROOT (or TBB_INSTALL_DIR) and/or TBB_ARCH_PLATFORM environment variables.") message(STATUS "Looked for Threading Building Blocks in ${_TBB_INSTALL_DIR}") SET(TBB_INSTALL_DIR "TBB_INSTALL_DIR_NOT_FOUND" CACHE STRING "Intel TBB install directory") # do only throw fatal, if this pkg is REQUIRED From d1f65375c09091fe4cf67c993894a1ca5b493924 Mon Sep 17 00:00:00 2001 From: Clement Jamin Date: Tue, 29 Jan 2013 14:11:22 +0100 Subject: [PATCH 06/17] Removed TBB_configuration We will rely on tbb::task_scheduler_init itself for now --- Installation/include/CGAL/TBB_configuration.h | 76 ------------------- 1 file changed, 76 deletions(-) delete mode 100644 Installation/include/CGAL/TBB_configuration.h diff --git a/Installation/include/CGAL/TBB_configuration.h b/Installation/include/CGAL/TBB_configuration.h deleted file mode 100644 index 331879f0738..00000000000 --- a/Installation/include/CGAL/TBB_configuration.h +++ /dev/null @@ -1,76 +0,0 @@ -// Copyright (c) 2013 -// INRIA Sophia-Antipolis (France). All rights reserved. -// -// This file is part of CGAL (www.cgal.org); you can redistribute it and/or -// modify it under the terms of the GNU Lesser General Public License as -// published by the Free Software Foundation; either version 3 of the License, -// or (at your option) any later version. -// -// Licensees holding a valid commercial license may use this file in -// accordance with the commercial license agreement provided with the software. -// -// This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE -// WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. -// -// $URL$ -// $Id$ -// -// -// Author(s) : Clement Jamin - -#ifndef CGAL_TBB_H -#define CGAL_TBB_H - -#ifdef CGAL_LINKED_WITH_TBB - -#include -#include - -namespace CGAL { - -/*! -\ingroup Installation - -\brief The class TBB_configuration provides control over TBB. -*/ -class TBB_configuration -{ -public: - /*! - \brief Set the maximum number of threads that TBB may create. - \details If max_num_threads <= 0, TBB will decide the number of threads, - which is typically the number of hardware threads. - */ - static void set_max_number_of_threads(int max_num_threads = -1) - { - static tbb::task_scheduler_init init(tbb::task_scheduler_init::deferred); - - if (init.is_active()) - init.terminate(); - - if (max_num_threads > 0) - init.initialize(max_num_threads); - else - init.initialize(); - } - - /*! - \brief Returns the number of threads TBB scheduler would create if initialized by - default. - \details This number is typically the number of hardware threads (logical - processors). - */ - static int get_default_number_of_threads() - { - return tbb::task_scheduler_init::default_num_threads(); - } - -protected: - // We don't want this class to be instantiated by an user - TBB_configuration() {} -}; - -} //namespace CGAL - -#endif // CGAL_LINKED_WITH_TBB -#endif // CGAL_TBB_H From cd83c4680a067fbf75f5403fac98ee56b7839a16 Mon Sep 17 00:00:00 2001 From: Clement Jamin Date: Wed, 6 Feb 2013 18:15:25 +0100 Subject: [PATCH 07/17] Tags for concurrency --- STL_Extension/include/CGAL/tags.h | 3 +++ 1 file changed, 3 insertions(+) diff --git a/STL_Extension/include/CGAL/tags.h b/STL_Extension/include/CGAL/tags.h index c343ff411cb..d26dd44f4f4 100644 --- a/STL_Extension/include/CGAL/tags.h +++ b/STL_Extension/include/CGAL/tags.h @@ -54,6 +54,9 @@ struct Null_functor { typedef Null_tag second_argument_type; }; +// For concurrency +struct Sequential_tag {}; +struct Parallel_tag {}; // A function that asserts a specific compile time tag // forcing its two arguments to have equal type. From 4a90303dc2432ae4cba59c39ce0cc58b9ba24214 Mon Sep 17 00:00:00 2001 From: Clement Jamin Date: Fri, 8 Mar 2013 11:24:20 +0100 Subject: [PATCH 08/17] Doc for Sequential_tag and Parallel_tag --- STL_Extension/doc/STL_Extension/CGAL/tags.h | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/STL_Extension/doc/STL_Extension/CGAL/tags.h b/STL_Extension/doc/STL_Extension/CGAL/tags.h index d4f5455387b..e3720628d04 100644 --- a/STL_Extension/doc/STL_Extension/CGAL/tags.h +++ b/STL_Extension/doc/STL_Extension/CGAL/tags.h @@ -68,6 +68,18 @@ struct Null_functor { }; +/*! +\ingroup PkgStlExtensionUtilities +Tag to indicate that a class or a function IS NOT concurrency-safe. +*/ +struct Sequential_tag {}; + +/*! +\ingroup PkgStlExtensionUtilities +Tag to indicate that a class or a function IS concurrency-safe. +*/ +struct Parallel_tag {}; + /*! \ingroup PkgStlExtensionUtilities From bbb5fec836b7784e9a78fe91dcee3bedf01274c5 Mon Sep 17 00:00:00 2001 From: Clement Jamin Date: Fri, 31 May 2013 10:44:41 +0200 Subject: [PATCH 09/17] The Parallel_tag inherits Sequential_tag --- STL_Extension/include/CGAL/tags.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/STL_Extension/include/CGAL/tags.h b/STL_Extension/include/CGAL/tags.h index d26dd44f4f4..8bf81c78a83 100644 --- a/STL_Extension/include/CGAL/tags.h +++ b/STL_Extension/include/CGAL/tags.h @@ -56,7 +56,7 @@ struct Null_functor { // For concurrency struct Sequential_tag {}; -struct Parallel_tag {}; +struct Parallel_tag : public Sequential_tag {}; // A function that asserts a specific compile time tag // forcing its two arguments to have equal type. From 90d01257413d5fbe158d21d611ef6ad8a18d9330 Mon Sep 17 00:00:00 2001 From: Clement Jamin Date: Thu, 27 Jun 2013 15:54:39 +0200 Subject: [PATCH 10/17] Improved FindTBB.cmake - Untabified - Does not link with the TBB mallow proxy anymore, but set TBB_MALLOCPROXY_DEBUG_LIBRARY and TBB_MALLOCPROXY_RELEASE_LIBRARY so that a user can still link with it if necessary Note: the malloc proxy is not available on MacOS. - Calls include_directories ( ${TBB_INCLUDE_DIRS} ) and link_directories( ${TBB_LIBRARY_DIRS} ) to set paths --- Installation/cmake/modules/FindTBB.cmake | 57 +++++++++++++++--------- 1 file changed, 35 insertions(+), 22 deletions(-) diff --git a/Installation/cmake/modules/FindTBB.cmake b/Installation/cmake/modules/FindTBB.cmake index 7c772fa2531..e60143e684f 100644 --- a/Installation/cmake/modules/FindTBB.cmake +++ b/Installation/cmake/modules/FindTBB.cmake @@ -47,15 +47,15 @@ # TBB_INCLUDE_DIRS, where to find task_scheduler_init.h, etc. # TBB_LIBRARY_DIRS, where to find TBB libraries (both release and debug versions, using "optimized" and "debug" CMake keywords). # TBB_INSTALL_DIR, the base TBB install directory. -# TBB_LIBRARIES, all the TBB libraries (both release and debug versions, using "optimized" and "debug" CMake keywords). -# TBB_RELEASE_LIBRARY, the TBB release library -# TBB_MALLOC_RELEASE_LIBRARY, the TBB release malloc library -# TBB_MALLOCPROXY_RELEASE_LIBRARY, the TBB release malloc_proxy library -# TBB_DEBUG_LIBRARY, the TBB debug library -# TBB_MALLOC_DEBUG_LIBRARY, the TBB debug malloc library -# TBB_MALLOCPROXY_DEBUG_LIBRARY, the TBB debug malloc_proxy library +# TBB_LIBRARIES, all the following TBB libraries (both release and debug versions, using "optimized" and "debug" CMake keywords). +# TBB_RELEASE_LIBRARY, the TBB release library +# TBB_MALLOC_RELEASE_LIBRARY, the TBB release malloc library +# TBB_DEBUG_LIBRARY, the TBB debug library +# TBB_MALLOC_DEBUG_LIBRARY, the TBB debug malloc library # TBB_FOUND, If false, don't try to use TBB. # TBB_INTERFACE_VERSION, as defined in tbb/tbb_stddef.h +# TBB_MALLOCPROXY_DEBUG_LIBRARY, the TBB debug malloc_proxy library (not included in TBB_LIBRARIES since it's optionnal) +# TBB_MALLOCPROXY_RELEASE_LIBRARY, the TBB release malloc_proxy library (not included in TBB_LIBRARIES since it's optionnal) if (WIN32) @@ -94,10 +94,10 @@ if (UNIX) # libs: libtbb.dylib, libtbbmalloc.dylib, *_debug set(_TBB_LIB_RELEASE_NAME "tbb") set(_TBB_LIB_MALLOC_RELEASE_NAME "${_TBB_LIB_RELEASE_NAME}malloc") - set(_TBB_LIB_MALLOCPROXY_RELEASE_NAME "${_TBB_LIB_RELEASE_NAME}malloc_proxy") + #set(_TBB_LIB_MALLOCPROXY_RELEASE_NAME "${_TBB_LIB_RELEASE_NAME}malloc_proxy") set(_TBB_LIB_DEBUG_NAME "${_TBB_LIB_RELEASE_NAME}_debug") set(_TBB_LIB_MALLOC_DEBUG_NAME "${_TBB_LIB_MALLOC_RELEASE_NAME}_debug") - set(_TBB_LIB_MALLOCPROXY_DEBUG_NAME "${_TBB_LIB_MALLOCPROXY_RELEASE_NAME}_debug") + #set(_TBB_LIB_MALLOCPROXY_DEBUG_NAME "${_TBB_LIB_MALLOCPROXY_RELEASE_NAME}_debug") # default flavor on apple: ia32/cc4.0.1_os10.4.9 # Jiri: There is no reason to presume there is only one flavor and # that user's setting of variables should be ignored. @@ -252,7 +252,7 @@ get_filename_component(TBB_RELEASE_LIBRARY_DIR ${TBB_RELEASE_LIBRARY} PATH) #TBB_CORRECT_LIB_DIR(TBB_RELEASE_LIBRARY) #TBB_CORRECT_LIB_DIR(TBB_MALLOC_RELEASE_LIBRARY) #TBB_CORRECT_LIB_DIR(TBB_MALLOCPROXY_RELEASE_LIBRARY) -mark_as_advanced(TBB_RELEASE_LIBRARY TBB_MALLOC_RELEASE_LIBRARY TBB_MALLOCPROXY_RELEASE_LIBRARY) +mark_as_advanced(TBB_RELEASE_LIBRARY TBB_MALLOC_RELEASE_LIBRARY) #-- Look for debug libraries # Jiri: Changed the same way as for the release libraries. @@ -270,20 +270,31 @@ get_filename_component(TBB_DEBUG_LIBRARY_DIR ${TBB_DEBUG_LIBRARY} PATH) #TBB_CORRECT_LIB_DIR(TBB_DEBUG_LIBRARY) #TBB_CORRECT_LIB_DIR(TBB_MALLOC_DEBUG_LIBRARY) #TBB_CORRECT_LIB_DIR(TBB_MALLOCPROXY_DEBUG_LIBRARY) -mark_as_advanced(TBB_DEBUG_LIBRARY TBB_MALLOC_DEBUG_LIBRARY TBB_MALLOCPROXY_DEBUG_LIBRARY) - +mark_as_advanced(TBB_DEBUG_LIBRARY TBB_MALLOC_DEBUG_LIBRARY) if (TBB_INCLUDE_DIR) if (TBB_RELEASE_LIBRARY) set (TBB_FOUND "YES") - set (TBB_LIBRARIES - optimized ${TBB_RELEASE_LIBRARY} optimized ${TBB_MALLOC_RELEASE_LIBRARY} optimized ${TBB_MALLOCPROXY_RELEASE_LIBRARY} - debug ${TBB_DEBUG_LIBRARY} debug ${TBB_MALLOC_DEBUG_LIBRARY} debug ${TBB_MALLOCPROXY_DEBUG_LIBRARY} - CACHE PATH "TBB libraries" FORCE) + + # NOTE: Removed because we don't want to link with the malloc_proxy by default + #if (NOT "${TBB_MALLOCPROXY_RELEASE_LIBRARY}" STREQUAL "TBB_MALLOCPROXY_RELEASE_LIBRARY-NOTFOUND") + # mark_as_advanced(TBB_MALLOCPROXY_RELEASE_LIBRARY) + # set (_TBB_MALLOCPROXY optimized ${TBB_MALLOCPROXY_RELEASE_LIBRARY}) + #endif (NOT "${TBB_MALLOCPROXY_RELEASE_LIBRARY}" STREQUAL "TBB_MALLOCPROXY_RELEASE_LIBRARY-NOTFOUND") + #if (NOT "${TBB_MALLOCPROXY_DEBUG_LIBRARY}" STREQUAL "TBB_MALLOCPROXY_DEBUG_LIBRARY-NOTFOUND") + # mark_as_advanced(TBB_MALLOCPROXY_DEBUG_LIBRARY) + # set (_TBB_MALLOCPROXY ${_TBB_MALLOCPROXY} debug ${TBB_MALLOCPROXY_DEBUG_LIBRARY}) + #endif (NOT "${TBB_MALLOCPROXY_DEBUG_LIBRARY}" STREQUAL "TBB_MALLOCPROXY_DEBUG_LIBRARY-NOTFOUND") + + set (TBB_LIBRARIES + optimized ${TBB_RELEASE_LIBRARY} optimized ${TBB_MALLOC_RELEASE_LIBRARY} + debug ${TBB_DEBUG_LIBRARY} debug ${TBB_MALLOC_DEBUG_LIBRARY} + #${_TBB_MALLOCPROXY} # NOTE: Removed because we don't want to link with the malloc_proxy by default + CACHE PATH "TBB libraries" FORCE) set (TBB_INCLUDE_DIRS ${TBB_INCLUDE_DIR} CACHE PATH "TBB include directory" FORCE) set (TBB_LIBRARY_DIRS - optimized ${TBB_RELEASE_LIBRARY_DIR} debug ${TBB_DEBUG_LIBRARY_DIR} - CACHE PATH "TBB library directories" FORCE) + optimized ${TBB_RELEASE_LIBRARY_DIR} debug ${TBB_DEBUG_LIBRARY_DIR} + CACHE PATH "TBB library directories" FORCE) mark_as_advanced(TBB_INCLUDE_DIRS TBB_LIBRARY_DIRS TBB_LIBRARIES) message(STATUS "Found Intel TBB") endif (TBB_RELEASE_LIBRARY) @@ -302,8 +313,10 @@ endif (NOT TBB_FOUND) endif (NOT _TBB_INSTALL_DIR) if (TBB_FOUND) - set(TBB_INTERFACE_VERSION 0) - FILE(READ "${TBB_INCLUDE_DIRS}/tbb/tbb_stddef.h" _TBB_VERSION_CONTENTS) - STRING(REGEX REPLACE ".*#define TBB_INTERFACE_VERSION ([0-9]+).*" "\\1" TBB_INTERFACE_VERSION "${_TBB_VERSION_CONTENTS}") - set(TBB_INTERFACE_VERSION "${TBB_INTERFACE_VERSION}") + set(TBB_INTERFACE_VERSION 0) + FILE(READ "${TBB_INCLUDE_DIRS}/tbb/tbb_stddef.h" _TBB_VERSION_CONTENTS) + STRING(REGEX REPLACE ".*#define TBB_INTERFACE_VERSION ([0-9]+).*" "\\1" TBB_INTERFACE_VERSION "${_TBB_VERSION_CONTENTS}") + set(TBB_INTERFACE_VERSION "${TBB_INTERFACE_VERSION}") + include_directories ( ${TBB_INCLUDE_DIRS} ) + link_directories( ${TBB_LIBRARY_DIRS} ) endif (TBB_FOUND) From da77b4d879888879e6b385482e00f0d947a3d430 Mon Sep 17 00:00:00 2001 From: Clement Jamin Date: Thu, 27 Jun 2013 16:50:55 +0200 Subject: [PATCH 11/17] Correct FindTBB.cmake + add a UseTBB.cmake --- Installation/cmake/modules/FindTBB.cmake | 4 ++-- Installation/cmake/modules/UseTBB.cmake | 6 ++++++ 2 files changed, 8 insertions(+), 2 deletions(-) create mode 100644 Installation/cmake/modules/UseTBB.cmake diff --git a/Installation/cmake/modules/FindTBB.cmake b/Installation/cmake/modules/FindTBB.cmake index e60143e684f..28722407373 100644 --- a/Installation/cmake/modules/FindTBB.cmake +++ b/Installation/cmake/modules/FindTBB.cmake @@ -317,6 +317,6 @@ if (TBB_FOUND) FILE(READ "${TBB_INCLUDE_DIRS}/tbb/tbb_stddef.h" _TBB_VERSION_CONTENTS) STRING(REGEX REPLACE ".*#define TBB_INTERFACE_VERSION ([0-9]+).*" "\\1" TBB_INTERFACE_VERSION "${_TBB_VERSION_CONTENTS}") set(TBB_INTERFACE_VERSION "${TBB_INTERFACE_VERSION}") - include_directories ( ${TBB_INCLUDE_DIRS} ) - link_directories( ${TBB_LIBRARY_DIRS} ) endif (TBB_FOUND) + +set(TBB_USE_FILE "UseTBB") \ No newline at end of file diff --git a/Installation/cmake/modules/UseTBB.cmake b/Installation/cmake/modules/UseTBB.cmake new file mode 100644 index 00000000000..966d0f59749 --- /dev/null +++ b/Installation/cmake/modules/UseTBB.cmake @@ -0,0 +1,6 @@ +# This module setups the compiler for using TBB library. +# It assumes that find_package(TBB) was already called. + +include_directories ( ${TBB_INCLUDE_DIRS} ) +link_directories( ${TBB_LIBRARY_DIRS} ) +add_definitions( -DNOMINMAX -DCGAL_LINKED_WITH_TBB ) \ No newline at end of file From 3dfb28141fc7864622d51521a462fa5b779bd888 Mon Sep 17 00:00:00 2001 From: Clement Jamin Date: Fri, 28 Jun 2013 17:55:12 +0200 Subject: [PATCH 12/17] Mark TBB_MALLOCPROXY_XXX_LIBRARY as advanced in CMake --- Installation/cmake/modules/FindTBB.cmake | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Installation/cmake/modules/FindTBB.cmake b/Installation/cmake/modules/FindTBB.cmake index 28722407373..a86b40ffca3 100644 --- a/Installation/cmake/modules/FindTBB.cmake +++ b/Installation/cmake/modules/FindTBB.cmake @@ -252,7 +252,7 @@ get_filename_component(TBB_RELEASE_LIBRARY_DIR ${TBB_RELEASE_LIBRARY} PATH) #TBB_CORRECT_LIB_DIR(TBB_RELEASE_LIBRARY) #TBB_CORRECT_LIB_DIR(TBB_MALLOC_RELEASE_LIBRARY) #TBB_CORRECT_LIB_DIR(TBB_MALLOCPROXY_RELEASE_LIBRARY) -mark_as_advanced(TBB_RELEASE_LIBRARY TBB_MALLOC_RELEASE_LIBRARY) +mark_as_advanced(TBB_RELEASE_LIBRARY TBB_MALLOC_RELEASE_LIBRARY TBB_MALLOCPROXY_RELEASE_LIBRARY) #-- Look for debug libraries # Jiri: Changed the same way as for the release libraries. @@ -270,7 +270,7 @@ get_filename_component(TBB_DEBUG_LIBRARY_DIR ${TBB_DEBUG_LIBRARY} PATH) #TBB_CORRECT_LIB_DIR(TBB_DEBUG_LIBRARY) #TBB_CORRECT_LIB_DIR(TBB_MALLOC_DEBUG_LIBRARY) #TBB_CORRECT_LIB_DIR(TBB_MALLOCPROXY_DEBUG_LIBRARY) -mark_as_advanced(TBB_DEBUG_LIBRARY TBB_MALLOC_DEBUG_LIBRARY) +mark_as_advanced(TBB_DEBUG_LIBRARY TBB_MALLOC_DEBUG_LIBRARY TBB_MALLOCPROXY_DEBUG_LIBRARY) if (TBB_INCLUDE_DIR) if (TBB_RELEASE_LIBRARY) From 9c57c17a3454ba02659acea49971eb8f8c6bab88 Mon Sep 17 00:00:00 2001 From: Clement Jamin Date: Wed, 3 Jul 2013 12:28:50 +0200 Subject: [PATCH 13/17] Bugfix for TBB_LIBRARY_DIRS --- Installation/cmake/modules/FindTBB.cmake | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/Installation/cmake/modules/FindTBB.cmake b/Installation/cmake/modules/FindTBB.cmake index a86b40ffca3..7f06ee7d765 100644 --- a/Installation/cmake/modules/FindTBB.cmake +++ b/Installation/cmake/modules/FindTBB.cmake @@ -292,10 +292,15 @@ if (TBB_INCLUDE_DIR) #${_TBB_MALLOCPROXY} # NOTE: Removed because we don't want to link with the malloc_proxy by default CACHE PATH "TBB libraries" FORCE) set (TBB_INCLUDE_DIRS ${TBB_INCLUDE_DIR} CACHE PATH "TBB include directory" FORCE) - set (TBB_LIBRARY_DIRS - optimized ${TBB_RELEASE_LIBRARY_DIR} debug ${TBB_DEBUG_LIBRARY_DIR} - CACHE PATH "TBB library directories" FORCE) - mark_as_advanced(TBB_INCLUDE_DIRS TBB_LIBRARY_DIRS TBB_LIBRARIES) + if( ${TBB_RELEASE_LIBRARY_DIR} STREQUAL ${TBB_DEBUG_LIBRARY_DIR} ) + set (TBB_LIBRARY_DIRS + ${TBB_RELEASE_LIBRARY_DIR} + CACHE PATH "TBB library directories" FORCE) + else( ${TBB_RELEASE_LIBRARY_DIR} STREQUAL ${TBB_DEBUG_LIBRARY_DIR} ) + set (TBB_LIBRARY_DIRS + ${TBB_RELEASE_LIBRARY_DIR} ${TBB_DEBUG_LIBRARY_DIR} + CACHE PATH "TBB library directories" FORCE) + endif( ${TBB_RELEASE_LIBRARY_DIR} STREQUAL ${TBB_DEBUG_LIBRARY_DIR} ) message(STATUS "Found Intel TBB") endif (TBB_RELEASE_LIBRARY) endif (TBB_INCLUDE_DIR) From 31342deb22805746e6021a02f739c8b90fecf354 Mon Sep 17 00:00:00 2001 From: Clement Jamin Date: Wed, 3 Jul 2013 13:01:09 +0200 Subject: [PATCH 14/17] Better doc for tags. --- STL_Extension/doc/STL_Extension/CGAL/tags.h | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/STL_Extension/doc/STL_Extension/CGAL/tags.h b/STL_Extension/doc/STL_Extension/CGAL/tags.h index e3720628d04..37bc4ff1ef5 100644 --- a/STL_Extension/doc/STL_Extension/CGAL/tags.h +++ b/STL_Extension/doc/STL_Extension/CGAL/tags.h @@ -70,13 +70,15 @@ struct Null_functor { /*! \ingroup PkgStlExtensionUtilities -Tag to indicate that a class or a function IS NOT concurrency-safe. +Tag used to enable/disable concurrency. +For example, it may be used by a user to request the sequential version of an algorithm. */ struct Sequential_tag {}; /*! \ingroup PkgStlExtensionUtilities -Tag to indicate that a class or a function IS concurrency-safe. +Tag used to enable/disable concurrency. +For example, it may be used by a user to request the parallel version of an algorithm. */ struct Parallel_tag {}; From 4d0c6a6bb042c88a8172951ffbddfc4d05f135c3 Mon Sep 17 00:00:00 2001 From: Clement Jamin Date: Wed, 3 Jul 2013 16:48:10 +0200 Subject: [PATCH 15/17] Better FindTBB.cmake which works even if the debug version is not found If the debug versions are not found, the release versions will be used instead for the debug mode. If the tbb_malloc library is not found, doesn't link with it. --- Installation/cmake/modules/FindTBB.cmake | 45 ++++++++++++++++++------ 1 file changed, 35 insertions(+), 10 deletions(-) diff --git a/Installation/cmake/modules/FindTBB.cmake b/Installation/cmake/modules/FindTBB.cmake index 7f06ee7d765..5ddfff8c220 100644 --- a/Installation/cmake/modules/FindTBB.cmake +++ b/Installation/cmake/modules/FindTBB.cmake @@ -45,9 +45,9 @@ # This module defines # TBB_INCLUDE_DIRS, where to find task_scheduler_init.h, etc. -# TBB_LIBRARY_DIRS, where to find TBB libraries (both release and debug versions, using "optimized" and "debug" CMake keywords). +# TBB_LIBRARY_DIRS, where to find TBB libraries # TBB_INSTALL_DIR, the base TBB install directory. -# TBB_LIBRARIES, all the following TBB libraries (both release and debug versions, using "optimized" and "debug" CMake keywords). +# TBB_LIBRARIES, all the following TBB libraries (both release and debug versions, using "optimized" and "debug" CMake keywords). Note that if the debug versions are not found, the release versions will be used instead for the debug mode. # TBB_RELEASE_LIBRARY, the TBB release library # TBB_MALLOC_RELEASE_LIBRARY, the TBB release malloc library # TBB_DEBUG_LIBRARY, the TBB debug library @@ -286,21 +286,46 @@ if (TBB_INCLUDE_DIR) # set (_TBB_MALLOCPROXY ${_TBB_MALLOCPROXY} debug ${TBB_MALLOCPROXY_DEBUG_LIBRARY}) #endif (NOT "${TBB_MALLOCPROXY_DEBUG_LIBRARY}" STREQUAL "TBB_MALLOCPROXY_DEBUG_LIBRARY-NOTFOUND") - set (TBB_LIBRARIES - optimized ${TBB_RELEASE_LIBRARY} optimized ${TBB_MALLOC_RELEASE_LIBRARY} - debug ${TBB_DEBUG_LIBRARY} debug ${TBB_MALLOC_DEBUG_LIBRARY} - #${_TBB_MALLOCPROXY} # NOTE: Removed because we don't want to link with the malloc_proxy by default - CACHE PATH "TBB libraries" FORCE) + # TBB release library + set (ALL_TBB_LIBRARIES optimized ${TBB_RELEASE_LIBRARY}) + + # TBB debug library found? + if (TBB_DEBUG_LIBRARY) + list(APPEND ALL_TBB_LIBRARIES debug ${TBB_DEBUG_LIBRARY}) + else (TBB_DEBUG_LIBRARY) + # Otherwise, link with the release library even in debug mode + list(APPEND ALL_TBB_LIBRARIES debug ${TBB_RELEASE_LIBRARY}) + endif (TBB_DEBUG_LIBRARY) + + # TBB malloc - release + if (TBB_MALLOC_RELEASE_LIBRARY) + list(APPEND ALL_TBB_LIBRARIES optimized ${TBB_MALLOC_RELEASE_LIBRARY}) + + # TBB malloc - debug + if (TBB_MALLOC_DEBUG_LIBRARY) + list(APPEND ALL_TBB_LIBRARIES debug ${TBB_MALLOC_DEBUG_LIBRARY}) + else (TBB_MALLOC_DEBUG_LIBRARY) + list(APPEND ALL_TBB_LIBRARIES debug ${TBB_MALLOC_RELEASE_LIBRARY}) + endif (TBB_MALLOC_DEBUG_LIBRARY) + endif (TBB_MALLOC_RELEASE_LIBRARY) + + set (TBB_LIBRARIES ${ALL_TBB_LIBRARIES} + CACHE PATH "TBB libraries" FORCE) + + # Include dirs set (TBB_INCLUDE_DIRS ${TBB_INCLUDE_DIR} CACHE PATH "TBB include directory" FORCE) - if( ${TBB_RELEASE_LIBRARY_DIR} STREQUAL ${TBB_DEBUG_LIBRARY_DIR} ) + + # Library dirs + if( "${TBB_DEBUG_LIBRARY_DIR}" STREQUAL "" OR "${TBB_RELEASE_LIBRARY_DIR}" STREQUAL "${TBB_DEBUG_LIBRARY_DIR}" ) set (TBB_LIBRARY_DIRS ${TBB_RELEASE_LIBRARY_DIR} CACHE PATH "TBB library directories" FORCE) - else( ${TBB_RELEASE_LIBRARY_DIR} STREQUAL ${TBB_DEBUG_LIBRARY_DIR} ) + else( "${TBB_DEBUG_LIBRARY_DIR}" STREQUAL "" OR "${TBB_RELEASE_LIBRARY_DIR}" STREQUAL "${TBB_DEBUG_LIBRARY_DIR}" ) set (TBB_LIBRARY_DIRS ${TBB_RELEASE_LIBRARY_DIR} ${TBB_DEBUG_LIBRARY_DIR} CACHE PATH "TBB library directories" FORCE) - endif( ${TBB_RELEASE_LIBRARY_DIR} STREQUAL ${TBB_DEBUG_LIBRARY_DIR} ) + endif( "${TBB_DEBUG_LIBRARY_DIR}" STREQUAL "" OR "${TBB_RELEASE_LIBRARY_DIR}" STREQUAL "${TBB_DEBUG_LIBRARY_DIR}" ) + message(STATUS "Found Intel TBB") endif (TBB_RELEASE_LIBRARY) endif (TBB_INCLUDE_DIR) From 4b9df4540a8ff537acd8dec3e07339a52530abc7 Mon Sep 17 00:00:00 2001 From: Clement Jamin Date: Wed, 3 Jul 2013 19:00:54 +0200 Subject: [PATCH 16/17] Added a test for TBB --- Installation/test/Installation/CMakeLists.txt | 7 ++ Installation/test/Installation/test_TBB.cpp | 65 +++++++++++++++++++ 2 files changed, 72 insertions(+) create mode 100644 Installation/test/Installation/test_TBB.cpp diff --git a/Installation/test/Installation/CMakeLists.txt b/Installation/test/Installation/CMakeLists.txt index 9ff309b1d6a..462364fccba 100644 --- a/Installation/test/Installation/CMakeLists.txt +++ b/Installation/test/Installation/CMakeLists.txt @@ -44,6 +44,13 @@ if ( CGAL_FOUND ) create_single_source_cgal_program( "test_use_h.cpp" ) + find_package( TBB ) + if( TBB_FOUND ) + include(${TBB_USE_FILE}) + list(APPEND CGAL_3RD_PARTY_LIBRARIES ${TBB_LIBRARIES}) + endif() + create_single_source_cgal_program( "test_TBB.cpp" ) + create_link_to_program(CGAL) if ( WITH_CGAL_Core ) diff --git a/Installation/test/Installation/test_TBB.cpp b/Installation/test/Installation/test_TBB.cpp new file mode 100644 index 00000000000..f4ea6746ca6 --- /dev/null +++ b/Installation/test/Installation/test_TBB.cpp @@ -0,0 +1,65 @@ +//#undef CGAL_LINKED_WITH_TBB + +#include + +#ifdef CGAL_LINKED_WITH_TBB +# include +# include +#endif + +#include +#include + +#ifdef CGAL_LINKED_WITH_TBB +class Change_array_functor +{ +public: + Change_array_functor(std::vector &v) + : m_v(v) {} + + void operator() (const tbb::blocked_range& r) const + { + for(size_t i = r.begin(); i != r.end(); i++ ) + m_v[i] *= 10; + } + +private: + std::vector &m_v; +}; + +void change_array(std::vector &v, CGAL::Parallel_tag) +{ + std::cout << "[Parallel] Using a tbb::parallel_for loop..."; + tbb::parallel_for( + tbb::blocked_range(0, v.size()), + Change_array_functor(v) + ); + std::cout << " done." << std::endl; +} +#endif + +void change_array(std::vector &v, CGAL::Sequential_tag) +{ + std::cout << "[Sequential] Using a sequential for loop..."; + std::vector::iterator it = v.begin(), it_end = v.end(); + for ( ; it != it_end ; ++it) + *it *= 10; + std::cout << " done." << std::endl; +} + +int main() +{ + std::vector v; + for (int i = 0 ; i < 10000 ; ++i) + v.push_back(i); + + std::cout << "Trying to call the sequential algorithm => "; + change_array(v, CGAL::Sequential_tag()); + std::cout << "Trying to call the parallel algorithm => "; + change_array(v, CGAL::Parallel_tag()); + + /*for (int i = 0 ; i < 100 ; ++i) + std::cerr << v[i] << " ";*/ + + return 0; +} From e724c1f519d60f6375009a6ef6348e26631c6313 Mon Sep 17 00:00:00 2001 From: Laurent Rineau Date: Thu, 4 Jul 2013 11:51:23 +0200 Subject: [PATCH 17/17] Fix end-of-lines and end-of-files --- Installation/cmake/modules/FindTBB.cmake | 22 +++++++++---------- Installation/cmake/modules/UseTBB.cmake | 2 +- Installation/test/Installation/CMakeLists.txt | 4 ++-- Installation/test/Installation/test_TBB.cpp | 6 ++--- STL_Extension/doc/STL_Extension/CGAL/tags.h | 4 ++-- 5 files changed, 19 insertions(+), 19 deletions(-) diff --git a/Installation/cmake/modules/FindTBB.cmake b/Installation/cmake/modules/FindTBB.cmake index 5ddfff8c220..6c47e8b31e1 100644 --- a/Installation/cmake/modules/FindTBB.cmake +++ b/Installation/cmake/modules/FindTBB.cmake @@ -210,7 +210,7 @@ mark_as_advanced(TBB_INCLUDE_DIR) #-- Look for libraries # GvdB: $ENV{TBB_ARCH_PLATFORM} is set by the build script tbbvars[.bat|.sh|.csh] if (NOT $ENV{TBB_ARCH_PLATFORM} STREQUAL "") - set (_TBB_LIBRARY_DIR + set (_TBB_LIBRARY_DIR ${_TBB_INSTALL_DIR}/lib/$ENV{TBB_ARCH_PLATFORM} ${_TBB_INSTALL_DIR}/$ENV{TBB_ARCH_PLATFORM}/lib ) @@ -275,7 +275,7 @@ mark_as_advanced(TBB_DEBUG_LIBRARY TBB_MALLOC_DEBUG_LIBRARY TBB_MALLOCPROXY_DEBU if (TBB_INCLUDE_DIR) if (TBB_RELEASE_LIBRARY) set (TBB_FOUND "YES") - + # NOTE: Removed because we don't want to link with the malloc_proxy by default #if (NOT "${TBB_MALLOCPROXY_RELEASE_LIBRARY}" STREQUAL "TBB_MALLOCPROXY_RELEASE_LIBRARY-NOTFOUND") # mark_as_advanced(TBB_MALLOCPROXY_RELEASE_LIBRARY) @@ -285,14 +285,14 @@ if (TBB_INCLUDE_DIR) # mark_as_advanced(TBB_MALLOCPROXY_DEBUG_LIBRARY) # set (_TBB_MALLOCPROXY ${_TBB_MALLOCPROXY} debug ${TBB_MALLOCPROXY_DEBUG_LIBRARY}) #endif (NOT "${TBB_MALLOCPROXY_DEBUG_LIBRARY}" STREQUAL "TBB_MALLOCPROXY_DEBUG_LIBRARY-NOTFOUND") - + # TBB release library set (ALL_TBB_LIBRARIES optimized ${TBB_RELEASE_LIBRARY}) - + # TBB debug library found? if (TBB_DEBUG_LIBRARY) list(APPEND ALL_TBB_LIBRARIES debug ${TBB_DEBUG_LIBRARY}) - else (TBB_DEBUG_LIBRARY) + else (TBB_DEBUG_LIBRARY) # Otherwise, link with the release library even in debug mode list(APPEND ALL_TBB_LIBRARIES debug ${TBB_RELEASE_LIBRARY}) endif (TBB_DEBUG_LIBRARY) @@ -300,7 +300,7 @@ if (TBB_INCLUDE_DIR) # TBB malloc - release if (TBB_MALLOC_RELEASE_LIBRARY) list(APPEND ALL_TBB_LIBRARIES optimized ${TBB_MALLOC_RELEASE_LIBRARY}) - + # TBB malloc - debug if (TBB_MALLOC_DEBUG_LIBRARY) list(APPEND ALL_TBB_LIBRARIES debug ${TBB_MALLOC_DEBUG_LIBRARY}) @@ -308,13 +308,13 @@ if (TBB_INCLUDE_DIR) list(APPEND ALL_TBB_LIBRARIES debug ${TBB_MALLOC_RELEASE_LIBRARY}) endif (TBB_MALLOC_DEBUG_LIBRARY) endif (TBB_MALLOC_RELEASE_LIBRARY) - + set (TBB_LIBRARIES ${ALL_TBB_LIBRARIES} CACHE PATH "TBB libraries" FORCE) - + # Include dirs set (TBB_INCLUDE_DIRS ${TBB_INCLUDE_DIR} CACHE PATH "TBB include directory" FORCE) - + # Library dirs if( "${TBB_DEBUG_LIBRARY_DIR}" STREQUAL "" OR "${TBB_RELEASE_LIBRARY_DIR}" STREQUAL "${TBB_DEBUG_LIBRARY_DIR}" ) set (TBB_LIBRARY_DIRS @@ -325,7 +325,7 @@ if (TBB_INCLUDE_DIR) ${TBB_RELEASE_LIBRARY_DIR} ${TBB_DEBUG_LIBRARY_DIR} CACHE PATH "TBB library directories" FORCE) endif( "${TBB_DEBUG_LIBRARY_DIR}" STREQUAL "" OR "${TBB_RELEASE_LIBRARY_DIR}" STREQUAL "${TBB_DEBUG_LIBRARY_DIR}" ) - + message(STATUS "Found Intel TBB") endif (TBB_RELEASE_LIBRARY) endif (TBB_INCLUDE_DIR) @@ -349,4 +349,4 @@ if (TBB_FOUND) set(TBB_INTERFACE_VERSION "${TBB_INTERFACE_VERSION}") endif (TBB_FOUND) -set(TBB_USE_FILE "UseTBB") \ No newline at end of file +set(TBB_USE_FILE "UseTBB") diff --git a/Installation/cmake/modules/UseTBB.cmake b/Installation/cmake/modules/UseTBB.cmake index 966d0f59749..25122e25825 100644 --- a/Installation/cmake/modules/UseTBB.cmake +++ b/Installation/cmake/modules/UseTBB.cmake @@ -3,4 +3,4 @@ include_directories ( ${TBB_INCLUDE_DIRS} ) link_directories( ${TBB_LIBRARY_DIRS} ) -add_definitions( -DNOMINMAX -DCGAL_LINKED_WITH_TBB ) \ No newline at end of file +add_definitions( -DNOMINMAX -DCGAL_LINKED_WITH_TBB ) diff --git a/Installation/test/Installation/CMakeLists.txt b/Installation/test/Installation/CMakeLists.txt index 462364fccba..e8ef9f3d6c0 100644 --- a/Installation/test/Installation/CMakeLists.txt +++ b/Installation/test/Installation/CMakeLists.txt @@ -47,10 +47,10 @@ if ( CGAL_FOUND ) find_package( TBB ) if( TBB_FOUND ) include(${TBB_USE_FILE}) - list(APPEND CGAL_3RD_PARTY_LIBRARIES ${TBB_LIBRARIES}) + list(APPEND CGAL_3RD_PARTY_LIBRARIES ${TBB_LIBRARIES}) endif() create_single_source_cgal_program( "test_TBB.cpp" ) - + create_link_to_program(CGAL) if ( WITH_CGAL_Core ) diff --git a/Installation/test/Installation/test_TBB.cpp b/Installation/test/Installation/test_TBB.cpp index f4ea6746ca6..38693cf5550 100644 --- a/Installation/test/Installation/test_TBB.cpp +++ b/Installation/test/Installation/test_TBB.cpp @@ -27,7 +27,7 @@ private: std::vector &m_v; }; -void change_array(std::vector &v, CGAL::Parallel_tag) +void change_array(std::vector &v, CGAL::Parallel_tag) { std::cout << "[Parallel] Using a tbb::parallel_for loop..."; tbb::parallel_for( @@ -38,7 +38,7 @@ void change_array(std::vector &v, CGAL::Parallel_tag) } #endif -void change_array(std::vector &v, CGAL::Sequential_tag) +void change_array(std::vector &v, CGAL::Sequential_tag) { std::cout << "[Sequential] Using a sequential for loop..."; std::vector::iterator it = v.begin(), it_end = v.end(); @@ -52,7 +52,7 @@ int main() std::vector v; for (int i = 0 ; i < 10000 ; ++i) v.push_back(i); - + std::cout << "Trying to call the sequential algorithm => "; change_array(v, CGAL::Sequential_tag()); std::cout << "Trying to call the parallel algorithm => "; diff --git a/STL_Extension/doc/STL_Extension/CGAL/tags.h b/STL_Extension/doc/STL_Extension/CGAL/tags.h index 37bc4ff1ef5..2352ab3afa9 100644 --- a/STL_Extension/doc/STL_Extension/CGAL/tags.h +++ b/STL_Extension/doc/STL_Extension/CGAL/tags.h @@ -70,14 +70,14 @@ struct Null_functor { /*! \ingroup PkgStlExtensionUtilities -Tag used to enable/disable concurrency. +Tag used to enable/disable concurrency. For example, it may be used by a user to request the sequential version of an algorithm. */ struct Sequential_tag {}; /*! \ingroup PkgStlExtensionUtilities -Tag used to enable/disable concurrency. +Tag used to enable/disable concurrency. For example, it may be used by a user to request the parallel version of an algorithm. */ struct Parallel_tag {};