# JOB\_POOLS vs ninja jobs flag arg?

**URL:** <https://discourse.cmake.org/t/job-pools-vs-ninja-jobs-flag-arg/5652>\
**Category:** Code\
**Created:** [May 11, 2022, 3:04pm UTC](https://discourse.cmake.org/t/job-pools-vs-ninja-jobs-flag-arg/5652 "2022-05-11T15:04:38Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![cmak](https://discourse.cmake.org/letter_avatar_proxy/v4/letter/c/eb8c5e/32.png) [@cmak](https://discourse.cmake.org/u/cmak)\
**Post date:** [May 11, 2022, 3:04pm UTC](https://discourse.cmake.org/t/job-pools-vs-ninja-jobs-flag-arg/5652/1 "2022-05-11T15:04:38Z")

</div>

How is `JOB_POOL_COMPILE` and `JOB_POOL_LINK` different from `-j` flag passed to ninja on command line?

---

<div class="post-metadata">

**Author:** ![ben.boeckel](https://discourse.cmake.org/letter_avatar_proxy/v4/letter/b/ea5d25/32.png) [@ben.boeckel](https://discourse.cmake.org/u/ben.boeckel)\
**Post date:** [May 11, 2022, 8:08pm UTC](https://discourse.cmake.org/t/job-pools-vs-ninja-jobs-flag-arg/5652/2 "2022-05-11T20:08:15Z")

</div>

The `-j` flag tells `ninja` the maximum number of jobs to allow. Pools limit build rules annotated with them to that number at once. So with a pool size of 3 and `-j2`, the pool doesn’t do much because, at most, 2 jobs are running anyways. With `-j5`, you ensure that no more than 3 jobs that share that pool are running at a time. CMake gives you per-target controls for how to manage its compile and link jobs.

Common use cases:

- in a static build, put all executables into a single pool of size 1 (since linking tends to be memory-intensive)
- for CUDA or other memory-intensive compiles, put them all into one pool with a size calculated based on total memory dividing by the expected per-TU usage

---

<div class="post-metadata">

**Author:** ![cmak](https://discourse.cmake.org/letter_avatar_proxy/v4/letter/c/eb8c5e/32.png) [@cmak](https://discourse.cmake.org/u/cmak)\
**Post date:** [May 18, 2022, 8:36am UTC](https://discourse.cmake.org/t/job-pools-vs-ninja-jobs-flag-arg/5652/3 "2022-05-18T08:36:38Z")

</div>

So effectively the number of jobs is limited by the smallest of `JOB_POOL_COMPILE ` and `-j` flag?

On command line I can specify both jobs and limit, e.g. `ninja -j0 -l14`, anything similar to `l` flag here too?

---

<div class="post-metadata">

**Author:** ![ben.boeckel](https://discourse.cmake.org/letter_avatar_proxy/v4/letter/b/ea5d25/32.png) [@ben.boeckel](https://discourse.cmake.org/u/ben.boeckel)\
**Post date:** [May 18, 2022, 1:01pm UTC](https://discourse.cmake.org/t/job-pools-vs-ninja-jobs-flag-arg/5652/4 "2022-05-18T13:01:31Z")

</div>

No, the `-l` flag is for “load average” and basically says “don’t spawn new jobs if the machine is ‘too busy’”. There is no pool mechanism for load average in `ninja` itself, so CMake would have no way to do anything there.
