
[Sponsors] 
March 21, 2011, 08:31 
Mixing single and double precision

#1 
Senior Member
BastiL
Join Date: Mar 2009
Posts: 502
Rep Power: 13 
Hi all,
because of this: http://www.hpcwire.com/features/17885244.html?viewAll=y it might make sense to generate a mixed sp/dp solver. I found all mesh operations to be very critical for meshes with short edge length but I want to do all calculations in single precision. How can this be done? As far as I can see this needs some quite basic changes in OpenFOAM? Thanks and regards Bastian 

March 22, 2011, 14:34 

#2 
Senior Member
Alberto Passalacqua
Join Date: Mar 2009
Location: Ames, Iowa, United States
Posts: 1,911
Rep Power: 28 
Hi,
what the article is saying is that they keep double precision accuracy, using single precision operations on the machine. Clearly I don't know the details of their implementation, however what they do seems to manipulate a double type as a set of floats, which, as a concept is not new. Similar ideas are used, with a different goal, in arbitrary precision libraries (GNU MP http://gmplib.org/ for example). Best,
__________________
Alberto Passalacqua GeekoCFD  A free distribution based on openSUSE 64 bit with CFD tools, including OpenFOAM. Available as in both physical and virtual formats (current status: http://albertopassalacqua.com/?p=1541) OpenQBMM  An opensource implementation of quadraturebased moment methods. To obtain more accurate answers, please specify the version of OpenFOAM you are using. 

March 23, 2011, 03:38 

#3  
Senior Member
BastiL
Join Date: Mar 2009
Posts: 502
Rep Power: 13 
Quote:
Regards Bastian 

March 23, 2011, 04:24 

#4 
Senior Member
Alberto Passalacqua
Join Date: Mar 2009
Location: Ames, Iowa, United States
Posts: 1,911
Rep Power: 28 
Not that I know. In your case you actually care of double precision accuracy. If you need a mesh in double precision (can't you simply scale it? or is the aspect ratio extreme?), you need, for example, to compute differential operators in double precision too for example, or you end up in large errors.
Best,
__________________
Alberto Passalacqua GeekoCFD  A free distribution based on openSUSE 64 bit with CFD tools, including OpenFOAM. Available as in both physical and virtual formats (current status: http://albertopassalacqua.com/?p=1541) OpenQBMM  An opensource implementation of quadraturebased moment methods. To obtain more accurate answers, please specify the version of OpenFOAM you are using. 

March 23, 2011, 05:50 

#5  
Senior Member
BastiL
Join Date: Mar 2009
Posts: 502
Rep Power: 13 
Quote:
I don't really understand how you want to scale the mesh? Yes, I have high aspect ratios. I have the following observations:
Regards Bastian 

April 11, 2011, 16:26 

#6 
Senior Member
Eugene de Villiers
Join Date: Mar 2009
Posts: 725
Rep Power: 14 
Hi Bastian,
Unfortunately, what you want is not possible without a hell of a lot of effort. Every single number in foam is templated on the scalar type, which can be compiled for either float or double, but not a mix of both (as you probably know). To have only the mesh work in double precision, you would have to redefine every single scalar or scalar derived variable used in the mesh. This would mean duplicating a massive number of foam data structures. This is not something you can do on the weekend. However, arbitrary variable precision would be a really useful thing to have. I know that the code Xflow uses 10 bit precision as part of its acceleration strategy. It would be fantastic if we could get say 40% speedup by doing the same kind of thing. Eugene 

April 11, 2011, 21:56 

#7  
Senior Member
Alberto Passalacqua
Join Date: Mar 2009
Location: Ames, Iowa, United States
Posts: 1,911
Rep Power: 28 
Quote:
One doubt/suggestion. What happens if you increase the accuracy used to write the mesh in OpenFOAM? Check in controlDict the writePrecision option. The default is 6 digits if you use ASCII format. As an alternative, try the binary format. Quote:
Quote:
Quote:
Alberto
__________________
Alberto Passalacqua GeekoCFD  A free distribution based on openSUSE 64 bit with CFD tools, including OpenFOAM. Available as in both physical and virtual formats (current status: http://albertopassalacqua.com/?p=1541) OpenQBMM  An opensource implementation of quadraturebased moment methods. To obtain more accurate answers, please specify the version of OpenFOAM you are using. 

April 12, 2011, 05:52 

#8 
Senior Member
Eugene de Villiers
Join Date: Mar 2009
Posts: 725
Rep Power: 14 
A more viable option might be to translate only some specific matrix solution components to reduced precision and see how that works out. Interestingly, GMP is already included with the foam distribution as a Gcc dependency. Seems criminal not to take advantage of it!
You could also check whether it is possible to use gmp to template the scalars in foam onto something like a 48bit number. This obviously won't give you quite the speedup of a 32bit float or the accuracy of a 64bit double, but the compromise might be acceptable and it would be much easier than rewriting large chunks of code. Eugene 

April 12, 2011, 09:55 

#9 
Senior Member
Sandeep Menon
Join Date: Mar 2009
Location: Amherst, MA
Posts: 396
Rep Power: 17 
Did it already. Not sure how useful this would be, but I guess it doesn't hurt to post it:
http://www.ecs.umass.edu/~smenon/tarballs/multiPrecision.tgz Basically wraps around the MPFR library to provide arbitrary precision arithmetic. You can replace the scalar class with this. 

April 12, 2011, 10:30 

#10  
Senior Member
Eugene de Villiers
Join Date: Mar 2009
Posts: 725
Rep Power: 14 
Quote:


April 12, 2011, 10:48 

#11 
Senior Member
Sandeep Menon
Join Date: Mar 2009
Location: Amherst, MA
Posts: 396
Rep Power: 17 
Well, at least not at the linearsolvers level. The performance would go through the floor if I tried that, but I don't see why not.
I was mainly using it for geometric intersection calculations, since those tend to be finicky about roundoff. Clearly, this is intended for numerical robustness, and not performance. 

April 12, 2011, 11:43 

#12 
Senior Member
Eugene de Villiers
Join Date: Mar 2009
Posts: 725
Rep Power: 14 
I will put it on my list of things to try. Thanks for the wrapper code Sandeep.


August 13, 2017, 18:19 
please repost

#13 
Senior Member
Klaus
Join Date: Mar 2009
Posts: 119
Rep Power: 10 
Hello Sandeep,would you please repost the the multiPrecision wrapper for arbitrary precision.
I'd like to use it with linear solvers. Klaus 

Thread Tools  
Display Modes  


Similar Threads  
Thread  Thread Starter  Forum  Replies  Last Post 
Single or double precision  Jonas Larsson  Main CFD Forum  16  June 20, 2017 06:53 
Single v.s. double precision  Confused  CFX  15  November 10, 2016 05:42 
Parallel User Defined Real Gas Model  aeroman  FLUENT  4  July 1, 2015 06:09 
Switch from single precision to double precision  kk81  OpenFOAM Bugs  0  March 11, 2010 07:14 
OpenFOAM Double precision vs Single Precision  alexandrepereira  OpenFOAM Running, Solving & CFD  1  June 11, 2008 14:30 