Skip to content
Snippets Groups Projects

P2P

Open
Jammer, Timrequested to merge
p2p into main
1 file
+ 10
4
Compare changes
  • Side-by-side
  • Inline
+ 10
4
@@ -126,9 +126,9 @@ class TemplateManager:
@@ -126,9 +126,9 @@ class TemplateManager:
for i in range(len(instr_copy)):
for i in range(len(instr_copy)):
for j in range(len(instr_copy) - 1):
for j in range(len(instr_copy) - 1):
rankj = instr_copy[j].get_rank_executing()
rankj = instr_copy[j].get_rank_executing()
rankj1 = instr_copy[j+1].get_rank_executing()
rankj1 = instr_copy[j + 1].get_rank_executing()
# if not int: 'all' so not allowed to move
# if not int: 'all' so not allowed to move
if ( isinstance(rankj,int) and isinstance(rankj1,int) and rankj1> rankj):
if (isinstance(rankj, int) and isinstance(rankj1, int) and rankj1 > rankj):
# Swap the elements if they are out of order
# Swap the elements if they are out of order
instr_copy[j], instr_copy[j + 1] = instr_copy[j + 1], instr_copy[j]
instr_copy[j], instr_copy[j + 1] = instr_copy[j + 1], instr_copy[j]
@@ -255,8 +255,8 @@ class TemplateManager:
@@ -255,8 +255,8 @@ class TemplateManager:
assert self._descr_short != ""
assert self._descr_short != ""
return self._descr_short
return self._descr_short
def get_instruction(self, identifier: str = None, return_list=False, idx: int = None) -> Instruction | typing.List[
def get_instruction(self, identifier: str = None, return_list=False, rank_excuting: int | str = None,
Instruction]:
idx: int = None) -> Instruction | typing.List[Instruction]:
"""
"""
Retrieves an instruction or list fh them based on its identifier or index.
Retrieves an instruction or list fh them based on its identifier or index.
@@ -264,6 +264,7 @@ class TemplateManager:
@@ -264,6 +264,7 @@ class TemplateManager:
identifier (str): The identifier of the instruction.
identifier (str): The identifier of the instruction.
return_list (bool): Whether to return a list of instruction.
return_list (bool): Whether to return a list of instruction.
idx (int): The index of the instruction block.
idx (int): The index of the instruction block.
 
rank_excuting(None |int|'all'|'not0'): get instruction from given rank; None: consider instructions from all ranks
Returns:
Returns:
Instruction | List[Instruction]: The instruction block(s).
Instruction | List[Instruction]: The instruction block(s).
@@ -278,6 +279,8 @@ class TemplateManager:
@@ -278,6 +279,8 @@ class TemplateManager:
if identifier is not None:
if identifier is not None:
to_return = [i for i in self._instructions if i.get_identifier() == identifier]
to_return = [i for i in self._instructions if i.get_identifier() == identifier]
 
if rank_excuting is not None:
 
to_return = [i for i in to_return if i.get_rank_executing() == rank_excuting]
if return_list:
if return_list:
return to_return
return to_return
@@ -288,6 +291,9 @@ class TemplateManager:
@@ -288,6 +291,9 @@ class TemplateManager:
raise IndexError("Found too many elements")
raise IndexError("Found too many elements")
if idx is not None:
if idx is not None:
 
if rank_excuting is not None:
 
if self._instructions[idx].get_rank_executing() != rank_excuting:
 
raise IndexError("Found no matching Instruction")
if return_list:
if return_list:
return [self._instructions[idx]]
return [self._instructions[idx]]
return self._instructions[idx]
return self._instructions[idx]
Loading