- MPI_Recv(&sig, sizeof(control_message_t), MPI_BYTE, status.MPI_SOURCE,
- CONTROL_SIGNAL, MPI_COMM_WORLD, MPI_STATUS_IGNORE);
-
- pthread_mutex_lock(&state_mutex);
- deficit--; // Rule D: A child finished its work and reported back
- trace("%d: [CONTROL] Got signal from %d (New Deficit: %d)\n",
- id, status.MPI_SOURCE, deficit);
-
- try_resolve_tree(id);
- pthread_mutex_unlock(&state_mutex);
+ MPI_Recv(
+ &sig, // pointer to the memory space where the incoming message will be stored
+ sizeof(control_message_t), // the maximum size (in bytes) of the data willing to receive.
+ MPI_BYTE, // raw stream of bytes
+ status.MPI_SOURCE, // the ID (rank) of the process you want to receive from MPI_Iprobe.
+ CONTROL_SIGNAL, // label of the message
+ MPI_COMM_WORLD, // the overall group of processes this message belongs to.
+ MPI_STATUS_IGNORE // just to save memory and processing time.
+ );
+
+ if(sig.type == MSG_KILL){
+ trace("%d: [CONTROL] Received KILL signal. Shutting down.\n", id);
+ break;
+ }
+ else if(sig.type == MSG_ACK){
+ pthread_mutex_lock(&state_mutex);
+ deficit--; // Rule D: A child finished its work and reported back
+ trace("%d: [CONTROL] Got signal from %d (New Deficit: %d)\n",
+ id, status.MPI_SOURCE, deficit);
+
+ try_resolve_tree(id);
+ pthread_mutex_unlock(&state_mutex);
+ }