Print crashes when using Nemo from another module

Skip to first unread message

Mao Zeng

Feb 2, 2021, 7:24:46 AM2/2/21
to nemo-devel
I'm trying to use Nemo to access Flint's multivariate polynomials, but run into a strange problem. A toy example is this. Here's a file "test1.jl":

# test1.jl
module test1
export x,y
using Nemo
Ring, (x,y) = PolynomialRing(ZZ, ["x", "y"])

Now I run these line in the Julia REPL:
push!(LOAD_PATH, ".") # add current directory to package search path
using test1
println(x + y)

The last line results in a segmentation fault. However, the following lines run without problem in the Julia REPL:
# print output: x + y

This workaround is inconvenient, since I want the variables / namespace to be exported.

I don't know if this is specific to Nemo, or it's because of my ignorance about using Julia modules in a nested manner.

Feb 2, 2021, 7:31:51 AM2/2/21
to nemo-devel
Could you please provide `versioninfo(verbose = true)` and Pkg.status()?

Mao Zeng

Feb 2, 2021, 7:40:23 AM2/2/21
to nemo-devel
julia> versioninfo(verbose=true)
Julia Version 1.5.3
Commit 788b2c77c1 (2020-11-09 13:37 UTC)
Platform Info:
  OS: Linux (x86_64-pc-linux-gnu)
      Ubuntu 20.04.2 LTS
  uname: Linux 5.4.0-65-generic #73-Ubuntu SMP Mon Jan 18 17:25:17 UTC 2021 x86_64 x86_64
  CPU: Intel(R) Core(TM) i7-8550U CPU @ 1.80GHz: 
              speed         user         nice          sys         idle          irq
       #1  2719 MHz     336487 s       1001 s      84220 s   18617291 s          0 s
       #2  2545 MHz     333565 s       2495 s      84938 s   18615669 s          0 s
       #3  2560 MHz     332332 s       1834 s      91239 s   18604872 s          0 s
       #4  2550 MHz     326774 s       1712 s      86333 s   18601649 s          0 s
       #5  2619 MHz     334680 s       2238 s      83019 s   18602381 s          0 s
       #6  2759 MHz     333976 s       3927 s      82765 s   18610945 s          0 s
       #7  2681 MHz     314221 s       1362 s      91307 s   18629689 s          0 s
       #8  2698 MHz     334525 s       5269 s      89576 s   18610551 s          0 s
  Memory: 15.402080535888672 GB (240.1640625 MB free)
  Uptime: 190905.0 sec
  Load Avg:  1.35205078125  1.2802734375  1.34423828125
  LIBM: libopenlibm
  LLVM: libLLVM-9.0.1 (ORCJIT, skylake)
  MATHEMATICA_HOME = /usr/local/Wolfram/Mathematica/12.1
  HOME = /home/mzeng
  PYTHONPATH = /home/mzeng/code/pySecDec-1.4.3/pySecDec-1.4.3:
  TERM = xterm-256color
  PATH = /home/mzeng/.cargo/bin:/home/mzeng/.local/bin:/home/mzeng/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:/snap/bin

julia> Pkg.status()
Status `~/.julia/environments/v1.5/Project.toml`
  [c3fe647b] AbstractAlgebra v0.12.0
  [861a8166] Combinatorics v1.0.2
  [864edb3b] DataStructures v0.18.9
  [c27321d9] Glob v1.3.0
  [7073ff75] IJulia v1.23.1
  [50d2b5c4] Lazy v0.15.1
  [18c93696] MathLink v0.3.1
  [3b2b4ff1] Multisets v0.3.3
  [2edaba10] Nemo v0.19.1
  [c46f51b8] ProfileView v0.6.9
  [123dc426] SymEngine v0.8.3
  [ac1d9e8a] ThreadsX v0.1.7

Mao Zeng

Feb 2, 2021, 7:44:36 AM2/2/21
to nemo-devel
By the way, are you able to reproduce the problem as I initially reported? Or do you think it's related to the specific OS or Julia version I'm using?

Feb 2, 2021, 7:56:55 AM2/2/21
to nemo-devel
OK, I remember what is going on. This is It is a problem with precompilation. Here is the solution:

function __init__()
  global Ring, (x,y) = PolynomialRing(ZZ, ["x", "y"])

Mao Zeng

Feb 2, 2021, 9:02:10 AM2/2/21
to nemo-devel
Thanks, that solved the problem! Using "__init__" is even necessary when I access x and y from within the module, like this

# new version of test1.jl
module test1
export print1
using Nemo
function __init__()
   global Ring, (x,y) = PolynomialRing(ZZ, ["x", "y"])
print1() = println(x+y)

After loading the above module, running print1() would trigger a segmentation fault if I didn't use the "__init()__". I'm still mystified by what Julia is doing internally for precompilation, but at least the problem was solved.

Feb 2, 2021, 9:12:10 AM2/2/21
to nemo-devel
You can have a look here if you are interested in the details:
Reply all
Reply to author
0 new messages