Calculation on different JVMs = same?

W

Wayne

Hi all,

I have an online application that computes many many mathatical
calculations based on collisions of objects in space. As far as I'm
aware if you have 2 JVM's (in the form of applets) running in browsers
on different machines, they should come up with the same result.

BUT I finding that this happening 90 percent of the time, but
occasionaly they go 'out of sync'. Is this a propblem of JVM, my code,
or the laws of calsulty???

Any ideas or thoughts welcome
 
J

Jon Skeet

Wayne said:
I have an online application that computes many many mathatical
calculations based on collisions of objects in space. As far as I'm
aware if you have 2 JVM's (in the form of applets) running in browsers
on different machines, they should come up with the same result.

Not necessarily. Unless you've got the "strictfp" modifier on a class,
two different CPUs are able to perform floating point calculations in
different ways. For instance, on x86 boxes most floating point
calculations will be done in 80 bits, and that's the faster way of
doing things. If you have strictfp on, however, things should be
reproducible.
 
J

John C. Bollinger

Jon said:
Not necessarily. Unless you've got the "strictfp" modifier on a class,
two different CPUs are able to perform floating point calculations in
different ways. For instance, on x86 boxes most floating point
calculations will be done in 80 bits, and that's the faster way of
doing things. If you have strictfp on, however, things should be
reproducible.

If the input is the same and strictfp is in effect then all should be
the same.

Other variables for the non-strictfp case include the JVM version, where
differences in the hotspot compiler might conceivably cause small
differences in some calculations, which could escalate into large
differences further along. If there is any interactivity involved then
even with matching JVM versions on equivalent hardware there could be a
difference in which parts of the code are subjected to native
compilation and when, leading to noticable differences in the result.

If you application is sensitive to small differences in the results of
floating-point calculations then you should carefully evaluate the
validity of your results.


John Bollinger
(e-mail address removed)
 
W

Wayne

Thanks for the strictfp tip - I wasn't aware of this keyword. However
this i believe is just a 1.3 keyword - and most browser are using the
Microsoft JVM which is 1.1. So i guess I'm a little stuck on this. (at
least for a few more years)

All the calculations are performed on doubles - can anything think of
a way to reduce this problem?
 
M

Michael Borgwardt

Wayne said:
All the calculations are performed on doubles - can anything think of
a way to reduce this problem?

Is it actually a problem? It's not as if in the absence of strictfp the
results are less correct. The opposite is in fact the case: strictfp forces
identical results by following the IEEE FP standards to the letter, while
without it, the VM is allowed to use more than 64 bits for intermediate
results (which is also faster on modern processors that implement FP
arithmetic in hardware that way), so it can produce "more correct"
results.

So if the correctness of the results is important to you, it seems that
your actual problem is that you're not using a stable algorithm.
 
W

Wayne

Point taken, but in fact its the oppersite for my need - the results
don't have to be 100 percent accurate, so as long as the results are
the same. I don't want the 2 JVM's to go out of sync - I don't really
want to resort to re-sync'ing the results all the time.

Any ideas welcome.
Thanks.
 
C

Chris Smith

Wayne said:
Point taken, but in fact its the oppersite for my need - the results
don't have to be 100 percent accurate, so as long as the results are
the same. I don't want the 2 JVM's to go out of sync - I don't really
want to resort to re-sync'ing the results all the time.

Unfortunately, you're running out of options. If you don't have
strictfp available, then the next thing to try is to emulate the
calculations using integer data types and lookup tables, which will be
far slower and perhaps not even feasible. It's an option, though.

--
www.designacourse.com
The Easiest Way to Train Anyone... Anywhere.

Chris Smith - Lead Software Developer/Technical Trainer
MindIQ Corporation
 
R

Roedy Green

Point taken, but in fact its the oppersite for my need - the results
don't have to be 100 percent accurate, so as long as the results are
the same. I don't want the 2 JVM's to go out of sync - I don't really
want to resort to re-sync'ing the results all the time.

If you do have to resync, look into Rsync or my own product the
Replicator to automatically keep a set of files in sync with the
master copy.

See http://mindprod.com/jgloss/rsync.html
http://mindprod.com/zips/java/replicator.html
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,579
Members
45,053
Latest member
BrodieSola

Latest Threads

Top