Open valgur opened 1 month ago
@jcar87
Hi @valgur thanks a lot for the write-up, we appreciate it :)
I just wanted to let you know that we are in fact looking into this and how to best approach openmp support - it might even include some built-in Conan client support, but we're in preliminary stages yet! Thanks a lot for your effort and patience while we also figure this out
Ok, I'm glad to hear that. Thanks!
Realistically, though, the OpenMP runtime and the preprocessor flag will probably need to be included in the dependency graph in one form or another, with the correct visibility as well, right? If not as a (meta-)package, then do you have some kind of an alternative mechanism in mind, perhaps? Not intending this as a critique, just curious.
If it's going to end up looking more or less like a package anyway, then could you still consider the openmp
meta-package approach in the mean time? The approach looks very viable to me and only basically does the same that is already done in existing recipes, just less sloppily. This would allow OpenMP usage to be cleaned up in recipes that depend on it and once there's a more appropriate solution available, then maybe:
openmp
package,openmp
package with the alternative solution to migrate without breaking things,openmp
at a steady pace with whatever the alternative solution is, if necessary.The llvm-openmp
issues should still be addressed, though, imo, so I'll reopen the PR and apply any tweaks that you deem necessary.
Still working on this - however, I think it needs to be clarified that there is no limitation in Conan Center recipes to support OpenMP, or with Conan in general.
Recipes that currently support OpenMP should already work for the most part, provided the compiler supports it and it comes with the appropriate runtime.
There are a few limitations currently:
ws2_32
on Windows). Some libraries already have this logic, and it should work.
so If I'm understanding correctly, the real issues are:
Not included in major Linux distributions with the clang package by default (Ubuntu, Arch, Fedora)
This is a worthy discussion with the distro maintainers too. The matching libomp headers and runtime are made available by the distros. On ubuntu libomp-dev
package needs to be installed. I would suggest opening an issue with Ubuntu, or debian if a default installation of the clang
package does not have a functional -fopenmp
, it may be argued this is a bug, for example https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=882781. I can see the llvm-toolchain
package is more complete, but unsure why that is not part of the default debian installations.
please note that the assessment of the debian maintainers:
openmp is a niche and I don't think we should have a hard dependency for every clang user.
seems to contradict the "widely adopted" premise in this issue. For what is worth, their assessment matches what we have seen - we don't have any issues reported in Conan for openmp support, and in Conan Center we've never had requests or issues reported by users of the libraries, all openmp related discussions seem to be motivated by recipe maintainers. I should remind that our focus should always be the users - and that our efforts and priorities are guided by demand from the users of recipes. We don't want to run the risk of diverting resources for something that may not actually be used.
Please note that these distributions of clang do contain the runtime, so we can't generalise around compiler=clang
:
The fact that we are discussing the problems and correct ways of using the library should be enough of a reason for encapsulating and abstracting away the complexity, especially if there's a straightforward and low-risk solution available (based on what has been discussed so far at least). While a motivated developer can figure it out on their own, sure, it does not mean that they should.
Regarding the interest from "real users" - the near complete lack of computer vision, ML, and robotics communities on Conan/CCI does not mean that they don't exist or care. Far from it. See some of the most actively discussed packages on Vcpkg: colmap, ceres, suitesparse, lapack. And while it's much more down to CUDA support, other technical reasons or plain momentum, having to fight Conan where Vcpkg gets by with a nice abstraction with proper visibility support from CMake out of the box really does not help move the needle in the right direction.
Regarding whether splitting libomp-dev
into an optional package from clang
/llvm
packages in Linux distros is correct or not, that's business as usual for them and hardly unique to libomp
. Installing extra packages for libraries for a build is the norm and expected. There's also the quite niche libc++
header/runtime library that they don't include with their clang
package by default on Debian/Ubuntu, for example.
To give some more objective numbers, I grepped through all of the source archives of the latest versions of packages on CCI (plus some pending PRs) for #pragma omp
and #include <omp.h>
. There are currently 122 packages that use OpenMP directly, of which 76 use it in a header file (not all of which are exposed publicly, of course).
For reference, that's more than double the number of direct uses of libjpeg
(56), libpng
(56), xorg/system
(50) or opengl/system
(38), but less than zlib
(175) and pthread
(427).
Here's a detailed list including all of the packages and their respective files (excluding tests, examples and vendored libraries unvendored by the recipes) that make use of OpenMP: https://gist.github.com/valgur/15d5dc0c31dbfc94f168188a4d1859f7
And just the list of packages, where usages in headers are in bold:
@jcar87
Motivation
OpenMP (Open Multi-Processing) is a widely adopted API that provides parallel programming in C, C++, and Fortran, optionally with multi-platform shared-memory support. It is a critical building block for many numerical and scientific libraries, but is used in general-purpose software as well for easy parallelization support.
OpenMP consists of a set of
#pragma omp ...
compiler directives that get translated into OpenMP API calls, which are then handled by the runtime library, which is often (but not always) provided with the compiler toolchain and linked dynamically. The translation of OpenMP directives needs to be enabled with a suitable compiler flag, typically-fopenmp
or/openmp
. Passing the same flag to a linker instructs it to link against the OpenMP runtime library found in the compiler toolchain.Based on the info in recipes alone, there are currently about 50 recipes on CCI currently or upcoming in PRs. Some more notable ones include:
Although some of these libraries support alternative parallelization mechanisms, such as plain pthreads or TBB, several of these libraries don't and are entirely (e.g. SuiteSparse) or close to unusable without parallelization via OpenMP enabled.
Problems
clang
package by default (Ubuntu, Arch, Fedora)@property def _openmp_flags(self): if self.settings.compiler == "clang": return ["-fopenmp=libomp"] elif self.settings.compiler == "apple-clang": return ["-Xclang", "-fopenmp"] elif self.settings.compiler == "gcc": return ["-fopenmp"] elif self.settings.compiler == "intel-cc": return ["-Qopenmp"] elif self.settings.compiler == "sun-cc": return ["-xopenmp"] elif is_msvc(self): return ["-openmp"] return None
def package_info(self): ... if self.options.with_openmp: if self.settings.compiler in ["clang", "apple-clang"]: self.cpp_info.requires.append("llvm-openmp::llvm-openmp") openmp_flags = self._openmp_flags self.cpp_info.cflags = openmp_flags self.cpp_info.cxxflags = openmp_flags self.cpp_info.sharedlinkflags = openmp_flags self.cpp_info.exelinkflags = openmp_flags
-- Conan: Target declared 'OpenMP::OpenMP' OpenMP_FOUND: OpenMP_VERSION: 17.0.6 OpenMP_C_FOUND: OpenMP_CXX_FOUND: OpenMP_CXX_VERSION: OpenMP_CXX_SPEC_DATE: OpenMP_CXX_INCLUDE_DIRS: OpenMP_CXX_LIB_NAMES: OpenMP_CXX_LIBRARIES: OpenMP_CXX_FLAGS: OpenMP_omp_LIBRARY:
-- Conan: Component target declared 'OpenMP::OpenMP' -- Conan: Target declared 'llvm-openmp::llvm-openmp' -- Conan: Including build module from '/home/martin/.conan2/p/b/llvm-e49ba89a6637a/p/lib/cmake/openmp/conan-llvm-openmp-vars.cmake' -- Found OpenMP: -fopenmp=libomp (found version "5.0") OpenMP_FOUND: TRUE OpenMP_VERSION: 5.0 OpenMP_C_FOUND: TRUE OpenMP_CXX_FOUND: TRUE OpenMP_CXX_VERSION: 5.0 OpenMP_CXX_SPEC_DATE: 201611 OpenMP_CXX_INCLUDE_DIRS: /home/martin/.conan2/p/b/llvm-e49ba89a6637a/p/include OpenMP_CXX_LIB_NAMES: omp;m;dl;pthread;rt OpenMP_CXX_LIBRARIES: llvm-openmp::llvm-openmp OpenMP_CXX_FLAGS: -fopenmp=libomp OpenMP_omp_LIBRARY: llvm-openmp::llvm-openmp