Sign in to follow this  
Followers 0
SigFLUP

standard for checking to see how many cpus are on a host?

3 posts in this topic

Is there a standard way for your program to check to see how many cpus are on a host?

I know openbsd has hw.ncpu in the sys variables. On linux is there a better way then to look at /proc/cpuinfo? Is there any standard way to do this on unixes?

thanks mates

0

Share this post


Link to post
Share on other sites

There is no standard way to determine the number of CPUs on a system. Instead, the manual way is preferred. For example, the make command has a -j switch, to specify the number of jobs. You should leave the number of worker threads up to the user, not the system.

If you really want to though, all you need to do is put all the methods together in a C file (or whatever language you're using) and protect them all with #ifdef preprocessor statements. That way, the right one will magically appear in your source code when you compile it on each platform.

0

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0