Hi Bradley,<div><br></div><div>Interesting. Nice numbers!<br><br>Was your Gambit pi-calculator compiled with (declare (not safe)) and any other related setting for optimizing speed, like increasing inlining, setting mostly generic and inlining standard and extended bindings, and executed with a minimum heap size of at least ~6MB?<div>

<br><div><br></div><div>Just to address a thought, and not because it would be needed for what I personally do or anything like that, on the possibility of GMP support for Gambit: it could potentially be added as a plugin/path, however:</div>

<div><br></div><div>As I got it, GMP does not support using a custom memory allocator, and also its structures have internal pointers between each others, so GMP user code cannot move around GMP-allocated memory blocks.</div>

<div><br></div><div>Presuming that this understanding is correct, it's like a compromised thing because using it in Gambit would imply a memory fragmentation-inducing mechanism at a basal language layer, which would at least theoretically be complete crap, and I'd guess these two points constitute such a big problem that the GMP guys should address it really.</div>

<div><br></div><div>Apart from being a large, separate code library project which implies some limitation of usability in some sense, GMP's license is LGPL so it comes with some quirks that at least hypothethically could be major for some uses.</div>

<div><br></div><div>I guess if the two tech issues with GMP were resolved, it could be interesting for someone to implement a GMP support patch for Gambit.</div><div><br></div><div><br></div><div>What's the scope of use of GMP in Python and in a hypothetical Gambit GMP support patch, only integer bignums?</div>

<div><br></div><div><br></div><div><div>If you have any thought on this feel free to share.</div></div><div><br></div><div><br></div><div>In all cases it's awesome that Gambit bundles its own bignum logics as by that Gambit is without any dependency requirement and thus makes Gambit completely portable and self-sustaining.</div>

<div><br></div><div>Best regards,</div><div>Mikael</div><div><br><div class="gmail_quote">2013/6/7 Bradley Lucier <span dir="ltr"><<a href="mailto:lucier@math.purdue.edu" target="_blank">lucier@math.purdue.edu</a>></span><br>

<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">Bakul Shah wrote a particularly elegant Scheme program for Chudnovskys' algorithm for pi based on the Common Lisp program here:<br>


<br>
<a href="https://bitbucket.org/tarballs_are_good/numericl/src/5fe8fe7089f48ab1c8a388632f815fc35b4dec7e/src/experimental/pi-chudnovsky.lisp?at=default" target="_blank">https://bitbucket.org/<u></u>tarballs_are_good/numericl/<u></u>src/<u></u>5fe8fe7089f48ab1c8a388632f815f<u></u>c35b4dec7e/src/experimental/<u></u>pi-chudnovsky.lisp?at=default</a><br>


<br>
Nick Craig-Wood wrote a Python program using the GMP multiprecision library that appears to use exactly the same algorithm here:<br>
<br>
<a href="http://www.craig-wood.com/nick/articles/pi-chudnovsky/" target="_blank">http://www.craig-wood.com/<u></u>nick/articles/pi-chudnovsky/</a><br>
<br>
I modified both programs a bit and include them here.<br>
<br>
They time the calculation of $10^n$ digits of pi for $n=1,2,3,4,5,6,7$.  The results are<br>
<br>
heine:~/programs/gambiteer/<u></u>gambit> !py<br>
python pi_chudnovsky_bs_gmpy.py<br>
314159265358979323846264338327<u></u>950288419716939937510582097494<u></u>459230781640628620899862803482<u></u>53421170679<br>
('chudnovsky_gmpy_mpz_bs: digits', 10, 'time', 1.0967254638671875e-05)<br>
('chudnovsky_gmpy_mpz_bs: digits', 100, 'time', 3.0040740966796875e-05)<br>
Last 5 digits 70679 OK<br>
('chudnovsky_gmpy_mpz_bs: digits', 1000, 'time', 0.00025582313537597656)<br>
Last 5 digits 01989 OK<br>
('chudnovsky_gmpy_mpz_bs: digits', 10000, 'time', 0.00386810302734375)<br>
Last 5 digits 75678 OK<br>
('chudnovsky_gmpy_mpz_bs: digits', 100000, 'time', 0.0834801197052002)<br>
Last 5 digits 24646 OK<br>
('chudnovsky_gmpy_mpz_bs: digits', 1000000, 'time', 1.655979871749878)<br>
Last 5 digits 58151 OK<br>
('chudnovsky_gmpy_mpz_bs: digits', 10000000, 'time', 30.67442488670349)<br>
Last 5 digits 55897 OK<br>
heine:~/programs/gambiteer/<u></u>gambit> gsi chud1.scm<br>
Chudnovsky's algorithm using binary splitting in Gambit Scheme: digits 10, CPU time: 0..<br>
Last 5 digits 26535.<br>
Chudnovsky's algorithm using binary splitting in Gambit Scheme: digits 100, CPU time: 0..<br>
Last 5 digits 70679.<br>
Chudnovsky's algorithm using binary splitting in Gambit Scheme: digits 1000, CPU time: .004.<br>
Last 5 digits 1989.<br>
Chudnovsky's algorithm using binary splitting in Gambit Scheme: digits 10000, CPU time: .028.<br>
Last 5 digits 75678.<br>
Chudnovsky's algorithm using binary splitting in Gambit Scheme: digits 100000, CPU time: .472.<br>
Last 5 digits 24646.<br>
Chudnovsky's algorithm using binary splitting in Gambit Scheme: digits 1000000, CPU time: 6.448.<br>
Last 5 digits 58151.<br>
Chudnovsky's algorithm using binary splitting in Gambit Scheme: digits 10000000, CPU time: 98.612.<br>
Last 5 digits 55897.<br>
<br>
So it appears that for this algorithm applied to large integers, GMP's bignum routines are about 3-4 times as fast as Gambit's bignum routines.  Not so bad.  For smaller bignums, GMP has a bigger advantage.<br>
<br>
The C program gmp-chudnovsky.c includes certain optimizations to this basic algorithm:<br>
<br>
<a href="http://gmplib.org/pi-with-gmp.html" target="_blank">http://gmplib.org/pi-with-gmp.<u></u>html</a><br>
<a href="ftp://ftp.gmplib.org/pub/misc/gmp-chudnovsky.c" target="_blank">ftp://ftp.gmplib.org/pub/misc/<u></u>gmp-chudnovsky.c</a><br>
<br>
On my machine, compiled with<br>
<br>
gcc -O3 -march=native -o gmp-chudnovsky gmp-chudnovsky.c -lgmp -lm<br>
<br>
the CPU times for 1,000,000 and 10,000,000 digits are 1.064 and 18.200 seconds, respectively.<br>
<br>
This is with a somewhat older machine<br>
<br>
model name    : Intel(R) Core(TM)2 Quad  CPU   Q8200  @ 2.33GHz<br>
<br>
running Ubuntu 13.04 with<br>
<br>
heine:~/programs/gambiteer/<u></u>gambit> gcc -v<br>
Using built-in specs.<br>
COLLECT_GCC=gcc<br>
COLLECT_LTO_WRAPPER=/usr/lib/<u></u>gcc/x86_64-linux-gnu/4.7/lto-<u></u>wrapper<br>
Target: x86_64-linux-gnu<br>
Configured with: ../src/configure -v --with-pkgversion='Ubuntu/<u></u>Linaro 4.7.3-1ubuntu1' --with-bugurl=file:///usr/<u></u>share/doc/gcc-4.7/README.Bugs --enable-languages=c,c++,go,<u></u>fortran,objc,obj-c++ --prefix=/usr --program-suffix=-4.7 --enable-shared --enable-linker-build-id --libexecdir=/usr/lib --without-included-gettext --enable-threads=posix --with-gxx-include-dir=/usr/<u></u>include/c++/4.7 --libdir=/usr/lib --enable-nls --with-sysroot=/ --enable-clocale=gnu --enable-libstdcxx-debug --enable-libstdcxx-time=yes --enable-gnu-unique-object --enable-plugin --with-system-zlib --enable-objc-gc --with-cloog --enable-cloog-backend=ppl --disable-cloog-version-check --disable-ppl-version-check --enable-multiarch --disable-werror --with-arch-32=i686 --with-abi=m64 --with-multilib-list=m32,m64,<u></u>mx32 --with-tune=generic --enable-checking=release --build=x86_64-linux-gnu --host=x86_64-linux-gnu --target=x86_64-linux-gnu<br>


Thread model: posix<br>
gcc version 4.7.3 (Ubuntu/Linaro 4.7.3-1ubuntu1)<br>
heine:~/programs/gambiteer/<u></u>gambit> gsi -v<br>
v4.6.9 20130607151908 x86_64-unknown-linux-gnu "./configure '--enable-single-host' '--enable-multiple-versions' '--enable-shared'"<br>
<br>
and the Ubuntu-provided GMP 5.0.5.  (I'm sure the GMP folks have a better way to build GMP on my machine than the "generic" 64-bit version provided by Ubuntu.)<br>
<br>
Brad<br>
<br>_______________________________________________<br>
Gambit-list mailing list<br>
<a href="mailto:Gambit-list@iro.umontreal.ca">Gambit-list@iro.umontreal.ca</a><br>
<a href="https://webmail.iro.umontreal.ca/mailman/listinfo/gambit-list" target="_blank">https://webmail.iro.umontreal.ca/mailman/listinfo/gambit-list</a><br>
<br></blockquote></div><br></div></div></div>