Java-Gaming.org Hi !
Featured games (83)
games approved by the League of Dukes
Games in Showcase (517)
Games in Android Showcase (123)
games submitted by our members
Games in WIP (577)
games currently in development
News: Read the Java Gaming Resources, or peek at the official Java tutorials
 
    Home     Help   Search   Login   Register   
Pages: [1]
  ignore  |  Print  
  Find out how many CPUs a system has  (Read 1833 times)
0 Members and 1 Guest are viewing this topic.
Offline NativeOne

Senior Newbie




Java games rock!


« Posted 2004-01-10 04:27:33 »

In my application I need to find out how many processors the host system has, in order to start an appropriate numer of threads (in my case numberOfThreads = numberOfCPUs). Is there a standard means of achieving this in Java? If not, can anyone please give me a hint how to do this platform-independantly with JNI... (I never used native code, so please explain this in a fool-proof manner) Thanks a lot!
Offline Mark Thornton

Senior Duke





« Reply #1 - Posted 2004-01-10 10:30:08 »

java.lang.Runtime.availableProcessors()

added in 1.4
Offline NativeOne

Senior Newbie




Java games rock!


« Reply #2 - Posted 2004-01-10 13:48:39 »

Thanks, that will be optimal. Strange they added this functionality so late...

An other question comes to my mind. What about this new hyperthreading technology of intels P4 (I read of a 25% performance increase): will a multithreaded java application benefit from it? If that's true, I should use the parallel algorithm with two threads even on a single processor system, hmm... how to detect a hyperthreading processor?
Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline Mark Thornton

Senior Duke





« Reply #3 - Posted 2004-01-10 14:14:35 »

In my own tests I get a gain from HT nearer 10% --- not enough to be worth worrying about. Possibly because my machine is a 3.06GHz model with only the 533FSB. Allegedly the 800MHz FSB machines show greater benefits from HT. Even so it still looks more like a marketing feature than something of significant value.

I think a HT processor (with it enabled) will show as having 2 processors available. You could run two threads in parallel and see if the elapsed time looks like the result of a genuine dual or a HT processor.
Offline swpalmer

JGO Coder


Exp: 12 years


Where's the Kaboom?


« Reply #4 - Posted 2004-01-11 17:41:08 »

FYI: With my company's non-java stuff (media encoding applications and device drivers) we found hyperthreading caused problems.  Some systems only worked with hyperthreading off.  The code works fine on traditional multi-processor systems.

Offline Jeff

JGO Coder




Got any cats?


« Reply #5 - Posted 2004-01-12 07:29:35 »

Our general opinion around Sun, which you can buy or not, is that Intel's so called "HT" is a cheap and cheesy attempt to respond to sun's Sparc CMT  (On-Chip Multi-Tasking), except its not nearly as functional or useful.

Smiley


Got a question about Java and game programming?  Just new to the Java Game Development Community?  Try my FAQ.  Its likely you'll learn something!

http://wiki.java.net/bin/view/Games/JeffFAQ
Offline cfmdobbie

Senior Duke


Medals: 1


Who, me?


« Reply #6 - Posted 2004-02-02 12:56:32 »

Jeff, I think Intel has proven that the cheap-and-cheerful approach often wins out over precise-but-expensive!

I had a co-worker once who owned a number of very high-quality 2400 baud modems - he complained that today's tacky modems were unreliable.  It seemed rude to point out how many times a 56K can resend any duff data while the 2400 sends the message just once.

But yeah, I personally wouldn't bother optimising Java code to take better advantage of HT.  May as well go back to hand-tuned assembly...

Hellomynameis Charlie Dobbie.
Offline blahblahblahh

JGO Coder


Medals: 1


http://t-machine.org


« Reply #7 - Posted 2004-02-02 15:28:24 »

Quote
Our general opinion around Sun, which you can buy or not, is that Intel's so called "HT" is a cheap and cheesy attempt to respond to sun's Sparc CMT  (On-Chip Multi-Tasking), except its not nearly as functional or useful.

Smiley



Who got DEC's work on this, in the end? I guess Intel (?), but maybe  HPaq managed to hang onto it...? I vaguely recall that the DEC design had good potential, but from what little (nb: very little) I've seen of Intel's current impl, I'd agree it doesn't seem much good.

OTOH, AFAICS Intel still has major problems with the fact that they  don't have a 32-bit multiprocessor architecture (...until they get with the program and start using crossbar switches or some equivalent...), so perhaps HT / MT / HPT (whatever you want to call it Wink) will prove a way out that doesn't involve 128Mb cache on each CPU just to keep it busy...Wink

malloc will be first against the wall when the revolution comes...
Offline Jeff

JGO Coder




Got any cats?


« Reply #8 - Posted 2004-02-02 22:41:45 »

Quote
Jeff, I think Intel has proven that the cheap-and-cheerful approach often wins out over precise-but-expensive!..


But not if all youa re "buying' is a name with no real advantage in the hadrware. AIUI this is HT. 99% hype, tiny bit of functionality that a really clever assmebly coder might be able to make some use out of in just the right situations.

Again though I'm NOT a processor expert.  This is just my general imrpession from tlaking to flks who are.


Got a question about Java and game programming?  Just new to the Java Game Development Community?  Try my FAQ.  Its likely you'll learn something!

http://wiki.java.net/bin/view/Games/JeffFAQ
Offline princec

JGO Kernel


Medals: 409
Projects: 3
Exp: 16 years


Eh? Who? What? ... Me?


« Reply #9 - Posted 2004-02-03 06:46:13 »

Quote
...really clever assmebly coder might be able to make some use out of in just the right situations...

That would be, uh, a JVM engineer then? Wink

Cas Smiley

Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline ChrisRijk

Senior Newbie




Optimise or Die


« Reply #10 - Posted 2004-02-04 15:10:13 »

One thing I have noticed with Hyperthreading is that comparing on a multiprocessor system, the time taken to compile byte-codes is much faster (like 10x faster). Of course, you can just put on -Xbatch and then HotSpot's compiler runs in the foreground, which is more efficient. Basically, if the main thread is on 1 CPU and HotSpot is on the 2nd, then the communication overhead between the threads slows the optimisation down a bit. With Hyperthreading, the optimiser runs on the same CPU as the main thread, so is more efficient.

How much effect Hyperthreading has is highly dependant on your benchmark - with some server benchmarks, a 50% boost is possible, but this is rare.

btw, the latest Pentium 4 (Prescott) has a much longer pipeline making it even less suitable for server work, or more complex code in general. If you want a good development or runtime platform for Java, I'd suggest getting an Opteron or Athlon 64.


If you want more of an introduction to multi-core chip designs (like what Sun is working on), then read my recent article Azn
http://www.aceshardware.com/read.jsp?id=60000312
Pages: [1]
  ignore  |  Print  
 
 
You cannot reply to this message, because it is very, very old.

 

Add your game by posting it in the WIP section,
or publish it in Showcase.

The first screenshot will be displayed as a thumbnail.

TehJavaDev (38 views)
2014-10-27 03:28:38

TehJavaDev (29 views)
2014-10-27 03:27:51

DarkCart (43 views)
2014-10-26 19:37:11

Luminem (24 views)
2014-10-26 10:17:50

Luminem (29 views)
2014-10-26 10:14:04

theagentd (35 views)
2014-10-25 15:46:29

Longarmx (63 views)
2014-10-17 03:59:02

Norakomi (61 views)
2014-10-16 15:22:06

Norakomi (50 views)
2014-10-16 15:20:20

lcass (46 views)
2014-10-15 16:18:58
Understanding relations between setOrigin, setScale and setPosition in libGdx
by mbabuskov
2014-10-09 22:35:00

Definite guide to supporting multiple device resolutions on Android (2014)
by mbabuskov
2014-10-02 22:36:02

List of Learning Resources
by Longor1996
2014-08-16 10:40:00

List of Learning Resources
by SilverTiger
2014-08-05 19:33:27

Resources for WIP games
by CogWheelz
2014-08-01 16:20:17

Resources for WIP games
by CogWheelz
2014-08-01 16:19:50

List of Learning Resources
by SilverTiger
2014-07-31 16:29:50

List of Learning Resources
by SilverTiger
2014-07-31 16:26:06
java-gaming.org is not responsible for the content posted by its members, including references to external websites, and other references that may or may not have a relation with our primarily gaming and game production oriented community. inquiries and complaints can be sent via email to the info‑account of the company managing the website of java‑gaming.org
Powered by MySQL Powered by PHP Powered by SMF 1.1.18 | SMF © 2013, Simple Machines | Managed by Enhanced Four Valid XHTML 1.0! Valid CSS!