# Single, Double or Mixed Precision?

**URL:** <https://fortran-lang.discourse.group/t/single-double-or-mixed-precision/7074>\
**Category:** Help\
**Created:** [December 29, 2023, 4:23pm UTC](https://fortran-lang.discourse.group/t/single-double-or-mixed-precision/7074 "2023-12-29T16:23:05Z")\
**Posts on this page:** 1\
**Showing post:** 8

<div class="post-metadata">

**Author:** ![ivanpribec](https://yyz2.discourse-cdn.com/free1/user_avatar/fortran-lang.discourse.group/ivanpribec/32/3290_2.png) [@ivanpribec](https://fortran-lang.discourse.group/u/ivanpribec)\
**Post date:** [December 30, 2023, 12:09pm UTC](https://fortran-lang.discourse.group/t/single-double-or-mixed-precision/7074/8 "2023-12-30T12:09:36Z")

</div>

> [@aerosayan](#):
>
> I tried to use mixed precision before, because StarCCM does mixed precision, but realized that I couldn’t guarantee accuracy, so decided not to.

Moritz Lehmann (now working at Intel) has looked at using mixed precision in lattice Boltzmann solvers:

> **[On the accuracy and performance of the lattice Boltzmann method with 64-bit,...](https://arxiv.org/abs/2112.08926)**
>
> Fluid dynamics simulations with the lattice Boltzmann method (LBM) are very memory-intensive. Alongside reduction in memory footprint, significant performance benefits can be achieved by using FP32 (single) precision compared to FP64 (double)...

While the reduction in bandwidth does improve performance, it indeed limits the accuracy you can achieve, as seen from this graph:

 ![image](https://global.discourse-cdn.com/free1/uploads/fortran_lang/original/2X/7/7f268f72848000611df21924d53156850488cc32.png)

For this test case - laminar flow in a circular channel - only the FP32 and FP64 solvers were able to reach an error lower than 1 % (which is arguably sufficient if you know there are other modelling errors that are larger). This is a relatively simple case, I imagine that in a multiphase flow or a combustion problem there would be parameters with wildly different magnitudes, and you may encounter convergence problems sooner rather than later.

At least for LBM, if you use distribution shifting (a change of variables that helps gain one extra digit of precision), single precision appears to be sufficient for many problems. I’d still remain careful if the simulation has to be performed over long time periods (the time convergence is only first order…).

I saw a similar work published recently on mixed precision in OpenFOAM, but haven’t had time to read it yet:

> **[On floating point precision in computational fluid dynamics using OpenFOAM](https://arxiv.org/abs/2209.06105)**
>
> Thanks to the computational power of modern cluster machines, numerical simulations can provide, with an unprecedented level of details, new insights into fluid mechanics. However, taking full advantage of this hardware remains challenging since data...

In a previous thread, I mentioned some works which find that for _chaotic systems_, even double precision may not be enough: [Use case of single-precision real number - #7 by ivanpribec](https://fortran-lang.discourse.group/t/use-case-of-single-precision-real-number/4965/7)

---

_[View the full topic](https://fortran-lang.discourse.group/t/single-double-or-mixed-precision/7074)._
