# \--parallel does not really enable parallel compiles with msbuild?

**URL:** https://discourse.cmake.org/t/parallel-does-not-really-enable-parallel-compiles-with-msbuild/964
**Category:** Usage
**Tags:** os:windows, gen:vs
**Created:** [April 9, 2020, 4:42pm UTC](https://discourse.cmake.org/t/parallel-does-not-really-enable-parallel-compiles-with-msbuild/964 "2020-04-09T16:42:59Z")
**Posts on this page:** 12
**Page:** 1

<div class="post-metadata">

### Author: ![Rich\_von\_Lehe](https://discourse.cmake.org/user_avatar/discourse.cmake.org/rich_von_lehe/32/307_2.png) [@Rich\_von\_Lehe](https://discourse.cmake.org/u/Rich_von_Lehe)
#### Post date: [April 9, 2020, 4:42pm UTC](https://discourse.cmake.org/t/parallel-does-not-really-enable-parallel-compiles-with-msbuild/964/1 "2020-04-09T16:42:59Z")

</div>

Somebody warned me against using (or trusting) the --parallel option on the command line recently saying that it always sets cl\_mpcount to 1 when using msbuild. I tried and sure enough this is true. After reading what cl\_mpcount is, it seems like --parallel isn’t doing what it claims to do for visual studio generators. Is there something I’m missing? Shouldn’t the --parallel option pass /p:CL\_MPcount=N where N is the number of virtual processors detected?

---

<div class="post-metadata">

### Author: ![robert.maynard](https://discourse.cmake.org/user_avatar/discourse.cmake.org/robert.maynard/32/4_2.png) [@robert.maynard](https://discourse.cmake.org/u/robert.maynard)
#### Post date: [April 9, 2020, 7:35pm UTC](https://discourse.cmake.org/t/parallel-does-not-really-enable-parallel-compiles-with-msbuild/964/2 "2020-04-09T19:35:15Z")

</div>

`--parallel` option currently maps to the `/m` flag as that was originally the only parallel flag offered by Visual Studio. So you get multiple projects being built in parallel but not multiple compilation units from the same project.

---

<div class="post-metadata">

### Author: ![Rich\_von\_Lehe](https://discourse.cmake.org/user_avatar/discourse.cmake.org/rich_von_lehe/32/307_2.png) [@Rich\_von\_Lehe](https://discourse.cmake.org/u/Rich_von_Lehe)
#### Post date: [April 9, 2020, 7:55pm UTC](https://discourse.cmake.org/t/parallel-does-not-really-enable-parallel-compiles-with-msbuild/964/3 "2020-04-09T19:55:10Z")

</div>

Do you know of any plans to update this? As it is today it covers IMO the less-useful parallelism case. If not I can submit a feature request.

---

<div class="post-metadata">

### Author: ![McMartin](https://discourse.cmake.org/user_avatar/discourse.cmake.org/mcmartin/32/150_2.png) [@McMartin](https://discourse.cmake.org/u/McMartin)
#### Post date: [April 9, 2020, 8:05pm UTC](https://discourse.cmake.org/t/parallel-does-not-really-enable-parallel-compiles-with-msbuild/964/4 "2020-04-09T20:05:06Z")

</div>

The CMake code says:

```cpp
      // Having msbuild.exe and cl.exe using multiple jobs is discouraged
      makeCommand.Add("/p:CL_MPCount=1");

```

([https://gitlab.kitware.com/cmake/cmake/-/blob/v3.17.1/Source/cmGlobalVisualStudio10Generator.cxx#L1082-1083](https://gitlab.kitware.com/cmake/cmake/-/blob/v3.17.1/Source/cmGlobalVisualStudio10Generator.cxx#L1082-1083)).

So it seems to be done on purpose, I guess to avoid over-using the CPUs.

---

<div class="post-metadata">

### Author: ![Rich\_von\_Lehe](https://discourse.cmake.org/user_avatar/discourse.cmake.org/rich_von_lehe/32/307_2.png) [@Rich\_von\_Lehe](https://discourse.cmake.org/u/Rich_von_Lehe)
#### Post date: [April 9, 2020, 8:24pm UTC](https://discourse.cmake.org/t/parallel-does-not-really-enable-parallel-compiles-with-msbuild/964/5 "2020-04-09T20:24:36Z")

</div>

I tihnk the settings should be reversed, at least based on the C++ projects I’ve seen. Perhaps MSBuild is geared with two “knobs” like this because C# projects are different and have more project parallelism (only guessing)? In my experience C++ projects benefit more from running multiple instances of cl within one project than allowing multiple projects to be processed together.

I would propose maximizing CL\_MPcount and setting /m:1. This IMO most closely reflects how --parallel works in other environments.

---

<div class="post-metadata">

### Author: ![McMartin](https://discourse.cmake.org/user_avatar/discourse.cmake.org/mcmartin/32/150_2.png) [@McMartin](https://discourse.cmake.org/u/McMartin)
#### Post date: [April 9, 2020, 8:31pm UTC](https://discourse.cmake.org/t/parallel-does-not-really-enable-parallel-compiles-with-msbuild/964/6 "2020-04-09T20:31:16Z")

</div>

> [@Rich\_von\_Lehe](#):
>
> I would propose maximizing CL\_MPcount and setting /m:1.

This is achievable for many years, long before `--parallel` was added to `cmake --build`, by adding `/MP` to the compile options and not passing any flag to `cmake --build`/MSBuild.

---

<div class="post-metadata">

### Author: ![Rich\_von\_Lehe](https://discourse.cmake.org/user_avatar/discourse.cmake.org/rich_von_lehe/32/307_2.png) [@Rich\_von\_Lehe](https://discourse.cmake.org/u/Rich_von_Lehe)
#### Post date: [April 9, 2020, 8:35pm UTC](https://discourse.cmake.org/t/parallel-does-not-really-enable-parallel-compiles-with-msbuild/964/7 "2020-04-09T20:35:57Z")

</div>

Yes, that’s perfectly valid. Of course you’re right. I’m saying for projects that are maybe not your own (e.g. building a dependency), it’s arguably easier to not have to modify that top-level CMakeLists.txt with something like this:

> ```
> add_compile_options($<$<CXX_COMPILER_ID:MSVC>:/MP>)
> 
> ```

Ultimately, I feel it would be nice to have better consistency across platforms in how --parallel works.

---

<div class="post-metadata">

### Author: ![McMartin](https://discourse.cmake.org/user_avatar/discourse.cmake.org/mcmartin/32/150_2.png) [@McMartin](https://discourse.cmake.org/u/McMartin)
#### Post date: [April 9, 2020, 8:43pm UTC](https://discourse.cmake.org/t/parallel-does-not-really-enable-parallel-compiles-with-msbuild/964/8 "2020-04-09T20:43:40Z")

</div>

> [@Rich\_von\_Lehe](#):
>
> Ultimately, I feel it would be nice to have better consistency across platforms in how --parallel works.

I totally agree!

I recently tried using `--parallel` in a project of mine and had to give up because xcodebuild requires a number of jobs, but:

- if I give a low number (2 or 4), I won’t get maximum parallelization, and
- if I give a high number (6 or 8), I might exhaust all memory on CI nodes.

So I sticked to `-j4` when using `make`, `-maxcpucount` when using MSBuild, and nothing when using xcodebuild 🤷‍♂️

---

<div class="post-metadata">

### Author: ![Rich\_von\_Lehe](https://discourse.cmake.org/user_avatar/discourse.cmake.org/rich_von_lehe/32/307_2.png) [@Rich\_von\_Lehe](https://discourse.cmake.org/u/Rich_von_Lehe)
#### Post date: [April 9, 2020, 8:51pm UTC](https://discourse.cmake.org/t/parallel-does-not-really-enable-parallel-compiles-with-msbuild/964/9 "2020-04-09T20:51:20Z")

</div>

Good point. I think it’s great just to have a common option (–parallel / -j) now across various compilers/build tools. If I have to put a number in there versus using the auto-determined number that’s not a huge loss to me.

---

<div class="post-metadata">

### Author: ![Rich\_von\_Lehe](https://discourse.cmake.org/user_avatar/discourse.cmake.org/rich_von_lehe/32/307_2.png) [@Rich\_von\_Lehe](https://discourse.cmake.org/u/Rich_von_Lehe)
#### Post date: [April 9, 2020, 9:14pm UTC](https://discourse.cmake.org/t/parallel-does-not-really-enable-parallel-compiles-with-msbuild/964/10 "2020-04-09T21:14:12Z")

</div>

I’ll try making this a formal request - if it gets thru great, if not I can always fall back on the harder-to-remember:

> ```
> cmake --build . -- /p:CL_MPcount=8
> 
> ```

---

<div class="post-metadata">

### Author: ![brad.king](https://discourse.cmake.org/user_avatar/discourse.cmake.org/brad.king/32/11_2.png) [@brad.king](https://discourse.cmake.org/u/brad.king)
#### Post date: [April 10, 2020, 11:06am UTC](https://discourse.cmake.org/t/parallel-does-not-really-enable-parallel-compiles-with-msbuild/964/11 "2020-04-10T11:06:44Z")

</div>

For reference, this has been raised as [CMake Issue 20564](https://gitlab.kitware.com/cmake/cmake/-/issues/20564).

---

<div class="post-metadata">

### Author: ![robert.maynard](https://discourse.cmake.org/user_avatar/discourse.cmake.org/robert.maynard/32/4_2.png) [@robert.maynard](https://discourse.cmake.org/u/robert.maynard)
#### Post date: [April 10, 2020, 3:18pm UTC](https://discourse.cmake.org/t/parallel-does-not-really-enable-parallel-compiles-with-msbuild/964/12 "2020-04-10T15:18:47Z")

</div>

If we are going to update this I think the new mtt flag ( [https://devblogs.microsoft.com/cppblog/improved-parallelism-in-msbuild/](https://devblogs.microsoft.com/cppblog/improved-parallelism-in-msbuild/) ) that does auto balancing between multi-TU and multi-project would be the best approach
