// Copyright (c) 2012 INRIA Sophia-Antipolis (France). // All rights reserved. // // This file is part of CGAL (www.cgal.org). // // $URL: https://github.com/CGAL/cgal/blob/v5.2/Mesh_3/include/CGAL/Mesh_3/Concurrent_mesher_config.h $ // $Id: Concurrent_mesher_config.h 0779373 2020-03-26T13:31:46+01:00 Sébastien Loriot // SPDX-License-Identifier: GPL-3.0-or-later OR LicenseRef-Commercial // // // Author(s) : Clement Jamin // //****************************************************************************** // File Description : //****************************************************************************** #ifndef CGAL_MESH_3_CONCURRENT_MESHER_CONFIG_H #define CGAL_MESH_3_CONCURRENT_MESHER_CONFIG_H #include #ifdef CGAL_USE_BOOST_PROGRAM_OPTIONS # include namespace po = boost::program_options; #endif #include #include #include // class Concurrent_mesher_config /// Singleton containing config class Concurrent_mesher_config { // Private constructor (singleton) Concurrent_mesher_config() : locking_grid_num_cells_per_axis(50), first_grid_lock_radius(0), work_stats_grid_num_cells_per_axis(5), num_work_items_per_batch(50), refinement_grainsize(10), refinement_batch_size(10000), min_num_vertices_of_coarse_mesh(100), num_vertices_of_coarse_mesh_per_core(3.5f), num_pseudo_infinite_vertices_per_core(5.0f), m_config_file_loaded(false) {} public: static Concurrent_mesher_config &get() { static Concurrent_mesher_config singleton; return singleton; } static bool load_config_file(const char *filename, bool reload_if_already_loaded = false) { return get().load_file(filename, reload_if_already_loaded); } //=============== PUBLIC PARAMETERS ============== // From config file (or default) int locking_grid_num_cells_per_axis; int first_grid_lock_radius; int work_stats_grid_num_cells_per_axis; int num_work_items_per_batch; int refinement_grainsize; int refinement_batch_size; int min_num_vertices_of_coarse_mesh; float num_vertices_of_coarse_mesh_per_core; float num_pseudo_infinite_vertices_per_core; // Others //================================================ protected: bool load_file( const char *filename, bool reload_if_already_loaded = false) { CGAL_USE(reload_if_already_loaded); #ifdef CGAL_USE_BOOST_PROGRAM_OPTIONS if (m_config_file_loaded && reload_if_already_loaded == false) return true; try { std::ifstream in(filename); if (in.fail()) { std::string err = "could not open file '"; err += filename; err += "'. Using default values."; throw std::runtime_error(err); } // Declare the supported options. po::options_description desc("Allowed options"); desc.add_options() ("locking_grid_num_cells_per_axis", po::value(), "") ("first_grid_lock_radius", po::value(), "") ("work_stats_grid_num_cells_per_axis", po::value(), "") ("num_work_items_per_batch", po::value(), "") ("refinement_grainsize", po::value(), "") ("refinement_batch_size", po::value(), "") ("min_num_vertices_of_coarse_mesh", po::value(), "") ("num_vertices_of_coarse_mesh_per_core", po::value(), "") ("num_pseudo_infinite_vertices_per_core", po::value(), ""); po::store(po::parse_config_file(in, desc), m_variables_map); po::notify(m_variables_map); } catch (std::exception &e) { std::cerr << "Concurrency configuration file error: " << e.what() << std::endl; return false; } locking_grid_num_cells_per_axis = get_config_file_option_value("locking_grid_num_cells_per_axis"); first_grid_lock_radius = get_config_file_option_value("first_grid_lock_radius"); work_stats_grid_num_cells_per_axis = get_config_file_option_value("work_stats_grid_num_cells_per_axis"); num_work_items_per_batch = get_config_file_option_value("num_work_items_per_batch"); refinement_grainsize = get_config_file_option_value("refinement_grainsize"); refinement_batch_size = get_config_file_option_value("refinement_batch_size"); min_num_vertices_of_coarse_mesh = get_config_file_option_value("min_num_vertices_of_coarse_mesh"); num_vertices_of_coarse_mesh_per_core = get_config_file_option_value("num_vertices_of_coarse_mesh_per_core"); num_pseudo_infinite_vertices_per_core = get_config_file_option_value("num_pseudo_infinite_vertices_per_core"); m_config_file_loaded = true; #else // CGAL_USE_BOOST_PROGRAM_OPTIONS not defined std::cerr << "Warning: could not load concurrency configuration file '" << filename << "'. Default values will be used." << std::endl; #endif // CGAL_USE_BOOST_PROGRAM_OPTIONS return true; } #ifdef CGAL_USE_BOOST_PROGRAM_OPTIONS template OptionType get_config_file_option_value(const char *option_name) { if (m_variables_map.count(option_name)) return m_variables_map[option_name].as(); else return OptionType(); } #endif #ifdef CGAL_USE_BOOST_PROGRAM_OPTIONS po::variables_map m_variables_map; #endif bool m_config_file_loaded; }; #endif // CGAL_MESH_3_CONCURRENT_MESHER_CONFIG_H