[英]Adjusting the affinity of an process for high core counts
我想調整我的程序的親和性,但是核心數很高
有沒有辦法可以通過 PowerShell 代碼在應用程序上設置所有內核?
核心數是64個,有時候我們用112個核心。
這是我的代碼
PowerShell "$Process = Get-Process -Id 6048; $Process.ProcessorAffinity=All"
我搜索了整個谷歌,但找不到任何使用所有內核的代碼。
注意:我無法親自驗證以下是否有效。
.ProcessorAffinity
是作為System.IntPtr
值實現的位掩碼。
但是,位掩碼必須僅包含實際可用內核的位,因此不能使用[IntPtr]::MaxValue
。
假設有112
可用內核,您需要提供一個位掩碼,將可用內核范圍內的所有可能位設置為1
,您可以按如下方式計算:
$allCores =
[Math]::Pow(
2,
[Math]::Ceiling([Math]::Log2(112))
) - 1
(Get-Process -Id 6048).ProcessorAffinity = $allCores
翻譯成powershell.exe
從PowerShell外部調用:
powershell.exe "(Get-Process -Id 6048).ProcessorAffinity = [Math]::Pow(2, [Math]::Ceiling([Math]::Log2(112))) - 1"
注意:如果您想以編程方式確定可用(邏輯)內核的數量,請使用:
$totalLogicalCores = (
(Get-CimInstance –ClassName Win32_Processor).NumberOfLogicalProcessors |
Measure-Object -Sum
).Sum
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.