Arithmetic without limitations?

Paul Zimmermann Paul.Zimmermann at
Thu Feb 11 13:29:20 CET 2010

> My idea for GMP has long been to make "hierarchical locality" take care
> of it all.  A row in in the k-dimensional matrix would fit into L1
> cache, a plane would fit into memory, further dimensions would live in
> swap space (not exlicit files).

I'm not sure this will work. Here is a concrete example, on a Core 2 with
16Gb of RAM and 4Gb of swap. I'm trying to multiply two numbers of 6e9
decimal digits, thus using about 2.5G of memory each.

With GMP 5.0.1, top says:

27123 pzimmerm  20   0 13.9g  10g  436 R  100 66.5   2:48.90 a.out             
27123 pzimmerm  20   0 18.7g  15g  436 R  100 96.7   2:57.91 a.out             
27123 pzimmerm  20   0 18.7g  15g  160 D   13 98.1   5:32.93 a.out

then I get:

GNU MP: Cannot allocate memory (size=5100535824)

With Fabrice Bellard's "mptest" program (this is a sub-product of TPI that
performs just one multiplication):

% time ./ -u -m 16G -p /tmp mul -n ntt_crt 6000M
27139 pzimmerm  20   0 14.8g  14g  688 R  100 94.0   2:22.64        
27139 pzimmerm  20   0 14.8g  14g  692 R  100 94.2   7:25.22       
  time=683.535 s
704.704u 38.254s 13:46.97 89.8% 0+0k 2160+9732216io 11pf+0w

Here I explicitely said that I wanted to use only 16G of RAM (-m 16G), and
that I want to use the disk (-p /tmp) for extra memory needs.


More information about the gmp-devel mailing list