-
Notifications
You must be signed in to change notification settings - Fork 1
/
logical_partition.py
51 lines (42 loc) · 1.67 KB
/
logical_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
from itertools import chain
from cpp_code import *
class LogicalPartition():
def __init__(self, name, task_name, index_partition, subspaces):
self.name = name
self.task_name = task_name
self.subspaces = subspaces
self.index_partition = index_partition
self.is_needed = False
def should_print_if_any_child_is_needed(self):
if self.any_child_is_needed():
self.should_print()
def any_child_is_needed(self):
child_is_needed = False
for color in self.subspaces:
s = self.subspaces[color]
s.should_print_if_any_child_is_needed()
if s.is_needed:
child_is_needed = True
return child_is_needed
def shouldnt_print_anything(self):
self.shouldnt_print()
map(lambda c: self.subspaces[c].shouldnt_print_anything(), self.subspaces)
def shouldnt_print(self):
self.is_needed = False
self.index_partition.is_needed = False
def should_print(self):
self.is_needed = True
self.index_partition.is_needed = True
def pretty_code(self, parent_name):
init_call = 'runtime->get_logical_partition(ctx, ' + parent_name + ', ' + self.index_partition.name + ')'
partition_init = cpp_assign('LogicalPartition ' + self.name, init_call)
subspace_init = []
for color in self.subspaces:
s = self.subspaces[color]
subspace_init.extend(s.init_code(self.name, color))
return [partition_init] + subspace_init
def init_code(self, parent_name):
if self.is_needed:
return self.pretty_code(parent_name)
else:
return []