Skip to content

Commit a1c7a3a

Browse files
explicitly load libomp.so when required
remove the need to set env var PATH & LD_LIBRARY_PATH for omp kernels
1 parent fcecfc1 commit a1c7a3a

File tree

6 files changed

+97
-62
lines changed

6 files changed

+97
-62
lines changed

notebooks/openmp-notebooks/hello_world.ipynb

Lines changed: 20 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -36,24 +36,32 @@
3636
},
3737
{
3838
"cell_type": "code",
39-
"execution_count": 4,
39+
"execution_count": 3,
4040
"id": "a37a13d4-fc82-496e-8f42-9e718a8c2aa0",
4141
"metadata": {},
4242
"outputs": [
4343
{
4444
"name": "stdout",
4545
"output_type": "stream",
4646
"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"
47+
"max threads: 16\n",
48+
"Hello World from thread = 0 with 16 threads\n",
49+
"Hello World from thread = 3 with 16 threads\n",
50+
"Hello World from thread = 13 with 16 threads\n",
51+
"Hello World from thread = 4 with 16 threads\n",
52+
"Hello World from thread = 12 with 16 threads\n",
53+
"Hello World from thread = 1 with 16 threads\n",
54+
"Hello World from thread = 14 with 16 threads\n",
55+
"Hello World from thread = 15 with 16 threads\n",
56+
"Hello World from thread = 8 with 16 threads\n",
57+
"Hello World from thread = 6 with 16 threads\n",
58+
"Hello World from thread = 11 with 16 threads\n",
59+
"Hello World from thread = 5 with 16 threads\n",
60+
"Hello World from thread = 7 with 16 threads\n",
61+
"Hello World from thread = 10 with 16 threads\n",
62+
"Hello World from thread = 9 with 16 threads\n",
63+
"Hello World from thread = 2 with 16 threads\n",
64+
"all done, with hopefully 16 threads\n"
5765
]
5866
}
5967
],
@@ -64,7 +72,7 @@
6472
],
6573
"metadata": {
6674
"kernelspec": {
67-
"display_name": "C++17 (xcpp+OpenMP)",
75+
"display_name": "C++17 + OpenMP",
6876
"language": "cpp",
6977
"name": "xcpp17-omp"
7078
},

notebooks/openmp-notebooks/linked_list.ipynb

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@
4343
},
4444
{
4545
"cell_type": "code",
46-
"execution_count": 5,
46+
"execution_count": 4,
4747
"id": "b16b1e8a-8831-4b8d-9d57-09deeaaa88ee",
4848
"metadata": {},
4949
"outputs": [],
@@ -55,7 +55,7 @@
5555
},
5656
{
5757
"cell_type": "code",
58-
"execution_count": 6,
58+
"execution_count": 5,
5959
"id": "0ef8af6c-1d6f-4c68-84bc-3dd1d8092b06",
6060
"metadata": {},
6161
"outputs": [],
@@ -74,7 +74,7 @@
7474
},
7575
{
7676
"cell_type": "code",
77-
"execution_count": 7,
77+
"execution_count": 6,
7878
"id": "1fa0307d-fdc9-4503-95cb-1c6448791354",
7979
"metadata": {},
8080
"outputs": [],
@@ -90,7 +90,7 @@
9090
},
9191
{
9292
"cell_type": "code",
93-
"execution_count": 8,
93+
"execution_count": 7,
9494
"id": "03acb599-9329-49ff-8aff-c0902adb6c3c",
9595
"metadata": {},
9696
"outputs": [],
@@ -119,7 +119,7 @@
119119
},
120120
{
121121
"cell_type": "code",
122-
"execution_count": 9,
122+
"execution_count": 8,
123123
"id": "f2dfb41b-e55f-43c0-b7f6-546a1697acb1",
124124
"metadata": {},
125125
"outputs": [],
@@ -177,7 +177,7 @@
177177
},
178178
{
179179
"cell_type": "code",
180-
"execution_count": 10,
180+
"execution_count": 9,
181181
"id": "353e5dfd-fcae-43e6-97e3-ec98070811a1",
182182
"metadata": {},
183183
"outputs": [
@@ -188,14 +188,14 @@
188188
"Process linked list\n",
189189
" Each linked list node will be processed by function 'processwork()'\n",
190190
" Each ll node will compute 5 fibonacci numbers beginning with 38\n",
191-
"Threads: 8\n",
191+
"Threads: 16\n",
192192
"38 : 39088169\n",
193193
"39 : 63245986\n",
194194
"40 : 102334155\n",
195195
"41 : 165580141\n",
196196
"42 : 267914296\n",
197197
"43 : 433494437\n",
198-
"Compute Time: 2.617225 seconds\n"
198+
"Compute Time: 3.560749 seconds\n"
199199
]
200200
}
201201
],
@@ -206,7 +206,7 @@
206206
],
207207
"metadata": {
208208
"kernelspec": {
209-
"display_name": "C++17 (xcpp+OpenMP)",
209+
"display_name": "C++17 + OpenMP",
210210
"language": "cpp",
211211
"name": "xcpp17-omp"
212212
},

notebooks/openmp-notebooks/mandel.ipynb

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626
},
2727
{
2828
"cell_type": "code",
29-
"execution_count": 4,
29+
"execution_count": 3,
3030
"id": "d89dd57c-fe19-4233-a33a-df9b24fae98a",
3131
"metadata": {},
3232
"outputs": [],
@@ -36,7 +36,7 @@
3636
},
3737
{
3838
"cell_type": "code",
39-
"execution_count": 5,
39+
"execution_count": 4,
4040
"id": "5c35c479-2f79-46b7-bc66-24be6b1694e0",
4141
"metadata": {},
4242
"outputs": [],
@@ -64,7 +64,7 @@
6464
},
6565
{
6666
"cell_type": "code",
67-
"execution_count": 6,
67+
"execution_count": 5,
6868
"id": "ea116fef-7d05-4e29-97a1-55c85c7241d8",
6969
"metadata": {},
7070
"outputs": [],
@@ -96,15 +96,15 @@
9696
},
9797
{
9898
"cell_type": "code",
99-
"execution_count": 7,
99+
"execution_count": 6,
100100
"id": "39cf129c-8106-4e67-a2f1-1a7fff17cd38",
101101
"metadata": {},
102102
"outputs": [
103103
{
104104
"name": "stdout",
105105
"output_type": "stream",
106106
"text": [
107-
"Area of Mandlebrot set = 3.80247750 +/- 0.00380248\n",
107+
"Area of Mandlebrot set = 5.23447313 +/- 0.00523447\n",
108108
"Correct answer should be around 1.510659\n"
109109
]
110110
}
@@ -116,7 +116,7 @@
116116
],
117117
"metadata": {
118118
"kernelspec": {
119-
"display_name": "C++17 (xcpp+OpenMP)",
119+
"display_name": "C++17 + OpenMP",
120120
"language": "cpp",
121121
"name": "xcpp17-omp"
122122
},

notebooks/openmp-notebooks/openmp-demo.ipynb

Lines changed: 50 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -34,20 +34,28 @@
3434
},
3535
{
3636
"cell_type": "code",
37-
"execution_count": 4,
37+
"execution_count": 3,
3838
"id": "53fb7656-b72e-42bc-ade7-2ae2077142da",
3939
"metadata": {},
4040
"outputs": [
4141
{
4242
"name": "stdout",
4343
"output_type": "stream",
4444
"text": [
45-
"Hello World!Hello World!\n",
46-
"Hello World!Hello World!\n",
4745
"Hello World!\n",
48-
"\n",
4946
"Hello World!\n",
50-
"\n",
47+
"Hello World!\n",
48+
"Hello World!\n",
49+
"Hello World!\n",
50+
"Hello World!\n",
51+
"Hello World!\n",
52+
"Hello World!\n",
53+
"Hello World!\n",
54+
"Hello World!\n",
55+
"Hello World!\n",
56+
"Hello World!\n",
57+
"Hello World!\n",
58+
"Hello World!\n",
5159
"Hello World!\n",
5260
"Hello World!\n"
5361
]
@@ -65,22 +73,30 @@
6573
},
6674
{
6775
"cell_type": "code",
68-
"execution_count": 5,
76+
"execution_count": 4,
6977
"id": "efcdfdb6-a60b-46af-8194-75ef9cc0e27f",
7078
"metadata": {},
7179
"outputs": [
7280
{
7381
"name": "stdout",
7482
"output_type": "stream",
7583
"text": [
76-
"Hello World! (Hello World! (Hello World! (Hello World! (34)\n",
77-
"Hello World! (7)\n",
78-
"0)\n",
79-
"2Hello World! (6))\n",
80-
"\n",
84+
"Hello World! (Hello World! (Hello World! (Hello World! (Hello World! (12Hello World! (1)\n",
8185
")\n",
86+
"9)\n",
87+
"11)\n",
88+
"Hello World! (14)\n",
89+
"Hello World! (13)\n",
90+
"Hello World! (7)\n",
8291
"Hello World! (5)\n",
83-
"Hello World! (1)\n"
92+
"Hello World! (6)\n",
93+
"8)\n",
94+
"Hello World! (3)\n",
95+
"Hello World! (4)\n",
96+
"0)\n",
97+
"Hello World! (10)\n",
98+
"Hello World! (15)\n",
99+
"Hello World! (2)\n"
84100
]
85101
}
86102
],
@@ -96,22 +112,30 @@
96112
},
97113
{
98114
"cell_type": "code",
99-
"execution_count": 6,
115+
"execution_count": 5,
100116
"id": "d86a9efa-ba28-4cb6-bbfc-abc00ee63506",
101117
"metadata": {},
102118
"outputs": [
103119
{
104120
"name": "stdout",
105121
"output_type": "stream",
106122
"text": [
107-
"Hello World! (Hello World! (34))\n",
108-
"Hello World! (0)\n",
123+
"Hello World! (Hello World! (Hello World! (Hello World! (Hello World! (Hello World! (9Hello World! (8)Hello World! (\n",
124+
"Hello World! ()\n",
125+
"11)\n",
126+
"1)\n",
109127
"Hello World! (2)\n",
110-
"Hello World! (Hello World! (1)\n",
111-
"\n",
112-
"7)Hello World! (\n",
113-
"6)\n",
128+
"3)\n",
129+
"Hello World! (7)\n",
130+
"Hello World! (6)\n",
131+
"Hello World! (15)\n",
132+
"Hello World! (10)\n",
133+
"14)\n",
114134
"Hello World! (5)\n",
135+
"0)\n",
136+
"Hello World! (4)\n",
137+
"13)\n",
138+
"12)\n",
115139
"This is another message! (0)\n",
116140
"Goodbye World! (0)\n",
117141
"Goodbye World! (1)\n"
@@ -137,20 +161,20 @@
137161
},
138162
{
139163
"cell_type": "code",
140-
"execution_count": 7,
164+
"execution_count": 6,
141165
"id": "5557e01a-7c7d-4b54-8545-962ad11027df",
142166
"metadata": {},
143167
"outputs": [
144168
{
145169
"name": "stdout",
146170
"output_type": "stream",
147171
"text": [
148-
"Initialize a[] time: 0.588681\n",
149-
"Initialize b[] time: 0.513927\n",
150-
"Add arrays time: 1.58928\n",
151-
"Average result time: 0.637053\n",
172+
"Initialize a[] time: 0.341905\n",
173+
"Initialize b[] time: 0.392285\n",
174+
"Add arrays time: 0.401034\n",
175+
"Average result time: 0.191882\n",
152176
"Average: 5e+08\n",
153-
"Total time: 3.33191\n"
177+
"Total time: 1.32776\n"
154178
]
155179
}
156180
],
@@ -203,7 +227,7 @@
203227
],
204228
"metadata": {
205229
"kernelspec": {
206-
"display_name": "C++17 (xcpp+OpenMP)",
230+
"display_name": "C++17 + OpenMP",
207231
"language": "cpp",
208232
"name": "xcpp17-omp"
209233
},

notebooks/openmp-notebooks/pi_integral.ipynb

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
},
2525
{
2626
"cell_type": "code",
27-
"execution_count": 4,
27+
"execution_count": 3,
2828
"id": "f3c10995-6f29-4d71-9e61-1993ca9d1cc9",
2929
"metadata": {},
3030
"outputs": [],
@@ -62,26 +62,26 @@
6262
},
6363
{
6464
"cell_type": "code",
65-
"execution_count": 5,
65+
"execution_count": 4,
6666
"id": "0f84442a-d947-4860-bd3c-aeeea963b419",
6767
"metadata": {},
6868
"outputs": [
6969
{
7070
"name": "stdout",
7171
"output_type": "stream",
7272
"text": [
73-
"Num threads available: 8\n",
73+
"Num threads available: 16\n",
7474
"Num threads allocated for this run: 1\n",
75-
"pi is 3.141593 in 0.179501 seconds using 1 threads\n",
75+
"pi is 3.141593 in 0.965932 seconds using 1 threads\n",
7676
"\n",
7777
"Num threads allocated for this run: 2\n",
78-
"pi is 3.141592 in 0.184605 seconds using 2 threads\n",
78+
"pi is 3.141593 in 0.536038 seconds using 2 threads\n",
7979
"\n",
8080
"Num threads allocated for this run: 3\n",
81-
"pi is 3.141593 in 0.097145 seconds using 3 threads\n",
81+
"pi is 3.141594 in 0.484255 seconds using 3 threads\n",
8282
"\n",
8383
"Num threads allocated for this run: 4\n",
84-
"pi is 3.141593 in 0.071473 seconds using 4 threads\n",
84+
"pi is 3.141593 in 0.480806 seconds using 4 threads\n",
8585
"\n"
8686
]
8787
}
@@ -93,7 +93,7 @@
9393
],
9494
"metadata": {
9595
"kernelspec": {
96-
"display_name": "C++17 (xcpp+OpenMP)",
96+
"display_name": "C++17 + OpenMP",
9797
"language": "cpp",
9898
"name": "xcpp17-omp"
9999
},

src/xinterpreter.cpp

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,10 @@ void* createInterpreter(const Args &ExtraArgs = {}) {
6868
)
6969
!= ClangArgs.end())
7070
{
71-
Cpp::LoadLibrary("libomp");
71+
if (!Cpp::LoadLibrary("libomp"))
72+
{
73+
std::cerr << "Failed to load libomp (tried location: " << omp_lib_path << ")\n";
74+
}
7275
}
7376
return res;
7477
}

0 commit comments

Comments
 (0)