@@ -232,33 +232,26 @@ class BaseXCppOpenMPTests(jupyter_kernel_test.KernelTests):
232232 # language_info.name in a kernel_info_reply should match this
233233 language_name = 'C++'
234234
235- # Code that should write the exact string `hello, world` to STDOUT
236- code_omp = """
235+ # Code that prints Hello from thread followed by thread number
236+ omp_test_code = """
237237 #include <omp.h>
238238 #include <iostream>
239239 #include <clang/Interpreter/CppInterOp.h>
240240 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);
241+ omp_set_num_threads(4);
242+ #pragma omp parallel
243+ {
244+ int id = omp_get_thread_num();
245+ std::cout << "Hello from thread " << id << std::endl;
254246 }
255- main();
256- """
257-
247+ """
258248 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 ]['msg_type' ], 'stream' )
249+ self .flush_channels ()
250+ reply , output_msgs = self .execute_helper (code = self .omp_test_code , timeout = 20 )
251+ output_text = '' .join (msg ['content' ]['text' ] for msg in stream_msgs )
252+ thread_ids = set (map (int , re .findall (r'Hello from thread (\d+)' , output_text )))
253+ expected_ids = set (range (4 ))
254+ self .assertEqual (thread_ids , expected_ids ,f"Expected thread IDs { expected_ids } , but got { thread_ids } " )
262255
263256 kernel_names = ['xcpp17-omp' , 'xcpp20-omp' , 'xcpp23-omp' ]
264257
0 commit comments