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

Drop the need for python by using nproc --all/hw.logicalcpu_max #186

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

Kranzes
Copy link

@Kranzes Kranzes commented Jul 22, 2023

on my R7 8c/16t system nproc prints 16 and nproc --all prints 32, so i think this is the same behavior.

@domenkozar
Copy link
Member

It used to be nproc, but I can't remember why we ditched it.

@Kranzes
Copy link
Author

Kranzes commented Jul 22, 2023

It used to be nproc, but I can't remember why we ditched it.

Oh well there we have it, it doesn't exist on MacOS, that's weird. There has to be a better way to just get the core count without needing an entire python interpreter.

@Kranzes
Copy link
Author

Kranzes commented Jul 22, 2023

After 10 seconds of googling, sysctl -n hw.logicalcpu_max on MacOS should return the same thing as nproc --all.

Docs: https://opensource.apple.com/source/xnu/xnu-792.2.4/libkern/libkern/sysctl.h.auto.html

(I tested this via darling on my Linux host.)

[kranzes@pongo ~]$ nproc
16
[kranzes@pongo ~]$ nproc --all
32
[kranzes@pongo ~]$ sudo nix run nixpkgs#darling shell
[sudo] password for kranzes:
Bootstrapping the container with launchd...
Authorization required, but no authorization protocol specified

Authorization required, but no authorization protocol specified

Authorization required, but no authorization protocol specified

Authorization required, but no authorization protocol specified

Authorization required, but no authorization protocol specified

Authorization required, but no authorization protocol specified


The default interactive shell is now zsh.
To update your account to use zsh, please run `chsh -s /bin/zsh`.
For more details, please visit https://support.apple.com/kb/HT208050.
Darling [/Volumes/SystemRoot/home/kranzes]# sysctl -n hw.logicalcpu
16
Darling [/Volumes/SystemRoot/home/kranzes]# sysctl -n hw.logicalcpu_max
32

@Kranzes Kranzes changed the title Drop the need for python by using nproc Drop the need for python by using nproc --all/hw.logicalcpu_max Jul 22, 2023
@max-privatevoid
Copy link

nproc --all seems to give weird results on at least one of my systems, and on none of them does it return twice the core count.

Physical desktop:
Model name:                      AMD Ryzen 5 2600 Six-Core Processor
CPU(s):                          12
nproc: 12
nproc --all: 32

Ampere A1 VM:
Model name:                      Neoverse-N1
CPU(s):                          4
nproc: 4
nproc --all: 4

Physical server:
Model name:                      Intel(R) Core(TM) i7-7700 CPU @ 3.60GHz
CPU(s):                          8
nproc: 8
nproc --all: 8

Micro cloud instance:
Model name:                      AMD EPYC 7551 32-Core Processor
CPU(s):                          2
nproc: 2
nproc --all: 2

Maybe it's better to use "$(($(nproc) * 2))"?

@Kranzes
Copy link
Author

Kranzes commented Jul 23, 2023

Also, it seems the nix installer by default just creates 32 users and the detsys one does 32 on Darwin and auto-uid-allocation on Linux...

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.

None yet

3 participants