diff options
author | Tavian Barnes <tavianator@tavianator.com> | 2024-02-05 14:20:02 -0500 |
---|---|---|
committer | Tavian Barnes <tavianator@tavianator.com> | 2024-02-06 15:22:39 -0500 |
commit | 6bb323d446e2500c5a20866b56335ac8633e1c23 (patch) | |
tree | f7d37105eef1fdf5d9e75243cfb2dc02c8d53771 /src/ctx.c | |
parent | 3b82c88d1950291b1b703f082df43ec1b9654eb5 (diff) | |
download | bfs-6bb323d446e2500c5a20866b56335ac8633e1c23.tar.xz |
ctx: Fill in ctx->threads earlier
Diffstat (limited to 'src/ctx.c')
-rw-r--r-- | src/ctx.c | 16 |
1 files changed, 16 insertions, 0 deletions
@@ -15,6 +15,21 @@ #include <limits.h> #include <stdio.h> #include <stdlib.h> +#include <unistd.h> + +/** 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); |