# [gmx-developers] stuff in double precision

David van der Spoel spoel at xray.bmc.uu.se
Mon Feb 5 19:20:13 CET 2007

```Erik Lindahl wrote:
> Hi,
>
> On Feb 5, 2007, at 5:08 PM, Berk Hess wrote:
>
>> Hi,
>>
>> This difference can be avoided by having all energy terms in double
>> precision. In general this is for free, but it might need recoding
>> of the assembly loops.
>> We should consider making most/all variables double precision,
>> except for the natoms sized arrays.
>
> One problem I can see is that single/double conversions are not free,
> and you would do extra operations to sum in double (SSE is 2-way for
> double 4-way for single).
>
> A possible intermediary approach could be to introduce a handful of
> extra single precision variables that we zero in the outer loop, and
> after each inner loop we convert the sum to double and add it to a
> double precision summation.
>
> I've started to go more in the direction of "double unless it's an
> array" recently, but for the innermost loop it would mean sacrificing
> performance.
>
> In principle I could also recode the loops to enable a solution with
> "double for all summation variables", but then we might want to have
> that as a third option besides all-double and all-single. Before doing
> that for ASM I'd like to see hard result that it solves the problem when
> done for the C loops, though :-)

If you do an operation in C in which a double is involved, then as far
as I know everything is converted to double, possibly unless you use
brackets.

The problem David experienced is just due to an in a sense ill-posed
problem, since looking for 1 in 10^6 energy differences (i.e.
subtracting large numbers) is asking for trouble (think diverging
trajectories due to round off with different average energies). This is
why people generally shy away from absolute free energies.

A very simple workaround would be to always use the free energy loops,
also for "reference no-free energy simulations", then you are running
the same code twice.

--
David.
________________________________________________________________________
David van der Spoel, PhD, Assoc. Prof., Molecular Biophysics group,
Dept. of Cell and Molecular Biology, Uppsala University.
Husargatan 3, Box 596,  	75124 Uppsala, Sweden
phone:	46 18 471 4205		fax: 46 18 511 755
spoel at xray.bmc.uu.se	spoel at gromacs.org   http://folding.bmc.uu.se
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

```