2 % @brief Compute Harmonic sum H_K = sum(1/k)
for k=1 to K
4 % @author LINE Development Team
8 % @brief Compute Harmonic sum H_K = sum(1/k)
for k=1 to K
11 % Computes the K-th Harmonic number, which
is the sum of reciprocals
12 % from 1 to K. This
is a fundamental quantity in Fork-Join analysis.
14 % For large K, H_K ≈ ln(K) + γ, where γ ≈ 0.57721
is the Euler-Mascheroni
24 % <tr><th>Name<th>Description
25 % <tr><td>K<td>Number of parallel servers (positive integer)
30 % <tr><th>Name<th>Description
31 % <tr><td>H<td>Harmonic sum H_K = 1 + 1/2 + 1/3 + ... + 1/K
35 % A. Thomasian, "Analysis of Fork/Join and Related Queueing Systems",
36 % ACM Computing Surveys, Vol. 47, No. 2, Article 17, July 2014.
38function H = fj_harmonic(K)
41 line_error(mfilename, 'K must be a positive integer. Got K=%d.', K);
44% Compute harmonic sum: H_K = sum_{k=1}^{K} 1/k