@@ -225,5 +225,60 @@ 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+ # OpenMP test that creates 2 threads, and gets them to output their thread
236+ # number in descending order
237+ code_omp = """
238+ #include <omp.h>
239+ #include <iostream>
240+ #include <clang/Interpreter/CppInterOp.h>
241+ Cpp::LoadLibrary("libomp");
242+ """
243+
244+ code_omp_2 = """
245+ int main() {
246+ omp_set_num_threads(2);
247+ #pragma omp parallel
248+ {
249+ if (omp_get_thread_num() == 1) {
250+ printf("1");
251+ #pragma omp barrier
252+ }
253+ else if (omp_get_thread_num() == 0) {
254+ #pragma omp barrier
255+ printf("0");
256+ }
257+ }
258+ }
259+ main();
260+ """
261+
262+ def test_xcpp_omp (self ):
263+ self .flush_channels ()
264+ reply , output_msgs = self .execute_helper (code = self .code_omp ,timeout = 20 )
265+ reply , output_msgs = self .execute_helper (code = self .code_omp_2 ,timeout = 20 )
266+ self .assertEqual (output_msgs [0 ]['msg_type' ], 'stream' )
267+ self .assertEqual (output_msgs [0 ]['content' ]['name' ], 'stdout' )
268+ self .assertEqual (output_msgs [0 ]['content' ]['text' ], '10' )
269+
270+ kernel_names = ['xcpp17-omp' , 'xcpp20-omp' , 'xcpp23-omp' ]
271+
272+ for name in kernel_names :
273+ class_name = f"XCppOpenMPTests_{ name } "
274+ globals ()[class_name ] = type (
275+ class_name ,
276+ (BaseXCppOpenMPTests ,),
277+ {
278+ 'kernel_name' : name ,
279+ '__test__' : True
280+ }
281+ )
282+
228283if __name__ == '__main__' :
229284 unittest .main ()
0 commit comments