Skip to content

Commit

Permalink
Fix resolution with decompression nbworkers
Browse files Browse the repository at this point in the history
  • Loading branch information
daniellerozenblit committed Dec 11, 2024
1 parent b369bc6 commit edf4268
Showing 1 changed file with 12 additions and 8 deletions.
20 changes: 12 additions & 8 deletions programs/zstdcli.c
Original file line number Diff line number Diff line change
Expand Up @@ -760,7 +760,7 @@ static int init_cLevel(void) {
}

#ifdef ZSTD_MULTITHREAD
static unsigned init_nbThreads(void) {
static unsigned default_nbThreads(void) {
const char* const env = getenv(ENV_NBTHREADS);
if (env != NULL) {
const char* ptr = env;
Expand Down Expand Up @@ -855,7 +855,7 @@ int main(int argCount, const char* argv[])
ZSTD_paramSwitch_e mmapDict=ZSTD_ps_auto;
ZSTD_paramSwitch_e useRowMatchFinder = ZSTD_ps_auto;
FIO_compressionType_t cType = FIO_zstdCompression;
unsigned nbWorkers = 0;
int nbWorkers = -1; /* -1 means unset */
double compressibility = -1.0; /* lorem ipsum generator */
unsigned bench_nbSeconds = 3; /* would be better if this value was synchronized from bench */
size_t blockSize = 0;
Expand Down Expand Up @@ -896,17 +896,13 @@ int main(int argCount, const char* argv[])
#endif
ZSTD_paramSwitch_e literalCompressionMode = ZSTD_ps_auto;


/* init */
checkLibVersion();
(void)recursive; (void)cLevelLast; /* not used when ZSTD_NOBENCH set */
(void)memLimit;
assert(argCount >= 1);
if ((filenames==NULL) || (file_of_names==NULL)) { DISPLAYLEVEL(1, "zstd: allocation error \n"); exit(1); }
programName = lastNameFromPath(programName);
#ifdef ZSTD_MULTITHREAD
nbWorkers = init_nbThreads();
#endif

/* preset behaviors */
if (exeNameMatch(programName, ZSTD_ZSTDMT)) nbWorkers=0, singleThread=0;
Expand Down Expand Up @@ -1298,7 +1294,7 @@ int main(int argCount, const char* argv[])
DISPLAYLEVEL(3, WELCOME_MESSAGE);

#ifdef ZSTD_MULTITHREAD
if ((operation==zom_decompress) && (!singleThread) && (nbWorkers > 1)) {
if ((operation==zom_decompress) && (nbWorkers > 1)) {
DISPLAYLEVEL(2, "Warning : decompression does not support multi-threading\n");
}
if ((nbWorkers==0) && (!singleThread)) {
Expand All @@ -1311,7 +1307,15 @@ int main(int argCount, const char* argv[])
DISPLAYLEVEL(3, "Note: %d physical core(s) detected \n", nbWorkers);
}
}
DISPLAYLEVEL(3, "Compressing with %u worker threads \n", nbWorkers);
// Resolve to default if nbWorkers is still unset
if (nbWorkers == -1) {
if (operation == zom_decompress) {
nbWorkers = 1;
} else {
nbWorkers = default_nbThreads();
}
}
DISPLAYLEVEL(4, "Compressing with %u worker threads \n", nbWorkers);
#else
(void)singleThread; (void)nbWorkers; (void)defaultLogicalCores;
#endif
Expand Down

0 comments on commit edf4268

Please sign in to comment.