diff --git a/Installation/cmake/modules/FindITT.cmake b/Installation/cmake/modules/FindITT.cmake new file mode 100644 index 00000000000..2d49f7ca74e --- /dev/null +++ b/Installation/cmake/modules/FindITT.cmake @@ -0,0 +1,204 @@ +# CGAL note: copy from https://raw.githubusercontent.com/dmitry-gurulev/cmake/104ca4a6c462e3d5a1c217571212238c6446cfca/FindITT.cmake +# +# Distributed under the OSI-approved BSD 3-Clause License. See accompanying +# file Copyright.txt or https://cmake.org/licensing for details. + +#.rst: +# FindITT +# --------- +# +# Find Instrumentation and Tracing Technology (ITT) API include dirs and libraries +# +# Use this module by invoking find_package with the form +# +# :: +# +# find_package(ITT +# [REQUIRED] # Fail with error if ITT is not found +# ) +# +# This module finds headers and libraries +# For the former case results are reported in variables +# +# :: +# +# ITT_FOUND - True if headers and requested libraries were found +# ITT_INCLUDE_DIRS - ITT include directories +# ITT_LIBRARIES - ITT libraries to be linked +# +# This module reads hints about search locations from variables +# +# :: +# +# SEAPI_ROOT - Preferred installation path for Intel® Single Event API (Intel® SEAPI) +# (https://github.com/intel/IntelSEAPI) +# ITT_ROOT/ +# CMAKE_ITT_HOME - Preferred installation path for standalone ITT library +# INTEL_LIBITTNOTIFY32/ +# INTEL_LIBITTNOTIFY64 - Preferred ITT library directory +# VTUNE_AMPLIFIER__DIR - VTune Amplifier XE installation path which is set by amplxe-vars.sh/bat script +# See notes about [ITT_NO_VTUNE_PATH] below +# CMAKE_VTUNE_HOME - Explicitly defined VTune Amplifier XE installation path +# +# Other variables one may set to control this module are +# +# :: +# +# ITT_DEBUG - Set to ON to enable debug output from FindITT. +# Please enable this before filing any bug report. +# ITT_NO_VTUNE_PATH - Set to ON to not try to find VTUNE_AMPLIFIER__DIR environment variable +# +# Example to find ITT headers and libraries +# +# :: +# +# find_package(ITT) +# if (ITT_FOUND) +# include_directories(${ITT_INCLUDE_DIRS}) +# add_executable(foo foo.cc) +# target_link_libraries(foo ${ITT_LIBRARIES}) +# endif() +# +# Example to find ITT library and use imported targets:: +# +# :: +# +# find_package(ITT REQUIRED) +# add_executable(foo foo.cc) +# target_link_libraries(foo ITT::ITT) + +unset (_itt_INC_DIR_HINT) +unset (_itt_LIB_DIR_HINT) + +set (_itt_ARC "") +if (${CMAKE_CXX_COMPILER_ARCHITECTURE_ID} MATCHES "x86") + set (_itt_ARC "64") +elseif (${CMAKE_CXX_COMPILER_ARCHITECTURE_ID} MATCHES "x64") + set (_itt_ARC "64") +endif() + +if ("x${_itt_ARC}" STREQUAL "x") + if (CMAKE_SIZEOF_VOID_P EQUAL 8) + set (_itt_ARC "64") + else() + set (_itt_ARC "32") + endif() +endif() + +list (APPEND _itt_INC_DIR_HINT + $ENV{ITT_ROOT} + $ENV{SEAPI_ROOT}/ittnotify + ${CMAKE_ITT_HOME} + ${CMAKE_VTUNE_HOME} +) + +set (_itt_LIBITTNOTIFY $ENV{INTEL_LIBITTNOTIFY${_itt_ARC}}) +if (_itt_LIBITTNOTIFY) + get_filename_component (_itt_LIB_DIR_HINT ${_itt_LIBITTNOTIFY} DIRECTORY) + get_filename_component (_itt_INC_DIR_HINT ${_itt_LIB_DIR_HINT} DIRECTORY) +endif() + +list (APPEND _itt_INC_DIR_HINT + ${_itt_INC_DIR_HINT}/ittnotify +) + +if (NOT ITT_NO_VTUNE_PATH) + execute_process (COMMAND "${CMAKE_COMMAND}" "-E" "environment" + OUTPUT_VARIABLE _itt_ENV_LIST + ) + + string (REGEX MATCH "VTUNE_AMPLIFIER_[0-9]+_DIR" + _itt_VTUNE_DIR ${_itt_ENV_LIST} + ) +endif() + +if (_itt_VTUNE_DIR) + list (APPEND _itt_INC_DIR_HINT $ENV{${_itt_VTUNE_DIR}}) +endif() + +if (ITT_DEBUG) + message(STATUS "[ ${CMAKE_CURRENT_LIST_FILE}:${CMAKE_CURRENT_LIST_LINE} ] " + "_itt_INC_DIR_HINT = ${_itt_INC_DIR_HINT}") +endif() + +find_path (ITT_INCLUDE_DIR + NAMES ittnotify.h + HINTS + ${_itt_INC_DIR_HINT} + PATH_SUFFIXES + include +) + +if (ITT_DEBUG) + message(STATUS "[ ${CMAKE_CURRENT_LIST_FILE}:${CMAKE_CURRENT_LIST_LINE} ] " + "ITT_INCLUDE_DIR = ${ITT_INCLUDE_DIR}") +endif() + +if (ITT_DEBUG) + message(STATUS "[ ${CMAKE_CURRENT_LIST_FILE}:${CMAKE_CURRENT_LIST_LINE} ] " + "_itt_ARC = ${_itt_ARC}") +endif() + +if (ITT_INCLUDE_DIR) + get_filename_component (_itt_INC_DIR_HINT ${ITT_INCLUDE_DIR} DIRECTORY) + list (APPEND _itt_LIB_DIR_HINT ${_itt_INC_DIR_HINT}) +endif() + +list (APPEND _itt_LIB_DIR_HINT + $ENV{ITT_ROOT} + $ENV{SEAPI_ROOT} +) + +if (ITT_DEBUG) + message (STATUS "[ ${CMAKE_CURRENT_LIST_FILE}:${CMAKE_CURRENT_LIST_LINE} ] " + "_itt_LIB_DIR_HINT = ${_itt_LIB_DIR_HINT}") +endif() + +find_library (ITT_LIBRARY + NAMES + libittnotify + libittnotify${_itt_ARC} + ittnotify + ittnotify${_itt_ARC} + HINTS + ${_itt_LIB_DIR_HINT} + PATH_SUFFIXES + lib${_itt_ARC} + lib + bin +) + +if (ITT_DEBUG) + message(STATUS "[ ${CMAKE_CURRENT_LIST_FILE}:${CMAKE_CURRENT_LIST_LINE} ] " + "ITT_LIBRARY = ${ITT_LIBRARY}") +endif() + +# handle the QUIETLY and REQUIRED arguments and set MFX_FOUND to TRUE if +# all listed variables are TRUE +include (${CMAKE_ROOT}/Modules/FindPackageHandleStandardArgs.cmake) +FIND_PACKAGE_HANDLE_STANDARD_ARGS (ITT + REQUIRED_VARS ITT_INCLUDE_DIR ITT_LIBRARY +) + +mark_as_advanced(ITT_INCLUDE_DIR ITT_LIBRARY) + +if (ITT_FOUND) + set (ITT_INCLUDE_DIRS ${ITT_INCLUDE_DIR}) + set (ITT_LIBRARIES ${ITT_LIBRARY}) + + if (NOT TARGET ITT::ITT) + add_library(ITT::ITT UNKNOWN IMPORTED) + + set_target_properties(ITT::ITT PROPERTIES + INTERFACE_INCLUDE_DIRECTORIES "${ITT_INCLUDE_DIRS}" + ) + + set_target_properties(ITT::ITT PROPERTIES + IMPORTED_LOCATION "${ITT_LIBRARIES}" + ) + + set_target_properties(ITT::ITT PROPERTIES + INTERFACE_LINK_LIBRARIES "${CMAKE_DL_LIBS}" + ) + endif() +endif() diff --git a/Mesh_3/examples/Mesh_3/CMakeLists.txt b/Mesh_3/examples/Mesh_3/CMakeLists.txt index 851ce574dec..ab9c1878aea 100644 --- a/Mesh_3/examples/Mesh_3/CMakeLists.txt +++ b/Mesh_3/examples/Mesh_3/CMakeLists.txt @@ -169,7 +169,7 @@ if ( CGAL_FOUND ) # create_single_source_cgal_program( "mesh_polyhedral_surface_tolerance_region.cpp" ) # create_single_source_cgal_program( "mesh_polyhedral_edge_tolerance_region.cpp" ) - if(CGAL_ACTIVATE_CONCURRENT_MESH_3 AND TARGET CGAL::TBB_support AND TARGET ${target}) + if(CGAL_ACTIVATE_CONCURRENT_MESH_3 AND TARGET CGAL::TBB_support) foreach(target mesh_3D_image_with_features mesh_3D_image @@ -184,12 +184,21 @@ if ( CGAL_FOUND ) mesh_polyhedral_domain_sm mesh_polyhedral_domain_with_lipschitz_sizing mesh_polyhedral_complex + mesh_implicit_domains mesh_polyhedral_domain_with_features mesh_3D_image_variable_size) - target_link_libraries(${target} PUBLIC CGAL::TBB_support) + if(TARGET ${target}) + target_link_libraries(${target} PUBLIC CGAL::TBB_support) + endif() endforeach() endif() + find_package( ITT QUIET ) + if(TARGET ITT::ITT) + target_link_libraries(mesh_implicit_domains PRIVATE ITT::ITT) + target_compile_definitions(mesh_implicit_domains PRIVATE CGAL_MESH_3_USE_INTEL_ITT) + endif() + else() message(STATUS "This program requires the CGAL library, and will not be compiled.") endif() diff --git a/Mesh_3/examples/Mesh_3/mesh_implicit_domains.cpp b/Mesh_3/examples/Mesh_3/mesh_implicit_domains.cpp index 6f0823b6f8c..efb5ea0f743 100644 --- a/Mesh_3/examples/Mesh_3/mesh_implicit_domains.cpp +++ b/Mesh_3/examples/Mesh_3/mesh_implicit_domains.cpp @@ -14,6 +14,12 @@ using namespace CGAL::parameters; +#ifdef CGAL_CONCURRENT_MESH_3 +typedef CGAL::Parallel_tag Concurrency_tag; +#else +typedef CGAL::Sequential_tag Concurrency_tag; +#endif + // Domain typedef CGAL::Exact_predicates_inexact_constructions_kernel K; typedef FT_to_point_function_wrapper Function; @@ -23,7 +29,7 @@ typedef Function_wrapper::Function_vector Function_vector; typedef CGAL::Labeled_mesh_domain_3 Mesh_domain; // Triangulation -typedef CGAL::Mesh_triangulation_3::type Tr; +typedef CGAL::Mesh_triangulation_3::type Tr; typedef CGAL::Mesh_complex_3_in_triangulation_3 C3t3; // Mesh Criteria diff --git a/Mesh_3/include/CGAL/Mesh_3/Mesher_3.h b/Mesh_3/include/CGAL/Mesh_3/Mesher_3.h index fb54c96a4ae..e0b192f274f 100644 --- a/Mesh_3/include/CGAL/Mesh_3/Mesher_3.h +++ b/Mesh_3/include/CGAL/Mesh_3/Mesher_3.h @@ -25,6 +25,15 @@ #include +#if CGAL_MESH_3_USE_INTEL_ITT +# include +# define CGAL_MESH_3_TASK_BEGIN(task_handle) __itt_task_begin(mesh_3_domain, __itt_null, __itt_null, task_handle); +# define CGAL_MESH_3_TASK_END(task_handle) __itt_task_end(mesh_3_domain); +#else +# define CGAL_MESH_3_TASK_BEGIN(task_handle) +# define CGAL_MESH_3_TASK_END(task_handle) +#endif + #include #include @@ -406,6 +415,15 @@ refine_mesh(std::string dump_after_refine_surface_prefix) CGAL::Real_timer timer; timer.start(); double elapsed_time = 0.; +#if CGAL_MESH_3_USE_INTEL_ITT + auto mesh_3_domain = __itt_domain_create("org.cgal.Mesh_3.refine_mesh"); + auto refine_mesh_task_handle = __itt_string_handle_create("Mesher_3::refine_mesh"); + auto initialize_task_handle = __itt_string_handle_create("Mesher_3::initialize"); + auto refine_surface_mesh_task_handle = __itt_string_handle_create("Mesher_3 refine surface mesh"); + auto scan_cells_task_handle = __itt_string_handle_create("Mesher_3 scan triangulation for bad cells"); + auto refine_volume_mesh_task_handle = __itt_string_handle_create("Mesher_3 refine volume mesh"); + CGAL_MESH_3_TASK_BEGIN(refine_mesh_task_handle); +#endif // CGAL_MESH_3_USE_INTEL_ITT // First surface mesh could modify c3t3 without notifying cells_mesher // So we have to ensure that no old cell will be left in c3t3 @@ -419,12 +437,15 @@ refine_mesh(std::string dump_after_refine_surface_prefix) #ifndef CGAL_MESH_3_VERBOSE // Scan surface and refine it + CGAL_MESH_3_TASK_BEGIN(initialize_task_handle); initialize(); + CGAL_MESH_3_TASK_END(initialize_task_handle); #ifdef CGAL_MESH_3_PROFILING std::cerr << "Refining facets..." << std::endl; WallClockTimer t; #endif + CGAL_MESH_3_TASK_BEGIN(refine_surface_mesh_task_handle); facets_mesher_.refine(facets_visitor_); facets_mesher_.scan_edges(); refinement_stage = REFINE_FACETS_AND_EDGES; @@ -432,6 +453,7 @@ refine_mesh(std::string dump_after_refine_surface_prefix) facets_mesher_.scan_vertices(); refinement_stage = REFINE_FACETS_AND_EDGES_AND_VERTICES; facets_mesher_.refine(facets_visitor_); + CGAL_MESH_3_TASK_END(refine_surface_mesh_task_handle); #ifdef CGAL_MESH_3_PROFILING double facet_ref_time = t.elapsed(); std::cerr << "==== Facet refinement: " << facet_ref_time << " seconds ====" @@ -464,13 +486,17 @@ refine_mesh(std::string dump_after_refine_surface_prefix) if(!forced_stop()) { // Then scan volume and refine it + CGAL_MESH_3_TASK_BEGIN(scan_cells_task_handle); cells_mesher_.scan_triangulation(); + CGAL_MESH_3_TASK_END(scan_cells_task_handle); refinement_stage = REFINE_ALL; #ifdef CGAL_MESH_3_PROFILING std::cerr << "Refining cells..." << std::endl; t.reset(); #endif + CGAL_MESH_3_TASK_BEGIN(refine_volume_mesh_task_handle); cells_mesher_.refine(cells_visitor_); + CGAL_MESH_3_TASK_END(refine_volume_mesh_task_handle); #ifdef CGAL_MESH_3_PROFILING double cell_ref_time = t.elapsed(); std::cerr << "==== Cell refinement: " << cell_ref_time << " seconds ====" @@ -599,6 +625,7 @@ refine_mesh(std::string dump_after_refine_surface_prefix) << std::endl << std::endl; #endif + CGAL_MESH_3_TASK_END(refine_mesh_task_handle); return elapsed_time; } diff --git a/Mesh_3/test/Mesh_3/CMakeLists.txt b/Mesh_3/test/Mesh_3/CMakeLists.txt index d731e12d4e4..90d2e32b355 100644 --- a/Mesh_3/test/Mesh_3/CMakeLists.txt +++ b/Mesh_3/test/Mesh_3/CMakeLists.txt @@ -18,6 +18,8 @@ if ( CGAL_FOUND ) find_package( TBB QUIET ) include(CGAL_TBB_support) + find_package( ITT QUIET ) + # Use Eigen find_package(Eigen3 3.1.0 REQUIRED) #(3.1.0 or greater) include(CGAL_Eigen_support) @@ -117,6 +119,10 @@ if ( CGAL_FOUND ) endif() endforeach() endif() + if(TARGET ITT::ITT) + target_link_libraries(test_meshing_verbose PRIVATE ITT::ITT) + target_compile_definitions(test_meshing_verbose PRIVATE CGAL_MESH_3_USE_INTEL_ITT) + endif() else()