Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Don't specify -j option when parallel builds is set to 1 #1958

Closed
MGraefe opened this issue Jun 28, 2021 · 7 comments
Closed

Don't specify -j option when parallel builds is set to 1 #1958

MGraefe opened this issue Jun 28, 2021 · 7 comments
Labels
enhancement an enhancement to the product that is either not present or an improvement to an existing feature Feature: configure
Milestone

Comments

@MGraefe
Copy link

MGraefe commented Jun 28, 2021

Summary

For CMake builds, the plugin defines the -j flag even if parallelism is set to 1 in the settings. This interferes with MSBuild builds, which behave different when -j is defined. Instead the -j option shouldn't be defined at all when parallelism is set to 1.

Elaboration

CMake disables the /MP option from MSVC builds when the -j flag is specified, to avoid overloading the CPU. For Visual Studio / MSBuild builds, the /MP option enables parallel building of source files, while the CMake -j option enables parallel compilation of projects. In fact, CMake effectively removes any manually defined /MP flag from the compiler options in case -j is defined.

But I want my project to be compiled with /MP because for me it's much faster then relying on CMake -j. With the CMake plugin I can't, because it keeps specifying -j 1 on the command line even if I set the parallelism to 1.
It all works fine from command line if I just do cmake --build . and I can reproduce the /MP problem when I do cmake --build . -j 16

Proposal:

Don't add the -j option at all if parallelism is set to 1. Alternatively add another settings which can be used to completely disable addition of the -j flag.

Platform and Versions

  • Operating System: Windows 10
  • CMake Version: 3.20.5
  • VSCode Version: 1.57.1
  • CMake Tools Extension Version: 1.7.3
  • Compiler/Toolchain: Visual Studio 2017 AMD64
@andreeis
Copy link
Contributor

@MGraefe, thank you for this suggestion. We will address this.

@andreeis andreeis added Feature: configure enhancement an enhancement to the product that is either not present or an improvement to an existing feature labels Jun 30, 2021
@andreeis andreeis added this to the 1.9.1 milestone Oct 25, 2021
@andreeis
Copy link
Contributor

@MGraefe, a fix for this problem was included in the CMake Tools 1.9.1 release. Upgrade your extension in VSCode and let us know if you encounter any other issues.

@MGraefe
Copy link
Author

MGraefe commented Oct 26, 2021

Awesome, thanks to everyone involved!

@mikedld
Copy link

mikedld commented Oct 26, 2021

Won't omitting it affect Ninja (and maybe other tools) then, where max parallelization is the default, i.e. omitting -j will not result in a single job?

@andreeis
Copy link
Contributor

@mikedld, excellent question. I just double checked, the extension will only omit -j when parallel builds is set to 1. If not set, the extension defaults to number of cpus + 2.

@mikedld
Copy link

mikedld commented Oct 27, 2021

@andreeis, right, so if I'm using Ninja generator and setting cmake.parallelJobs to 1 now, it won't really be 1, so I can't limit ninja jobs this way? Or am I missing something?

@MGraefe
Copy link
Author

MGraefe commented Oct 27, 2021

These kinds of inconsistencies that come by overloading a single value with a special meaning is why I didn't immediately create a PR for this.

I think a separate toggle option "specify parallel builds" in addition to the existing option would be the way to go. But I don't feel comfortable adding this as I never worked with this codebase.

@github-actions github-actions bot locked and limited conversation to collaborators Jan 30, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
enhancement an enhancement to the product that is either not present or an improvement to an existing feature Feature: configure
Projects
None yet
Development

No branches or pull requests

3 participants