Repository navigation
[C API] Add OpenMP support validation in ThreadPoolBuilder - #412
Conversation
There was a problem hiding this comment.
🟡 Changes recommended
The tests accept either capability state and therefore cannot detect broken OpenMP build configuration.
2 open findings
What changed in this PR
Adds optional OpenMP support handling to the C API.
Changes:
- Conditionally enables OpenMP and returns
SVS_ERROR_NOT_IMPLEMENTEDwhen unavailable. - Updates public documentation for OpenMP thread pools.
- Adapts thread-pool tests for OpenMP-disabled builds.
| File | Description |
|---|---|
bindings/c/CMakeLists.txt |
Makes OpenMP optional. |
bindings/c/src/threadpool.hpp |
Validates OpenMP availability. |
bindings/c/include/svs/c/svs_c.h |
Documents availability and errors. |
bindings/c/docs/C_API_Design.md |
Updates thread-pool guidance. |
bindings/c/tests/c_api_index.cpp |
Adjusts OMP index tests. |
bindings/c/tests/c_api_index_builder.cpp |
Adjusts OMP builder tests. |
🧠 Review effort: Balanced
Give feedback about Copilot approvals in this survey to enter a drawing for a $150 gift card.
546debd to
6bc4d2a
Compare
There was a problem hiding this comment.
Warning
Copilot couldn't run its full agentic review because it didn't start before the timeout. Make sure your repository has a runner available, or add a copilot-code-review.yml file specifying one with the runs-on attribute. See the docs for more details.
Copilot review overview
6 open findings
This code assumesSVS_OMPis always defined (and boolean-like). In this PR, CMake conditionally… · NewSVS_VALIDATE_BOOL_ENV(SVS_OMP)is invoked without a trailing semicolon; if the macro expands to a… · New BasingSVS_TEST_EXPECT_OPENMPonOpenMP_CXX_FOUNDcan desynchronize test expectations from the… · New Test fails to verify OpenMP detection compile definition Test does not detect incorrect OpenMP capability configuration The comment says 'OMP is not implemented', but the behavior being tested is 'library was built… · New
🧠 Review effort: Lite
6bc4d2a to
935a534
Compare
There was a problem hiding this comment.
Warning
Copilot couldn't run its full agentic review because it didn't start before the timeout. Make sure your repository has a runner available, or add a copilot-code-review.yml file specifying one with the runs-on attribute. See the docs for more details.
Copilot review overview
7 open findings
The implementation is keyed offSVS_OMP, but the build-system change in this PR defines… · New The implementation is keyed offSVS_OMP, but the build-system change in this PR defines… · New Adding-fvisibility=hiddenunconditionally can break builds on toolchains that don't support… · New This is internally inconsistent: ifnum_threadsis ignored for… · NewOpenMP_CXX_FOUNDis only guaranteed to be set whenfind_package(OpenMP ...)has been run in a… · New The OpenMP unsupported path is handled twice (invalidate()and again inbuild()). This… · New The OpenMP unsupported path is handled twice (invalidate()and again inbuild()). This… · New
6 resolved since last review
SVS_VALIDATE_BOOL_ENV(SVS_OMP)is invoked without a trailing semicolon; if the macro expands to a… This code assumesSVS_OMPis always defined (and boolean-like). In this PR, CMake conditionally… BasingSVS_TEST_EXPECT_OPENMPonOpenMP_CXX_FOUNDcan desynchronize test expectations from the… Test fails to verify OpenMP detection compile definition Test does not detect incorrect OpenMP capability configuration The comment says 'OMP is not implemented', but the behavior being tested is 'library was built…
🧠 Review effort: Lite
| find_package(OpenMP) | ||
| if (OpenMP_CXX_FOUND) | ||
| # PRIVATE: OpenMP is an implementation detail linked into the shared library. | ||
| # Exporting it would force consumers of the C ABI to resolve a C++ OpenMP | ||
| # target they never asked for. | ||
| target_link_libraries(${TARGET_NAME} PRIVATE OpenMP::OpenMP_CXX) | ||
| target_compile_definitions(${TARGET_NAME} PRIVATE SVS_ENABLE_OMP=1) | ||
| endif() # OpenMP_CXX_FOUND |
There was a problem hiding this comment.
Only concern here is that OpenMP could be silently not found. What if instead the findpackage was moved inside a conditional related to the flag, something like:
| find_package(OpenMP) | |
| if (OpenMP_CXX_FOUND) | |
| # PRIVATE: OpenMP is an implementation detail linked into the shared library. | |
| # Exporting it would force consumers of the C ABI to resolve a C++ OpenMP | |
| # target they never asked for. | |
| target_link_libraries(${TARGET_NAME} PRIVATE OpenMP::OpenMP_CXX) | |
| target_compile_definitions(${TARGET_NAME} PRIVATE SVS_ENABLE_OMP=1) | |
| endif() # OpenMP_CXX_FOUND | |
| if (SVS_C_API_ENABLE_OPENMP) | |
| find_package(OpenMP REQUIRED) | |
| # PRIVATE: OpenMP is an implementation detail linked into the shared library. | |
| # Exporting it would force consumers of the C ABI to resolve a C++ OpenMP | |
| # target they never asked for. | |
| target_link_libraries(${TARGET_NAME} PRIVATE OpenMP::OpenMP_CXX) | |
| target_compile_definitions(${TARGET_NAME} PRIVATE SVS_ENABLE_OMP=1) | |
| endif() # OpenMP_CXX_FOUND |
There was a problem hiding this comment.
Addressed by adding the option SVS_ENABLE_OMP which is ON by default
|
Tick the box to add this pull request to the merge queue (same as
|
935a534 to
1674200
Compare
|
LGTM, verified from the consumer side. valkey-search compiles the C API sources itself without OpenMP and has been force-including a stub for the unguarded |



This pull request improves the handling of OpenMP thread pool support in the C bindings, making OpenMP an optional feature that can be toggled at build time. It ensures that the API and documentation clearly indicate when OpenMP is available, returns appropriate errors if OpenMP is requested but not built in, and updates tests to handle both configurations. The main changes are grouped below:
Build System and Feature Flagging:
SVS_ENABLE_OMPCMake option (enabled by default) to control whether OpenMP thread pool support is built into the library. The build system now only enables OpenMP-related code and definitions if this option is set and OpenMP is found. Default symbol visibility is also set to hidden for shared libraries. [1] [2] [3]API Behavior and Error Handling:
svs_index_builder_set_threadpool) and its documentation to clarify that selecting the OpenMP thread pool kind will fail withSVS_ERROR_NOT_IMPLEMENTEDif the library was not built with OpenMP support. The implementation now checks for OpenMP support at runtime and throws an appropriate error if unavailable. [1] [2] [3] [4]Documentation Updates:
C_API_Design.mdand header comments to accurately reflect the conditional availability of OpenMP thread pools and the associated error handling. [1] [2]Testing Improvements:
check_openmp_supporthelper, allowing tests to pass whether or not OpenMP is enabled in the build. Test code now conditionally executes OpenMP-specific assertions and logic. [1] [2] [3] [4]