# Minimizing Energy and Computation in Long-Running Software
## 4 A Program with a Single Long Loop  
In this section, we will apply the previous results to a program with a single long loop of length \(L\) instructions which is executed some number, say \(T\) times, so that \(Y=LT\). For this program, we may be constrained to place checkpoints either at the start of a loop so that \(y=m.L\) with one checkpoint for each \(m>1\) loops, or \(n\) checkpoints may be placed within the loop with \(L=ny\) where \(n>1\), or we set \(n=1\). We first apply the previous results to compute \(y^{*}\):  
\[y^{*}=-\frac{1}{\ln a}[W(\frac{B-A}{e.A})+1], \tag{23}\]  
where:  
\[B=B_{0}+B_{1}L.T,\ A=b_{0}+\frac{c+b_{1}}{1-a}, \tag{24}\]  
so that  
\[y^{*}=-\frac{1}{\ln a}[W(\frac{(1-a)(B_{0}+B_{1}L.T)}{e[b_{0}(1-a)+c+b_{1}]}- \frac{1}{e})+1]. \tag{25}\]  
Let us denote by \(I(x)\) the integer that is closest to the real number \(x\). Then we compute \(r=\frac{L}{y^{*}}\), and:  
* If \(r\geq 1\) we set \(n=I(r)\),
* If \(r<1\), we set \(n=I(\frac{1}{r})\). To illustrate these results, numerical examples are provided in order to show the effect of the checkpoint interval \(n\) (expressed in terms of the number of loop repetitions between checkpoints) on the expected execution time and the total energy consumption of a software application that operates in the presence of failures. In order to differentiate the effect of computation time and energy consumption, we use \(n^{o}\) to represent the checkpoint interval that minimizes the total computation time, while \(n^{+}\) refers to the optimum checkpoint interval that minimizes the total energy consumption. Note that in the preceding analysis, \(n^{o}\) can be obtained by setting \(\alpha=1,\ \beta=0\), while \(n^{+}\) is obtained by setting \(\alpha=0,\ \beta=1\). These examples consider the case of a program with a single loop in which checkpoints are established at the beginning (or at the end) of the loop. We consider a small, medium, large, and very large program, comprised of \(Y=10^{4},\ 10^{5},\ 10^{6},\ 10^{7}\) instructions, respectively. The expected execution time of the same program with and without the adoption of the ALCR mechanism is calculated and the corresponding optimization problem is shown numerically. The parameter values that we use are:  
\[B^{e}_{0}=500,\ B^{e}_{1}=0,\ B^{c}_{0}=10^{5},\ B^{c}_{1}=0,\ K ^{c}=1\] \[K^{e}=10^{-5},\ b^{e}_{0}=100,b^{e}_{1}=10,\ b^{c}_{0}=100,\ b^{e }_{1}=10\] \[g=5\times 10^{-6},\ L=100.\]  
In Figure 1, the example of a small software program (i.e., \(Y=10^{4}\)) is considered. Figure 1(a) compares the expected execution time of the application with and without the ALCR mechanism for different values of \(n\), while Figure 1(b) shows the expected \(Gain\) in terms of expected execution time for different values of \(n\). The values that correspond to the optimum checkpoint interval \(n^{o}\) are marked within a rectangle. Figure 1 illustrates the fact that the optimum checkpoint interval \(n^{o}\) minimizes the overall execution time of the application and maximizes the overall expected Gain. From  
Figure 1 it is clear that the ALCR mechanism will not reduce the expected execution time of a given software application unless the checkpoint interval is optimally selected. Indeed, for some poorly chosen values of \(n\), the expected execution time of the application with checkpointing is higher than the expected execution time of the same application without checkpoints. For instance in this example, choosing a very small checkpoint interval (i.e., below 5) will actually lead to an increase in the expected execution time of the software program, compared to the execution time of the same program when the checkpointing mechanism is not adopted. This suggests that frequent checkpointing which enhances the reliability of the software program, may result in increases of execution time due to the cost of checkpointing itself. Similar observations can be made for software with longer loops in Figures 2-4.