• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Floating point calculations performance

 
Alexey Kuntsevich
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello!

I'm rewriting a piece of fortran code to java to improve its maintability but i'm concerned about it's speed. This code doesn't make anything except lots of floating point calculations (electromagnetic fields simulations) and doesn't make heavy memory usages.

Does anyone have experience in such kind of projects? Any advices would be appreciated.

Thanks!
 
Kees Jan Koster
JavaMonitor Support
Rancher
Posts: 251
5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Dear Alexey,

Java is so different from Fortran that we cannot help you here. The best route forward is for you to write the code and then optimize it. Don't start optimizing now, you will end up with unmaintainable code and probably not actually gain anything significant.

Performance in Java is not clear-cut. You have the HotSpot compiler that (re)compiles your code at run-time. You have the server JVM (use -server on the command line) and the client JVM (don't use that one). So you won't know the performance by looking at the code. In fact, your code may start running faster the longer it runs. So be *very* careful when you do 2-minute benchmarks to find out what is fast and not.

Just write maintainable code. Once the code is done, get a decent CPU profiler and start locating hotspots in your code and fix those.
 
steve souza
Ranch Hand
Posts: 862
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I agree with the previous poster. I'd also add if you are concerned about performance create a small program that does the types of calculations your fortran program did and time the performance. I do a fair amount of calculations on doubles in my programs and I am continually surprised by how fast it executes.
 
Alexey Kuntsevich
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You're right, it's a good idea to make some tests.
Thank you for your replies!

 
Tim Holloway
Saloon Keeper
Pie
Posts: 18212
53
Android Eclipse IDE Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Actually, this is a particular sore spot with Java. Java is intended to be "write once, run anywhere", and they take that directive so seriously that even the floating-point calculations and binary serializations should be accurately reproducible.

However, there are a number of different floating-point implementations, depending on the hardware involved. To stay portable, Java dictates the IEEE floating-point representation.

The original IBM System/370 floating point (optional on selected S/360 models) was a rather odd format. So to run IEEE floating point on it, and its descendants, the floating-point hardware had to be totally ignored and the actual floating-point calculations be done totally in software. As a result, although on most benchmarks, Java can often exceed the runtime speeds of native C code, when you add floating-point, it loses badly (C isn't required to be write once, run anywhere so it can use whatever FP resources it wants).

Two mechanisms were provided to compensate for this. For general Java use, there's a modifier that says "Use the machine's native floating-point facilities". That way you can take advantage of the hardware accelerators. For IBM mainframes, the recent crop of z/Series machines added IEEE accelerators alongside their older unique FP hardware.
 
steve souza
Ranch Hand
Posts: 862
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
For general Java use, there's a modifier that says "Use the machine's native floating-point facilities". That way you can take advantage of the hardware accelerators.

How do you tell the jvm to use this facility?
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic