Skip to content

Commit 571023c

Browse files
committed
Add Simple OpenMP kernel test
1 parent ba86e39 commit 571023c

File tree

1 file changed

+48
-0
lines changed

1 file changed

+48
-0
lines changed

test/test_xcpp_kernel.py

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -225,5 +225,53 @@ class BaseXCppTests2(jupyter_kernel_test.KernelTests):
225225
}
226226
)
227227

228+
if platform.system() != 'Windows':
229+
class BaseXCppOpenMPTests(jupyter_kernel_test.KernelTests):
230+
__test__ = False
231+
232+
# language_info.name in a kernel_info_reply should match this
233+
language_name = 'C++'
234+
235+
# Code that should write the exact string `hello, world` to STDOUT
236+
code_omp="""
237+
#include <omp.h>
238+
#include <iostream>
239+
#include <clang/Interpreter/CppInterOp.h>
240+
Cpp::LoadLibrary("libomp");
241+
int main() {
242+
int max_threads = omp_get_max_threads();
243+
244+
printf("max threads: %d\n", max_threads);
245+
omp_set_num_threads(max_threads);
246+
247+
#pragma omp parallel
248+
{
249+
int id = omp_get_thread_num();
250+
printf("Hello World from thread = %d with %d threads\n", id, omp_get_num_threads());
251+
}
252+
253+
printf("all done, with hopefully %d threads\n", max_threads);
254+
}
255+
main();
256+
"""
257+
258+
def test_xcpp_omp(self):
259+
self.flush_channels()
260+
reply, output_msgs = self.execute_helper(code=self.code_omp,timeout=20)
261+
self.assertEqual(output_msgs[0]['content']['name'], 'stdout')
262+
263+
kernel_names = ['xcpp17-omp', 'xcpp20-omp', 'xcpp23-omp']
264+
265+
for name in kernel_names:
266+
class_name = f"XCppOpenMPTests_{name}"
267+
globals()[class_name] = type(
268+
class_name,
269+
(BaseXCppOpenMPTests,),
270+
{
271+
'kernel_name': name,
272+
'__test__': True
273+
}
274+
)
275+
228276
if __name__ == '__main__':
229277
unittest.main()

0 commit comments

Comments
 (0)