Scott Bucholtz linuxman at
Sat Dec 12 17:19:55 CET 2009

This could definitely save some overhead.  There is an MPI_BYTE type that 
I assume these Lib-GMP variables could be packed into for transmission 
(though I have never tried that myself).  If someone were brave enough to 
write a wrapper for MPI to use Lib-GMP variables; it would likely involve 
this approach behind the scenes.

I would think, however, that there would come a time when the numbers 
became large enough, though that the multiple MPI_BYTE transmissions would 
exceed the overhead in converting to a string and back.

Scott Bucholtz

On Sat, 12 Dec 2009, Will Galway wrote:

> One comment on Scott's suggestion: I'm not familiar with MPI so I could be 
> missing something here, but instead of converting back-and-forth between 
> strings using, e.g., mpz_get_str and mpz_set_str, you could instead convert 
> the mpz_t variable into a sequence of bytes (or unsigned longs) using GMP's 
> shift-right and mask operations (e.g., mpz_fdiv_q_2exp and mpz_fdiv_r_2exp) 
> -- and on the other machine convert the data sequence back into an mpz_t 
> using shift-left and add functions. This way you'd save quite a bit of 
> communication overhead and perhaps, depending on the size of your numbers, 
> quite a bit of memory.
> -- Regards, Will
> Scott Bucholtz wrote:
>> It requires a little more work then just sending the Lib-GMP variables 
>> directly over MPI. You have to:
>> 1) determine the length of the Lib-GMP variable in the desired base (e.g., 
>> mpz_sizeinbase); plus 1
>> 2) send #1 as an MPI_UNSIGNED_LONG
>> 3) convert the Lib-GMP variable in its base to a string (e.g., mpz_get_str)
>> 4) allocate a new string of that size on the other side (realloc)
>> 5) send the string from #3 as an MPI_CHAR
>> 6) convert the string at the other end to a Lib-GMP variable (e.g., 
>> mpz_set_str)
>> 7) clean up (i.e., free string memory)
>> Hope this helps.
>> Scott Bucholtz
>> On Fri, 11 Dec 2009, selcukkeskin at wrote:
>>> i'm sorry. i didn't write library. i'm using gmp primitives embedded in it
>>> best wishes
>>> --------------------------------------------------
>>> From: "Allan Menezes" <amenezes007 at>
>>> Sent: Friday, December 11, 2009 10:53 PM
>>> To: <selcukkeskin at>
>>> Cc: <gmp-discuss at>
>>> Subject: Re: MPI and GMP
>>>> selcukkeskin at wrote:
>>>>> Hi,
>>>>> I'm working on MPI with GMP. It works perfectly but i can't send gmp 
>>>>> variables like mpz_t, mpf_t
>>>>> -------------------------------------------------------
>>>>> Sel�uk Keskin
>>>>> Ege University
>>>>> The feasibility of Mathematics in Computer
>>>>> _______________________________________________
>>>>> gmp-discuss mailing list
>>>>> gmp-discuss at
>>>> Hi Selcuk,
>>>> Are you emedding MPI in GMP functions at a higher level to create a new 
>>>> gmp library with mpi?or just writing an mpi program in C/C++ with gmp 
>>>> primitives embedded in it and compiled like this
>>>> mpicc -o foo -m64 -lgmp -lm foo.c? If you are writing a library are you 
>>>> going to LGPL it and submit it to the gmplib website?
>>>> Thank you very much for your response,
>>>> Best wishes,
>>>> Allan MeneZes
>>> _______________________________________________
>>> gmp-discuss mailing list
>>> gmp-discuss at
>> ------------------------------------------------------------------------
>> _______________________________________________
>> gmp-discuss mailing list
>> gmp-discuss at

More information about the gmp-discuss mailing list