From 1747635ae3b07a8d2e0508d3c2e55c5936d64d65 Mon Sep 17 00:00:00 2001
From: Simon Schwitanski <schwitanski@itc.rwth-aachen.de>
Date: Sun, 4 Feb 2024 22:03:35 +0100
Subject: [PATCH] InstructionBlock: Add get_operations and register_operations
 for lists of operations

---
 scripts/Infrastructure/InstructionBlock.py | 24 ++++++++++++++++++++++
 1 file changed, 24 insertions(+)

diff --git a/scripts/Infrastructure/InstructionBlock.py b/scripts/Infrastructure/InstructionBlock.py
index ec5310b92..dfb40d40a 100644
--- a/scripts/Infrastructure/InstructionBlock.py
+++ b/scripts/Infrastructure/InstructionBlock.py
@@ -50,6 +50,20 @@ class InstructionBlock:
                 self.operations[as_int] = []
             self.operations[as_int].append(op)
 
+    def register_operations(self, ops, kind='all'):
+        """
+        Registers a list of operations based on rank.
+
+        Parameters:
+            - ops: The operations to register.
+            - kind: Rank to execute the operation ('all', 'not0', or integer).
+                - all: all Ranks execute this operation
+                - not0: all Ranks but the Root (rank 0) execute
+                - Or the integer of the rank that should execute
+        """
+        for op in ops:
+            self.register_operation(op, kind)
+
     def get_version(self):
         """
         Retrieves the minimum required MPI version.
@@ -114,6 +128,16 @@ class InstructionBlock:
             str: The operation specified by kind and index
         """
         return self.operations[kind][index]
+    
+    def get_operations(self, kind='all'):
+        """
+        Retrieve all operations registered for the given kind.
+        Parameters:
+            - kind ('all','not0' or integer): which ranks should execute the operation
+        Returns:
+            str: List of all operations with given kind
+        """
+        return self.operations[kind]
 
     def replace_operation(self, op, kind='all', index=0):
         """
-- 
GitLab