From db03f4ee68d87bd7d32ecb5fefe3412bfb3d5f77 Mon Sep 17 00:00:00 2001 From: AdityaGupta716 Date: Thu, 26 Feb 2026 01:39:48 +0530 Subject: [PATCH] Add /dev/shm space check before shared memory allocation in global adaptivity --- micro_manager/adaptivity/global_adaptivity.py | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/micro_manager/adaptivity/global_adaptivity.py b/micro_manager/adaptivity/global_adaptivity.py index 0d28aee7..1bc36602 100644 --- a/micro_manager/adaptivity/global_adaptivity.py +++ b/micro_manager/adaptivity/global_adaptivity.py @@ -6,6 +6,7 @@ Note: All ID variables used in the methods of this class are global IDs, unless they have *local* in their name. """ import hashlib +import shutil from copy import deepcopy import sys from typing import Dict @@ -90,6 +91,20 @@ def __init__( nbytes = ( self._global_number_of_sims * self._global_number_of_sims * itemsize ) + # Check if /dev/shm has enough space before attempting allocation. + # On some systems, /dev/shm is limited to 50% of RAM, which can cause + # a cryptic MPI internal error for large simulations. + _, _, shm_free = shutil.disk_usage("/dev/shm") + if nbytes > shm_free: + raise RuntimeError( + "Not enough space in /dev/shm to allocate the similarity distance matrix " + "for global adaptivity.\n" + " Required : {} B\n" + " Available: {} B\n" + "On some systems /dev/shm is limited to 50% of RAM. " + "Consider increasing /dev/shm size (e.g. `--shm-size` in Docker, or " + "`tmpfs` remount), or use local adaptivity instead.".format(nbytes, shm_free) + ) else: nbytes = 0