Calculation on different JVMs = same?

Discussion in 'Java' started by Wayne, Oct 9, 2003.

  1. Wayne

    Wayne Guest

    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
    Wayne, Oct 9, 2003
    #1
    1. Advertising

  2. 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
    Daniel Schneller, Oct 9, 2003
    #2
    1. Advertising

  3. Wayne

    Jon Skeet Guest

    Wayne <> 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 - <>
    http://www.pobox.com/~skeet
    If replying to the group, please do not mail me too
    Jon Skeet, Oct 9, 2003
    #3
  4. Jon Skeet wrote:

    > Wayne <> 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
    John C. Bollinger, Oct 9, 2003
    #4
  5. Wayne

    Wayne Guest

    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" <> wrote in message news:<bm48la$d5h$>...
    > Jon Skeet wrote:
    >
    > > Wayne <> 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
    >
    Wayne, Oct 10, 2003
    #5
  6. 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.
    Michael Borgwardt, Oct 10, 2003
    #6
  7. Wayne

    Wayne Guest

    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 <> wrote in message news:<bm5uko$iuotv$-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.
    Wayne, Oct 10, 2003
    #7
  8. Wayne

    Chris Smith Guest

    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
    Chris Smith, Oct 10, 2003
    #8
  9. Wayne

    Roedy Green Guest

    On 10 Oct 2003 10:05:35 -0700, (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.
    Roedy Green, Oct 10, 2003
    #9
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.

Share This Page