@@ -31,6 +31,9 @@ Pipeline ::Pipeline(std::string name, std::string description, int argc, char **
3131 , m_argc(argc)
3232 , m_argv(argv)
3333 , m_Version(" 0.1.0" )
34+ #ifdef ITK_WASM_PIPELINE_USE_THREADS
35+ , m_Threads(8 )
36+ #endif
3437{
3538 this ->footer (" Enjoy ITK!" );
3639
@@ -39,17 +42,39 @@ Pipeline ::Pipeline(std::string name, std::string description, int argc, char **
3942 this ->add_flag (" --memory-io" , m_UseMemoryIO, " Use itk-wasm memory IO" )->group (" " );
4043 this ->set_version_flag (" --version" , m_Version);
4144
45+ #ifdef ITK_WASM_PIPELINE_USE_THREADS
46+ this ->add_option (" --threads" , m_Threads, " Number of threads to use for processing" )->group (" " );
47+ #endif
48+
4249 // Set m_UseMemoryIO before it is used by other memory parsers
4350 this ->preparse_callback ([this ](size_t arg) {
4451 m_UseMemoryIO = false ;
52+ #ifdef ITK_WASM_PIPELINE_USE_THREADS
53+ m_Threads = 8 ; // Reset to default
54+ #endif
4555 for (int ii = 0 ; ii < this ->m_argc ; ++ii)
4656 {
4757 const std::string arg (this ->m_argv [ii]);
4858 if (arg == " --memory-io" )
4959 {
5060 m_UseMemoryIO = true ;
5161 }
62+ #ifdef ITK_WASM_PIPELINE_USE_THREADS
63+ if (arg == " --threads" && ii + 1 < this ->m_argc )
64+ {
65+ try {
66+ m_Threads = std::stoi (this ->m_argv [ii + 1 ]);
67+ } catch (...) {
68+ // Keep default value if parsing fails
69+ }
70+ }
71+ #endif
5272 }
73+ #ifdef ITK_WASM_PIPELINE_USE_THREADS
74+ // Set ITK's global number of threads
75+ itk::MultiThreaderBase::SetGlobalDefaultNumberOfThreads (m_Threads);
76+ std::cout << " m_Threads: " << m_Threads << std::endl;
77+ #endif
5378 });
5479
5580#ifndef ITK_WASM_NO_FILESYSTEM_IO
0 commit comments