optimizing GMP for my code

Blake Huff stangmechanic at gmail.com
Sun Oct 15 18:03:26 CEST 2006


Hi Usman:

I'll preface this by saying that my understanding of how floating  
points are stored is sketchy at best, so if anyone needs to set me  
straight, feel free.

I received your posts about using 128 bit floats on the GCC list as  
well.   You mention that a 64 bit number is "not sufficient" to  
contain your numbers and I assume this means you need greater  
precision, not greater range as the range on a 64 bit number is  
pretty darn large.

Keep in mind that in a traditional 32 or 64 (and I assume 128) bit  
floats, BOTH the exponent and mantissa are contained in that 32 or 64  
bits, which leads to 8 and 11 bit exponents, respectively.  With GMP,  
you're getting a 32 or 64 bit exponent , depending on the size of a  
machine word on your system, plus the mantissa that you request.  You  
might be able to minimize the memory requirement at the cost of  
performance by configuring with a 32 bit ABI instead of the 64 bit  
ABI (if your CPU/system will allow you to).  Using a 32 bit exponent  
should free up more memory to devote to precision.

  Also, I see you using mpf_get_d. The GMP manual says that all  
calculations are performed to the precision of the destination  
variable.  I'd make sure that you don't have excessive precision  
immediately before you truncate with mpf_get_d.   For example, it  
makes little sense (in my opinion, might be wrong) to multiply two  
numbers with 256 bits of precision, store them in another number of  
256 bits, and then call mpf_get_d.  You would probably be better off  
having a destination variable with less precision, perhaps 64 bits,  
and then calling mpf_get_d on it.  That might save some memory.

Finally, and I'm mostly speculating on this as I haven't dug this  
deep into the code.  Each variable keeps the size of the mantissa  
data actually in use regardless of the precision requested.  If  
you're willing to take the performance hit and use a fixed mantissa  
size, you might be able to delete this from the mpf_t  variable and  
alter the functions to assume a fixed mantissa, negating the need to  
keep track of how many bits are actually in use, again freeing up  
more memory.

Hope something in this is useable, not not toooooo  far into left  
field.  Perhaps a more experienced developer or programmer can help  
set us straight on this.

Blake Huff
stangmechanic at gmail.com

"When the going gets tough, the tough get aeronautical."-Howling Mad  
Murdoch





On Oct 14, 2006, at 5:21 PM, Usman W Roshan cis faculty/staff wrote:

> Hi,
>
> My code produces large 2D matrices containing very large numbers. I  
> use
> GMP since 64 bit (and 80 bit long double) is not sufficient to  
> contain my
> numbers. However, my program slows down significantly and also ends up
> using lots of memory. I'm using just the mpf_t types and the following
> functions from the library:
>
> mpf_set_default_prec, mpf_mul, mpf_set_d, mpf_mul, mpf_div, mpf_get_d,
> mpf_clear, mpf_init, mpf_add
>
> Is it possible to tweak the library to reduce the memory usage and
> increase speed if I'm using just these functions and the mpf_t  
> type? If
> so, can you suggest how? Thanks,
>
> Usman Roshan
> Department of Computer Science
> New Jersey Institute of Technology
> http://www.cs.njit.edu/usman
> _______________________________________________
> gmp-discuss mailing list
> gmp-discuss at swox.com
> https://gmplib.org/mailman/listinfo/gmp-discuss

-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://gmplib.org/list-archives/gmp-discuss/attachments/20061015/6f2696e7/attachment.html 


More information about the gmp-discuss mailing list