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

"cysignals.signals.SignalError: Segmentation fault" when using multiprocessing #36370

Open
2 tasks done
maxale opened this issue Sep 30, 2023 · 3 comments
Open
2 tasks done
Labels

Comments

@maxale
Copy link
Contributor

maxale commented Sep 30, 2023

Steps To Reproduce

The following code results in cysignals.signals.SignalError: Segmentation fault:

import multiprocessing
with multiprocessing.Pool() as pool:
    for t in pool.imap_unordered( print, (d for d in range(1,100) if is_squarefree(d)) ):
        pass

Expected Behavior

Segmentation fault should not happen.

Actual Behavior

The complete error message:

Traceback (most recent call last):
  File "/usr/lib/python3.10/threading.py", line 1016, in _bootstrap_inner
    self.run()
  File "/usr/lib/python3.10/threading.py", line 953, in run
    self._target(*self._args, **self._kwargs)
  File "/usr/lib/python3.10/multiprocessing/pool.py", line 535, in _handle_tasks
    for task in taskseq:
  File "/usr/lib/python3.10/multiprocessing/pool.py", line 391, in _guarded_task_generation
    for i, x in enumerate(iterable):
  File "/tmp/ipykernel_2667401/2212641732.py", line 4, in <genexpr>
  File "/home/sc_serv/sage/src/sage/arith/misc.py", line 2993, in is_squarefree
    return e.is_squarefree()
  File "sage/rings/integer.pyx", line 6090, in sage.rings.integer.Integer.is_squarefree
  File "sage/rings/integer.pyx", line 6182, in sage.rings.integer.Integer.__pari__
  File "sage/libs/pari/convert_sage.pyx", line 377, in sage.libs.pari.convert_sage.new_gen_from_integer
  File "sage/libs/pari/convert_sage.pyx", line 386, in sage.libs.pari.convert_sage.new_gen_from_integer
  File "sage/libs/pari/convert_gmp.pyx", line 52, in sage.libs.pari.convert_gmp.new_gen_from_mpz_t
cysignals.signals.SignalError: Segmentation fault

Additional Information

Somehow the issue is related to the use of is_squarefree(). Replacing it with, say, is_prime() makes the code works fine.

Environment

- **OS**: Ubuntu 22.04.3 LTS
- **Sage Version**: 10.2.beta1

Checklist

  • I have searched the existing issues for a bug report that matches the one I want to file, without success.
  • I have read the documentation and troubleshoot guide
@maxale maxale added the t: bug label Sep 30, 2023
@maxale
Copy link
Contributor Author

maxale commented Oct 1, 2023

The issue seems to be more widespread and not tied to is_squarefree(). I also see the following segmentation fault in different set-up when is_squarefree() is not used:

Exception in thread Thread-3 (_handle_results):
Traceback (most recent call last):
  File "/usr/lib/python3.10/threading.py", line 1016, in _bootstrap_inner
    self.run()
  File "/usr/lib/python3.10/threading.py", line 953, in run
    self._target(*self._args, **self._kwargs)
  File "/usr/lib/python3.10/multiprocessing/pool.py", line 579, in _handle_results
    task = get()
  File "/usr/lib/python3.10/multiprocessing/connection.py", line 251, in recv
    return _ForkingPickler.loads(buf.getbuffer())
  File "cypari2/gen.pyx", line 4706, in cypari2.gen.objtogen
  File "cypari2/gen.pyx", line 4813, in cypari2.gen.objtogen
  File "cypari2/convert.pyx", line 556, in cypari2.convert.PyObject_AsGEN
cysignals.signals.SignalError: Segmentation fault

@maxale maxale changed the title cysignals.signals.SignalError: Segmentation fault when using is_squarefree() with multiprocessing "cysignals.signals.SignalError: Segmentation fault" when using multiprocessing Oct 1, 2023
@yyyyx4
Copy link
Member

yyyyx4 commented Feb 16, 2024

This seems to be related to PARI conversions: For example,

import multiprocessing
with multiprocessing.Pool() as pool:
    for t in pool.imap_unordered( print, (d for d in ZZ.range(1,100) if is_prime(d)) ):
        pass

works, but

import multiprocessing
with multiprocessing.Pool() as pool:
    for t in pool.imap_unordered( print, (d for d in ZZ.range(2^99+1,2^99+100) if is_prime(d)) ):
        pass

fails. The difference is that a fast path is used for small integers whereas PARI is invoked for larger sizes.

Smaller failing example:

sage: import multiprocessing
sage: list(multiprocessing.Pool().map(print, [pari(42)]))

@yyyyx4
Copy link
Member

yyyyx4 commented Feb 16, 2024

Is this a duplicate of #28800?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants