Skip to content
Snippets Groups Projects

Add AssignmentCollection.has_exclusive_writes

1 file
+ 20
0
Compare changes
  • Side-by-side
  • Inline
@@ -3,6 +3,7 @@ from typing import Any, Dict, Iterable, Iterator, List, Optional, Sequence, Set,
import sympy as sp
import pystencils
from pystencils.assignment import Assignment
from pystencils.sympyextensions import count_operations, fast_subs, sort_assignments_topologically
@@ -346,6 +347,25 @@ class AssignmentCollection:
def __iter__(self):
return self.main_assignments.__iter__()
def has_exclusive_writes(self):
"""
Simple check for exclusive (non-overlapping) writes.
I.e. AssignmentCollection can be executed safely in parallel without caring about race conditions.
"""
assignments = self.main_assignments
write_field_accesses = [a.lhs for a in assignments if isinstance(a.lhs, pystencils.Field.Access)]
exclusive_writes = set()
for a in write_field_accesses:
if (a.field, a.index) in exclusive_writes:
return False
else:
exclusive_writes.add((a.field, a.index))
return True
@property
def main_assignments_dict(self):
return {a.lhs: a.rhs for a in self.main_assignments}
Loading