From 9199fe2e2075251b6c67a263de46ff9bf0f82a45 Mon Sep 17 00:00:00 2001 From: Andreas Kloeckner Date: Wed, 2 Mar 2022 14:13:16 -0600 Subject: [PATCH] User persistent_dict hashing to guess a tag --- grudge/trace_pair.py | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/grudge/trace_pair.py b/grudge/trace_pair.py index e142a954..3e627849 100644 --- a/grudge/trace_pair.py +++ b/grudge/trace_pair.py @@ -46,7 +46,9 @@ """ -from typing import List, Hashable, Optional +from typing import List, Hashable, Optional, Type, Any + +from pytools.persistent_dict import KeyBuilder from arraycontext import ( ArrayContainer, @@ -432,6 +434,11 @@ def finish(self): exterior=bdry_conn(self.remote_data)) +class _TagKeyBuilder(KeyBuilder): + def update_for_type(self, key_hash, key: Type[Any]): + self.rec(key_hash, (key.__module__, key.__name__, key.__name__,)) + + def cross_rank_trace_pairs( dcoll: DiscretizationCollection, ary, comm_tag: Hashable = None, @@ -499,7 +506,9 @@ def cross_rank_trace_pairs( # - https://github.com/inducer/grudge/pull/222 from mpi4py import MPI tag_ub = actx.mpi_communicator.Get_attr(MPI.TAG_UB) - num_tag = hash(comm_tag) % tag_ub + key_builder = _TagKeyBuilder() + digest = key_builder(comm_tag) + num_tag = sum(ord(ch) << i for i, ch in enumerate(digest)) % tag_ub from warnings import warn warn("Encountered unknown symbolic tag "