From 6a03f13d55947d4b0973a662cfa901d6e528b6af Mon Sep 17 00:00:00 2001 From: Dennis Luxen Date: Thu, 22 May 2014 18:24:11 +0200 Subject: [PATCH] fixes #1032: - remove left-overs from OpenMP - replace omp_* calls with TBB equivalents --- Contractor/Contractor.h | 1 - DataStructures/Percent.h | 1 - Extractor/PBFParser.cpp | 1 - Extractor/ScriptingEnvironment.cpp | 1 - Server/ServerFactory.h | 7 ++--- Util/OpenMPWrapper.h | 41 ------------------------------ extractor.cpp | 7 +++-- prepare.cpp | 1 - 8 files changed, 7 insertions(+), 53 deletions(-) delete mode 100644 Util/OpenMPWrapper.h diff --git a/Contractor/Contractor.h b/Contractor/Contractor.h index e0344c1f5..8e6bee2a3 100644 --- a/Contractor/Contractor.h +++ b/Contractor/Contractor.h @@ -35,7 +35,6 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. #include "../DataStructures/Percent.h" #include "../DataStructures/XORFastHash.h" #include "../DataStructures/XORFastHashStorage.h" -#include "../Util/OpenMPWrapper.h" #include "../Util/SimpleLogger.h" #include "../Util/StringUtil.h" #include "../Util/TimingUtil.h" diff --git a/DataStructures/Percent.h b/DataStructures/Percent.h index e3fc563cb..f201fc808 100644 --- a/DataStructures/Percent.h +++ b/DataStructures/Percent.h @@ -28,7 +28,6 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. #ifndef PERCENT_H #define PERCENT_H -#include "../Util/OpenMPWrapper.h" #include #include diff --git a/Extractor/PBFParser.cpp b/Extractor/PBFParser.cpp index d1688f66e..0468d71b0 100644 --- a/Extractor/PBFParser.cpp +++ b/Extractor/PBFParser.cpp @@ -35,7 +35,6 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. #include "../DataStructures/ImportNode.h" #include "../DataStructures/Restriction.h" #include "../Util/MachineInfo.h" -#include "../Util/OpenMPWrapper.h" #include "../Util/OSRMException.h" #include "../Util/SimpleLogger.h" #include "../typedefs.h" diff --git a/Extractor/ScriptingEnvironment.cpp b/Extractor/ScriptingEnvironment.cpp index 3379647ff..0e2df0494 100644 --- a/Extractor/ScriptingEnvironment.cpp +++ b/Extractor/ScriptingEnvironment.cpp @@ -31,7 +31,6 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. #include "ExtractionWay.h" #include "../DataStructures/ImportNode.h" #include "../Util/LuaUtil.h" -#include "../Util/OpenMPWrapper.h" #include "../Util/OSRMException.h" #include "../Util/SimpleLogger.h" #include "../typedefs.h" diff --git a/Server/ServerFactory.h b/Server/ServerFactory.h index bc153633e..91dadbf02 100644 --- a/Server/ServerFactory.h +++ b/Server/ServerFactory.h @@ -29,7 +29,6 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. #define SERVER_FACTORY_H #include "Server.h" -#include "../Util/OpenMPWrapper.h" #include "../Util/SimpleLogger.h" #include "../Util/StringUtil.h" @@ -39,11 +38,13 @@ struct ServerFactory { ServerFactory() = delete; ServerFactory(const ServerFactory &) = delete; - static Server *CreateServer(std::string &ip_address, int ip_port, int threads) + static Server *CreateServer(std::string &ip_address, int ip_port, unsigned requested_num_threads) { SimpleLogger().Write() << "http 1.1 compression handled by zlib version " << zlibVersion(); std::string port_stream = IntToString(ip_port); - return new Server(ip_address, port_stream, std::min(omp_get_num_procs(), threads)); + unsigned hardware_threads = std::max(1u, std::thread::hardware_concurrency()); + unsigned real_num_threads = std::min(hardware_threads, requested_num_threads); + return new Server(ip_address, port_stream, real_num_threads); } }; diff --git a/Util/OpenMPWrapper.h b/Util/OpenMPWrapper.h deleted file mode 100644 index 28957de41..000000000 --- a/Util/OpenMPWrapper.h +++ /dev/null @@ -1,41 +0,0 @@ -/* - -Copyright (c) 2013, Project OSRM, Dennis Luxen, others -All rights reserved. - -Redistribution and use in source and binary forms, with or without modification, -are permitted provided that the following conditions are met: - -Redistributions of source code must retain the above copyright notice, this list -of conditions and the following disclaimer. -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 OPENMP_WRAPPER_H -#define OPENMP_WRAPPER_H - -#ifdef _OPENMP -extern "C" { -#include -} -#else -inline int omp_get_num_procs() { return 1; } -inline int omp_get_max_threads() { return 1; } -inline int omp_get_thread_num() { return 0; } -inline void omp_set_num_threads(int i) {} -#endif // _OPENMP -#endif // OPENMP_WRAPPER_H diff --git a/extractor.cpp b/extractor.cpp index e27ccb097..0f1a78919 100644 --- a/extractor.cpp +++ b/extractor.cpp @@ -32,7 +32,6 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. #include "Extractor/XMLParser.h" #include "Util/GitDescription.h" #include "Util/MachineInfo.h" -#include "Util/OpenMPWrapper.h" #include "Util/OSRMException.h" #include "Util/ProgramOptions.h" #include "Util/SimpleLogger.h" @@ -63,7 +62,7 @@ int main(int argc, char *argv[]) std::chrono::steady_clock::now(); boost::filesystem::path config_file_path, input_path, profile_path; - unsigned int requested_num_threads; + unsigned requested_num_threads; // declare a group of options that will be allowed only on command line boost::program_options::options_description generic_options("Options"); @@ -166,8 +165,8 @@ int main(int argc, char *argv[]) return 1; } - unsigned int hardware_threads = std::max((unsigned int) 1, std::thread::hardware_concurrency()); - unsigned int real_num_threads = std::min(hardware_threads, requested_num_threads); + unsigned hardware_threads = std::max(1u, std::thread::hardware_concurrency()); + unsigned real_num_threads = std::min(hardware_threads, requested_num_threads); SimpleLogger().Write() << "Input file: " << input_path.filename().string(); SimpleLogger().Write() << "Profile: " << profile_path.filename().string(); diff --git a/prepare.cpp b/prepare.cpp index aeec5c095..0448299da 100644 --- a/prepare.cpp +++ b/prepare.cpp @@ -37,7 +37,6 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. #include "Util/GitDescription.h" #include "Util/GraphLoader.h" #include "Util/LuaUtil.h" -#include "Util/OpenMPWrapper.h" #include "Util/OSRMException.h" #include "Util/SimpleLogger.h"