Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Java > Calculation on different JVMs = same?

Reply
Thread Tools

Calculation on different JVMs = same?

 
 
Wayne
Guest
Posts: n/a
 
      10-09-2003
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
 
Reply With Quote
 
 
 
 
Daniel Schneller
Guest
Posts: n/a
 
      10-09-2003
Hi!

> Is this a propblem of JVM, my code,
> or the laws of calsulty???


Might be easier to tell if we saw some code...

Daniel

 
Reply With Quote
 
 
 
 
Jon Skeet
Guest
Posts: n/a
 
      10-09-2003
Wayne <(E-Mail Removed)> wrote:
> 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.

--
Jon Skeet - <(E-Mail Removed)>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too
 
Reply With Quote
 
John C. Bollinger
Guest
Posts: n/a
 
      10-09-2003
Jon Skeet wrote:

> Wayne <(E-Mail Removed)> wrote:
>
>>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.


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
http://www.velocityreviews.com/forums/(E-Mail Removed)

 
Reply With Quote
 
Wayne
Guest
Posts: n/a
 
      10-10-2003
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?




"John C. Bollinger" <(E-Mail Removed)> wrote in message news:<bm48la$d5h$(E-Mail Removed)>...
> Jon Skeet wrote:
>
> > Wayne <(E-Mail Removed)> wrote:
> >
> >>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.

>
> 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 Removed)

 
Reply With Quote
 
Michael Borgwardt
Guest
Posts: n/a
 
      10-10-2003
Wayne wrote:
> 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.

 
Reply With Quote
 
Wayne
Guest
Posts: n/a
 
      10-10-2003
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.

Michael Borgwardt <(E-Mail Removed)> wrote in message news:<bm5uko$iuotv$(E-Mail Removed)-berlin.de>...
> Wayne wrote:
> > 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.

 
Reply With Quote
 
Chris Smith
Guest
Posts: n/a
 
      10-10-2003
Wayne wrote:
> 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
 
Reply With Quote
 
Roedy Green
Guest
Posts: n/a
 
      10-10-2003
On 10 Oct 2003 10:05:35 -0700, (E-Mail Removed) (Wayne) wrote or
quoted :

>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

--
Canadian Mind Products, Roedy Green.
Coaching, problem solving, economical contract programming.
See http://mindprod.com/jgloss/jgloss.html for The Java Glossary.
 
Reply With Quote
 
 
 
Reply

Thread Tools

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 Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
running different plugins within a java application in different JVMs [urgent need of help] dima.alina@gmail.com Java 2 03-13-2006 06:39 PM
running different plugins within a java application in different JVMs [urgent need of help] dima.alina@gmail.com Java 3 03-09-2006 01:34 PM
running different plugins within a java application in different JVMs [urgent need of help] dima.alina@gmail.com Java 3 02-23-2006 01:07 PM
running different plugins within a java application in different JVMs dima.alina@gmail.com Java 0 02-22-2006 08:28 AM
Communication between Java applications running on different JVMs laura.paterson@gmail.com Java 1 01-05-2005 12:25 PM



Advertisments