When to terminate?
-Token Termination. When P0 becomes idle (its work stack become empty),
it initiates a token and makes no further requests. When Pi receives
the token, it holds it until it becomes idle. Then Pi passes the
token to Pi+1 and it makes no further requests for work. When P0
gets the token back, the program terminates. This algorithm can be
inefficient and cause load imbalance. The modified algorithm:
1. When P0 becomes idle, it initiates termination by making
itself white and sending a white token to P1;
2. If Pi sends work to Pj and i>j (sending a work backwards),
then processor Pi becomes black;
3. If Pi has the token and idle, then it passes the token to Pi+1.
If Pi is black, then make the token black before the token is sent
to Pi+1. If Pi is white, keep the color of the token unchanged;
4. After Pi passes the token to Pi+1, it becomes white;
5. The algorithm terminates when P0 receives a white token.
-Tree Based Termination. Each work piece is associated with a weight.
Initially, P0 has all work, say weight is 1.0. As processors complete
their work, P0 accumulates the weights of completed work pieces.
When the accumulation reaches 1.0, the work terminates.
Warning: be aware of underflow and rounding errors.