问题
I'm running Visual Studio 2008 with the stuff-of-nightmares awful MS test framework. Trouble is that it's sending my CPU to 100% (well 25% on a quad-core).
My question is why can't Visual Studio run on more than one core? Surely M$ must have a sufficient handle on threading to get this to work.
回答1:
I have VS2008 running on all 4 CPUs. Just set this environment variable / project flag.
/MP
(It can be set in C/C++ Settings, Advanced. In project settings)
Edit: The MP flag can also accept a number, e.g. /MP2 which means it will only run on 2 cores. Leaving it as just /MP means it will run on the maximum amount of cores.
Edit2: The MP flag is probably for the compiler only.
回答2:
You can ask VS to compile multiple projects in parallel as well as compiling parallelly (!?) within a project.
Tools > Options > Projects and Solutions > maximum number of parallel projects build.
This will build C++ and C# in parallel as well!
回答3:
In case anyone comes across this old question, VS2012 introduced parallel builds as a standard feature. Quote from the article:
Visual Studio 2010 included an option for "maximum number of parallel project builds." Although there was no indication of any restriction, this IDE option only worked for C++ projects. Fortunately, this restriction no longer applies to Visual Studio 11. Rather, there's now full support for parallel builds in other languages as well. To view this, run a copy of Process Explorer at the same time a solution with numerous projects is building. You'll see that multiple MSBuild instances are created -- as many as specified in the "maximum number of parallel project builds."
回答4:
Now that Visual Studio 2010 has been released for a bit, consider upgrading to make use of the parallelTestCount attribute in MSTest's .testsettings file, as described at How to: Run Unit Tests Faster Using a Computer with Multiple CPUs or Cores.
There are a few limitations, such as:
- Only simple unit tests are supported (i.e. excludes coded UI tests and ASP.NET-hosted tests)
- Tests must be thread-safe (all tests are run in the same process)
- You can't collect code coverage (among other data & diagnostics) at the same time
Example, using 0 to mean auto-detect (the default is 1):
<?xml version="1.0" encoding="UTF-8"?>
<TestSettings
name="Release"
id="{GUID}"
xmlns="http://microsoft.com/schemas/VisualStudio/TeamTest/2010">
<Description>
These are default test settings for a local test run.
</Description>
<Execution parallelTestCount="0">
(...)
</Execution>
</TestSettings>
A few blogs have noted that you might have to close and re-open your project for Visual Studio to notice you added/changed that attribute. Also, if you edit the test settings file using the GUI, you'll probably have to re-add the parallelTestCount attribute.
回答5:
We also added multiple core support for doing multi-threaded builds on the command line for those of you with a lot of projects and long build times. Enabling multiple core support requires only a few new properties, and MSBuild manages all of the work to schedule projects efficiently and effectively. The MSBuild team has tested this ability to scale by building some projects on a 64-CPU machine.
that is from somasegar blog
So they sort of started doing it, well at least for the build.
回答6:
The /MP flag is only for builds, we at least it is according to this msdn
Now I would love to be wrong about it, but im pretty sure its just for builds. Which of course is still very useful.
回答7:
I'm sure it's very hard. Huge existing GUI-heavy non-threaded code base to multi-threaded. Sounds like a 10 to me.
But it seems to use multi-cores to me. The Intellesense seems threaded. The build system has multi-project building and for C++ multi-file building as well.
You problems with these tools sounds a bit deeper then how well they use you CPUs.
回答8:
For Visual Studio 2010 Go to Tools > Options > Projects & Solutions > Build and Run.
You will then see an entry to enter a number for the 'maximum number of parallel project builds'; my PC has an i7-3770 CPU, a Quad Core with HyperThreading, so it is set to 8.
For information on different versions of Visual Studio go here and select your version: https://msdn.microsoft.com/en-us/library/cyhcc7zc(v=vs.100).aspx
e.g. for Visual Studio 2010 this property only affects C++ builds:
Specifies the maximum number of Visual C++ projects that can build at the same time. To optimize the build process, the maximum number of parallel project builds is automatically set to the number of CPUs of your computer. The maximum is 32.
But for Visual Studio it's for C++ and C#:
maximum number of parallel project builds Specifies the maximum number of Visual C++ and Visual C# projects that can build at the same time. To optimize the build process, the maximum number of parallel project builds is automatically set to the number of CPUs of your computer. The maximum is 32.
来源:https://stackoverflow.com/questions/53939/why-cant-visual-studio-run-on-more-than-one-core-cpu-at-25