Skip to content
Snippets Groups Projects

Add autodiff

Closed Stephan Seitz requested to merge seitz/pystencils:autodiff into master
1 unresolved thread
1 file
+ 20
0
Compare changes
  • Side-by-side
  • Inline
  • b5a56ad5
    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.
@@ -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
else:
exclusive_writes.add((a.field, a.index))
return True
class SymbolGen:
"""Default symbol generator producing number symbols ζ_0, ζ_1, ..."""
Loading