Skip to content

Commit 7958240

Browse files
committed
fix for windows tests
1 parent 6958dfd commit 7958240

File tree

3 files changed

+24
-2
lines changed

3 files changed

+24
-2
lines changed

cpp/open3d/pipelines/integration/UniformTSDFVolume.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -265,8 +265,8 @@ std::shared_ptr<geometry::VoxelGrid> UniformTSDFVolume::ExtractVoxelGrid()
265265
#pragma omp parallel num_threads(utility::EstimateMaxThreads())
266266
{
267267
#pragma omp single
268-
{ per_thread_voxels.resize(omp_get_num_threads()); }
269-
int thread_id = omp_get_thread_num();
268+
{ per_thread_voxels.resize(utility::GetNumThreads()); }
269+
int thread_id = utility::GetThreadNum();
270270

271271
#ifdef _WIN32
272272
#pragma omp for schedule(static)

cpp/open3d/utility/Parallel.cpp

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,22 @@ int EstimateMaxThreads() {
4545
#endif
4646
}
4747

48+
int GetNumThreads() {
49+
#ifdef _OPENMP
50+
return omp_get_num_threads();
51+
#else
52+
return 1; // No parallelism available.
53+
#endif
54+
}
55+
56+
int GetThreadNum() {
57+
#ifdef _OPENMP
58+
return omp_get_thread_num();
59+
#else
60+
return 0; // No parallelism available, so thread ID is always 0.
61+
#endif
62+
}
63+
4864
bool InParallel() {
4965
// TODO: when we add TBB/Parallel STL support to ParallelFor, update this.
5066
#ifdef _OPENMP

cpp/open3d/utility/Parallel.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,12 @@ namespace utility {
1313
/// Estimate the maximum number of threads to be used in a parallel region.
1414
int EstimateMaxThreads();
1515

16+
/// Returns the number of threads in the current parallel region.
17+
int GetNumThreads();
18+
19+
/// Returns the thread ID in the current parallel region.
20+
int GetThreadNum();
21+
1622
/// Returns true if in an parallel section.
1723
bool InParallel();
1824

0 commit comments

Comments
 (0)