# Limiting parallelism with max memory cap?

**URL:** <https://community.seqera.io/t/limiting-parallelism-with-max-memory-cap/575>\
**Category:** Ask for help\
**Created:** [March 19, 2024, 8:39am UTC](https://community.seqera.io/t/limiting-parallelism-with-max-memory-cap/575 "2024-03-19T08:39:13Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![bskubi](https://dub1.discourse-cdn.com/flex013/user_avatar/community.seqera.io/bskubi/32/545_2.png) [@bskubi](https://community.seqera.io/u/bskubi)\
**Post date:** [March 19, 2024, 8:39am UTC](https://community.seqera.io/t/limiting-parallelism-with-max-memory-cap/575/1 "2024-03-19T08:39:13Z")

</div>

I have a branching workflow where, if processes are freely allowed to run in parallel, they consume more memory than my system has available. I’m running on my local machine for now, but this will eventually be run on SLURM and other HPC environments.

I know I can specify how much memory to request, like this:

```auto
process processName {
    maxRetries 3
    memory {14.GB + 2.GB * task.attempt}
}

```

Is there a way to use this to limit the number of processes nextflow runs simultaneously to stay under a total memory cap?

---

<div class="post-metadata">

**Author:** ![mribeirodantas](https://dub1.discourse-cdn.com/flex013/user_avatar/community.seqera.io/mribeirodantas/32/235_2.png) [@mribeirodantas](https://community.seqera.io/u/mribeirodantas)\
**Post date:** [March 19, 2024, 1:41pm UTC](https://community.seqera.io/t/limiting-parallelism-with-max-memory-cap/575/2 "2024-03-19T13:41:42Z")

</div>

You can use `maxForks` (docs [here](https://www.nextflow.io/docs/latest/process.html#maxforks)) to control how many tasks Nextflow will instantiate from a process, but I’m having some trouble to make a closure in `maxForks` work with the value from `memory` ☹

---

<div class="post-metadata">

**Author:** ![bskubi](https://dub1.discourse-cdn.com/flex013/user_avatar/community.seqera.io/bskubi/32/545_2.png) [@bskubi](https://community.seqera.io/u/bskubi)\
**Post date:** [March 19, 2024, 6:00pm UTC](https://community.seqera.io/t/limiting-parallelism-with-max-memory-cap/575/3 "2024-03-19T18:00:27Z")

</div>

Thank you! I submitted a feature request to github. This is something Snakemake has as a feature, and I think it would really help both in cutting down the complexity of implementing workflows and increasing the efficiency of Nextflow if NF had it too.
