Changes

Jump to: navigation, search

Dev/null

1,933 bytes added, 23:28, 14 October 2015
Assignment 1
100.00 10.05 10.05 compute_pi(int)
0.00 10.05 0.00 1 0.00 0.00 _GLOBAL__sub_I__Z10compute_pii</pre>
 
 
==== Calculation of prime numbers ====
 
Prime numbers are essential in the science of cryptography and are a good test of computational capacity of computers. The bigger the number, the more exponentially the hardware must work to calculate the next prime number.
 
Calculation of prime numbers is a very simple objective with a simple double for loop:
 
 
for (int i = 2; i<100; i++)
for (int j = 2; j*j <= i; j++)
{
if (i % j == 0)
break;
else if (j + 1 > sqrt(i)) {
std::cout << i << " ";
}
}
 
 
However, this serial processing is extremely inefficient when the numbers become extremely large. For the range of 1-1,000,000 the results are as follows:
 
real 0m4.982s
user 0m3.644s
sys 0m0.072s
 
 
 
 
Flat profile:
 
Each sample counts as 0.01 seconds.
% cumulative self self total
time seconds seconds calls Ts/call Ts/call name
100.00 3.63 3.63 genPrime(unsigned long long, unsigned long long)
0.00 3.63 0.00 1 0.00 0.00 _GLOBAL__sub_I__Z8genPrimeyy
 
 
 
There are 78496 prime numbers in the calculated range. Splitting the for loop between several cores to handle each subrange separately can yield extremely high performance gains.
 
Console output:
 
 
\\CPD S4\GPU610\a1\a1Boris\Debug>a1Boris 5000
***Team /dev/null GPU610 PRIME NUMBER GENERATOR***
No range given (or bad input), using preset values
Generating from range (0~5000)
--------------------------------------------------------------------------------
5 7 11 13 17 19 23 29 31
37 41 43 47 53 59 61 67 71 73
79 83 89 97 101 103 107 109 113 127
131 137 139 149 151 157 163 167 173 179
181 191 193 197 199 211 223 227 229 233
=== Assignment 2 ===
=== Assignment 3 ===

Navigation menu