Box2D Forums

It is currently Tue Sep 02, 2014 11:57 pm

All times are UTC - 8 hours [ DST ]




Post new topic Reply to topic  [ 23 posts ]  Go to page Previous  1, 2, 3  Next
Author Message
PostPosted: Sun Jun 12, 2011 6:48 pm 
Offline

Joined: Wed Jan 06, 2010 4:57 pm
Posts: 12
Hi all.

Me and my friend are developing a network game, and are very interested in this topic. So we made some tests.

By initializing only the random number generator or by only adding strictfp to every class, isn't enough to supply determinism.

But by using both, we achieved consistent results on the same machine, os and virtual machine.
At first, we were very happy.

So, for example, running two times the DominoTest provided in the Jbox2D testBed project, gave the same position and angle of every body for at least (we didn't check further) 500 steps on a Windows 7 64 bit running a 64bit sun's jvm.

But then we ran the same test on the 32 bit jvm and lost consistency with the output of the 64bit vm after the first 100 steps (certainly earlier since it was our first check).

We also ran tests on a linux 32bit distribution and 32bit jvm, but the results differed from both of the window's ones.

It seems that providing determinism is fairly easy on the same platform, but impossible when even a slight variation is made in the configuration. We would be very grateful to anyone who could spot an evident bias in our tests or provide further information on the matter.

Cheers!

[Edit]
Actually it was the DominoTower test.


Top
 Profile  
 
PostPosted: Mon Jun 13, 2011 7:52 pm 
Offline

Joined: Wed Jan 06, 2010 4:57 pm
Posts: 12
Ok sorry everybody, we eventually achieved determinism, we were setting up the test wrong!

Wish there was a simpler method to render JBox2D deterministic, without having to modify its classes manually.
Anyway, this characteristic should definitively be much more advertised.


Top
 Profile  
 
PostPosted: Mon Jun 13, 2011 11:41 pm 
Offline

Joined: Tue Jun 24, 2008 8:25 pm
Posts: 1935
Location: Tokyo
Could you let us know what cases you got working? Linux/win, 32/64 etc


Top
 Profile  
 
PostPosted: Tue Jun 28, 2011 7:56 am 
Offline

Joined: Tue Jun 28, 2011 6:56 am
Posts: 20
hi,
Francesco has tested with me, so here what we get:
the test has been done on a win 7 64bit intel laptop, 32bit ubuntu laptop, 32bit (but 64bit cpu) arch linux desktop, an eeepc with celeron ~800MHz and arch linux 32bit.
All SUN JVM, no openJDK tested. JVM architecture was the same of the SO, so actually we can say Jbox2D IS deterministic, at least more than 1000 tick of DominoTower test.

Now another friend of mine gift me an very old mac ( Power Macintosh G4 867 (Quicksilver) ) and i'm going to resurrect it and then test it.

Ah the error in the test was that we "strictfp"ed all jbox2d engine, but not the test class where the body was created and translated :mrgreen:
we found this out starting from the fact that the simulation was diverging since turn 0 (only creation, no update). Also probably there was an error in the recording "trigger"..

1. strictfp all jbox engine class
2. in DinamicTree, MathTest e MathUtils, change all "new Random()" to "new Random(5)" (it's important it's 5 if you want test against my file)
3. ypu shoul make the org.jbox2d.testbed.tests.DominoTower strictfp
4. add this function to TestbedTest:
Code:
public int getStepCount(){
    return m_stepCount;
}

5. in TestPanel, run method, after
Code:
render();
            update();
            paintScreen();
            frameCount++;

put:
Code:
if (currTest!=null && currTest.getStepCount()%100==0) {
                stepMondoFisico++;
                Body body = currTest.m_world.getBodyList();
                File file = new File("Unknow Test "+fileCount+".txt");
                System.out.println("Saving file...");
                FileWriter writer = null;
                try {
                    writer = new FileWriter(file);
                } catch (IOException ex) {
                    Logger.getLogger(TestPanel.class.getName()).log(Level.SEVERE, null, ex);
                }
                while (body != null) {
                    try {                       
                        writer.append("X " +Float.toHexString( body.getPosition().x ) );
                        writer.append(" Y "+Float.toHexString( body.getPosition().y) );
                        writer.append(" A "+Float.toHexString( body.getAngle() )+"\n");
                    } catch (IOException ex) {
                        Logger.getLogger(TestPanel.class.getName()).log(Level.SEVERE, null, ex);
                    }
                    body = body.getNext();
                }
                try {
                    writer.close();
                } catch (IOException ex) {
                    Logger.getLogger(TestPanel.class.getName()).log(Level.SEVERE, null, ex);
                }
                System.out.println("Should have wrote "+currTest.m_world.getBodyCount()+" bodies");
                System.out.println("File saved as: "+file.getAbsolutePath());
                fileCount++;
            }


test the results of the 10000 turn (file number 100).. it should be equal for everyone!


Attachments:
File comment: here our 10000° turn..
Another test linux32bit 10.txt [45.05 KiB]
Downloaded 124 times
Top
 Profile  
 
PostPosted: Sun Jul 10, 2011 7:32 pm 
Offline

Joined: Mon May 11, 2009 9:57 am
Posts: 17
Strictfp shouldn't be necessary, at least from what I've found. Did you try this yet?

viewtopic.php?p=31266#p31266


Top
 Profile  
 
PostPosted: Mon Jul 11, 2011 7:26 am 
Offline

Joined: Tue Jun 28, 2011 6:56 am
Posts: 20
have you tested different operative system and different machine? or you are talking only about the same machine?

and if you're talking just about random, it has to be done but is not enough.(look my previous post, point 2).


Top
 Profile  
 
PostPosted: Mon Jul 11, 2011 8:01 pm 
Offline

Joined: Mon Jun 08, 2009 12:21 pm
Posts: 355
In case you guys didn't see, the new update fixes the use of Random. Sorry about that.


Top
 Profile  
 
PostPosted: Thu Jul 14, 2011 11:25 pm 
Offline

Joined: Mon May 11, 2009 9:57 am
Posts: 17
Awesome man, thanks!


Top
 Profile  
 
PostPosted: Tue Nov 01, 2011 10:38 am 
Offline

Joined: Tue Jun 28, 2011 6:56 am
Posts: 20
ok, i'm checking out the repository and adding stricftp to all library classes and trying to get determinism over network.

see you later :)

edit: toucasan are you sure about the use of Math.random()? I'm not sure it's deterministic, also if it is, it's determinism can be break if thread or other class use it in the application.
I think you should use a "new Random()" for every class, so we will be sure about the generated numner, even if your application is running two or more word instance.


Top
 Profile  
 
PostPosted: Wed Nov 02, 2011 12:45 am 
Offline

Joined: Mon Jun 08, 2009 12:21 pm
Posts: 355
well first of all, using 'new Random()' for every class could cause problems because they might get the same time seed and then generate the same sequence of random numbers Also, to make things deterministic with Random, you would use one random object and give it a common seed. Secondly, there is no use of random numbers anywhere in the engine, those methods are only used by the testbed ;)


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 23 posts ]  Go to page Previous  1, 2, 3  Next

All times are UTC - 8 hours [ DST ]


Who is online

Users browsing this forum: No registered users and 1 guest


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Powered by phpBB® Forum Software © phpBB Group