Efficiently importing/export GMP floats

Torbjorn Granlund tg at gmplib.org
Mon Jan 17 11:16:41 CET 2011


Jack Poulson <jack.poulson at gmail.com> writes:

  I have been scouring the manual and related archived conversations, but I
  can't seem to find a sufficient means of importing/exporting a large
  collection of mpf_t's as a binary format without a loss in precision (e.g.,
  converting to double-precision).
  
  The reason I ask is that I have written a templated parallel linear algebra
  library that I would like to stick GMP under the hood for in the cases where
  the user wanted higher than double-precision arithmetic. The main constraint
  is in importing/exporting large arrays of mpf_t's into a contiguous buffer
  so that I could use the Message Passing Interface (MPI) to communicate the
  data between a large number of nodes. I should also be able to handle
  distributed summations (e.g., MPI_Reduce with the MPI_SUM operation) by
  defining a MPI reduce operation and then calling mpf_add from within it.
  
  Does anyone have a suggestion as to how to efficiently pack/unpack a large
  number of mpf_t's *without losing precision*?
  
As Marc Glisse said, your best option within mpf is radix 2^k for some
suitable k input/output using mpf_inp_str ad mpf_out_str.  We usually
suggest that people do not write new applications for mpf, since the
independently maintained mpfr package aims at the same goals as mpf, but
does it much better.  (I don't know if mpfr provides any raw
input/output functions, you need to check their manual.)

-- 
Torbjörn


More information about the gmp-discuss mailing list