From 4842f0e0fd2ff925a44b3c67ee21c9d065415c59 Mon Sep 17 00:00:00 2001 From: Tom Schammo Date: Thu, 14 Nov 2024 12:41:49 +0100 Subject: [PATCH] fix: Add `omp single` region Add `omp single` region to make sure the number of threads are only set once. --- cpp/src/raytracing.cpp | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/cpp/src/raytracing.cpp b/cpp/src/raytracing.cpp index 179735d..816eefc 100644 --- a/cpp/src/raytracing.cpp +++ b/cpp/src/raytracing.cpp @@ -102,9 +102,13 @@ void rt::intersects(torch::Tensor point_cloud, #pragma omp parallel { - const auto nthreads = std::thread::hardware_concurrency(); - std::cout << "Setting OpenMP to use " << nthreads << " threads!\n"; - omp_set_num_threads(nthreads); +#pragma omp single + { + + const auto nthreads = std::thread::hardware_concurrency(); + std::cout << "Setting OpenMP to use " << nthreads << " threads!\n"; + omp_set_num_threads(nthreads); + } #pragma omp parallel for schedule(dynamic) for (tensor_size_t i = 0; i < num_points; i++) {