Skip to content

Commit 7828398

Browse files
committed
Added Intel Openmp support
1 parent 2b0b766 commit 7828398

File tree

2 files changed

+29
-5
lines changed

2 files changed

+29
-5
lines changed

CMakeLists.txt

+22-5
Original file line numberDiff line numberDiff line change
@@ -16,22 +16,26 @@ find_path(GFLAGS_INCLUDES NAMES gflags.h PATHS /usr/include/gflags/)
1616
message("GFLAGS INCLUDES: ${GFLAGS_INCLUDES}")
1717
include_directories(SYSTEM ${GFLAGS_INCLUDES})
1818

19-
find_package(OpenMP)
20-
if(OPENMP_FOUND)
21-
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${OpenMP_CXX_FLAGS}")
22-
set(OpenMP_SIMD_Test_Source
19+
# testing openmp program
20+
set(OpenMP_Test_Source
2321
" int main()
2422
{
2523
const int asize = 8;
2624
int a[asize] = {1,2,3,4,5,6,7,8};
2725
int sum = a[0];
28-
# pragma omp simd reduction(+:sum)
26+
# pragma omp parallel for reduction(+:sum)
2927
for (int i=1; i<asize; ++i) {
3028
sum += a[i];
3129
}
3230
return 0;
3331
}")
3432
file(WRITE ${CMAKE_BINARY_DIR}/test_openmp.cpp "${OpenMP_SIMD_Test_Source}")
33+
34+
if(NOT DEFINED INTEL_OMP_DIR)
35+
36+
find_package(OpenMP)
37+
if(OPENMP_FOUND)
38+
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${OpenMP_CXX_FLAGS}")
3539
try_compile(COMPILE_SUCCEEDED ${CMAKE_BINARY_DIR} ${CMAKE_BINARY_DIR}/test_openmp.cpp COMPILE_DEFINITIONS "-fopenmp -Werror -Wunknown-pragmas")
3640

3741
if(COMPILE_SUCCEEDED)
@@ -41,6 +45,19 @@ else()
4145
message("OpenMP support missing in compiler")
4246
endif()
4347

48+
else() # Here Intel openmp section
49+
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fopenmp ")
50+
try_compile(COMPILE_SUCCEEDED ${CMAKE_BINARY_DIR} ${CMAKE_BINARY_DIR}/test_openmp.cpp COMPILE_DEFINITIONS "-fopenmp -Werror -Wunknown-pragmas" LINK_OPTIONS "-Wl,--as-needed -L${INTEL_OMP_DIR}" LINK_LIBRAIRES "iomp5")
51+
52+
link_directories(${INTEL_OMPDIR})
53+
add_link_options("-Wl,--as-needed")
54+
55+
endif()
56+
57+
58+
59+
60+
4461
find_package(Git)
4562

4663
if(UNIX)

README.md

+7
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,11 @@
22
Little testing program for various openmp concepts
33

44

5+
# Using Intel openmp
6+
pip install intel-openmp
7+
pip show -f intel-openmp # Check where libiomp5.so is placed
8+
cmake ../ -DINTEL_OMP_DIR=<directory where libiomp5.so is located> <other options>
9+
10+
11+
512

0 commit comments

Comments
 (0)