mpz_root aborts for n-th root when n is very large

Volker Lukas vlukas at
Sun Feb 27 15:44:56 CET 2011


the following program aborts with GMP 5.0.1, on a machine with circa 
1.5 GB free main memory.
#include "gmp.h"

int main() {
  mpz_t out1, in1;
  mpz_init_set_str(in1, "1", 10);
  mpz_root(out1, in1, 100000000000UL);

Program output is
GNU MP: Cannot allocate memory (size=7312500040)

Is this program supposed to work? If not maybe the GMP manual could 
include a hint on how much memory is roughly required for mpz_root 
depending on the input values.

#0  0x00007ffff70b0ab5 in raise (sig=6) at 
#1  0x00007ffff70b1fb6 in abort () at abort.c:92
#2  0x00007ffff7b6e5d5 in __gmp_default_allocate (size=7312500040) at 
#3  0x00007ffff7b6fa21 in __gmp_tmp_reentrant_alloc (markp=0x7fffffffd930, 
size=7312500024) at tal-reent.c:53
#4  0x00007ffff7b952d8 in mpn_rootrem_internal (rootp=0x602010, 
remp=0x0, up=0x602030, un=1, k=100000000000, 
    approx=0) at rootrem.c:145
#5  0x00007ffff7b95334 in __gmpn_rootrem (rootp=0x602010, remp=<value 
optimized out>, up=0x602030, 
    un=<value optimized out>, k=<value optimized out>) at 
#6  0x00007ffff7b84413 in __gmpz_root (root=0x7fffffffda90, u=0x7fffffffda80, 
nth=<value optimized out>)
    at root.c:70
#7  0x000000000040076b in main () at

uname -a: Linux linux-5rjk #1 SMP 2011-02-21 
10:34:10 +0100 x86_64 x86_64 x86_64 GNU/Linux

gcc -v: gcc version 4.5.1 20101208 [gcc-4_5-branch revision 167585] 
(SUSE Linux)

config.guess: core2-unknown-linux-gnu
configfsf.guess: x86_64-unknown-linux-gnu

I tested both the GMP package as provided by Opensuse and a self-
compiled library with the original GMP 5.0.1 source code.

With best regards,
Volker Lukas

More information about the gmp-bugs mailing list