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

Segmentation fault using mpz on OSX #350

Closed
agtoever opened this issue Nov 27, 2022 · 6 comments
Closed

Segmentation fault using mpz on OSX #350

agtoever opened this issue Nov 27, 2022 · 6 comments

Comments

@agtoever
Copy link

I get a segmentation fault on OSX using my MacBook Pro M1, using a Python program for calculating a factorial and a modulo.

Used versions of Python, gmpy2 and OSX:

❯ python3 --version
Python 3.10.8
❯ pip3 freeze | grep gmpy
gmpy2==2.1.2
❯ sw_vers
ProductName:		macOS
ProductVersion:		13.0.1
BuildVersion:		22A400

Python program:

from gmpy2 import mpz


def factorial(n: int) -> mpz:
    result = mpz(1)

    for f in range(2, n + 1):
        result *= f

    return result


for n in range(2, 1001):
    m = factorial(n) % (n - 1)
    print(f'{n=}, {m=}')

This program gives every time a Segmentation Fault ([1] 33487 segmentation fault python3 ./gmpy2_factorial.py), but at different progress of the program (e.g.: each time after a different number of iterations).

I tried the same program on another platform (tio.run, Debian on amd64) without problems. So it seems to be specific for OSX and/or the M1 hardware. A bit more details for my platform:

❯ system_profiler SPSoftwareDataType SPHardwareDataType
Software:

    System Software Overview:

      System Version: macOS 13.0.1 (22A400)
      Kernel Version: Darwin 22.1.0
      Boot Volume: Macintosh HD
      Boot Mode: Normal
      Computer Name: Greyhound
      User Name: Albert ten Oever (agtoever)
      Secure Virtual Memory: Enabled
      System Integrity Protection: Enabled
      Time since boot: 11 days, 5 minutes

Hardware:

    Hardware Overview:

      Model Name: MacBook Pro
      Model Identifier: MacBookPro18,3
      Model Number: Z15G0013ZN/A
      Chip: Apple M1 Pro
      Total Number of Cores: 10 (8 performance and 2 efficiency)
      Memory: 16 GB
      System Firmware Version: 8419.41.10
      OS Loader Version: 8419.41.10
      Serial Number (system): K0DY13QKXH
      Hardware UUID: 20F61ECF-EE57-58EF-A8F0-7D40073BEC70
      Provisioning UDID: 00006000-001405C11162801E
      Activation Lock Status: Enabled
@casevh
Copy link
Collaborator

casevh commented Dec 7, 2022

I've released gmpy2 2.1.3 and it is a more recent build. Can you try testing it?

@agtoever
Copy link
Author

agtoever commented Dec 7, 2022

I get an import error. Also tried to force a re-install and confirmed that it's 2.1.3.:

❯ pip3 install --upgrade --force-reinstall gmpy2
Collecting gmpy2
  Using cached gmpy2-2.1.3-cp310-cp310-macosx_11_0_arm64.whl (407 kB)
Installing collected packages: gmpy2
  Attempting uninstall: gmpy2
    Found existing installation: gmpy2 2.1.3
    Uninstalling gmpy2-2.1.3:
      Successfully uninstalled gmpy2-2.1.3
Successfully installed gmpy2-2.1.3

❯ python3 ./gmpy2_factorial.py
Traceback (most recent call last):
  File "/Users/agtoever/Dropbox/Dev/Python Sandbox/./gmpy2_factorial.py", line 2, in <module>
    from gmpy2 import mpz
  File "/opt/homebrew/lib/python3.10/site-packages/gmpy2/__init__.py", line 1, in <module>
    from .gmpy2 import *
ImportError: dlopen(/opt/homebrew/lib/python3.10/site-packages/gmpy2/gmpy2.cpython-310-darwin.so, 0x0002): symbol not found in flat namespace '_mpc_abs'

@casevh
Copy link
Collaborator

casevh commented Dec 12, 2022

There was an error in the build process. I've upload 2.1.4. Can you try it?

@agtoever
Copy link
Author

I just updated to 2.1.4 and the issue is still there. Sorry.

Please let me know if there is anything I can do to provide you with more information to pinpoint / solve this.

@casevh
Copy link
Collaborator

casevh commented Dec 18, 2022

I've made another update to the build process. I don't have a machine I can use to test the binary wheels.

Can you test the build?

A zip file containing all four versions is at https://github.com/aleaxit/gmpy/suites/9929671653/artifacts/480553600

After extracting the appropriate file, you should be able to install it manually using

pip3 install --upgrade --force-reinstall gmpy2-2.1.4-cp310-cp310-macosx_11_0_arm64.whl

@agtoever
Copy link
Author

Kudos! You nailed it! Ran it several times, even with higher limits. No segmentation faults anymore. Well done! Case closed! 🎉

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

No branches or pull requests

2 participants