Skip to content

Commit

Permalink
Add thread control to exrmetrics (#1904)
Browse files Browse the repository at this point in the history
Add ability to test threading modes with exrmetrics

Signed-off-by: Kimball Thurston <[email protected]>
  • Loading branch information
kdt3rd authored Nov 3, 2024
1 parent 6fc0c63 commit 5ce329c
Showing 1 changed file with 35 additions and 0 deletions.
35 changes: 35 additions & 0 deletions src/bin/exrmetrics/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@

#include "ImfCompression.h"
#include "ImfMisc.h"
#include "ImfThreading.h"
#include "IlmThreadPool.h"

#include <iostream>
#include <vector>
Expand All @@ -22,6 +24,7 @@ using std::endl;
using std::ostream;
using std::vector;
using namespace Imf;
using namespace IlmThread;

void
usageMessage (ostream& stream, const char* program_name, bool verbose = false)
Expand All @@ -41,6 +44,10 @@ usageMessage (ostream& stream, const char* program_name, bool verbose = false)
" -p n part number to copy (only one part will be written to output file)\n"
" default is part 0\n"
"\n"
" -m set to multi-threaded (system selected thread count)\n"
" -t n use n threads for processing files\n"
" default is single / no threads\n"
"\n"
" -l level set DWA or ZIP compression level\n"
"\n"
" -z x sets the data compression method to x\n"
Expand All @@ -66,6 +73,7 @@ main (int argc, char** argv)
const char* outFile = nullptr;
const char* inFile = nullptr;
int part = 0;
int threads = 0;
float level = INFINITY;
int halfMode = 0; // 0 - leave alone, 1 - just RGBA, 2 - everything
Compression compression = Compression::NUM_COMPRESSION_METHODS;
Expand Down Expand Up @@ -98,6 +106,28 @@ main (int argc, char** argv)
cout << "License BSD-3-Clause" << endl;
return 0;
}
else if (!strcmp (argv[i], "-m"))
{
threads = -1;
i += 1;
}
else if (!strcmp (argv[i], "-t"))
{
if (i > argc - 2)
{
cerr << "Missing thread count value with -t option\n";
return 1;
}

threads = atoi (argv[i + 1]);
if (threads < 0)
{
cerr << "bad thread count " << argv[i + 1] << " specified to -t option\n";
return 1;
}

i += 2;
}
else if (!strcmp (argv[i], "-z"))
{
if (i > argc - 2)
Expand Down Expand Up @@ -188,6 +218,11 @@ main (int argc, char** argv)

try
{
if (threads < 0)
setGlobalThreadCount (ThreadPool::estimateThreadCountForFileIO ());
else
setGlobalThreadCount (threads);

exrmetrics (inFile, outFile, part, compression, level, halfMode);
}
catch (std::exception& what)
Expand Down

0 comments on commit 5ce329c

Please sign in to comment.