如何确定 PC 的 CPU 核心数?

发布于 2024-09-17 08:21:35 字数 69 浏览 3 评论 0原文

如何确定使用代码的 PC 的 CPU 核心数?有没有办法在SAS中做到这一点。我想确定核心数量,然后设置应该运行多少个线程。

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 the number of cores and then set how many threads I should run.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

断桥再见 2024-09-24 08:21:35

在 SAS 中:

%put &sysncpu;

在 java 中:

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

在 C# 中:

System.Environment.ProcessorCount

但这些只是操作系统设置的环境变量,可以通过编程进行修改。不知道能否真正获得真实的硬件信息。

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.

萌吟 2024-09-24 08:21:35

有一个名为 SYSNCPU 的自动宏变量,可以为您提供 CPU 的数量;不确定这是否是您想要的人物?

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?

魂牵梦绕锁你心扉 2024-09-24 08:21:35

Delphi

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

转码为 C# 风格的伪语言:

int NumberProcessors()
{
   SYSTEM_INFO systemInfo;

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

注意:发布到公共领域的任何代码。无需归属。

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.

知足的幸福 2024-09-24 08:21:35

此代码将告诉您,在您的 SAS 版本的 CPUCOUNT= 限制范围内。示例文档 https://documentation.sas.com /doc/en/pgmsascdc/9.4_3.5/lesysoptsref/p14arc7flhenwqn1v1gipt9e49om.htm

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

...CPUCOUNT=8 指定启用线程的应用程序应假定可用于并发处理的处理器数量...

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....

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文