Skip to content
Snippets Groups Projects
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
No related branches found
No related tags found
No related merge requests found
...@@ -3,6 +3,7 @@ from copy import copy ...@@ -3,6 +3,7 @@ from copy import copy
from typing import List, Optional, Dict, Any, Set, Sequence, Iterator, Iterable, Union from typing import List, Optional, Dict, Any, Set, Sequence, Iterator, Iterable, Union
from pystencils.assignment import Assignment from pystencils.assignment import Assignment
from pystencils.sympyextensions import fast_subs, count_operations, sort_assignments_topologically from pystencils.sympyextensions import fast_subs, count_operations, sort_assignments_topologically
import pystencils
class AssignmentCollection: class AssignmentCollection:
...@@ -360,6 +361,25 @@ class AssignmentCollection: ...@@ -360,6 +361,25 @@ class AssignmentCollection:
self.sub_expressions = [Assignment(k, v) self.sub_expressions = [Assignment(k, v)
for k, v in sub_expressions_dict.items()] 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
else:
exclusive_writes.add((a.field, a.index))
return True
class SymbolGen: class SymbolGen:
"""Default symbol generator producing number symbols ζ_0, ζ_1, ...""" """Default symbol generator producing number symbols ζ_0, ζ_1, ..."""
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment