Skip to content

Commit

Permalink
User persistent_dict hashing to guess a tag
Browse files Browse the repository at this point in the history
  • Loading branch information
inducer committed Mar 2, 2022
1 parent 2caeff5 commit 9199fe2
Showing 1 changed file with 11 additions and 2 deletions.
13 changes: 11 additions & 2 deletions grudge/trace_pair.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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 "
Expand Down

0 comments on commit 9199fe2

Please sign in to comment.