Skip to content

Commit 1dccd67

Browse files
committed
Add OpenMP kernels
1 parent 4d2e571 commit 1dccd67

16 files changed

Lines changed: 247 additions & 24 deletions

CMakeLists.txt

Lines changed: 22 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,7 @@ endif()
107107

108108
find_package(argparse REQUIRED)
109109
find_package(pugixml REQUIRED)
110+
find_package(OpenMP)
110111

111112
# Configuration
112113
# =============
@@ -128,14 +129,13 @@ function(configure_kernel kernel)
128129
string(APPEND XEUS_CPP_WASM_KERNEL_EXTRA_ARGS_JSON "\"${arg}\", ")
129130
endforeach()
130131
else()
131-
set(XEUS_CPP_PATH "$ENV{PATH}")
132-
set(XEUS_CPP_LD_LIBRARY_PATH "$ENV{LD_LIBRARY_PATH}")
133132
set(XEUS_CPP_INCLUDE_DIR ${CMAKE_INSTALL_PREFIX}/include)
133+
if(${kernel} MATCHES "omp/$")
134+
set(XEUS_CPP_OMP "${OpenMP_CXX_FLAGS}")
135+
endif()
134136
endif()
135137
if (WIN32)
136138
string(REPLACE "\\" "/" kernel "${kernel}")
137-
string(REPLACE "\\" "/" XEUS_CPP_PATH "${XEUS_CPP_PATH}")
138-
string(REPLACE "\\" "/" XEUS_CPP_LD_LIBRARY_PATH "${XEUS_CPP_LD_LIBRARY_PATH}")
139139
string(REPLACE "\\" "/" XEUS_CPP_RESOURCE_DIR "${XEUS_CPP_RESOURCE_DIR}")
140140
string(REPLACE "\\" "/" XEUS_CPP_INCLUDE_DIR "${XEUS_CPP_INCLUDE_DIR}")
141141
endif()
@@ -167,6 +167,10 @@ configure_kernel("/share/jupyter/kernels/xcpp23/")
167167
configure_kernel("/share/jupyter/kernels/xc11/")
168168
configure_kernel("/share/jupyter/kernels/xc17/")
169169
configure_kernel("/share/jupyter/kernels/xc23/")
170+
if(NOT EMSCRIPTEN)
171+
configure_kernel("/share/jupyter/kernels/xcpp23-omp/")
172+
configure_kernel("/share/jupyter/kernels/xc23-omp/")
173+
endif()
170174

171175
# Source files
172176
# ============
@@ -339,8 +343,21 @@ macro(xeus_cpp_create_target target_name linkage output_name)
339343
target_compile_options(${target_name} PRIVATE "/MD$<$<CONFIG:Debug>:d>")
340344
endif()
341345
elseif (NOT EMSCRIPTEN)
346+
find_package(CURL REQUIRED)
347+
348+
# Add CURL_STATICLIB definition if linking statically
349+
if (CURL_STATICLIB)
350+
target_compile_definitions(${target_name} PUBLIC CURL_STATICLIB)
351+
endif()
352+
353+
# Link against the correct libcurl target
354+
if (CURL_FOUND)
355+
target_include_directories(${target_name} PRIVATE ${CURL_INCLUDE_DIRS})
356+
target_link_libraries(${target_name} PRIVATE ${CURL_LIBRARIES})
357+
endif()
358+
342359
# Curl initialised specifically for xassist
343-
target_link_libraries(${target_name} PUBLIC ${XEUS_CPP_XEUS_TARGET} clangCppInterOp pugixml argparse::argparse curl)
360+
target_link_libraries(${target_name} PUBLIC ${XEUS_CPP_XEUS_TARGET} clangCppInterOp pugixml argparse::argparse CURL::libcurl)
344361
else ()
345362
target_link_libraries(${target_name} PUBLIC ${XEUS_CPP_XEUS_TARGET} clangCppInterOp pugixml argparse::argparse)
346363
endif()

environment-dev.yml

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,9 @@ dependencies:
55
# Build dependencies
66
- make
77
- cmake
8-
- cxx-compiler
8+
- sel(unix): clangxx=21
9+
- sel(win): cxx-compiler
10+
- sel(linux): cxx-compiler
911
# Host dependencies
1012
- xeus>=6.0.0
1113
- xeus-zmq
@@ -14,6 +16,10 @@ dependencies:
1416
- CppInterOp>=1.9
1517
- pugixml
1618
- cpp-argparse
19+
- sel(unix): llvm-openmp=21
20+
- curl
21+
- libcurl
22+
- libcurl-static
1723
# Test dependencies
1824
- pytest
1925
- jupyter_kernel_test<0.8

notebooks/hello_world.ipynb

Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
1+
{
2+
"cells": [
3+
{
4+
"cell_type": "code",
5+
"execution_count": 1,
6+
"id": "73cbab37-71dd-477d-981b-f2ec28c01bd6",
7+
"metadata": {},
8+
"outputs": [],
9+
"source": [
10+
"#include <stdio.h>\n",
11+
"#include <omp.h>"
12+
]
13+
},
14+
{
15+
"cell_type": "code",
16+
"execution_count": 3,
17+
"id": "c2b754ad-9553-4a42-b990-f990a9a269ed",
18+
"metadata": {},
19+
"outputs": [],
20+
"source": [
21+
"int main() {\n",
22+
" int max_threads = omp_get_max_threads();\n",
23+
"\n",
24+
" printf(\"max threads: %d\\n\", max_threads);\n",
25+
" omp_set_num_threads(max_threads);\n",
26+
"\n",
27+
"#pragma omp parallel\n",
28+
" {\n",
29+
" int id = omp_get_thread_num();\n",
30+
" printf(\"Hello World from thread = %d with %d threads\\n\", id, omp_get_num_threads());\n",
31+
" }\n",
32+
"\n",
33+
" printf(\"all done, with hopefully %d threads\\n\", max_threads);\n",
34+
"}"
35+
]
36+
},
37+
{
38+
"cell_type": "code",
39+
"execution_count": 4,
40+
"id": "a37a13d4-fc82-496e-8f42-9e718a8c2aa0",
41+
"metadata": {},
42+
"outputs": [
43+
{
44+
"name": "stdout",
45+
"output_type": "stream",
46+
"text": [
47+
"max threads: 8\n",
48+
"Hello World from thread = 0 with 8 threads\n",
49+
"Hello World from thread = 3 with 8 threads\n",
50+
"Hello World from thread = 4 with 8 threads\n",
51+
"Hello World from thread = 2 with 8 threads\n",
52+
"Hello World from thread = 7 with 8 threads\n",
53+
"Hello World from thread = 1 with 8 threads\n",
54+
"Hello World from thread = 6 with 8 threads\n",
55+
"Hello World from thread = 5 with 8 threads\n",
56+
"all done, with hopefully 8 threads\n"
57+
]
58+
}
59+
],
60+
"source": [
61+
"main();"
62+
]
63+
}
64+
],
65+
"metadata": {
66+
"kernelspec": {
67+
"display_name": "C++23 (xcpp+OpenMP)",
68+
"language": "cpp",
69+
"name": "xcpp23-omp"
70+
},
71+
"language_info": {
72+
"codemirror_mode": "text/x-c++src",
73+
"file_extension": ".cpp",
74+
"mimetype": "text/x-c++src",
75+
"name": "C++",
76+
"version": "23"
77+
}
78+
},
79+
"nbformat": 4,
80+
"nbformat_minor": 5
81+
}
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
{
2+
"display_name": "C23 + OpenMP",
3+
"argv": [
4+
"@XEUS_CPP_KERNELSPEC_PATH@xcpp",
5+
"-f",
6+
"{connection_file}",
7+
"-resource-dir", "@XEUS_CPP_RESOURCE_DIR@","-xc",
8+
"-I", "@XEUS_CPP_INCLUDE_DIR@",
9+
"-std=c23","@XEUS_CPP_OMP@"
10+
],
11+
"language": "c",
12+
"kernel_protocol_version": "5.6.0",
13+
"metadata": {"debugger": false
14+
}
15+
}
980 Bytes
Loading
1.95 KB
Loading
Lines changed: 28 additions & 0 deletions
Loading

share/jupyter/kernels/xcpp17/kernel.json.in

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
"{connection_file}",
77
"-resource-dir", "@XEUS_CPP_RESOURCE_DIR@",
88
"-I", "@XEUS_CPP_INCLUDE_DIR@",
9-
"-std=c++17"
9+
"-std=c++17","-D_LIBCPP_DISABLE_AVAILABILITY"
1010
],
1111
"language": "cpp",
1212
"kernel_protocol_version": "5.6.0",

share/jupyter/kernels/xcpp20/kernel.json.in

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
"{connection_file}",
77
"-resource-dir", "@XEUS_CPP_RESOURCE_DIR@",
88
"-I", "@XEUS_CPP_INCLUDE_DIR@",
9-
"-std=c++20"
9+
"-std=c++20","-D_LIBCPP_DISABLE_AVAILABILITY"
1010
],
1111
"language": "cpp",
1212
"kernel_protocol_version": "5.6.0",
Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,15 @@
11
{
2-
"display_name": "C++17 (xcpp+OpenMP)",
3-
"env": {
4-
"PATH":"@XEUS_CPP_PATH@",
5-
"LD_LIBRARY_PATH":"@XEUS_CPP_LD_LIBRARY_PATH@"
6-
},
2+
"display_name": "C++23 + OpenMP",
73
"argv": [
84
"@XEUS_CPP_KERNELSPEC_PATH@xcpp",
95
"-f",
106
"{connection_file}",
117
"-resource-dir", "@XEUS_CPP_RESOURCE_DIR@",
128
"-I", "@XEUS_CPP_INCLUDE_DIR@",
13-
"-std=c++17"@XEUS_CPP_OMP@
9+
"-std=c++23","@XEUS_CPP_OMP@","-D_LIBCPP_DISABLE_AVAILABILITY"
1410
],
1511
"language": "cpp",
12+
"kernel_protocol_version": "5.6.0",
1613
"metadata": {"debugger": false
1714
}
1815
}

0 commit comments

Comments
 (0)