C++ How to limit visual studios multi-processor co

2020-05-25 05:43发布

Every time I compile using visual studio the rest of my computer crawls because visual studio is hogging all the processors. Is there a way to limit the number of processors that visual studio is using so I can still get some work done during the compilation time?

By the way, I am using visual studio 2013 and 2015 and programming in C++.

Thanks!

7条回答
Luminary・发光体
2楼-- · 2020-05-25 06:15

If you're running Windows Vista/7 (possibly XP, but not sure) it's really rather simple. Type in: Control+Shift+Esc to get your taskmanager up. Click on the Processes tab Find the process that needs its processor affinity changed Right-click on the process Click on "Set Affinity" Here you can select which processor(s) your process will use. EDIT: You have to be administrator to get this to work.

查看更多
祖国的老花朵
3楼-- · 2020-05-25 06:19

The /MP option might do it. It limits the number of processes that are spawned when you build a project. So, in your case, you would use it like this /MP1 (/MP[processMax], where processMax is the maximum amount of processes that you want to use).

查看更多
爷的心禁止访问
4楼-- · 2020-05-25 06:24

I found a workaround that actually works for me. Manually restrict affinity for VS process. Open Task Manager, go to Details tab, right click on devenv.exe, select "Set affinity". In the dialog untick several cores. That's it. All spawned cl.exe processes will inherit affinity, and thus won't run on unticked cores.

enter image description here enter image description here

Also, go and cast your vote for a feature request for Visual Studio: https://developercommunity.visualstudio.com/content/idea/436208/limit-cpu-usage-of-visual-studio.html

查看更多
Viruses.
5楼-- · 2020-05-25 06:31

Setting the "Maximum number of parallel project builds" is not the answer if you have a single C++ project with lots of .cpp files and you don't want 8 building at once. To control that, go to Tools > Options > Projects and Solutions > VC++ Project Settings, and in the Build section, set Maximum Concurrent C++ Compilations to the max number of .cpp files you want to compile in parallel. The default setting appears to be 0, which apparently means there is no maximum. I have 4 cores/8 threads, and set this value to 4, and VS now only compiles 4 files at a time instead of 8.

These instructions are based on Visual Studio 2017, but I think it's been this way for a few releases.

Setting Max Concurrent C++ Compilations

查看更多
够拽才男人
6楼-- · 2020-05-25 06:33

For Visual Studio 2015, change "Maximum number of parallel project builds" to desired number. (May be half number of processers in your m/c)

Menu> Tools > Options > Projects and solutions > Build and Run. Edit value.

Screenshot from VS2015

enter image description here

Further, maximum concurrent c++ compilation can be restricted in

Menu> Tools > Options > Projects and solutions > VC++ Project Settings > Maximum concurrent c++ compilation > Edit value.

Please note, if used 0 then all CPU will be used.

enter image description here

查看更多
forever°为你锁心
7楼-- · 2020-05-25 06:36

For C++ Use

*msbuild /p:CL_MPCount=X 

Where X is the number of compiler driver. I use this to limit the CPU utilization when compiling the Tensorflow source code.

Read this for more details: ms's blog on vs2010 c++ parallel building

查看更多
登录 后发表回答