How to limit the number of parallel cl.exe processes during the Visual Studio solution build?
Asked Answered
S

4

15

I've recently noticed that once I start building the Visual Studio solution I'm working with (~200 C++ projects), I get a very large number of cl.exe processes. Task manager screenshot

I'm not surprised by the fact of several cl.exe running in parallel, because my projects are set up with /MP option. Project settings in one of the projects

But I would expect that their number would be limited by the following setting in the Visual Studio "Options". Visual Studio settings (Tools -> Options)

I presume that running tens of processes in parallel on the 4-core PC is not the most efficient way to build the solution.

So, basically I've got two questions:

  • Why do I observe such behavior?
  • Is it possible to limit the number of cl.exe instances?

P.S. I normally compile my solution with Visual Studio 2013 Update 4, but the same behavior can be observed with Visual Studio 2017.

Spherule answered 28/7, 2017 at 17:40 Comment(6)
You are building 8 projects in parallel. Each project is build in parallel.Ita
@manni66 Aha! Okay, that answers my first question. But I'm really curious if it's possible to limit the total number of processes, while keeping the /MP option (I often need to build a single or several projects whose compilation by itself takes quite a time).Spherule
Limit the number of projects build in parallel. Try 4.Ita
@manni66 frankly speaking, that sounds as a workaround rather than a solution. Furthermore, it doesn't help that much - I mean, the total number of processes during the solution build is still some tens.Spherule
And is that bad? As long as it is fast it's ok, isn't it?Ita
@manni66 it's definitely not bad, so thanks for advice. But at the same time, I've come with the question here hoping to learn if there's a general solution I'm not aware about, or whether it's a "known issue" which can only be work-arounded.Spherule
A
6

I think you need to read this where the conclusion is that you need to set up your compilation to fit VS idea of the world.

Also limit the number of parallel projects to 2-3 depending on the actual PC you run it on. If your PC is a monster with 16+ cores you might be able to go 1-2 up.

Ideally VS should have offered an option of using X threads but alas.

Abigail answered 2/8, 2017 at 11:31 Comment(1)
Well, I was indeed hoping that I've just overlooked some VS setting to limit the total number of threads, of that maybe it can somehow be done indirectly. But anyway, many thanks for the link, and especially for digesting it in your answer to another thread! (even though my hope seems to have been broken :))Spherule
M
6

To limit number of cl.exe you should use this option (at least it exists here in MSVC 2015):

Tools->Options->Projects and Solutions->VC++ Project Settings\Maximum concurrent C++ compilations

Zero by default means "number of CPUs".

Maxilliped answered 29/10, 2018 at 11:25 Comment(1)
This setting has no effect for me. The number of cl.exe:s rises to equal the number of processors. When I switch log level to detailed, I can see that VS still passes just a plain "/MP" with no number attached, to cl.exe. (VS2015)Hurtle
B
2

Make sure you don't have the /MP switch on any of your projects.

Then setting the maximum parallel project builds will directly relate to the number of compilation executable instances.

Will probably be slower. An alternative is to force Visual Studio/MSBuild to a specific affinity. This will not limit threads, but will keep some spare cores for the operating system/other programs.

Balancer answered 30/3, 2018 at 16:22 Comment(0)
C
-3

Under the Tools menu, choose Options. Then under Projects and Solutions, the Build and Run page has a field "maximum number of parallel project builds".

Calkins answered 28/7, 2017 at 17:52 Comment(1)
That is exactly what I have, see the last screenshot.Spherule

© 2022 - 2024 — McMap. All rights reserved.