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

What is the reason for this initial_num_jobs plus one? #89504

Closed
November20 opened this issue Mar 15, 2024 · 7 comments
Closed

What is the reason for this initial_num_jobs plus one? #89504

November20 opened this issue Mar 15, 2024 · 7 comments
Labels

Comments

@November20
Copy link

Tested versions

short_name = "godot"
name = "Godot Engine"
major = 4
minor = 3
patch = 0
status = "dev"
module_config = ""
website = "https://godotengine.org"
docs = "latest"

System information

linux

Issue description

    initial_num_jobs = env.GetOption("num_jobs") # 如果未指定-j就为1
    altered_num_jobs = initial_num_jobs + 1 # 希望最低以两核运行
    print(altered_num_jobs)
    env.SetOption("num_jobs", altered_num_jobs) # 默认重新设为2核
    if env.GetOption("num_jobs") == altered_num_jobs: # 默认为2(即没有指定-j时,才判断cpu核心数)
        cpu_count = os.cpu_count() # 返回cpu核心数
        if cpu_count is None:
            print("Couldn't auto-detect CPU count to configure build parallelism. Specify it with the -j argument.") # 无法自动检测CPU计数以配置构建并行性。用-j参数指定它。
        else:
            safer_cpu_count = cpu_count if cpu_count <= 4 else cpu_count - 1
            print(
                "Auto-detected %d CPU cores available for build parallelism. Using %d cores by default. You can override it with the -j argument."
                % (cpu_count, safer_cpu_count)
            )
            print(safer_cpu_count)
            env.SetOption("num_jobs", safer_cpu_count)

Steps to reproduce

scons platform=linuxbsd -j 2
scons: Reading SConscript files ...
editor
3
scons: done reading SConscript files.
scons: Building targets ...
scons: `.' is up to date.
scons: done building targets.
[Time elapsed: 00:00:00.154]

If I specify-j, it's always +1.I don't think this code is necessary, and the -j option should be widely known. It is better to delete this code!

Minimal reproduction project (MRP)

N/A

@November20
Copy link
Author

When the CPU core number is greater than 4, why-1?

@November20
Copy link
Author

If I specify-j, it will +1 regardless of the number of CPU cores.

1 similar comment
@November20

This comment was marked as duplicate.

@akien-mga
Copy link
Member

As I mentioned in your previous issue, this platform is for bug reports, not for asking questions about why the code is this way or that way.

I also asked you multiple times to explain why you're asking all those questions about our SCons usage. I'm the maintainer of the Godot buildsystem, and while I'm generally happy to help users understand how it works, but context is important. Without context, this is very likely a XY Problem type of situation (which was exemplified when you were trying to understand our 6 year old Godot 3.0 SCons code...).

This is starting to be a very one-sided conversation, on the wrong platform, and t.thus my patience is running ou

If I specify-j, it will +1 regardless of the number of CPU cores.

That's not correct. Here's me running scons -j2:

 846704 akien     20   0 1661804   1.4g  19860 R  99.0   2.2   0:09.84 cc1plus                                                                                                             
 849160 akien     20   0  250432 224556  21596 R  27.8   0.3   0:00.84 cc1plus 

Two threads.

The comment in the code explains why this code is like this.

    # Default num_jobs to local cpu count if not user specified.
    # SCons has a peculiarity where user-specified options won't be overridden
    # by SetOption, so we can rely on this to know if we should use our default.

You can use git blame to find when this was added, trace back the PR which included this commit (#63087), and find answers for yourself.

@November20
Copy link
Author

I suddenly understand. Thank you.

@November20
Copy link
Author

SetOption function is invalid when-j option is set on command line.

@November20
Copy link
Author

My translation software is so bad that I mistranslated comments.
env.SetOption("num_jobs", altered_num_jobs) # SetOption function is invalid when-j option is set on command line.
I think this comment can be more helpful.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants