-
-
Notifications
You must be signed in to change notification settings - Fork 5.5k
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
Segmentation fault when calling C code using GMP initialization together with OpenMP #33223
Comments
At first I thought that maybe Julia's bundled MPFR library isn't built with the julia> ccall((:mpfr_buildopt_tls_p,:libmpfr), Cint, ())
1
julia> ccall((:mpfr_buildopt_tls_p,:libmpfr), Cint, ())
1 However, I should note that we also replace the GMP memory allocator with our own: ccall((:__gmp_set_memory_functions, :libgmp), Cvoid,
(Ptr{Cvoid},Ptr{Cvoid},Ptr{Cvoid}),
cglobal(:jl_gc_counted_malloc),
cglobal(:jl_gc_counted_realloc_with_old_size),
cglobal(:jl_gc_counted_free_with_size)) and your segfault is occurring in @vtjnash, is |
@ederc I think I ran into something similar when enabling threading for flint in Nemo. Can you try the hack at https://github.com/Nemocas/Nemo.jl/blob/bb40f2055d2fdd50e58ac032937ce75f1a1ea5fa/src/Nemo.jl#L226? (As a workaround) |
@thofma Thanks Tommy, your hack works for me. Is this really the way one should do this or should we keep this issue open? |
I don't think this is the way one should do it. I hope that someone knowledgeable of the GC internals can help with this. |
Better align the API of the jl_ wrappers for malloc/realloc/free with the libc namesakes, including being safe to use on threads. fix #33223
Better align the API of the jl_ wrappers for malloc/realloc/free with the libc namesakes, including being safe to use on threads. fix #33223
When calling C code from julia I figured out a segmentation fault which appears when using in the C code GMP together with OpenMP and letting the code run in parallel. If I let the code run from the C library without calling it from julia, this error does not appear. Note that the error occurs only if I set
num_threads
greater than 1 in the OpenMP pragma.Here is a minimal example:
Running the C code directly no error appears, there is no memory issue, I even tried it with valgrind.
Doing now a ccall like
the call of
test
throws a segmentation fault:The error always appears when calling
mpz_init()
, also in my bigger real example where I have encountered the problem at first.Again, if
num_threads(1)
is given, no such error appears, but once the value ofnum_threads
is greater than 1 and the computation is done in parallel I run into this error. Of course,x
in the above example is private to each thread.Here is the versioninfo:
The text was updated successfully, but these errors were encountered: