@@ -31,6 +31,9 @@ Pipeline ::Pipeline(std::string name, std::string description, int argc, char **
31
31
, m_argc(argc)
32
32
, m_argv(argv)
33
33
, m_Version(" 0.1.0" )
34
+ #ifdef ITK_WASM_PIPELINE_USE_THREADS
35
+ , m_Threads(8 )
36
+ #endif
34
37
{
35
38
this ->footer (" Enjoy ITK!" );
36
39
@@ -39,17 +42,39 @@ Pipeline ::Pipeline(std::string name, std::string description, int argc, char **
39
42
this ->add_flag (" --memory-io" , m_UseMemoryIO, " Use itk-wasm memory IO" )->group (" " );
40
43
this ->set_version_flag (" --version" , m_Version);
41
44
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
+
42
49
// Set m_UseMemoryIO before it is used by other memory parsers
43
50
this ->preparse_callback ([this ](size_t arg) {
44
51
m_UseMemoryIO = false ;
52
+ #ifdef ITK_WASM_PIPELINE_USE_THREADS
53
+ m_Threads = 8 ; // Reset to default
54
+ #endif
45
55
for (int ii = 0 ; ii < this ->m_argc ; ++ii)
46
56
{
47
57
const std::string arg (this ->m_argv [ii]);
48
58
if (arg == " --memory-io" )
49
59
{
50
60
m_UseMemoryIO = true ;
51
61
}
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
52
72
}
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
53
78
});
54
79
55
80
#ifndef ITK_WASM_NO_FILESYSTEM_IO
0 commit comments