hermann on Mon, 19 Jun 2023 22:00:54 +0200


[Date Prev] [Date Next] [Thread Prev] [Thread Next] [Date Index] [Thread Index]

Re: void mpz_set_GEN(mpz_ptr z, GEN x) and GEN mpz_get_GEN(mpz_srcptr z)


On 2023-06-19 10:04, Andreas Enge wrote:
you may be interested in the PariTwine project:
   https://www.multiprecision.org/paritwine/home.html
which provides a link to GMP, but also MPFR, MPC, FLINT/ARB and CMH.
There are conversion functions and helpers to call functions of the
other libraries from GP scripts.

Thanks, that code looks like the posting I pointed to.

The code Max pointed to is smaller, and the function naming makes more sense to me (GEN2mpz, mpz2GEN). I found solution to avoid "munmap_chunk(): invalid pointer" for "return 0;" with using "exit(0);". I just did run new "./sqrtm1.smallest_known_1million_digit_prime" 100s of times with no memory increase. exit(0) does not call local to main() destructors, but that seems n ot to hurt.

I used "mpz_clear()" and "pari_close()" before, but that did not fix the invalid pointer in cleanup.

The basic difference of pointed to posting and paritwine conversion code
https://github.com/Hermann-SW/RSA_numbers_factored/blob/main/c%2B%2B/sqrtm1.smallest_known_1million_digit_prime.cc

to new version of based on Karim's code is that the first two create a copy using realloc2(), while KarimÄs code does a shallow copy:
https://github.com/Hermann-SW/RSA_numbers_factored/blob/main/c%2B%2B/sqrtm1.smallest_known_1million_digit_prime.cc#L30

So for current "sqrtm1.smallest_known_1million_digit_prime.cc" exit(0) if OK, and shallow copy as well. When needing realloced copy, paritwine code can be used as well.

Regards,

Hermann.


$ f=sqrtm1.smallest_known_1million_digit_prime
$ g++ $f.cc -lgmp -lgmpxx -O3 -o $f -lpari -DPARI
$ ./$f
a = y^(-1) (mod p) [powm]; a *= x; a %= p
0.249883s
[M,V] = halfgcdii(sqrtm1, p)
0.26405s
[x,y] = [V[2], M[2,1]]
0s
done
$
$ tail -2 $f.cc
    exit(0);  // avoid "munmap_chunk(): invalid pointer" for "return 0;"
}
$