]> vgcfreebox.myrthtech.pt Git - ue-pp-terminationdetectionalgorithm.git/blobdiff - util.c
detect_termination function mechanism, shared local vars protected by mutex
[ue-pp-terminationdetectionalgorithm.git] / util.c
diff --git a/util.c b/util.c
index 65e145edeeb99038286a2309462f657f07f6d0cd..f7fdbfaa401399985412734514a69e62d496e811 100644 (file)
--- a/util.c
+++ b/util.c
@@ -52,3 +52,29 @@ void warn(char *format, ...)
   vfprintf(stderr, format, args);
   va_end (args);
 }
   vfprintf(stderr, format, args);
   va_end (args);
 }
+
+/*
+  Evaluates Rule C & D of Dijkstra-Scholten. Caller must already hold state_mutex!
+*/
+static void try_resolve_tree(int my_id)
+{
+    if (state == PASSIVE_STATE && deficit == 0)
+    {
+        if (is_initiator) {
+            // Root is passive and deficit is 0 -> Global Termination!
+            return; 
+        }
+
+        if (parent != -1)
+        {
+            control_message_t sig = {0};
+            // Send acknowledgment signal up the tree to our parent
+            MPI_Send(&sig, sizeof(control_message_t), MPI_BYTE, parent, 
+                     CONTROL_SIGNAL, MPI_COMM_WORLD);
+            
+            trace("%d: [CONTROL] Sent tree-signal to parent %d\n", my_id, parent);
+            parent = -1; // Detach from tree
+            
+        }
+    }
+}
\ No newline at end of file