-
Notifications
You must be signed in to change notification settings - Fork 1.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
193 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,89 @@ | ||
from conan import ConanFile | ||
from conan.errors import ConanInvalidConfiguration | ||
from conan.tools.microsoft import is_msvc | ||
|
||
required_conan_version = ">=1.52.0" | ||
|
||
|
||
class PackageConan(ConanFile): | ||
name = "openmp" | ||
version = "cci.latest" | ||
description = "Conan meta-package for OpenMP (Open Multi-Processing)" | ||
license = "MIT" | ||
url = "https://github.com/conan-io/conan-center-index" | ||
homepage = "https://www.openmp.org/" | ||
topics = ("parallelism", "multiprocessing") | ||
|
||
package_type = "header-library" | ||
settings = "os", "arch", "compiler", "build_type" | ||
options = { | ||
"provider": ["auto", "llvm-openmp"], | ||
} | ||
default_options = { | ||
"provider": "auto", | ||
} | ||
|
||
def config_options(self): | ||
# GCC and MSVC provide OpenMP out of the box, use llvm-openmp from CCI for others | ||
if self.settings.compiler != "gcc" and not is_msvc(self): | ||
self.options.provider = "llvm-openmp" | ||
|
||
def layout(self): | ||
pass | ||
|
||
def requirements(self): | ||
if self.options.provider == "llvm-openmp": | ||
self.requires("llvm-openmp/17.0.6", transitive_headers=True, transitive_libs=True) | ||
|
||
def package_id(self): | ||
self.info.clear() | ||
|
||
def validate(self): | ||
if is_msvc(self) and self.options.provider == "llvm-openmp": | ||
raise ConanInvalidConfiguration("llvm-openmp is not compatible with MSVC") | ||
if not self._openmp_flags(): | ||
raise ConanInvalidConfiguration( | ||
f"{self.settings.compiler} is not supported by this recipe. Contributions are welcome!" | ||
) | ||
|
||
def source(self): | ||
pass | ||
|
||
def build(self): | ||
pass | ||
|
||
def package(self): | ||
pass | ||
|
||
def _openmp_flags(self): | ||
# Based on https://github.com/Kitware/CMake/blob/v3.28.1/Modules/FindOpenMP.cmake#L104-L135 | ||
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): | ||
self.cpp_info.set_property("cmake_find_mode", "none") | ||
|
||
self.cpp_info.frameworkdirs = [] | ||
self.cpp_info.libdirs = [] | ||
self.cpp_info.resdirs = [] | ||
self.cpp_info.includedirs = [] | ||
|
||
if self.options.provider == "auto": | ||
# Rely on CMake's FindOpenMP.cmake and an OpenMP implementation provided by the compiler. | ||
# Export appropriate flags for the transitive use case. | ||
openmp_flags = self._openmp_flags() | ||
self.cpp_info.sharedlinkflags = openmp_flags | ||
self.cpp_info.exelinkflags = openmp_flags | ||
self.cpp_info.cflags = openmp_flags | ||
self.cpp_info.cxxflags = openmp_flags |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
cmake_minimum_required(VERSION 3.15) | ||
project(PackageTest CXX C) | ||
|
||
find_package(OpenMP MODULE REQUIRED) | ||
|
||
message("OpenMP_FOUND: ${OpenMP_CXX_FOUND}") | ||
message("OpenMP_CXX_FOUND: ${OpenMP_CXX_FOUND}") | ||
message("OpenMP_CXX_VERSION: ${OpenMP_CXX_VERSION}") | ||
message("OpenMP_CXX_SPEC_DATE: ${OpenMP_CXX_SPEC_DATE}") | ||
message("OpenMP_CXX_INCLUDE_DIRS: ${OpenMP_CXX_INCLUDE_DIRS}") | ||
message("OpenMP_INCLUDE_DIRS: ${OpenMP_CXX_INCLUDE_DIRS}") | ||
|
||
if(NOT DEFINED OpenMP_C_INCLUDE_DIRS) | ||
message(FATAL_ERROR "OpenMP_C_INCLUDE_DIRS is not defined") | ||
endif() | ||
if(NOT DEFINED OpenMP_CXX_INCLUDE_DIRS) | ||
message(FATAL_ERROR "OpenMP_CXX_INCLUDE_DIRS is not defined") | ||
endif() | ||
|
||
add_executable(test_package_cxx test_package.cpp) | ||
target_link_libraries(test_package_cxx OpenMP::OpenMP_CXX) | ||
|
||
add_executable(test_package_c test_package.c) | ||
target_link_libraries(test_package_c OpenMP::OpenMP_C) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
from conan import ConanFile | ||
from conan.tools.build import can_run | ||
from conan.tools.cmake import cmake_layout, CMake | ||
import os | ||
|
||
|
||
class TestPackageConan(ConanFile): | ||
settings = "os", "arch", "compiler", "build_type" | ||
generators = "CMakeDeps", "CMakeToolchain", "VirtualRunEnv" | ||
test_type = "explicit" | ||
|
||
def requirements(self): | ||
self.requires(self.tested_reference_str) | ||
|
||
def layout(self): | ||
cmake_layout(self) | ||
|
||
def build(self): | ||
cmake = CMake(self) | ||
cmake.configure() | ||
cmake.build() | ||
|
||
def test(self): | ||
if can_run(self): | ||
for executable in ["test_package_cxx", "test_package_c"]: | ||
bin_path = os.path.join(self.cpp.build.bindir, executable) | ||
self.run(bin_path, env="conanrun") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
#include <omp.h> | ||
|
||
#include <stdio.h> | ||
|
||
int main() | ||
{ | ||
int num_threads = omp_get_num_procs(); | ||
if (num_threads < 5) | ||
num_threads = 5; | ||
omp_set_num_threads(num_threads); | ||
int actual_number; | ||
#pragma omp parallel | ||
{ | ||
#pragma omp single | ||
{ | ||
actual_number = omp_get_num_threads(); | ||
} | ||
} | ||
if(actual_number != num_threads){ | ||
printf("Something went wrong. Expecting %d threads but found %d.\n", num_threads, actual_number); | ||
printf("There are probably missing compiler flags.\n"); | ||
return 1; | ||
} | ||
printf("OpenMP year-month version: %d", _OPENMP); | ||
return 0; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
#include <omp.h> | ||
|
||
#include <iostream> | ||
|
||
int main() | ||
{ | ||
int num_threads = std::max(5, omp_get_num_procs()); | ||
omp_set_num_threads(num_threads); | ||
int actual_number; | ||
#pragma omp parallel | ||
{ | ||
#pragma omp single | ||
{ | ||
actual_number = omp_get_num_threads(); | ||
} | ||
} | ||
if(actual_number != num_threads){ | ||
std::cout << "Something went wrong. Expecting " << num_threads << " threads but found " << actual_number << ".\n"; | ||
std::cout << "There are probably missing compiler flags.\n"; | ||
return 1; | ||
} | ||
std::cout << "OpenMP year-month version: " << _OPENMP << "\n"; | ||
return 0; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
versions: | ||
"cci.latest": | ||
folder: all |