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

RFC:Removal of gmp_wrapper.c #2222

Merged
merged 1 commit into from
Feb 8, 2013
Merged

RFC:Removal of gmp_wrapper.c #2222

merged 1 commit into from
Feb 8, 2013

Conversation

andreasnoack
Copy link
Member

Inspired by librandom.jl I have tried to rewrite the gmp interface to avoid gmp_wrapper.c. I can't make it not work on OS X, Ubuntu 32 and 64 bit, but maybe I have missed some memory issues somewhere. I have introduced a limit to the size of the string that can be returned, but it should be easy to change.

See also: #1887 and #2190

@Keno
Copy link
Member

Keno commented Feb 7, 2013

LGTM

@aviks
Copy link
Member

aviks commented Feb 7, 2013

This causes a segfault in examples/bigfib.jl at the point of converting a large bigint to a string for display.

@ViralBShah
Copy link
Member

Is there a way to figure out the string length adaptively - doubling the allocation every time it fails until it is successful?

@aviks
Copy link
Member

aviks commented Feb 7, 2013

For larger numbers, it takes order of 10 secs to convert to strings. Doing it adaptively is going to hugely increase the time.

There are gmp functions to write out the string to a file handle. That may be an option.

http://gmplib.org/manual/I_002fO-of-Integers.html#I_002fO-of-Integers

@andreasnoack
Copy link
Member Author

@aviks Thank you for the example. It is a very big number. I think that sizeinbase can do the trick. I'll try to see if I can make it work.

@StefanKarpinski
Copy link
Member

Maybe we should move the bigfib example into the tests?

@andreasnoack
Copy link
Member Author

It works. I can add the bigfib to the tests as part of this request.

@aviks
Copy link
Member

aviks commented Feb 7, 2013

The example takes around 20 seconds, which might get annoying if you are trying to run the tests often (as you should :) )

@StefanKarpinski
Copy link
Member

That's a fair point. Perhaps we need a somewhat smaller version of the test?

@andreasnoack
Copy link
Member Author

I think it works now. The Fibonacci example runs and is included as test in a smaller version. The conversions to strings now use functions that are not warned against in the documentation. In order to get the the float conversion to work, I have changed to scientific notation and changed the tests accordingly. Is that okay?

@aviks
Copy link
Member

aviks commented Feb 7, 2013

Looks good to me.

@andreasnoack
Copy link
Member Author

@JeffBezanson Thank you for the comments. I have updated the code.

@ViralBShah
Copy link
Member

@andreasnoackjensen If you are ready with this one, please feel free to merge.

andreasnoack added a commit that referenced this pull request Feb 8, 2013
@andreasnoack andreasnoack merged commit a42f263 into JuliaLang:master Feb 8, 2013
@ViralBShah
Copy link
Member

While the test works for me if I run it with make test-bigint, it crashes in make testall on the mac.

@ViralBShah
Copy link
Member

Ok - this was perhaps some transient stuff, since a couple of updates and rebuilding of sys.ji, it works fine for me.

@andreasnoack
Copy link
Member Author

I cannot provoke it locally but Travis seem to segfault irregularly on the bigint test. Do you think it is a Travis thing or a BigInt thing?

@JeffBezanson
Copy link
Member

Valgrind says:

==31938== Invalid read of size 8
==31938==    at 0x2BFCCC4F: __gmpn_copyi (in /home/jeff/src/julia2/julia/usr/lib/libgmp.so.10.1.0)
==31938==    by 0x2BFC51D3: __gmpn_preinv_mu_div_qr (in /home/jeff/src/julia2/julia/usr/lib/libgmp.so.10.1.0)
==31938==    by 0x2BFC53BC: mpn_mu_div_qr2 (in /home/jeff/src/julia2/julia/usr/lib/libgmp.so.10.1.0)
==31938==    by 0x2BFABD32: __gmpn_tdiv_qr (in /home/jeff/src/julia2/julia/usr/lib/libgmp.so.10.1.0)
==31938==    by 0x2BFA63DF: mpn_dc_get_str (in /home/jeff/src/julia2/julia/usr/lib/libgmp.so.10.1.0)
==31938==    by 0x2BFA6419: mpn_dc_get_str (in /home/jeff/src/julia2/julia/usr/lib/libgmp.so.10.1.0)
==31938==    by 0x2BFA6419: mpn_dc_get_str (in /home/jeff/src/julia2/julia/usr/lib/libgmp.so.10.1.0)
==31938==    by 0x2BFA6951: __gmpn_get_str (in /home/jeff/src/julia2/julia/usr/lib/libgmp.so.10.1.0)
==31938==    by 0x2BF8F252: __gmpz_get_str (in /home/jeff/src/julia2/julia/usr/lib/libgmp.so.10.1.0)
==31938==    by 0x2BFCEE03: __gmp_doprnt (in /home/jeff/src/julia2/julia/usr/lib/libgmp.so.10.1.0)
==31938==    by 0x2BFD0297: __gmp_snprintf (in /home/jeff/src/julia2/julia/usr/lib/libgmp.so.10.1.0)
==31938==    by 0x1B5494B7: ???
==31938==  Address 0x14227f98 is 0 bytes after a block of size 92,184 alloc'd
==31938==    at 0x4C2A93D: malloc (in /usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so)
==31938==    by 0x2BF813A8: __gmp_default_allocate (in /home/jeff/src/julia2/julia/usr/lib/libgmp.so.10.1.0)
==31938==    by 0x2BF81C70: __gmp_tmp_reentrant_alloc (in /home/jeff/src/julia2/julia/usr/lib/libgmp.so.10.1.0)
==31938==    by 0x2BFAC42C: __gmpn_tdiv_qr (in /home/jeff/src/julia2/julia/usr/lib/libgmp.so.10.1.0)
==31938==    by 0x2BFA63DF: mpn_dc_get_str (in /home/jeff/src/julia2/julia/usr/lib/libgmp.so.10.1.0)
==31938==    by 0x2BFA6419: mpn_dc_get_str (in /home/jeff/src/julia2/julia/usr/lib/libgmp.so.10.1.0)
==31938==    by 0x2BFA6419: mpn_dc_get_str (in /home/jeff/src/julia2/julia/usr/lib/libgmp.so.10.1.0)
==31938==    by 0x2BFA6951: __gmpn_get_str (in /home/jeff/src/julia2/julia/usr/lib/libgmp.so.10.1.0)
==31938==    by 0x2BF8F252: __gmpz_get_str (in /home/jeff/src/julia2/julia/usr/lib/libgmp.so.10.1.0)
==31938==    by 0x2BFCEE03: __gmp_doprnt (in /home/jeff/src/julia2/julia/usr/lib/libgmp.so.10.1.0)
==31938==    by 0x2BFD0297: __gmp_snprintf (in /home/jeff/src/julia2/julia/usr/lib/libgmp.so.10.1.0)
==31938==    by 0x1B5494B7: ???
==31938== 

This only happens for a sufficiently large bigfib; if you remove a zero it is clean.

@ViralBShah
Copy link
Member

We should perhaps plan revert this one today, given that we have a pretty tight window, and we need the build to be in good condition.

@andreasnoackjensen Do you want to see if you can chase this one down or revert it today? This could live on a branch until it is figured out.

@andreasnoack
Copy link
Member Author

I'll look into it and see if can get that string conversion right (or revert).

@JeffBezanson
Copy link
Member

The build is consistently passing.

@nolta
Copy link
Member

nolta commented Feb 10, 2013

Does b92272a fix the problem?

@JeffBezanson
Copy link
Member

I get the same valgrind output. It only happens the first time I do string(bigfib(10000000)) though.

@andreasnoack
Copy link
Member Author

The segfault disappears if the string is assigned before return (I have added the zero again). Please have a look at af3e11d. Any ideas? I cannot get the segfault locally and hence not use valgrind.

@ViralBShah
Copy link
Member

If this fixes the issue, it would be worth to pull this in before tagging 0.1. @JeffBezanson should probably try it out with valgrind again.

Also a heads up to @StefanKarpinski

@StefanKarpinski
Copy link
Member

Huh?

@ViralBShah
Copy link
Member

Since you are going to tag, this issue needs to be resolved - either the suggestion fixes things and is merged, or we need to bring back gmp_wrapper.c again. Doing neither of these and leaving things as they are is probably not a good thing.

@JeffBezanson
Copy link
Member

I actually don't know whether the valgrind error is relevant; I've never seen the segfault on my system.

@ViralBShah
Copy link
Member

I have never seen the segfault too - but it could happen on debian's build systems if it happened on travis. Hopefully, we should find out quickly if that happens, and do something about it.

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

Successfully merging this pull request may close these issues.

7 participants