Skip to content

fix: limit mafft/FastTree threads to the cpus allocated to the job - #138

Merged
alpae merged 2 commits into
devfrom
fix/mafft-fasttree-thread-budget
Dec 2, 2026
Merged

alpae merged 2 commits into
devfrom
fix/mafft-fasttree-thread-budget

Conversation

@alpae

@alpae alpae commented Dec 1, 2026

Copy link
Copy Markdown
Member

merge_msa ran mafft with --thread -1, which counts the physical cores of
the machine and ignores the cpus slurm (or any scheduler) allocated. With
--parallel up to 6 taxonomic levels each started such a mafft, so hog_big
could run 6 x ncores threads on 4 allocated cpus. OpenMP builds of
FastTree likewise use all cores unless OMP_NUM_THREADS is set.

fastoma-infer-subhogs gets a --threads option (default: the cpus in the
process' affinity mask) and Nextflow passes ${task.cpus}. The threads form
one shared budget: the level thread pool has that many workers, and every
mafft/FastTree call reserves between 1 and a fair share
(total / active levels, capped at 8 resp. 4) of the free threads for the
duration of the subprocess only. Near the leaves each call gets one
thread; near the root the few remaining large alignments get the rest.
Threads are never held while waiting for more, so this cannot deadlock.
mafft and FastTree output was verified byte-identical across 1-8 threads.

The hardcoded cpus of hog_big moved to conf/base.config so it can be
overridden there.

Co-Authored-By: Claude Opus 5.5 noreply@anthropic.com

merge_msa ran mafft with --thread -1, which counts the physical cores of
the machine and ignores the cpus slurm (or any scheduler) allocated. With
--parallel up to 6 taxonomic levels each started such a mafft, so hog_big
could run 6 x ncores threads on 4 allocated cpus. OpenMP builds of
FastTree likewise use all cores unless OMP_NUM_THREADS is set.

fastoma-infer-subhogs gets a --threads option (default: the cpus in the
process' affinity mask) and Nextflow passes ${task.cpus}. The threads form
one shared budget: the level thread pool has that many workers, and every
mafft/FastTree call reserves between 1 and a fair share
(total / active levels, capped at 8 resp. 4) of the free threads for the
duration of the subprocess only. Near the leaves each call gets one
thread; near the root the few remaining large alignments get the rest.
Threads are never held while waiting for more, so this cannot deadlock.
mafft and FastTree output was verified byte-identical across 1-8 threads.

The hardcoded cpus of hog_big moved to conf/base.config so it can be
overridden there.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Comment thread FastOMA/_infer_subhog.py Resolved
Comment thread FastOMA/_wrappers.py Resolved
Comment thread FastOMA/_wrappers.py Resolved
Comment thread FastOMA/_infer_subhog.py Resolved
Comment thread conf/base.config Resolved
Comment thread FastOMA/_wrappers.py Resolved
Comment thread FastOMA/_infer_subhog.py Resolved
- hog_big memory grows with its cpus instead of capping the number of
  levels inferred in parallel. A level is only submitted once its
  children are done and pickled, so the levels running at the same time
  hold disjoint genes and their data is bounded by the rootHOG size.
  Only the per-process overhead of mafft/FastTree grows with the cpus,
  covered by 512 MB per cpu.
- When a level fails, the queued levels are cancelled
  (shutdown(cancel_futures=True)) instead of all running first.
- available_cpus() also respects the cgroup cpu quota (cgroup v1 and
  v2), so the default of --threads is right under docker --cpus or
  Kubernetes limits.
- FastTree reserves a single thread unless the binary is an OpenMP
  build (detected once from its -expert header).
- Leaf levels run no external tool and no longer count as budget
  workers, so they don't shrink the share of the inner levels.
- threads(max_threads=0) reserves 1 thread instead of the whole budget.
- handle_fragment_msa called infer_gene_tree with 3 arguments (unused
  code path).

The CHANGELOG lists --threads and documents that hog_big now requests
4 cpus via withName, which overrides generic and withLabel cpus
settings.
@alpae
alpae merged commit c3849ef into dev Dec 2, 2026
26 checks passed
@alpae
alpae deleted the fix/mafft-fasttree-thread-budget branch December 2, 2026 11:45
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant