1717#include < ImfOutputPart.h>
1818#include " ImfChannelList.h"
1919#include " ImfMisc.h"
20+ #include " IlmThread.h"
2021#include " IlmThreadPool.h"
2122#include " ImfFrameBuffer.h"
2223#include < ImfNamespace.h>
@@ -140,8 +141,13 @@ class WritingTask : public Task
140141 Header* header,
141142 int part_num,
142143 PartBuffer* buffer)
143- : Task (group), part (*file, part_num), buffer (buffer), header (header)
144- {}
144+ : Task (group)
145+ , part (*file, part_num)
146+ , buffer (buffer)
147+ , header (header)
148+ , part_num (part_num)
149+ {
150+ }
145151
146152 void execute ()
147153 {
@@ -154,6 +160,7 @@ class WritingTask : public Task
154160 OutputPart part;
155161 PartBuffer* buffer;
156162 Header* header;
163+ int part_num;
157164};
158165
159166class ReadingTask : public Task
@@ -193,7 +200,10 @@ main (int argc, char* argv[])
193200 " Repetition count" ,
194201 cxxopts::value<int > ()->default_value (" 5" )) (
195202 " t,threads" ,
196- " Number of threads" ,
203+ " Number of threads to handle encoding and decoding" ,
204+ cxxopts::value<int > ()->default_value (" 1" )) (
205+ " p,part_threads" ,
206+ " Number of threads to handle parts" ,
197207 cxxopts::value<int > ()->default_value (" 1" )) (
198208 " v,verbose" ,
199209 " Output more information" ,
@@ -210,6 +220,15 @@ main (int argc, char* argv[])
210220
211221 auto args = options.parse (argc, argv);
212222
223+ if (!supportsThreads ())
224+ {
225+ std::cout << " Threading not supported!" << std::endl;
226+ exit (-1 );
227+ }
228+
229+ if (args[" verbose" ].as <bool > ())
230+ std::cout << " Recommended # of I/O threads: " << ThreadPool::estimateThreadCountForFileIO () << std::endl;
231+
213232 if (args.count (" compression" ) != 1 || args.count (" file" ) != 1 )
214233 {
215234 std::cout << options.help () << std::endl;
@@ -220,7 +239,7 @@ main (int argc, char* argv[])
220239
221240 auto & src_fn = args[" file" ].as <std::string> ();
222241
223- /* thread count */
242+ /* encoding/decoding thread count */
224243
225244 setGlobalThreadCount (args[" threads" ].as <int > ());
226245
@@ -238,7 +257,7 @@ main (int argc, char* argv[])
238257 {
239258 InputPart src_part (src_file, part_index);
240259
241- headers[part_index] = src_part.header ();
260+ headers[part_index] = src_part.header ();
242261 /* set the target compressor */
243262 headers[part_index].compression () = c;
244263
@@ -323,8 +342,9 @@ main (int argc, char* argv[])
323342 /* MultiPartOutputFile o_file (
324343 "/var/tmp/out.exr", headers.data (), headers.size ());*/
325344
326- ThreadPool* thread_pool = new ThreadPool ();
327- TaskGroup task_group;
345+ ThreadPool* thread_pool =
346+ new ThreadPool (args[" part_threads" ].as <int > ());
347+ TaskGroup task_group;
328348
329349 auto start = std::chrono::high_resolution_clock::now ();
330350 for (int part_index = 0 ; part_index < src_file.parts (); part_index++)
@@ -355,8 +375,9 @@ main (int argc, char* argv[])
355375
356376 MultiPartInputFile i_file (i_memfile);
357377
358- ThreadPool* thread_pool = new ThreadPool ();
359- TaskGroup task_group;
378+ ThreadPool* thread_pool =
379+ new ThreadPool (args[" part_threads" ].as <int > ());
380+ TaskGroup task_group;
360381
361382 auto start = std::chrono::high_resolution_clock::now ();
362383 for (int part_index = 0 ; part_index < i_file.parts (); part_index++)
0 commit comments