aspose file tools*
The moose likes Performance and the fly likes Floating point calculations performance Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Performance
Bookmark "Floating point calculations performance" Watch "Floating point calculations performance" New topic
Author

Floating point calculations performance

Alexey Kuntsevich
Greenhorn

Joined: Jan 12, 2009
Posts: 12
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!


SCJP 6, SCBCD, SCWCD. Making SCEA assignment atm.
Kees Jan Koster
JavaMonitor Support
Rancher

Joined: Mar 31, 2009
Posts: 251
    
    5
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.


Java-monitor, JVM monitoring made easy <- right here on Java Ranch
steve souza
Ranch Hand

Joined: Jun 26, 2002
Posts: 861
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.


http://www.jamonapi.com/ - a fast, free open source performance tuning api.
JavaRanch Performance FAQ
Alexey Kuntsevich
Greenhorn

Joined: Jan 12, 2009
Posts: 12
You're right, it's a good idea to make some tests.
Thank you for your replies!

Tim Holloway
Saloon Keeper

Joined: Jun 25, 2001
Posts: 16305
    
  21

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.


Customer surveys are for companies who didn't pay proper attention to begin with.
steve souza
Ranch Hand

Joined: Jun 26, 2002
Posts: 861
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?
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Floating point calculations performance