Skip to content
Snippets Groups Projects
Commit 2236f39c authored by Jammer, Tim's avatar Jammer, Tim
Browse files

Ported Unmatched error generator to new TemplateManager

parent 36d5f394
No related branches found
No related tags found
1 merge request!14Infrastructure: Remove Instructionblock
......@@ -115,9 +115,10 @@ class TemplateManager:
code_string = ""
current_rank = 'all'
for inst in self._instructions:
if inst.get_rank_executing != current_rank:
if inst.get_rank_executing() != current_rank:
if current_rank != 'all':
code_string = code_string + "}\n" # end previous if
code_string = code_string + "}\n"
# end previous if
current_rank = inst.get_rank_executing()
if current_rank == 'not0':
code_string = code_string + "if (rank!=0){\n"
......@@ -164,7 +165,7 @@ class TemplateManager:
i.set_identifier(identifier)
if rank_to_execute is not None:
for i in inst:
i.set_ranks_executing(rank_to_execute)
i.set_rank_executing(rank_to_execute)
self._instructions.extend(inst)
elif isinstance(inst, str):
if rank_to_execute is not None:
......@@ -173,11 +174,11 @@ class TemplateManager:
# use default ('all')
self._instructions.append(Instruction(inst, identifier=identifier))
else:
assert isinstance(inst, Instruction)
if identifier is not None:
inst.set_identifier(identifier)
if rank_to_execute is not None:
for i in inst:
i.set_ranks_executing(rank_to_execute)
inst.set_rank_executing(rank_to_execute)
self._instructions.append(inst)
def get_version(self) -> str:
......@@ -251,21 +252,25 @@ class TemplateManager:
raise ValueError("Neither Both block name nor index is given")
def __get_instruction_index(self, identifier: str) -> typing.List[int]:
def __get_instruction_index(self, ident: str | Instruction) -> typing.List[int]:
"""
internal helper function to receive the indices of instructions with ghe given identifier
internal helper function to receive the indices of instructions with ghe given identifier oris the given isntruction
"""
return [idx for inst, idx in enumerate(self._instructions) if inst.get_identifier() == identifier]
def insert_instruction(self, new_instruction: Instruction, after_instruction: str | int = None,
before_instruction: str | int = None):
if isinstance(ident, str):
return [idx for idx, inst in enumerate(self._instructions) if inst.get_identifier() == ident]
if isinstance(ident, Instruction):
return [idx for idx, inst in enumerate(self._instructions) if inst == ident]
raise ValueError("Provide string or instruction")
def insert_instruction(self, new_instruction: Instruction, after_instruction: Instruction | str | int = None,
before_instruction: Instruction | str | int = None):
"""
Inserts a new instruction into the template.
Parameters:
new_instruction (Instruction): The new instruction to insert.
after_instruction (str | int): The instruction after which to insert the new one (identifier or index).
before_instruction (str | int): The instruction before which to insert the new one (identifier or index).
after_instruction (Instruction|str | int): The instruction after which to insert the new one (identifier or index).
before_instruction (Instruction|str | int): The instruction before which to insert the new one (identifier or index).
Raises:
ValueError: if both before and after are provided
IndexError: if it finds multiple places to insert by identifier
......@@ -280,7 +285,6 @@ class TemplateManager:
if isinstance(after_instruction, int):
idx_to_use = 1 + after_instruction
else:
assert isinstance(after_instruction, str)
inst_idx_list = self.__get_instruction_index(after_instruction)
if len(inst_idx_list) != 1:
raise IndexError("Did not find place to insert")
......@@ -289,7 +293,6 @@ class TemplateManager:
if isinstance(before_instruction, int):
idx_to_use = before_instruction
else:
assert isinstance(before_instruction, str)
inst_idx_list = self.__get_instruction_index(before_instruction)
if len(inst_idx_list) != 1:
raise IndexError("Did not find place to insert")
......@@ -297,20 +300,29 @@ class TemplateManager:
self._instructions.insert(idx_to_use, new_instruction)
def remove_instruction(self, identifier: str = None, idx: int | typing.List[int] = None):
def remove_instruction(self, identifier: str = None, idx: int | typing.List[int] = None,
instruction: Instruction | typing.List[Instruction] = None):
"""
Removes an instruction from the template.
Parameters:
identifier (str): The identifier of the instruction to remove.
idx (int | List[int]): The index or list of indices of the instruction(s) to remove.
instruction (Instruction | List[Instruction]) the list of instructions to remove
"""
# assert only one param is not None
parameters = [identifier, idx]
if parameters.count(None) != 1:
parameters = [identifier, idx, instruction]
if parameters.count(None) != 2:
raise ValueError("Only one parameter is allowed to be specified")
if instruction is not None:
if isinstance(instruction, Instruction):
instruction = [instruction]
for instruction in instruction:
self._instructions.remove(instruction)
return
idxs_to_remove = []
if idx is not None:
if isinstance(idx, int):
......@@ -327,13 +339,15 @@ class TemplateManager:
self._instructions = [elem for idx, elem in enumerate(self._instructions) if idx not in idxs_to_remove]
def replace_instruction(self, new_instruction=Instruction, identifier: str = None,
def replace_instruction(self, new_instruction=Instruction, old_instruction: Instruction | List[Instruction] = None,
identifier: str = None,
idx: int | typing.List[int] = None):
"""
Replaces an instruction in the template with a new one.
Parameters:
new_instruction (Instruction | List[Instruction]): The new instruction(s) to replace with.
old_instruction (Instruction | List[Instruction]): The old instruction(s) to replace.
identifier (str): The identifier of the instruction to replace.
idx (int | List[int]): The index or list of indices of the instruction(s) to replace.
Raises
......@@ -341,8 +355,8 @@ class TemplateManager:
or if both idx and identifier are provided
Notes: The instructions to be replaced must not be in contiguous order
"""
parameters = [identifier, idx]
if parameters.count(None) != 1:
parameters = [old_instruction, identifier, idx]
if parameters.count(None) != 2:
raise ValueError("Only one parameter is allowed to be specified")
new_instruction_list = []
......@@ -351,6 +365,10 @@ class TemplateManager:
else:
new_instruction_list = new_instruction
if old_instruction is not None:
raise EnvironmentError("NOT IMPLEMENTED")
# TODO implement
idxs_to_replace = []
if idx is not None:
if isinstance(idx, int):
......
......@@ -112,7 +112,7 @@ def get_send_recv_template(send_func: str = "mpi_isend", recv_func: str | typing
if recv_func in probe_pairs:
if recv_func in [["mpi_improbe", "mpi_mrecv"],
["mpi_improbe", "mpi_imrecv"]]:
tm.insert_instruction(Instruction("while (!flag){", rank=0), before_instruction="MPICALL")
tm.insert_instruction(Instruction("while (!flag){", rank=0), before_instruction=r)
# insertion before the improbe call
tm.register_instruction("}", rank_to_execute=0) # end while
tm.register_instruction(CorrectMPICallFactory.get(recv_func[1]), rank_to_execute=0)
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment