开发者

How do I determine the number of CPU cores the PC has?

How do I determine the number of CPU cores the PC using code? Is there a way to do it in SAS. I want to determine 开发者_StackOverflowthe number of cores and then set how many threads I should run.


In SAS:

%put &sysncpu;

In java one would do:

Runtime runtime = Runtime.getRuntime();
int nrOfProcessors = runtime.availableProcessors();

In C#:

System.Environment.ProcessorCount

But these are just environment variables which are set by the operating system and can probably be modified through programming. I don't know if you can actually get real hardware information.


There is an automatic macro variable called SYSNCPU that gives you the number of CPUs; not sure if this is the figure you're after?


Delphi:

function TSpinLockPerProcReaderWriterLock.NumberProcessors: Integer;
var
    systemInfo: SYSTEM_INFO;
begin
    GetSystemInfo({var}systemInfo);
    Result := systemInfo.dwNumberOfProcessors;
end;   

Transcoded into a C# style pseudo-language:

int NumberProcessors()
{
   SYSTEM_INFO systemInfo;

   GetSystemInfo(ref systemInfo);
   return systemInfo.dwNumberOfProcessors;
}

Note: Any code released into public domain. No attribution required.


This code will tell you, within the constraints of CPUCOUNT= for your version of SAS. Example documentation https://documentation.sas.com/doc/en/pgmsascdc/9.4_3.5/lesysoptsref/p14arc7flhenwqn1v1gipt9e49om.htm

OPTION CPUCOUNT=ACTUAL;
PROC OPTIONS GROUP=PERFORMANCE;
RUN;

...CPUCOUNT=8 Specifies the number of processors that thread-enabled applications should assume are available for concurrent processing....

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜