Opened 3 years ago

Closed 3 years ago

#26002 closed enhancement (fixed)

Support pari compiled with threads

Reported by: gh-timokau Owned by:
Priority: major Milestone: sage-8.4
Component: packages: standard Keywords:
Cc: Merged in:
Authors: Timo Kaufmann Reviewers: Jeroen Demeyer
Report Upstream: N/A Work issues:
Branch: ac752b8 (Commits, GitHub, GitLab) Commit: ac752b8ca446e0334940daea0c076b63e7894627
Dependencies: Stopgaps:

Status badges

Description

We currently compile pari without threads. Pari supports the -mt=pthread or -mt=mpi compile time options to enable thread support.

I tried to just use pari with threads in sage. That leads to 3 doctest failures:

sage -t --long /nix/store/jarfy06jh6csn9j376jdnj135sm4bl7z-sage-src-8.3/src/doc/de/tutorial/interactive_shell.rst
...skipping...
Failed example:
    pari('x^2 + 10^100 + 1').nfinit()
Exception raised:
    Traceback (most recent call last):
      File "/nix/store/yw04sqwli9z3j51risarnz7g5qgn56nx-python-2.7.15-env/lib/python2.7/site-packages/sage/doctest/forker.py", line 573, in _run
        self.compile_and_execute(example, compiler, test.globs)
      File "/nix/store/yw04sqwli9z3j51risarnz7g5qgn56nx-python-2.7.15-env/lib/python2.7/site-packages/sage/doctest/forker.py", line 983, in compile_and_execute
        exec(compiled, globs)
      File "<doctest sage.libs.pari.tests[807]>", line 1, in <module>
        pari('x^2 + 10^100 + 1').nfinit()
      File "cypari2/auto_gen.pxi", line 20193, in cypari2.gen.Gen_auto.nfinit
      File "cypari2/handle_error.pyx", line 196, in cypari2.handle_error._pari_err_handle
    PariError: the thread stack overflows !
      current stack size: 200000 (0.191 Mbytes)
      [hint] set 'threadsizemax' to a non-zero value in your GPRC
sage -t --long /nix/store/jarfy06jh6csn9j376jdnj135sm4bl7z-sage-src-8.3/src/sage/libs/singular/function_factory.py
    [8 tests, 0.23 s]
...skipping...
Failed example:
    for i in range(20):  # long time
        try:
            alarm(RDF.random_element(1e-3, 0.5))
            _ = n.divisors()
            cancel_alarm()  # we never get here
        except AlarmInterrupt:
            pass
Exception raised:
    Traceback (most recent call last):
      File "/nix/store/yw04sqwli9z3j51risarnz7g5qgn56nx-python-2.7.15-env/lib/python2.7/site-packages/sage/doctest/forker.py", line 573, in _run
        self.compile_and_execute(example, compiler, test.globs)
      File "/nix/store/yw04sqwli9z3j51risarnz7g5qgn56nx-python-2.7.15-env/lib/python2.7/site-packages/sage/doctest/forker.py", line 983, in compile_and_execute
        exec(compiled, globs)
      File "<doctest sage.rings.integer.Integer.divisors[19]>", line 4, in <module>
        _ = n.divisors()
      File "sage/rings/integer.pyx", line 3049, in sage.rings.integer.Integer.divisors (build/cythonized/sage/rings/integer.c:20221)
        ptr = <unsigned long*>check_allocarray(divisor_count, 3 * sizeof(unsigned long))
      File "memory.pxd", line 87, in cysignals.memory.check_allocarray (build/cythonized/sage/rings/integer.c:47940)
    MemoryError: failed to allocate 33554432 * 24 bytes
**********************************************************************
File "/nix/store/jarfy06jh6csn9j376jdnj135sm4bl7z-sage-src-8.3/src/sage/rings/integer.pyx", line 3657, in sage.rings.integer.Integer.trial_division
Failed example:
    n = 3 * next_prime(10^40); n.trial_division()
Exception raised:
    Traceback (most recent call last):
      File "/nix/store/yw04sqwli9z3j51risarnz7g5qgn56nx-python-2.7.15-env/lib/python2.7/site-packages/sage/doctest/forker.py", line 573, in _run
        self.compile_and_execute(example, compiler, test.globs)
      File "/nix/store/yw04sqwli9z3j51risarnz7g5qgn56nx-python-2.7.15-env/lib/python2.7/site-packages/sage/doctest/forker.py", line 983, in compile_and_execute
        exec(compiled, globs)
      File "<doctest sage.rings.integer.Integer.trial_division[11]>", line 1, in <module>
        n = Integer(3) * next_prime(Integer(10)**Integer(40)); n.trial_division()
      File "/nix/store/yw04sqwli9z3j51risarnz7g5qgn56nx-python-2.7.15-env/lib/python2.7/site-packages/sage/arith/misc.py", line 1080, in next_prime
        return ZZ(n).next_prime(proof)
      File "sage/rings/integer.pyx", line 5580, in sage.rings.integer.Integer.next_prime (build/cythonized/sage/rings/integer.c:35662)
        while not p._pseudoprime_is_prime(proof):
      File "sage/rings/integer.pyx", line 5115, in sage.rings.integer.Integer._pseudoprime_is_prime (build/cythonized/sage/rings/integer.c:33097)
        return self.__pari__().isprime()
      File "cypari2/gen.pyx", line 2099, in cypari2.gen.Gen.isprime
      File "src/cysignals/signals.pyx", line 100, in cysignals.signals.sig_raise_exception
    AlarmInterrupt

They are apparently memory related and could probably be resolved by setting threadsizemax as documented here to a reasonable value. But I don't know what that reasonable value is.

So instead I set the nbthreads option (also documented here) to 1. That option has *no effect* when pari is compiled without threads. Otherwise it limits the amount of threads to 1. That means that *current behaviour remains unchanged* but with the added benefit that distributions can use a pari version with threads enabled.

Change History (3)

comment:1 Changed 3 years ago by gh-timokau

  • Branch changed from u/gh-timokau/pari-thread to u/gh-timokau/pari-threads
  • Commit set to ac752b8ca446e0334940daea0c076b63e7894627
  • Status changed from new to needs_review

New commits:

ac752b8Support pari compiled with threads

comment:2 Changed 3 years ago by jdemeyer

  • Reviewers set to Jeroen Demeyer
  • Status changed from needs_review to positive_review

comment:3 Changed 3 years ago by vbraun

  • Branch changed from u/gh-timokau/pari-threads to ac752b8ca446e0334940daea0c076b63e7894627
  • Resolution set to fixed
  • Status changed from positive_review to closed
Note: See TracTickets for help on using tickets.