X-Git-Url: https://vgcfreebox.myrthtech.pt/gitweb/ue-pp-terminationdetectionalgorithm.git/blobdiff_plain/a1172429974beadbd21f351af069c6ceb2cd5200..0a57aa135aa37d96925e3a437e0690de0b13a9e4:/util.c?ds=inline diff --git a/util.c b/util.c index 65e145e..f7fdbfa 100644 --- a/util.c +++ b/util.c @@ -52,3 +52,29 @@ void warn(char *format, ...) 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