Class Hardware
java.lang.Object
org.ojalgo.machine.BasicMachine
org.ojalgo.machine.CommonMachine
org.ojalgo.machine.Hardware
- All Implemented Interfaces:
Comparable<Hardware>
- The first element in the array should correspond to total system resources; the total amount of RAM and the total number of threads (Typically the same as what is returned by Runtime.availableProcessors()).
- The last element in the array should describe the L1 cache. Typically Intel processors have 32k L1 cache and AMD 64k. 1 or maybe 2 threads use/share this cache.
- Caches, all levels except L1, are described between the first and last elements in descending order (L3 cache comes before L2 cache). Specify the size of the cache and the number of threads using/sharing the cache. (Do not worry about how many cache units there are - describe one unit.)
- The array must have at least 2 elements. You must describe the total system resources and the L1 cache.
It is strongly recommended to also describe the L2 cache. The L3 cache, if it exists, is less important to
describe. The derived attributes
processors,coresandunitsmay be incorrectly calculated if you fail to specify the caches. Known issue: If you have more than one processor, nut no L3 cache; theprocessorsattribute will be incorrectly set 1. A workaround that currently works is to define an L3 cache anyway and set the memory/size of that cache to 0bytes. This Workaround may stop working in the future. new MemoryThreads[] { SYSTEM, L3, L2, L1 }ornew MemoryThreads[] { SYSTEM, L2, L1 }ornew MemoryThreads[] { SYSTEM, L1 }
-
Nested Class Summary
Nested Classes -
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final longCache-line size is (typically) 64 bytesprivate final BasicMachine[]static final longPage size is usually determined by the processor architecture.Fields inherited from class CommonMachine
architecture, cache, cores, K, unitsFields inherited from class BasicMachine
memory, threads -
Constructor Summary
ConstructorsConstructorDescriptionHardware(Hardware.Architecture arch, BasicMachine[] levels) new BasicMachine[] { SYSTEM, L3, L2, L1 },new MemoryThreads[] { SYSTEM, L2, L1 }ornew MemoryThreads[] { SYSTEM, L1 } -
Method Summary
Modifier and TypeMethodDescriptionintbooleanprivate static BasicMachineestimateL1(Hardware.Architecture architecture, long memory, int threads) L1 cache is usually fixed per architecture.private static BasicMachineestimateLevel(Hardware.Architecture architecture, long memory, int threads, BasicMachine l1, int nbLevels, int level) private static intestimateNumberOfLevels(Hardware.Architecture architecture, long memory, int threads, BasicMachine l1) Usually 3, but could be 2.static Hardware.ArchitectureReturns the normalized processor architecture of the current system.static longSystem RAM - attempts multiple strategies to determine total physical memory with robust fallback mechanisms.static intReturns the number of processors (logical cores/threads) available to the Java Virtual Machine.inthashCode()booleanbooleanstatic Hardwaremake(Hardware.Architecture architecture, long memory, int threads) Creates a Hardware instance from available system properties and logical deduction.static HardwareDeprecated.static HardwaremakeSimple(Hardware.Architecture systemArchitecture, long systemMemory, int systemThreads) Deprecated.v56 Useinvalid reference
invalid input: 'instead'static HardwareCreates a Hardware instance by intelligently detecting system characteristics from available system properties and logical deduction.toString()Methods inherited from class CommonMachine
cache, elements, isMultiCore, isMultiThread, isMultiUnit
-
Field Details
-
CPU_CACHE_LINE_SIZE
public static final long CPU_CACHE_LINE_SIZECache-line size is (typically) 64 bytes- See Also:
-
OS_MEMORY_PAGE_SIZE
public static final long OS_MEMORY_PAGE_SIZEPage size is usually determined by the processor architecture. Traditionally, pages in a system had uniform size, such as 4,096 bytes. However, processor designs often allow two or more, sometimes simultaneous, page sizes due to its benefits. There are several points that can factor into choosing the best page size.Practically all architectures/OS:s have a page size of 4k (one notable exception is Solaris/SPARC that have 8k)
AArch64 supports three different granule sizes: 4KB, 16KB, and 64KB.
- See Also:
-
myLevels
-
-
Constructor Details
-
Hardware
new BasicMachine[] { SYSTEM, L3, L2, L1 },new MemoryThreads[] { SYSTEM, L2, L1 }ornew MemoryThreads[] { SYSTEM, L1 }
-
-
Method Details
-
getArchitecture
Returns the normalized processor architecture of the current system. This is used by ojAlgo's hardware detection system to determine appropriate cache configurations, threading models, and optimization strategies for different processor families.The architecture string is normalized to standard values for consistency across different JVM implementations and operating systems.
- Returns:
- The normalized processor architecture string, never null. Defaults to "other" if the architecture cannot be determined.
-
getMemory
public static long getMemory()System RAM - attempts multiple strategies to determine total physical memory with robust fallback mechanisms. -
getThreads
public static int getThreads()Returns the number of processors (logical cores/threads) available to the Java Virtual Machine. This includes both physical cores and logical threads created by technologies like Intel's Hyperthreading or IBM's SMT. This value is used by ojAlgo for parallel algorithm selection, thread pool sizing, and work distribution strategies.The value represents the total number of logical processors that the JVM can utilize for parallel execution. This is used by ojAlgo to:
- Size thread pools for parallel matrix operations
- Determine when to use parallel vs. sequential algorithms
- Configure parallelism thresholds for different operations
- Estimate optimal block sizes for parallel decomposition
Typical values:
1- Single-core systems or restricted environments2- Dual-core systems or dual-core with hyperthreading disabled4- Quad-core systems or dual-core with hyperthreading8- Octa-core systems or quad-core with hyperthreading16-32- High-end consumer or workstation processors64-128+- Server-class processors with many cores
- Returns:
- The number of logical processors available to the JVM, always at least 1.
-
make
Creates a Hardware instance from available system properties and logical deduction. This method supports a wide range of hardware from legacy systems to modern many-core processors.- Parameters:
architecture- The system architecture (x86, x86_64, aarch64, etc.)memory- The available system memory in bytes (now machine RAM, not JVM max heap)threads- The number of available processor threads- Returns:
- A Hardware instance that closely matches the actual system hardware
-
makeSimple
Deprecated.v56 UsenewInstance()instead -
makeSimple
@Deprecated public static Hardware makeSimple(Hardware.Architecture systemArchitecture, long systemMemory, int systemThreads) Deprecated.v56 Useinvalid reference
invalid input: 'instead' -
newInstance
Creates a Hardware instance by intelligently detecting system characteristics from available system properties and logical deduction. This method supports a wide range of hardware from legacy systems to modern many-core processors.- Returns:
- A Hardware instance that closely matches the actual system hardware
-
estimateL1
private static BasicMachine estimateL1(Hardware.Architecture architecture, long memory, int threads) L1 cache is usually fixed per architecture. -
estimateLevel
private static BasicMachine estimateLevel(Hardware.Architecture architecture, long memory, int threads, BasicMachine l1, int nbLevels, int level) -
estimateNumberOfLevels
private static int estimateNumberOfLevels(Hardware.Architecture architecture, long memory, int threads, BasicMachine l1) Usually 3, but could be 2. Theoretically could be any non-negative number (even 0). -
compareTo
- Specified by:
compareToin interfaceComparable<Hardware>
-
equals
- Overrides:
equalsin classCommonMachine
-
hashCode
public int hashCode()- Overrides:
hashCodein classCommonMachine
-
isL2Specified
public boolean isL2Specified() -
isL3Specified
public boolean isL3Specified() -
toString
- Overrides:
toStringin classBasicMachine
-
virtualise
-
newInstance()instead