Quantcast
Channel: Scripting - McNeel Forum
Viewing all articles
Browse latest Browse all 5873

How to get number of cores in Python script

$
0
0

@Terry_Chappell wrote:

I am using tasks.Parallel.ForEach(pieces, helper) that I copied from the Grasshopper parallel.py code to speed up Python when processing a mesh with 2.2M vertices. In order to minimize thread overhead, I divide the data into n pieces where n is the number of threads on my computer. But n is not fixed since I use my laptop (n = 8) when traveling, like now in NYC, and my tower computer (n = 36) when at home in Portland, OR.

My question is, how do I get the number of cores or threads from within a Python script?

I tried:
import os
print os.sysconf(“SC_NPROCESSORS_ONLN”)
but sysconf is not recognized.

I tried:
import multiprocessing
print ‘count =’, multiprocessing.cpu_count()
but import does not find multiprocessing.

I know Holomark shows the number of threads in its summary, but I have not located its source code in order to discover how it obtains this information.

Thanks in advance for your help.
Regards,
Terry.

Posts: 5

Participants: 3

Read full topic


Viewing all articles
Browse latest Browse all 5873

Trending Articles