473,763 Members | 4,584 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

How can I check nbr of cores of computer?

How can I check how many cores my computer has?
Is it possible to do this in a Python-app?
Jul 29 '08 #1
9 7347
gbs
On Tue, 29 Jul 2008 15:53:47 -0700, defn noob wrote:
How can I check how many cores my computer has? Is it possible to do
this in a Python-app?
Well you can try the functions in the 'platform' module, although in my
box(debian) nothing useful comes out. I don't think there's a simple &
portable way, you probably have to find one specific to your platform .
(if you are on linux, you can parse the output of 'cat /proc/cpuinfo')

Jul 30 '08 #2
On Jul 29, 5:53*pm, defn noob <circularf...@y ahoo.sewrote:
How can I check how many cores my computer has?
Is it possible to do this in a Python-app?
If you're using Windows, get PyWin32:

win32api.GetSys temInfo
tuple = GetSystemInfo()

Retrieves information about the current system.

Win32 API References

Search for GetSystemInfo at msdn, google or google groups.

Return Value
The return value is a tuple of 9 values,
which corresponds to the Win32 SYSTEM_INFO structure.
The element names are:
dwOemId
dwPageSize
lpMinimumApplic ationAddress
lpMaximumApplic ationAddress
dwActiveProcess orMask
dwNumberOfProce ssors
dwProcessorType
dwAllocationGra nularity
(wProcessorLeve l,wProcessorRev ision)

>>import win32api
win32api.GetS ystemInfo()
(0, 4096, 65536, 2147418111, 3L, 2, 586, 65536, (6, 3846))
|
processors

Jul 30 '08 #3
On Jul 29, 7:44*pm, Mensanator <mensana...@aol .comwrote:
On Jul 29, 5:53*pm, defn noob <circularf...@y ahoo.sewrote:
How can I check how many cores my computer has?
Is it possible to do this in a Python-app?

If you're using Windows, get PyWin32:

win32api.GetSys temInfo
tuple = GetSystemInfo()

Retrieves information about the current system.

Win32 API References

Search for GetSystemInfo at msdn, google or google groups.

Return Value
The return value is a tuple of 9 values,
which corresponds to the Win32 SYSTEM_INFO structure.
The element names are:
dwOemId
dwPageSize
lpMinimumApplic ationAddress
lpMaximumApplic ationAddress
dwActiveProcess orMask
dwNumberOfProce ssors
dwProcessorType
dwAllocationGra nularity
(wProcessorLeve l,wProcessorRev ision)
>import win32api
win32api.GetSy stemInfo()

(0, 4096, 65536, 2147418111, 3L, 2, 586, 65536, (6, 3846))
* * * * * * * * * * * * * * * * *|
* * * * * * * * * * * * * * * * *processors
This: http://pyprocessing.berlios.de/ has a method that returns CPU
count.
Jul 30 '08 #4
defn noob wrote:
How can I check how many cores my computer has?
Is it possible to do this in a Python-app?
Why do you care? Python can't use more than one of them at
a time anyway.

John Nagle
Jul 30 '08 #5
On Wed, Jul 30, 2008 at 2:22 PM, John Nagle <na***@animats. comwrote:
defn noob wrote:
>>
How can I check how many cores my computer has?
Is it possible to do this in a Python-app?

Why do you care? Python can't use more than one of them at
a time anyway.
Per Python process, but you might fork multiple processes and want to
know how many cores there are to know how many to fork, and which
cores to pin them to. (I don't know if there's a direct way in Python
to force it to a certain core, so I instead just wrote an extension to
interface with sched_setaffini ty on Linux.)

On Linux, an almost assuredly non-ideal way to find out the number of
cores is to read /proc/cpuinfo and look for the highest-numbered
"processor: " line (and add 1).
Jul 30 '08 #6
defn noob schrieb:
How can I check how many cores my computer has?
Is it possible to do this in a Python-app?
processing (http://pyprocessing.berlios.de/)
has an utility function processing.cpuC ount().

Leo
Jul 30 '08 #7
Single line using /proc/cpuinfo:

numprocs = [ int(line.strip( )[-1]) for line in open('/proc/cpuinfo', 'r') if \
line.startswith ('processor') ][-1] + 1
On Wed, Jul 30, 2008 at 2:16 PM, Dan Upton <up***@virginia .eduwrote:
>
On Wed, Jul 30, 2008 at 2:22 PM, John Nagle <na***@animats. comwrote:
defn noob wrote:
>
How can I check how many cores my computer has?
Is it possible to do this in a Python-app?
Why do you care? Python can't use more than one of them at
a time anyway.

Per Python process, but you might fork multiple processes and want to
know how many cores there are to know how many to fork, and which
cores to pin them to. (I don't know if there's a direct way in Python
to force it to a certain core, so I instead just wrote an extension to
interface with sched_setaffini ty on Linux.)

On Linux, an almost assuredly non-ideal way to find out the number of
cores is to read /proc/cpuinfo and look for the highest-numbered
"processor: " line (and add 1).
--
http://mail.python.org/mailman/listinfo/python-list
Jul 30 '08 #8
On Wed, 30 Jul 2008 11:22:12 -0700, John Nagle wrote:
defn noob wrote:
>How can I check how many cores my computer has? Is it possible to do
this in a Python-app?

Why do you care? Python can't use more than one of them at
a time anyway.
Why do you care why he cares? And he didn't ask how to *use* multiple
cores, but how to detect if they're there.

Maybe all he wants is to write a toy program that outputs "Hello Fred,
your computer has N cores in the CPU. Have a nice day!".

I don't expect that Python will have a built-in core-counting function.
You would probably need to ask the operating system. On Linux, you could
do this:

import os
text = os.popen('cat /proc/cpuinfo').read( )
How you would do it in Windows or Mac, I have no idea.

--
Steven
Jul 31 '08 #9
Steven D'Aprano <st***@REMOVE-THIS-cybersource.com .auwrote:
I don't expect that Python will have a built-in core-counting function.
You would probably need to ask the operating system. On Linux, you could
do this:

import os
text = os.popen('cat /proc/cpuinfo').read( )
How you would do it in Windows or Mac, I have no idea.
One way on windows:
>>import win32pdhutil
def howmanycores():
for i in range(9999):
try: win32pdhutil.Ge tPerformanceAtt ributes("Proces sor(%d)" % i,"%
Processor Time")
except: break
return i
>>print howmanycores()
2

--
Duncan Booth http://kupuguy.blogspot.com
Jul 31 '08 #10

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

27
7126
by: mrbog | last post by:
Tell me if my assertion is wrong here: The only way to prevent session hijacking is to NEVER store authentication information (such as name/password) in the session. Well, to never authenticate a user from information you got from the session. Each secure app on a site must challenge the user for name and password, each and every time the user accesses it (not just once and then store it in the session). If a secure app is multi-page,...
4
11040
by: Jared | last post by:
Radio Button or Check Box and Event Procedures I need to insert either radio buttons or check boxes onto my form. I'm not sure which to use, or if there are other options. I am using the buttons to: if one is clicked, its corresponding information will become available on another document, if it's not clicked no information will be provided. If multiple buttons are clicked their information will available on the same document. I'm not...
0
952
by: Stephen | last post by:
Hi, I am trying to copy files from one computer to another, the problem I am facing is that the program chokes when the other computer is not available (shut down/off the n/w). is there any way programmatically that i check whether the other computer is available? Thanks, Stephen
5
1948
by: Coaster | last post by:
I am designing a process which will spawn a good number of threads and some of them will execute a c++ process which is quite memory intensive (although not multithreaded). This will run on a 2 cpu (both dual core) server. What do I need to do if anything in order to spread the workload across the cpu's / cores in order to tune it properly? I googled it and found this post but its somewhat dated and didn't know if it applied to 2.0
2
6192
by: Jekyll | last post by:
hi, I have two questions, 1/ is there any OS function which return me the number of core on each processor on my computer (callable from C++) 2/ is there any OS function which return me the number of processor on my computer (callable from C++) By OS I mean Windows (XP and later), Linux, Solaris... Thanks XS
3
3884
by: Akash | last post by:
Hi, I am using getProcessTimes API for calculating CPU Usage On a Multi-Core processor i have observed that the %CPU Usage that is multiple of the number of cores of the processor Is there any API in VC to find the number of Cores of a processor? (PS: Without using WMI ie) url:http://www.ureader.com/gp/1452-1.aspx
5
2009
by: whisk3rs | last post by:
Hello, I have a conceptual question. I need to write a program that will take as input a list of images and then process each image individually (extract useful features from the image) Processing each image takes about 20 seconds, and I would like to utilize all available cores / CPUs on a machine to do processing in parallel - for simplicity, I think it'd be easier for now to have each core process an individual image (rather than have...
1
1360
by: Jon Harrop | last post by:
I'd like to measure performance results as a function of the number of cores by restricting parallel FX to using only a subset of my cores. Is this possible and, if so, how? -- Dr Jon D Harrop, Flying Frog Consultancy http://www.ffconsultancy.com/products/?u
9
1339
by: Carl Johansson | last post by:
If a multithreaded .NET application is executed on a computer with a multicore processor. Will the application automatically run the threads on different processor cores? Regards Carl Johansson
0
9386
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10144
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
9997
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
8821
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7366
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5270
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5405
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3917
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
3
3522
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.