

|
End-user products => VAST/DPC => DPC example
| ||
|
DPC Example | ||
Here's a little DPC program that calculates the value of pi. Note
in particular the "shape" declaration (in this case no distribution
is specified by the programmer, so the compiler chooses one), the array
assignment of x, and the summation operation.
#includeIf you're wondering what the code is doing... for 1 processor:
...
dpce_descriptor_t span;
int vdpc_span = 0;
double fabs(double );
main( )
{
int j1, *j2, j3, j4;
float r1, r2;
double d1;
double sum;
double width;
double x[10000];
if ( !vdpc_span )
{
vdpc_init_desc( &span, 3,1,10000,10000,1 );
vdpc_span = 1;
}
r1 = 1.F / 10000;
r2 = 0.;
for ( j1=0; j1 < 10000; j1++ )
{
x[j1] = ((r2 + 0.5) * 1.0) * r1;
r2 = r2 + 1.;
}
d1 = 0;
for ( j1=0; j1 <= 9999; j1 += 1 )
d1 = d1 + 4.0 / (1.0 + x[j1] * x[j1]);
sum = d1;
sum *= 1.0 / 10000;
printf( "Estimation of pi is %14.12f\n", sum );
fabs( sum - 3.141592 ) < 0.00001 ? (void )0 : _assert(
"fabs (sum - 3.141592) < 0.00001", "pi.dpc",25 );
}
| ||
Contact
Legal