jnt.scimark2.MonteCarlo Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of scimark Show documentation
Show all versions of scimark Show documentation
SciMark 2.0 is a Java benchmark for scientific and numerical
computing. It measures several computational kernels and reports a composite
score in approximate Mflops (Millions of floating point operations per
second).
The newest version!
package jnt.scimark2;
/**
Estimate Pi by approximating the area of a circle.
How: generate N random numbers in the unit square, (0,0) to (1,1)
and see how are within a radius of 1 or less, i.e.
sqrt(x^2 + y^2) < r
since the radius is 1.0, we can square both sides
and avoid a sqrt() computation:
x^2 + y^2 <= 1.0
this area under the curve is (Pi * r^2)/ 4.0,
and the area of the unit of square is 1.0,
so Pi can be approximated by
# points with x^2+y^2 < 1
Pi =~ -------------------------- * 4.0
total # points
*/
public class MonteCarlo
{
final static int SEED = 113;
public static final double num_flops(int Num_samples)
{
// 3 flops in x^2+y^2 and 1 flop in random routine
return ((double) Num_samples)* 4.0;
}
public static final double integrate(int Num_samples)
{
Random R = new Random(SEED);
int under_curve = 0;
for (int count=0; count