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

docs: Update linux build instructions #142

Closed
wants to merge 1 commit into from

Conversation

Nickrader
Copy link
Contributor

@Nickrader Nickrader commented Apr 19, 2024

Building protobuf with '--parallel' parameter causes computer to freeze and shell to crash.
Using 'n-1' threads that your cpu supports seems to avoid google crashing the shell.

Tried building protobuf outside the project with '--parallel' and it broke similar place as in our project.

closes #141

docs/building.md Outdated
$ cmake --build build --parallel
# Note: number after '-j' is threads used.
# Max is 'n-1' threads your cpu supports.
$ cmake --build build --parallel -j 4
Copy link
Member

Choose a reason for hiding this comment

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

Do we have this issue only in Linux? At least macOs has the same problem.

Also, we can try to use all available cores - 1 e.g. by doing:
https://unix.stackexchange.com/questions/208568/how-to-determine-the-maximum-number-to-pass-to-make-j-option

Copy link
Member

Choose a reason for hiding this comment

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

The following works on mac:

$ nproc
12

$ nproc --ignore=1
11

See: https://blog.robertelder.org/intro-to-nproc-command/

Copy link
Contributor Author

@Nickrader Nickrader Apr 23, 2024

Choose a reason for hiding this comment

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

cmake --build build -j $(nproc) built without issue. I just now realize that -j and --parallel are equivalent in cmake. So we could use whichever, don't need both.

$cmake --build
If <jobs> is omitted the native build tool's default number is used.

https://www.gnu.org/software/make/manual/html_node/Parallel.html
If there is nothing looking like an integer after the ‘-j’ option, there is no limit on the number of job slots.

So it looks like GNU make has no limit, and building the protobuf library must bump that number of jobs above `nproc' for me. (which then maxes out my memory? From what I read, it's not just about jobs, but the memory it uses. So when google uses 9 jobs, it is over 13.5 GBs on my machine?)

So it seems it's build system dependent (native build tool that cmake is calling). I have to re-install windows to test that, I've never been able to clone a windows drive without it complaining and it got demoted to my slowest drive, I'll probably get that done in the next week or so.

TL;DR: (I guess --paralllel is more explicit to the user, I'm indifferent)
cmake --build build -j $(nproc)
or
cmake --build build --parallel $(nproc)

Copy link
Member

Choose a reason for hiding this comment

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

From what I read, it's not just about jobs, but the memory it uses. So when google uses 9 jobs, it is over 13.5 GBs on my machine?)

Ah, that could be. Nice catch!

Ok, lets do the following:

  1. For macOs and Linux add $(nproc) (or probably $(nproc --ignore=1)).
  2. For windows: keep it as is until further issues.

Copy link
Member

Choose a reason for hiding this comment

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

Addressed in e4e7baf with suggested corrections.

Thank you for the patch!

@Nickrader
Copy link
Contributor Author

I tried including the ignore parameter. I didn't encounter any problems using nproc, so I left it at zero, with a note to increase if building freezes.
Didn't have any problems building on windows command line. Probably have to use make for windows https://gnuwin32.sourceforge.net/packages/make.htm as build system to encounter same behavior.

$ cmake --build build --parallel
$ cmake --build build --parallel $(nproc --ignore=0)

# If building freezes in above step, increase number: --ignore=1, ignore=2 ...
Copy link
Member

Choose a reason for hiding this comment

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

Lets reshape it in the following way:

# Build the project.
cmake --build build --parallel $(nproc)

# If building freezes in above step, decrease nproc to 1 or more, e.g.:
cmake --build build --parallel $(nproc --ignore=1)

Copy link
Member

Choose a reason for hiding this comment

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

Since the first command must work for everyone, we provide fallback command to those who have build issues.

alkurbatov added a commit that referenced this pull request May 28, 2024
Kudos to @Nickrader

Signed-off-by: Alexander Kurbatov <sir.alkurbatov@yandex.ru>
@alkurbatov alkurbatov closed this May 28, 2024
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.

Building Linux parallel parameter shell freezes
2 participants