-
Notifications
You must be signed in to change notification settings - Fork 1
/
index_partition.py
61 lines (54 loc) · 2.3 KB
/
index_partition.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
class IndexPartition():
def __init__(self, name, task_name, subspaces):
self.name = name
self.task_name = task_name
self.subspaces = subspaces
self.is_needed = False
def color_init(self, dom_name, color, start, end):
lhs = dom_name + '[' + str(color) + '] = '
rhs = 'Domain::from_rect<1>(Rect<1>(Point<1>(' + str(start) + '), Point<1>(' + str(end) + ')))'
return lhs + rhs
def domain_coloring_init(self):
dom_name = self.name + '_coloring'
domain_init = 'DomainColoring ' + dom_name
code = [domain_init]
for color in self.subspaces:
s = self.subspaces[color]
code.append(self.color_init(dom_name, color, s.start, s.end))
return code
def color_max(self):
max_color = -10
for color in self.subspaces:
if color > max_color:
max_color = color
return max_color
def color_min(self):
min_color = 100000000
for color in self.subspaces:
if color < min_color:
min_color = color
return min_color
def is_disjoint(self):
disjoint = True
for color1 in self.subspaces:
for color2 in self.subspaces:
sub1 = self.subspaces[color1]
sub2 = self.subspaces[color2]
if color1 != color2 and sub1.overlaps(sub2):
disjoint = False
return disjoint
def pretty_code(self, parent_name):
color_dom_name = self.name + '_color_domain'
dom_name = self.name + '_coloring'
dom_init = 'Domain ' + color_dom_name + ' = Domain::from_rect<1>(Rect<1>(Point<1>(' + str(self.color_min()) + '), Point<1>(' + str(self.color_max()) + ')))'
part_init = 'IndexPartition ' + self.name + ' = ' + 'runtime->create_index_partition(ctx, ' + parent_name + ', ' + color_dom_name + ', ' + dom_name + ', ' + str(self.is_disjoint()).lower() + ')'
code = self.domain_coloring_init() + [dom_init, part_init]
for color in self.subspaces:
s = self.subspaces[color]
code.extend(s.init_code(self.name, color))
return code
def init_code(self, parent_name):
if self.is_needed:
return self.pretty_code(parent_name)
else:
return []