From 8341096773627269e19de4834a2b1b3b25f59847 Mon Sep 17 00:00:00 2001 From: Username404 Date: Tue, 1 Nov 2022 10:18:32 +0100 Subject: [PATCH 1/2] Revert "CMakeLists.txt: Don't link against OpenMP when using static linking" This reverts commit 1469d92b Signed-off-by: Username404 --- CMakeLists.txt | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 7c44d3f..4591324 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -64,12 +64,10 @@ find_package(Threads) if (${IS_GNU} OR ${IS_CLANG}) set(THREADS_PREFER_PTHREAD_FLAG TRUE) if (Threads_FOUND AND NOT MINGW) - if (NOT ("${CMAKE_EXE_LINKER_FLAGS}" MATCHES -static)) - include(FindOpenMP) - if (OpenMP_CXX_FOUND) - set(CMAKE_CXX_FLAGS "${OpenMP_CXX_FLAGS} ${CMAKE_CXX_FLAGS}") - add_definitions(-D_GLIBCXX_PARALLEL) - endif() + include(FindOpenMP) + if (OpenMP_CXX_FOUND) + set(CMAKE_CXX_FLAGS "${OpenMP_CXX_FLAGS} ${CMAKE_CXX_FLAGS}") + add_definitions(-D_GLIBCXX_PARALLEL) endif() endif() if (NOT DEFINED EMSCRIPTEN) From 5c1780a9affa6c656f3da005e56f3b5c5a63df3d Mon Sep 17 00:00:00 2001 From: Username404 Date: Tue, 1 Nov 2022 11:01:34 +0100 Subject: [PATCH 2/2] main.cpp: Set the number of threads used by OpenMP to one when parallel is false Signed-off-by: Username404 --- src/main.cpp | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/src/main.cpp b/src/main.cpp index a96e7e9..b5993ee 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -38,7 +38,10 @@ int main(int argc, char* argv[]) { } else goto invalid_argument; } else if (currentArgument == ArgumentShort("text")) printResult = text_provided = true; - else if (text_provided || currentArgument.ends_with(".ybcon")) + else if (text_provided || currentArgument.ends_with(".ybcon")) { + #ifdef _OPENMP + if (not parallel) omp_set_num_threads(1); + #endif Units.insert_or_assign(currentArgument, async(not parallel ? launch::deferred : launch::async, [currentArgument, &text_provided, &target, &newLines]() { unit_result resultingPair; try { @@ -61,7 +64,7 @@ int main(int argc, char* argv[]) { } return resultingPair; })); - else { + } else { if (argc == 2) { if (currentArgument == Argument("version")) { cout << Yerbacon::getVersion();