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

Add os.getnumcpus function to get number of logical CPU cores. #2241

Merged
merged 1 commit into from
Sep 11, 2024

Conversation

tritao
Copy link
Contributor

@tritao tritao commented Sep 1, 2024

What does this PR do?

Adds a new os.getnumcpus API to get the number of logical CPU cores.

This can be helpful to know the parameter to pass to make -j flag, which in my case I need to generate correct VS Code tasks files.

Did you check all the boxes?

  • Focus on a single fix or feature; remove any unrelated formatting or code changes
  • Add unit tests showing fix or feature works; all tests pass
  • Mention any related issues (put closes #XXXX in comment to auto-close issue when PR is merged)
  • Follow our coding conventions
  • Minimize the number of commits
  • Align documentation to your changes

@tritao tritao force-pushed the os-getnumcpus branch 2 times, most recently from 41f984f to 3c1c85d Compare September 1, 2024 17:16
@tritao tritao marked this pull request as ready for review September 1, 2024 17:17
website/docs/os.getnumcpus.md Show resolved Hide resolved
website/docs/os.getnumcpus.md Outdated Show resolved Hide resolved
@tritao tritao force-pushed the os-getnumcpus branch 2 times, most recently from aab54ae to 2e593cf Compare September 1, 2024 17:35
@tritao
Copy link
Contributor Author

tritao commented Sep 1, 2024

Thanks for the super fast review, addressed the nits 👍

src/host/os_getnumcpus.c Outdated Show resolved Hide resolved
src/host/os_getnumcpus.c Outdated Show resolved Hide resolved
src/host/os_getnumcpus.c Outdated Show resolved Hide resolved
src/host/os_getnumcpus.c Outdated Show resolved Hide resolved
src/host/os_getnumcpus.c Show resolved Hide resolved
@tritao tritao force-pushed the os-getnumcpus branch 2 times, most recently from 755b782 to a4a73df Compare September 2, 2024 10:36
@tritao
Copy link
Contributor Author

tritao commented Sep 2, 2024

Updated with new round of reviews.

Copy link
Member

@nickclark2016 nickclark2016 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pretty minor, fix and I'll merge.

src/host/os_getnumcpus.c Show resolved Hide resolved
@tritao
Copy link
Contributor Author

tritao commented Sep 5, 2024

Updated again.

@theComputeKid
Copy link
Contributor

Thanks for this! Previously, I had to use this code for my projects:

function getNumProc()
    if os.host() == "windows" then
        return os.getenv("NUMBER_OF_PROCESSORS")
    else
        output, errorCode = os.outputof("getconf _NPROCESSORS_ONLN")
        return output
    end
end

Now I can use the function you have added instead.

@nickclark2016 nickclark2016 merged commit 4be79a0 into premake:master Sep 11, 2024
14 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants