-
Notifications
You must be signed in to change notification settings - Fork 84
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
gmpy2 Sieve Example Code Problem #492
Comments
Could you provide your code? Which gmpy2 version you are using? Please note, that |
I am running gmpy2==2.2.0 using the code below. When I run it, I get no error and no output! `import time def sieve(limit=5000000000):
if name == "main": |
This is not, apparently, the code you are trying to run in the issue description. This is just an example from docs with an insane Could you, please, show us code which you run before and where you got different error messages? |
The fundamental issue is that we are over-flowing the limits of a The GMP library just does a core dump when it detects an overflow. gmpy2 v2.1.5 links to a C runtime library that outputs the error message
|
I have found some other strange behaviors. I will continue to investigate. |
Thanks for investigating. I've gotten various error messages on different machines and on Windows or WSL. |
It does.
Which is a bit strange, that OP claims he have seen "gmp: overflow in mpz type" (same type error for earlier versions, see #280) and that gmpy2 version is 2.2. |
I should be more specific. This is a native Windows issue. The GMP library used in v2.2.0 for x64 native Windows applications is linked against UCRT. It does not display the error message. The GMP library used in v2.1.5 for x64 native Windows applications is linked against MSVCRT. It does display the error message. The GMP library used on Linux displays the expected error message. I haven't researched why, but I'm guessing that the GMP error message is sent to stderr and UCRT handles it differently. In either case, GMP is aborting. We get an error message in most environments but not all. It is a red herring for the real issue - how can we make an x64 native application have the same limits as (for example) an x64 Linux application. |
Nothing at all, i.e. no something like "Aborted" above (this is coming from libc)? Just in case, are you running Python interpreter from CLI or from some IDE like VS? If later, stderr might be redirected somehow. |
For whatever it's worth, I run large primes using the 'bitstring' module. The Sieve code example can be found at [https://github.com/scott-griffiths/bitstring/blob/main/doc/walkthrough.ipynb]. I modified the code, as shown below, to run on my SurfacePro6 with 8GB RAM. I set the limit is 10,000,000,000. It ran in about 120 seconds. `#### Landry Note: source is - https://github.com/scott-griffiths/bitstring/blob/main/doc/walkthrough.ipynb Added 'import bitstring' and 'import math'Added code for timingfrom bitstring import BitArray Code_Start_Time = time.time() Scott Griffiths code belowHis code example has 'limit = 100_000_000'I have increasted it to: 10_000_000_000Create a BitArray with a hundred million 'one' bitslimit = 10_000_000_000 Manually set 0 and 1 to be not prime.is_prime.set(False, [0, 1]) For every other integer, if it's set as prime then unset all of its multiplesfor i in range(2, math.ceil(math.sqrt(limit))): My timing codeTotal_Execution_Time = time.time() - Code_Start_Time end my timing codeprint(f"There are {is_prime.count(True)} primes less than {limit},") |
When I run the Sieve of Eratosthenes example code (Python 3.11.5, Win 11 Pro, VS Code editor, RAM-32GB), it fails at around 4.5*10^9. The error message is: "gmp: overflow in mpz type". I've also run the code with WSL on a machine with nearly 200GB RAM. Previously, I've had gotten more extensive messages previously.
![image](https://private-user-images.githubusercontent.com/15175396/348488318-c087eb0e-a767-48cd-be91-5d7e99ecffaf.png?jwt=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJnaXRodWIuY29tIiwiYXVkIjoicmF3LmdpdGh1YnVzZXJjb250ZW50LmNvbSIsImtleSI6ImtleTUiLCJleHAiOjE3MjIyNzA4NjEsIm5iZiI6MTcyMjI3MDU2MSwicGF0aCI6Ii8xNTE3NTM5Ni8zNDg0ODgzMTgtYzA4N2ViMGUtYTc2Ny00OGNkLWJlOTEtNWQ3ZTk5ZWNmZmFmLnBuZz9YLUFtei1BbGdvcml0aG09QVdTNC1ITUFDLVNIQTI1NiZYLUFtei1DcmVkZW50aWFsPUFLSUFWQ09EWUxTQTUzUFFLNFpBJTJGMjAyNDA3MjklMkZ1cy1lYXN0LTElMkZzMyUyRmF3czRfcmVxdWVzdCZYLUFtei1EYXRlPTIwMjQwNzI5VDE2MjkyMVomWC1BbXotRXhwaXJlcz0zMDAmWC1BbXotU2lnbmF0dXJlPThkNDcyNGY4OWU1Yjk4YTk3YzI1NzQ3N2I1ZWUwZWNjMDE0NGNiMjNjYjAzOTUzNzZkNDRiYjRmMTcwNGVjNTAmWC1BbXotU2lnbmVkSGVhZGVycz1ob3N0JmFjdG9yX2lkPTAma2V5X2lkPTAmcmVwb19pZD0wIn0.4KlApEsfuEVi3wLTa8syAIbfFZ4PYArnrDSmORUcLIQ)
The text was updated successfully, but these errors were encountered: