calculate_target_memory#

mufasa.utils.memory.calculate_target_memory(multicore, use_total=False, max_usable_fraction=0.85)[source]#

Calculate target memory per core for chunked computations.

Parameters:
  • multicore (int) – Number of cores available for computation. Memory is divided evenly among these cores.

  • use_total (bool, optional, default=False) – If True, calculate based on the total system memory. If False, use available memory instead.

  • max_usable_fraction (float, optional, default=0.85) – Maximum fraction of memory to allocate for computation. For example, 0.85 means 85% of memory is considered usable.

Returns:

target_memory_mb – Target memory per core, in megabytes (MB).

Return type:

float

Examples

Calculate target memory per core using available system memory:

>>> calculate_target_memory(multicore=4, use_total=False, max_usable_fraction=0.9)
4096.0  # Example value, system-dependent

Notes

  • If use_total=True, the calculation includes memory currently in use by other processes.

  • Ensure multicore > 0 to avoid division errors.

  • The calculated memory assumes even distribution across all cores.