资源简介
linpack benchmark c code
代码片段和文件信息
# include
# include
# include
# include
int main ( void );
double cpu_time ( void );
void daxpy ( int n double da double dx[] int incx double dy[] int incy );
double ddot ( int n double dx[] int incx double dy[] int incy );
int dgefa ( double a[] int lda int n int ipvt[] );
void dgesl ( double a[] int lda int n int ipvt[] double b[] int job );
void dscal ( int n double sa double x[] int incx );
int idamax ( int n double dx[] int incx );
double r8_abs ( double x );
double r8_epsilon ( void );
double r8_max ( double x double y );
double r8_random ( int iseed[4] );
double *r8mat_gen ( int lda int n );
void timestamp ( void );
/******************************************************************************/
int main ( void )
/******************************************************************************/
/*
Purpose:
MAIN is the main program for LINPACK_BENCH.
Discussion:
LINPACK_BENCH drives the double precision LINPACK benchmark program.
Modified:
25 July 2008
Parameters:
N is the problem size.
*/
{
# define N 1000
# define LDA ( N + 1 )
double *a;
double a_max;
double *b;
double b_max;
double cray = 0.056;
double eps;
int i;
int info;
int *ipvt;
int j;
int job;
double ops;
double *resid;
double resid_max;
double residn;
double *rhs;
double t1;
double t2;
double time[6];
double total;
double *x;
timestamp ( );
printf ( “\n“ );
printf ( “LINPACK_BENCH\n“ );
printf ( “ C version\n“ );
printf ( “\n“ );
printf ( “ The LINPACK benchmark.\n“ );
printf ( “ Language: C\n“ );
printf ( “ Datatype: Double precision real\n“ );
printf ( “ Matrix order N = %d\n“ N );
printf ( “ Leading matrix dimension LDA = %d\n“ LDA );
ops = ( double ) ( 2 * N * N * N ) / 3.0 + 2.0 * ( double ) ( N * N );
/*
Allocate space for arrays.
*/
a = r8mat_gen ( LDA N );
b = ( double * ) malloc ( N * sizeof ( double ) );
ipvt = ( int * ) malloc ( N * sizeof ( int ) );
resid = ( double * ) malloc ( N * sizeof ( double ) );
rhs = ( double * ) malloc ( N * sizeof ( double ) );
x = ( double * ) malloc ( N * sizeof ( double ) );
a_max = 0.0;
for ( j = 0; j < N; j++ )
{
for ( i = 0; i < N; i++ )
{
a_max = r8_max ( a_max a[i+j*LDA] );
}
}
for ( i = 0; i < N; i++ )
{
x[i] = 1.0;
}
for ( i = 0; i < N; i++ )
{
b[i] = 0.0;
for ( j = 0; j < N; j++ )
{
b[i] = b[i] + a[i+j*LDA] * x[j];
}
}
t1 = cpu_time ( );
info = dgefa ( a LDA N ipvt );
if ( info != 0 )
{
printf ( “\n“ );
printf ( “LINPACK_BENCH - Fatal error!\n“ );
printf ( “ The matrix A is apparently singular.\n“ );
printf ( “ Abnormal end of execution.\n“ );
return 1;
}
t2 = cpu_time ( );
time[0] = t2 - t1;
t1 = cpu_time ( );
job = 0;
dgesl ( a LDA N ipvt b job );
t2 = cpu_time ( );
time[1] = t2 - t1;
total = time[0] +
- 上一篇:蚁群算法实验室
- 下一篇:2017山大软件项目管理期末复习
评论
共有 条评论