diff --git a/pyop2/caching.py b/pyop2/caching.py index 4771de511..6e0d47a36 100644 --- a/pyop2/caching.py +++ b/pyop2/caching.py @@ -402,12 +402,12 @@ class DEFAULT_CACHE(dict): pass -# Examples of how to instrument and use different default caches: -# ~ DEFAULT_CACHE = instrument(DEFAULT_CACHE) -# ~ DEFAULT_CACHE = instrument(cachetools.LRUCache) -# ~ DEFAULT_CACHE = partial(DEFAULT_CACHE, maxsize=100) +# Example of how to instrument and use different default caches: EXOTIC_CACHE = partial(instrument(cachetools.LRUCache), maxsize=100) -# ~ DictLikeDiskAccess = instrument(DictLikeDiskAccess) +# Turn on cache measurements if printing cache info is enabled +if configuration["print_cache_info"] or _running_on_ci: + DEFAULT_CACHE = instrument(DEFAULT_CACHE) + DictLikeDiskAccess = instrument(DictLikeDiskAccess) # JBTODO: This functionality should only be enabled with a PYOP2_SPMD_STRICT @@ -509,7 +509,6 @@ def wrapper(*args, **kwargs): return decorator -# JBTODO: This needs some more thought def clear_memory_cache(comm): with temp_internal_comm(comm) as icomm: if icomm.Get_attr(comm_cache_keyval) is not None: @@ -540,6 +539,6 @@ def decorator(func): # * Refactor compilation.py to use @mem_and_disk_cached, where get_so is just uses DictLikeDiskAccess with an overloaded self.write() method ✓ # * Systematic investigation into cache sizes/types for Firedrake # - Is a mem cache needed for DLLs? ~~No~~ Yes!! -# - Is LRUCache better than a simple dict? (memory profile test suite) -# - What is the optimal maxsize? +# - Is LRUCache better than a simple dict? (memory profile test suite) No +# - What is the optimal maxsize? ∞ # * Add some docstrings and maybe some exposition! diff --git a/pyop2/compilation.py b/pyop2/compilation.py index ce45c7e99..c7a278feb 100644 --- a/pyop2/compilation.py +++ b/pyop2/compilation.py @@ -68,8 +68,10 @@ def _check_hashes(x, y, datatype): _check_op = mpi.MPI.Op.Create(_check_hashes, commute=True) _compiler = None -# Directory must be unique per user for shared machines -MEM_TMP_DIR = Path(gettempdir()).joinpath(f"pyop2-tempcache-uid{os.getuid()}") +# Directory must be unique per VENV for multiple installs +# _and_ per user for shared machines +_EXE_HASH = md5(sys.executable.encode()).hexdigest()[-6:] +MEM_TMP_DIR = Path(gettempdir()).joinpath(f"pyop2-tempcache-uid{os.getuid()}").joinpath(_EXE_HASH) def set_default_compiler(compiler): @@ -678,9 +680,8 @@ def _add_profiling_events(dll, events): ctypes.c_int.in_dll(dll, 'ID_'+e).value = PETSc.Log.Event(e).id -# JBTODO: Move to caching?? -def clear_cache(prompt=False): - """Clear the PyOP2 compiler cache. +def clear_compiler_disk_cache(prompt=False): + """Clear the PyOP2 compiler disk cache. :arg prompt: if ``True`` prompt before removing any files """ diff --git a/scripts/pyop2-clean b/scripts/pyop2-clean index ab29f1245..52f667ec4 100755 --- a/scripts/pyop2-clean +++ b/scripts/pyop2-clean @@ -1,6 +1,6 @@ #!/usr/bin/env python -from pyop2.compilation import clear_cache +from pyop2.compilation import clear_compiler_disk_cache if __name__ == '__main__': - clear_cache(prompt=True) + clear_compiler_disk_cache(prompt=True)