Составители:
* - calculates the areas of its rectangles
* - synchronizes for a global summation
* Process 0 prints the result and the time it took
******/
class Pi extends Thread
{
int from,to ;
static int nn,n=72000000,np=4; // np - number of processors
double h,sum,x;
static double ssum = 0.0 ;
static int j ;
static long st,end ;
public Pi(int from, int to)
{
this.from = from;
this.to = to;
}
public double f(double a)
{
return(4.0 / (1.0 + a*a));
}
// synchronization
synchronized void count()
{
j = j + 1;
ssum += h * sum ;
System.out.println("ssum == " + ssum);
if ( j == np )
System.out.println("ssum-pi="+(ssum-Math.PI));
}
public void run()
{
st = System.currentTimeMillis(); // start
System.out.println(this);
h = 1.0 / (double) n;
sum = 0.0;
for (int i=from; i<to; i++)
72
Страницы
- « первая
- ‹ предыдущая
- …
- 70
- 71
- 72
- 73
- 74
- …
- следующая ›
- последняя »