你已经派生过 gprMax
镜像自地址
https://gitee.com/sunhf/gprMax.git
已同步 2025-08-06 04:26:52 +08:00
Changed detection of physical and logical cores to workaround bug with psutil detection. Reverted to perf_counter for timing.
这个提交包含在:
@@ -33,7 +33,7 @@ from colorama import Fore
|
|||||||
from colorama import Style
|
from colorama import Style
|
||||||
init()
|
init()
|
||||||
import numpy as np
|
import numpy as np
|
||||||
from time import process_time
|
from time import perf_counter
|
||||||
|
|
||||||
from gprMax.constants import complextype
|
from gprMax.constants import complextype
|
||||||
from gprMax.constants import floattype
|
from gprMax.constants import floattype
|
||||||
@@ -238,11 +238,8 @@ def get_host_info():
|
|||||||
except subprocess.CalledProcessError:
|
except subprocess.CalledProcessError:
|
||||||
pass
|
pass
|
||||||
|
|
||||||
# Hyperthreading
|
physicalcores = psutil.cpu_count(logical=False)
|
||||||
if psutil.cpu_count(logical=False) != psutil.cpu_count(logical=True):
|
logicalcores = psutil.cpu_count(logical=True)
|
||||||
hyperthreading = True
|
|
||||||
else:
|
|
||||||
hyperthreading = False
|
|
||||||
|
|
||||||
# OS version
|
# OS version
|
||||||
if platform.machine().endswith('64'):
|
if platform.machine().endswith('64'):
|
||||||
@@ -267,15 +264,13 @@ def get_host_info():
|
|||||||
sockets = int(sockets)
|
sockets = int(sockets)
|
||||||
cpuID = subprocess.check_output("sysctl -n machdep.cpu.brand_string", shell=True, stderr=subprocess.STDOUT).decode('utf-8').strip()
|
cpuID = subprocess.check_output("sysctl -n machdep.cpu.brand_string", shell=True, stderr=subprocess.STDOUT).decode('utf-8').strip()
|
||||||
cpuID = ' '.join(cpuID.split())
|
cpuID = ' '.join(cpuID.split())
|
||||||
|
physicalcores = subprocess.check_output("sysctl -n hw.physicalcpu", shell=True, stderr=subprocess.STDOUT).decode('utf-8').strip()
|
||||||
|
physicalcores = int(physicalcores)
|
||||||
|
logicalcores = subprocess.check_output("sysctl -n hw.logicalcpu", shell=True, stderr=subprocess.STDOUT).decode('utf-8').strip()
|
||||||
|
logicalcores = int(logicalcores)
|
||||||
except subprocess.CalledProcessError:
|
except subprocess.CalledProcessError:
|
||||||
pass
|
pass
|
||||||
|
|
||||||
# Hyperthreading
|
|
||||||
if psutil.cpu_count(logical=False) != psutil.cpu_count(logical=True):
|
|
||||||
hyperthreading = True
|
|
||||||
else:
|
|
||||||
hyperthreading = False
|
|
||||||
|
|
||||||
# OS version
|
# OS version
|
||||||
if int(platform.mac_ver()[0].split('.')[1]) < 12:
|
if int(platform.mac_ver()[0].split('.')[1]) < 12:
|
||||||
osversion = 'Mac OS X (' + platform.mac_ver()[0] + ')'
|
osversion = 'Mac OS X (' + platform.mac_ver()[0] + ')'
|
||||||
@@ -301,17 +296,16 @@ def get_host_info():
|
|||||||
allcpuinfo = subprocess.check_output("lscpu", shell=True, stderr=subprocess.STDOUT).decode('utf-8').strip()
|
allcpuinfo = subprocess.check_output("lscpu", shell=True, stderr=subprocess.STDOUT).decode('utf-8').strip()
|
||||||
for line in allcpuinfo.split('\n'):
|
for line in allcpuinfo.split('\n'):
|
||||||
if 'Socket(s)' in line:
|
if 'Socket(s)' in line:
|
||||||
sockets = int(line.strip()[-1])
|
sockets = int(re.sub("\D", "", line.strip()))
|
||||||
if 'Thread(s) per core' in line:
|
if 'Thread(s) per core' in line:
|
||||||
threadspercore = int(line.strip()[-1])
|
threadspercore = int(re.sub("\D", "", line.strip()))
|
||||||
|
if 'Core(s) per socket' in line:
|
||||||
|
corespersocket = int(re.sub("\D", "", line.strip()))
|
||||||
except subprocess.CalledProcessError:
|
except subprocess.CalledProcessError:
|
||||||
pass
|
pass
|
||||||
|
|
||||||
# Hyperthreading
|
physicalcores = sockets * corespersocket
|
||||||
if threadspercore == 2:
|
logicalcores = sockets * corespersocket * threadspercore
|
||||||
hyperthreading = True
|
|
||||||
else:
|
|
||||||
hyperthreading = False
|
|
||||||
|
|
||||||
# OS version
|
# OS version
|
||||||
osrelease = subprocess.check_output("cat /proc/sys/kernel/osrelease", shell=True).decode('utf-8').strip()
|
osrelease = subprocess.check_output("cat /proc/sys/kernel/osrelease", shell=True).decode('utf-8').strip()
|
||||||
@@ -324,13 +318,17 @@ def get_host_info():
|
|||||||
hostinfo['sockets'] = sockets
|
hostinfo['sockets'] = sockets
|
||||||
hostinfo['cpuID'] = cpuID
|
hostinfo['cpuID'] = cpuID
|
||||||
hostinfo['osversion'] = osversion
|
hostinfo['osversion'] = osversion
|
||||||
hostinfo['hyperthreading'] = hyperthreading
|
|
||||||
hostinfo['logicalcores'] = psutil.cpu_count()
|
# Hyperthreading
|
||||||
try:
|
if logicalcores != physicalcores:
|
||||||
# Get number of physical CPU cores, i.e. avoid hyperthreading with OpenMP
|
hostinfo['hyperthreading'] = True
|
||||||
hostinfo['physicalcores'] = psutil.cpu_count(logical=False)
|
else:
|
||||||
except ValueError:
|
hostinfo['hyperthreading'] = False
|
||||||
hostinfo['physicalcores'] = hostinfo['logicalcores']
|
|
||||||
|
hostinfo['logicalcores'] = logicalcores
|
||||||
|
# Number of physical CPU cores, i.e. avoid hyperthreading with OpenMP
|
||||||
|
hostinfo['physicalcores'] = physicalcores
|
||||||
|
|
||||||
# Handle case where cpu_count returns None on some machines
|
# Handle case where cpu_count returns None on some machines
|
||||||
if not hostinfo['physicalcores']:
|
if not hostinfo['physicalcores']:
|
||||||
hostinfo['physicalcores'] = hostinfo['logicalcores']
|
hostinfo['physicalcores'] = hostinfo['logicalcores']
|
||||||
@@ -415,4 +413,4 @@ def detect_check_gpus(deviceIDs):
|
|||||||
|
|
||||||
def timer():
|
def timer():
|
||||||
"""Function to return the current process wide time in fractional seconds."""
|
"""Function to return the current process wide time in fractional seconds."""
|
||||||
return process_time()
|
return perf_counter()
|
||||||
|
在新工单中引用
屏蔽一个用户