@@ -24,23 +24,26 @@ void calcPi(unsigned short threadid) {
24
24
mpf_t value;
25
25
mpf_t divisor;
26
26
mpf_t one;
27
+ mpf_t two;
27
28
mpf_t nptr;
28
29
29
30
mpf_init (local_pi);
30
31
mpf_init (value);
31
32
mpf_init (divisor);
32
33
mpf_init2 (one, 53 );
33
34
mpf_set_d (one, 1.0 );
35
+ mpf_init2 (two, 53 );
36
+ mpf_set_d (two, 2.0 );
34
37
mpf_init2 (nptr, 53 );
35
38
36
39
for (unsigned long long n=start; n<=end; n++) {
37
- mpf_set_d (value, 1.0 );
38
- mpf_set_d (divisor, 2.0 );
40
+ // mpf_set_d(value, 1.0);
41
+ // mpf_set_d(divisor, 2.0);
39
42
mpf_set_d (nptr, n);
40
43
41
- mpf_mul (divisor, divisor , nptr); // divisor = 2 * n
44
+ mpf_mul (divisor, two , nptr); // divisor = 2 * n
42
45
mpf_add (divisor, divisor, one); // divisor = 2 * n + 1
43
- mpf_div (value, value , divisor); // value = 1 / (2 * n + 1)
46
+ mpf_div (value, one , divisor); // value = 1 / (2 * n + 1)
44
47
45
48
if (lastAddition)
46
49
mpf_sub (local_pi, local_pi, value);
@@ -57,13 +60,11 @@ void calcPi(unsigned short threadid) {
57
60
void run (unsigned short threadsCount, unsigned long long totalRounds) {
58
61
std::vector<std::thread> threads (threadsCount);
59
62
if ((totalRounds == 0 || threadsCount == 0 )) {
60
- printf (" Either totalRounds or timeout must be specified or else the program runs forever \n " );
63
+ printf (" TotalRounds and threadsCount must not be 0 \n " );
61
64
exit (1 );
62
65
}
63
- if (totalRounds) {
64
- splitRounds = checkTotalRounds = totalRounds;
65
- checkTotalRounds *= threadsCount;
66
- }
66
+ splitRounds = checkTotalRounds = totalRounds;
67
+ checkTotalRounds *= threadsCount;
67
68
for (unsigned short threadid=0 ; threadid<threadsCount; threadid++) {
68
69
threads[threadid] = std::thread (calcPi, threadid);
69
70
}
0 commit comments