Skip to content

Initial OpenMP support#25937

Open
JAicewizard wants to merge 12 commits into
emscripten-core:mainfrom
JAicewizard:libomp
Open

Initial OpenMP support#25937
JAicewizard wants to merge 12 commits into
emscripten-core:mainfrom
JAicewizard:libomp

Conversation

@JAicewizard

@JAicewizard JAicewizard commented Dec 11, 2025

Copy link
Copy Markdown
Contributor

This makes emcc recognize -fopenmp, and links it as needed.

When updating openmp, it neesd to be compiled. This is not strictly neccesary, but we need to invoke cmake in order to generate the headers. When compiling openemp, we need to make use of cmake as well, as the build system is quite long and complicated. I am sure it can be done another way using ninja, and I encourage others to implement this, but I do not have the capacity right now to make this happen.

Fixes: #13892
Fixes: #17637

@JAicewizard

Copy link
Copy Markdown
Contributor Author

To clarify, I have tested this by compiling + linking a program requiring openmp

@sbc100 sbc100 changed the title Initial OMP support Initial OpenMP support Dec 11, 2025

@sbc100 sbc100 left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

I assume the contents of system/lib/libomp is coming from an upstream repo?

Can you using git submodule for this and put it in third_party/ maybe?

Comment thread tools/cmdline.py Outdated
Comment thread tools/cmdline.py Outdated
Comment thread tools/settings.py Outdated
Comment thread tools/system_libs.py Outdated
Comment thread tools/system_libs.py Outdated
@JAicewizard

Copy link
Copy Markdown
Contributor Author

I assume the contents of system/lib/libomp is coming from an upstream repo?

Can you using git submodule for this and put it in third_party/ maybe?

Yess, it is from llvm. Since all the other llvm libraries are in this location, it made sense to put it here. Do you want the entire LLVM repository as a submodule? It seems a bit overkill, at that point the other libraries can also be pulled from there

@sbc100

sbc100 commented Dec 11, 2025

Copy link
Copy Markdown
Collaborator

I assume the contents of system/lib/libomp is coming from an upstream repo?
Can you using git submodule for this and put it in third_party/ maybe?

Yess, it is from llvm. Since all the other llvm libraries are in this location, it made sense to put it here. Do you want the entire LLVM repository as a submodule? It seems a bit overkill, at that point the other libraries can also be pulled from there

Oh i see, I didn't realize this was from llvm. I that case the import approach your took does seem reasonable.

@JAicewizard JAicewizard marked this pull request as draft December 11, 2025 17:25
@JAicewizard JAicewizard marked this pull request as ready for review December 16, 2025 01:13
@JAicewizard

Copy link
Copy Markdown
Contributor Author

Failing tests:

  • other.test_shell_cmd_with_quotes: No idea, the failing command works for me, but it fails in the test. No idea how to debug
  • wasm2js1.test_openmp_max_threads: Seems to fail because of unimplemented in binaryen: Assertion !curr->isAtomic && "atomic store not implemented"' failed.`
  • wasm64_4gb.test_openmp_max_threads: I fixed that libomp is no longer compiled for 32bit on 64 bit target, however libomp is not supported for 64bit wasm.

For the last two I would like to disable the tests, but I don't know how.
For the first, I really don't know how to find out what the issue is, let alone how to fix it.

Ruff issues can be easily fixed ofc

@anutosh491

Copy link
Copy Markdown

Hi @JAicewizard @sbc100,

Thanks a lot for working on this. I along with many other folks would surely be interested in this use case.

My use case revolves around being able to run OpenMP based code in a REPL format in the browser using clang-repl (try out basic C++ usecases here). Being able to support OpenMP in the previous link would be great.

@anutosh491

Copy link
Copy Markdown

Is there a timeline, when we can expect emscripten to support OpenMP ?

@JAicewizard

Copy link
Copy Markdown
Contributor Author

I am just waiting on the maintainers for what I am supposed to do with the failing tests

@anutosh491

Copy link
Copy Markdown

I am just waiting on the maintainers for what I am supposed to do with the failing tests

Let's tag @sbc100 who should be able to help us here !

Comment thread src/settings_internal.js Outdated
Comment thread tools/system_libs.py Outdated
Comment thread tools/system_libs.py Outdated
Comment thread tools/system_libs.py Outdated
Comment thread tools/system_libs.py Outdated
Comment thread tools/system_libs.py
Comment thread tools/system_libs.py Outdated
Comment thread tools/system_libs.py Outdated
Comment thread tools/system_libs.py Outdated
Comment thread tools/system_libs.py Outdated

@JAicewizard JAicewizard left a comment

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Whats resolved is fixed locally, will test the other changes before resolving and pushing

@anutosh491

Copy link
Copy Markdown

We have openmp working with clang-repl now natively.

Check this C++ notebook out for running openmp in a repl format. This is built on xeus-cpp, the C++ Jupyter kernel that is powered by clang-repl.

Here's me drawing the mandelbrot plot with a speed up offered by openmp
MandelBrot.ipynb

Xues-cpp also offers wasm kernels alongside native kernels that work completely in the browser. Check : https://compiler-research.org/xeus-cpp/lab/index.html

So to have the same example through in the wasm kernel, we would like to have support for OpenMp through emscripten.

@duerrbaby

Copy link
Copy Markdown

@JAicewizard Hi, thanks for working on this. From the logs of the failing tests, it seems like it's just toolchain drift (LLVM 23 vs expected 22).
Can you rebase your branch on main and rerun CI?

@duerrbaby

Copy link
Copy Markdown

@JAicewizard @sbc100 I rebased and resolved the failing tests in this PR
#27073

Can you review?

@JAicewizard

Copy link
Copy Markdown
Contributor Author

Thank you very much! I am currently overcome by events, and last time rebasing was quite a lot more work than expected.

I will take a quick look later today at your PR, but any step towards getting this merged is highly appreciated!

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.

OpenMP support (omp.h file not found) Enabling openmp

4 participants