parallel programs with MPI and GMP

Kevin Ryde
Sat, 14 Jun 2003 07:54:45 +1000

"June Co." <> writes:

I couldn't see license conditions stated.  When you reach a state of
completeness and if you publish under free terms we can perhaps put a
link in the gmp manual.

> size_t get_bufsize_mpz(mpz_t a)
> ...
>	bufsize = sizeof(int) * 2 + sizeof(mp_limb_t) * a->_mp_alloc;

You might want ABS(a->_mp_size) there, and elsewhere.  _mp_size is the
current size of a value.  (See "Internals" in the manual.)

> void pack_mpz(mpz_t a, void *buf)
> ...
>	memcpy(tmp_buf, a->_mp_d, (size_t)(sizeof(mp_limb_t) * (a->_mp_alloc)));

You could use mpz_export there, to avoid depending on gmp internals.
If you ask for limbs in host endianness then that function is a nice
efficient copy.

Incidentally, do you need to communicate limb size and endianness in
the data you pack, or does MPI only operate among homogeneous systems?
GMP always uses the native endianness, as you can imagine, and limb
size of course varies.