• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Floating point calculations performance

 
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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!
 
JavaMonitor Support
Posts: 251
5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Ranch Hand
Posts: 862
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You're right, it's a good idea to make some tests.
Thank you for your replies!

 
Saloon Keeper
Posts: 27764
196
Android Eclipse IDE Tomcat Server Redhat Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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?
 
Please enjoy this holographic presentation of our apocalyptic dilemma right after this tiny ad:
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic