Commit b5a56ad5 authored by Stephan Seitz's avatar Stephan Seitz
Browse files

Add AssignmentCollection.has_exclusive_writes

This properties checks whether all writes of this AC are exclusive,
i.e. can be safely parallelized. AC not fulfilling this property are
malformed for pystencils since this property is implicitly assumed.
parent 1754ef27
......@@ -3,6 +3,7 @@ from copy import copy
from typing import List, Optional, Dict, Any, Set, Sequence, Iterator, Iterable, Union
from pystencils.assignment import Assignment
from pystencils.sympyextensions import fast_subs, count_operations, sort_assignments_topologically
import pystencils
class AssignmentCollection:
......@@ -360,6 +361,25 @@ class AssignmentCollection:
self.sub_expressions = [Assignment(k, v)
for k, v in sub_expressions_dict.items()]
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
exclusive_writes.add((a.field, a.index))
return True
class SymbolGen:
"""Default symbol generator producing number symbols ζ_0, ζ_1, ..."""
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment