From 6bb323d446e2500c5a20866b56335ac8633e1c23 Mon Sep 17 00:00:00 2001 From: Tavian Barnes Date: Mon, 5 Feb 2024 14:20:02 -0500 Subject: ctx: Fill in ctx->threads earlier --- src/ctx.c | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) (limited to 'src/ctx.c') diff --git a/src/ctx.c b/src/ctx.c index 1f3e72e..6c84f75 100644 --- a/src/ctx.c +++ b/src/ctx.c @@ -15,6 +15,21 @@ #include #include #include +#include + +/** Get the initial value for ctx->threads (-j). */ +static int bfs_nproc(void) { + long nproc = sysconf(_SC_NPROCESSORS_ONLN); + + if (nproc < 1) { + nproc = 1; + } else if (nproc > 8) { + // Not much speedup after 8 threads + nproc = 8; + } + + return nproc; +} struct bfs_ctx *bfs_ctx_new(void) { struct bfs_ctx *ctx = ZALLOC(struct bfs_ctx); @@ -28,6 +43,7 @@ struct bfs_ctx *bfs_ctx_new(void) { ctx->maxdepth = INT_MAX; ctx->flags = BFTW_RECOVER; ctx->strategy = BFTW_BFS; + ctx->threads = bfs_nproc(); ctx->optlevel = 3; trie_init(&ctx->files); -- cgit v1.2.3