mirror of
https://github.com/facebook/zstd.git
synced 2025-07-30 22:23:13 +03:00
[pzstd] Smart default # of threads (#331)
This commit is contained in:
@ -10,6 +10,7 @@
|
|||||||
|
|
||||||
#include <cstdio>
|
#include <cstdio>
|
||||||
#include <cstring>
|
#include <cstring>
|
||||||
|
#include <thread>
|
||||||
|
|
||||||
namespace pzstd {
|
namespace pzstd {
|
||||||
|
|
||||||
@ -103,6 +104,7 @@ bool Options::parse(int argc, const char** argv) {
|
|||||||
numThreads = parseUnsigned(argv[i]);
|
numThreads = parseUnsigned(argv[i]);
|
||||||
if (numThreads == 0) {
|
if (numThreads == 0) {
|
||||||
std::fprintf(stderr, "Invalid argument: # of threads must be > 0.\n");
|
std::fprintf(stderr, "Invalid argument: # of threads must be > 0.\n");
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case 'p':
|
case 'p':
|
||||||
@ -169,12 +171,17 @@ bool Options::parse(int argc, const char** argv) {
|
|||||||
if (compressionLevel > maxCLevel) {
|
if (compressionLevel > maxCLevel) {
|
||||||
std::fprintf(
|
std::fprintf(
|
||||||
stderr, "Invalid compression level %u.\n", compressionLevel);
|
stderr, "Invalid compression level %u.\n", compressionLevel);
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// Check that numThreads is set
|
// Check that numThreads is set
|
||||||
if (numThreads == 0) {
|
if (numThreads == 0) {
|
||||||
std::fprintf(stderr, "Invalid arguments: # of threads not specified.\n");
|
numThreads = std::thread::hardware_concurrency();
|
||||||
return false;
|
if (numThreads == 0) {
|
||||||
|
std::fprintf(stderr, "Invalid arguments: # of threads not specified "
|
||||||
|
"and unable to determine hardware concurrency.\n");
|
||||||
|
return false;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
@ -118,11 +118,11 @@ TEST(Options, ValidInputs) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST(Options, BadNumThreads) {
|
TEST(Options, NumThreads) {
|
||||||
{
|
{
|
||||||
Options options;
|
Options options;
|
||||||
std::array<const char*, 3> args = {{nullptr, "-o", "-"}};
|
std::array<const char*, 3> args = {{nullptr, "-o", "-"}};
|
||||||
EXPECT_FALSE(options.parse(args.size(), args.data()));
|
EXPECT_TRUE(options.parse(args.size(), args.data()));
|
||||||
}
|
}
|
||||||
{
|
{
|
||||||
Options options;
|
Options options;
|
||||||
|
Reference in New Issue
Block a user