Class Hardware

All Implemented Interfaces:
Comparable<Hardware>

public final class Hardware extends CommonMachine implements 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, cores and units may be incorrectly calculated if you fail to specify the caches. Known issue: If you have more than one processor, nut no L3 cache; the processors attribute 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 } or new MemoryThreads[] { SYSTEM, L2, L1 } or new MemoryThreads[] { SYSTEM, L1 }
  • Field Details

    • CPU_CACHE_LINE_SIZE

      public static final long CPU_CACHE_LINE_SIZE
      Cache-line size is (typically) 64 bytes
      See Also:
    • OS_MEMORY_PAGE_SIZE

      public static final long OS_MEMORY_PAGE_SIZE
      Page 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

      private final BasicMachine[] myLevels
  • Constructor Details

    • Hardware

      public Hardware(Hardware.Architecture arch, BasicMachine[] levels)
      new BasicMachine[] { SYSTEM, L3, L2, L1 }, new MemoryThreads[] { SYSTEM, L2, L1 } or new MemoryThreads[] { SYSTEM, L1 }
  • Method Details

    • getArchitecture

      public static Hardware.Architecture 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 environments
      • 2 - Dual-core systems or dual-core with hyperthreading disabled
      • 4 - Quad-core systems or dual-core with hyperthreading
      • 8 - Octa-core systems or quad-core with hyperthreading
      • 16-32 - High-end consumer or workstation processors
      • 64-128+ - Server-class processors with many cores
      Returns:
      The number of logical processors available to the JVM, always at least 1.
    • make

      public static Hardware make(Hardware.Architecture architecture, long memory, int threads)
      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 public static Hardware makeSimple()
      Deprecated.
      v56 Use newInstance() instead
    • makeSimple

      @Deprecated public static Hardware makeSimple(Hardware.Architecture systemArchitecture, long systemMemory, int systemThreads)
      Deprecated.
      v56 Use
      invalid reference
      invalid input: 'instead'
    • newInstance

      public static Hardware 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

      public int compareTo(Hardware other)
      Specified by:
      compareTo in interface Comparable<Hardware>
    • equals

      public boolean equals(Object obj)
      Overrides:
      equals in class CommonMachine
    • hashCode

      public int hashCode()
      Overrides:
      hashCode in class CommonMachine
    • isL2Specified

      public boolean isL2Specified()
    • isL3Specified

      public boolean isL3Specified()
    • toString

      public String toString()
      Overrides:
      toString in class BasicMachine
    • virtualise

      public VirtualMachine virtualise()