]> vgcfreebox.myrthtech.pt Git - ue-pp-terminationdetectionalgorithm.git/blob - control-skeleton.c
464b8cc0b78de4e732ed745d0174ce1440d84a76
[ue-pp-terminationdetectionalgorithm.git] / control-skeleton.c
1 /*
2 Parallel Programming - 2026/2027
3
4 Skeleton of an implementation of a termination detection algorithm
5 */
6
7 #include <mpi.h>
8 #include <pthread.h>
9
10 #include <stdio.h>
11 #include <stdbool.h>
12 #include <unistd.h>
13
14 #include "global.h"
15 #include "control.h"
16 #include "util.h"
17
18 // the tag(s) of the control messages
19 //#define ...
20
21 // type for control messages
22 //typedef struct {
23 // ...
24 //} control_message_t;
25
26 // local variables
27 //static ...
28
29 /*
30 Main loop of the termination detection algorithm.
31
32 When termination is detected, it must end (returning NULL or another
33 appropriate value), which signals the main thread that the basic
34 algorithm has terminated.
35
36 The arguments of the termination detection algorithm are the ID of
37 the process, the number of PROCESSES running the basic algorithm,
38 and whether the process is an initiator.
39 */
40 void *detect_termination(void *_args)
41 {
42 thread_args_t *args = _args;
43 int id = args->id;
44 int processes = args->processes;
45 bool initiator = args->initiator;
46
47 // THE FOLLOWING TWO LINES OF CODE MUST BE REPLACED BY THE CODE OF
48 // THE TERMINATION DETECTION ALGORITHM
49
50 // let the basic algorithm run for 10 seconds
51 sleep(10);
52
53 return NULL;
54 }
55
56 /*
57 Called at startup of the basic algorithm in process ID.
58 */
59 void control_basic_start_hook(int id)
60 {
61 }
62
63 /*
64 Called when the basic algorithm process ID becomes passive.
65 */
66 void control_become_passive_hook(int id)
67 {
68 }
69
70 /*
71 Called when the basic algorithm process ID becomes active.
72 */
73 void control_become_active_hook(int id)
74 {
75 }
76
77 /*
78 Called when the basic algorithm process ID sends a basic message to
79 process PEER.
80 */
81 void control_basic_send_hook(int id, int peer)
82 {
83 }
84
85 /*
86 Called when the basic algorithm process ID receives a basic message
87 from process PEER.
88 */
89 void control_basic_receive_hook(int id, int peer)
90 {
91 }