[ENHANCEMENT] Provide CPU information/control

BlitzMax Forums/BlitzMax Programming/[ENHANCEMENT] Provide CPU information/control

Brazilian Joe(Posted 2009) [#1]
This is most important for threaded apps.
Getting information such as number of CPU cores, model, speed, features etc.

Especially the number of CPU cores is important for threaded apps, in case we want to have paralellizable apps distributed on every core. Say, for example, I develop a threaded homegrown physics library for a game. I will want to set up one thread per core, to maximize performance.


plash(Posted 2009) [#2]
Is this a request (probably doesn't belong here), a bug report (I don't see any bugs..), or a rambling?


Brucey(Posted 2009) [#3]
My custom BMK contains code for counting cores.... FYI.


Brazilian Joe(Posted 2009) [#4]
I posted on the bug reports, as I thought the BlitzMax devs would be more likely to read it... but they moved it here.

Brucey: Which of your modules provides it? I haven't seen a reference to it on your list.
Are they cross-platform? I intend my code to run on Windows, Mac OS X and Linux.


plash(Posted 2009) [#5]
Which of your modules provides it? I haven't seen a reference to it on your list.
Brucey said "My custom BMK contains code for counting cores.... FYI."

I believe that means the code is in his custom BMK, not a module.


Arowx(Posted 2009) [#6]
Leadworks did it here using GetSystemInfo


Brazilian Joe(Posted 2009) [#7]
OK, I got my hands just a little bit dirty and found out the following:

We already have Leadwerk's Win32 solution.

I don't have a complete solution, but I found out how to generate the information:

On Linux, I found it easy to adapt the code in a complete BlitzMax solution:



For Mac OS X, so far I got the following C code:



I played with the code I found a bit, and made the above commmand line app.
Which I lack the expertise to integrate with BlitzMax, but from what I see on the modules sources, it's doable.

For completeness, I will copy-paste the excerpt from Leadwerks' makedds code:



I think that, while it will be good if those system-specific cpu counter functions get integrated (I believe in the System package), if it becomes available as a separate module for the time being, so that people who are not willing to muck up with the core modules can already have access to it. Can anyone step up to the task, or at least point me the way on how to do it? My hurdle currently is finding out a way to access the C code from BlitzMax.

Help is much appreciated!


markcw(Posted 2009) [#8]
The "C for Blitzers" tutorial by Otus (which you can get here http://www.blitzmax.com/logs/userlog.php?user=8652&log=1737) should get you going.


Brucey(Posted 2009) [#9]
FYI, your Linux code gives me an answer of 2 on my system. I have 4 cores.


Brazilian Joe(Posted 2009) [#10]
@Brucey:

Hmmm, since I have only 2 cores, I assumed the returned string is n-n-n-n-n, with one number for each core.
looks like returned cpu string is actually 0-(n-1), where n is the number of cores. It's a conjecture though.
try this version:




Brucey(Posted 2009) [#11]
From previously mentioned BMK source :

Works on all three platforms.


Grisu(Posted 2009) [#12]
Thanks for sharing Brucey.
Works fine: 8 (virtual) cores detected.

P.S. I sense a multicore version of PRP in the future... called "Multi Pocket Radio Player" 8)


Brazilian Joe(Posted 2009) [#13]
Great!

I got myself around to make this solution:

http://www.blitzmax.com/codearcs/codearcs.php?code=2526

But yours work too, and is better, because it does not need 2 source files - mine needs a C code for Mac.

I think the Linux would be more 'cuspy' accessing the single file inside /sys, instead of piping 2 command line outputs.

@Brucey,Grisu: have you tested the 2nd Linux code (Comment #10) I posted? Does it report the correct value?