CFD Online Logo CFD Online URL
www.cfd-online.com
[Sponsors]
Home > Forums > OpenFOAM Running, Solving & CFD

Mixing single and double precision

Register Blogs Members List Search Today's Posts Mark Forums Read

Like Tree1Likes
  • 1 Post By deepsterblue

Reply
 
LinkBack Thread Tools Display Modes
Old   March 21, 2011, 08:31
Default Mixing single and double precision
  #1
Senior Member
 
BastiL
Join Date: Mar 2009
Posts: 471
Rep Power: 11
bastil is on a distinguished road
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
bastil is offline   Reply With Quote

Old   March 22, 2011, 14:34
Default
  #2
Senior Member
 
Alberto Passalacqua
Join Date: Mar 2009
Location: Ames, Iowa, United States
Posts: 1,894
Rep Power: 26
alberto will become famous soon enoughalberto will become famous soon enough
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 live DVD/USB, hard drive image and virtual image.
OpenQBMM - An open-source implementation of quadrature-based moment methods
alberto is offline   Reply With Quote

Old   March 23, 2011, 03:38
Default
  #3
Senior Member
 
BastiL
Join Date: Mar 2009
Posts: 471
Rep Power: 11
bastil is on a distinguished road
Quote:
Originally Posted by alberto View Post
Hi,
what the article is saying is that they keep double precision accuracy, using single precision operations on the machine
Exactly. And that is what I want to do in simpleFoam. I don't even mind double precision accuracy since I have small differences between single and double. However, I need to have mesh (saving, reading,...) in double since I have short edge lengths. Has anybody done something similar before?

Regards Bastian
bastil is offline   Reply With Quote

Old   March 23, 2011, 04:24
Default
  #4
Senior Member
 
Alberto Passalacqua
Join Date: Mar 2009
Location: Ames, Iowa, United States
Posts: 1,894
Rep Power: 26
alberto will become famous soon enoughalberto will become famous soon enough
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 live DVD/USB, hard drive image and virtual image.
OpenQBMM - An open-source implementation of quadrature-based moment methods
alberto is offline   Reply With Quote

Old   March 23, 2011, 05:50
Default
  #5
Senior Member
 
BastiL
Join Date: Mar 2009
Posts: 471
Rep Power: 11
bastil is on a distinguished road
Quote:
Originally Posted by alberto View Post
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.
Alberto,

I don't really understand how you want to scale the mesh? Yes, I have high aspect ratios. I have the following observations:
  • My high aspect ratio meshes run fine in simpleFOAM in DP
  • The same meshes run fine in FLUENT in both SP and DP without remarkable result differences between SP and DP.
  • FLUENT saves the mesh in DP regardless if you run SP or DP
  • I see a speedup of nearly 50% when running in SP for both codes
So my aim is to run my model in OF using SP maths (to get the 50% speedup). That is why I came across this. Hints?

Regards Bastian
bastil is offline   Reply With Quote

Old   April 11, 2011, 16:26
Default
  #6
Senior Member
 
Eugene de Villiers
Join Date: Mar 2009
Posts: 725
Rep Power: 12
eugene is on a distinguished road
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% speed-up by doing the same kind of thing.

Eugene
eugene is offline   Reply With Quote

Old   April 11, 2011, 21:56
Default
  #7
Senior Member
 
Alberto Passalacqua
Join Date: Mar 2009
Location: Ames, Iowa, United States
Posts: 1,894
Rep Power: 26
alberto will become famous soon enoughalberto will become famous soon enough
Quote:
Originally Posted by bastil View Post
Alberto,

I don't really understand how you want to scale the mesh? Yes, I have high aspect ratios. I have the following observations:
If you have high aspect ratios in the geometry (not mesh) that are so extreme to require double precision to represent the geometry, you really have no choice than solving in double precision the whole problem, or you will obtain a solution seriously affected by the truncation error when switching from double precision (mesh) to single precision (your data). I have already given you an example where this happens.

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:
  • The same meshes run fine in FLUENT in both SP and DP without remarkable result differences between SP and DP.
This seems contradictory with your statement that you need to represent your mesh in double precision, since the run in SP will be affected by the truncation error.

Quote:
  • FLUENT saves the mesh in DP regardless if you run SP or DP
Yes, but it will perform a conversion when working on SP data. There you will lose information. The question is: is this conversion performed while reading the mesh? FLUENT warns you when you load a 64-bit case (not mesh, whole case) in the 32-bit solver...

Quote:
  • I see a speedup of nearly 50% when running in SP for both codes
So my aim is to run my model in OF using SP maths (to get the 50% speedup). That is why I came across this. Hints?
The speedup in SP is normal. However, as Eugene said, there is no easy way. You will not only need to re-implement OpenFOAM structures, but you will have to code specific algorithms that take care your accuracy is not reduced excessively by the truncation (of course if you want to do it properly).

Alberto
__________________
Alberto Passalacqua

GeekoCFD - A free distribution based on openSUSE 64 bit with CFD tools, including OpenFOAM. Available as live DVD/USB, hard drive image and virtual image.
OpenQBMM - An open-source implementation of quadrature-based moment methods
alberto is offline   Reply With Quote

Old   April 12, 2011, 05:52
Default
  #8
Senior Member
 
Eugene de Villiers
Join Date: Mar 2009
Posts: 725
Rep Power: 12
eugene is on a distinguished road
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 speed-up of a 32bit float or the accuracy of a 64bit double, but the compromise might be acceptable and it would be much easier than re-writing large chunks of code.

Eugene
eugene is offline   Reply With Quote

Old   April 12, 2011, 09:55
Default
  #9
Senior Member
 
Sandeep Menon
Join Date: Mar 2009
Location: Amherst, MA
Posts: 386
Rep Power: 15
deepsterblue will become famous soon enough
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.
wyldckat likes this.
__________________
Sandeep Menon
University of Massachusetts Amherst
https://github.com/smenon
deepsterblue is offline   Reply With Quote

Old   April 12, 2011, 10:30
Default
  #10
Senior Member
 
Eugene de Villiers
Join Date: Mar 2009
Posts: 725
Rep Power: 12
eugene is on a distinguished road
Quote:
Originally Posted by deepsterblue View Post
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.
Interesting. So you haven't tried replacing scalar with this yourself yet?
eugene is offline   Reply With Quote

Old   April 12, 2011, 10:48
Default
  #11
Senior Member
 
Sandeep Menon
Join Date: Mar 2009
Location: Amherst, MA
Posts: 386
Rep Power: 15
deepsterblue will become famous soon enough
Well, at least not at the linear-solvers 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 round-off. Clearly, this is intended for numerical robustness, and not performance.
__________________
Sandeep Menon
University of Massachusetts Amherst
https://github.com/smenon
deepsterblue is offline   Reply With Quote

Old   April 12, 2011, 11:43
Default
  #12
Senior Member
 
Eugene de Villiers
Join Date: Mar 2009
Posts: 725
Rep Power: 12
eugene is on a distinguished road
I will put it on my list of things to try. Thanks for the wrapper code Sandeep.
eugene is offline   Reply With Quote

Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
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
Single or double precision Jonas Larsson Main CFD Forum 15 March 26, 2007 23:15
Single v.s. double precision Confused CFX 9 April 19, 2004 18:33


All times are GMT -4. The time now is 01:34.