/* Test setup for polynomial evaluation. Do not change this. */ #include #include #include #include //#include #include "poly.h" #include "cpe.h" #include "clock.h" double CPU_Mhz; /* Degree for fixed evaluation */ #define FIXDEGREE 10 /* Largest degree polynomial tested */ #define MAXDEGREE 2000 static int coeff[MAXDEGREE+1]; #define MAX_ITER_COUNT 100 #define REF_CPU_MHZ 2292.6 // 这是我的处理器主频 /* Define performance standards */ static struct { double cref; /* Cycles taken by reference solution */ double cbest; /* Cycles taken by our best implementation */ } cstandard[3] = {{4.00, 1.75}, /* CPE */ {50, 43}, /* C(10) */ {57,31} /* 常系数多项式计算 */ }; int coeff_const[4]; /* Should I print extra information? */ int verbose = 0; /* Standard value for polynomial evaluation */ static int xval; /* How many degrees should I compute reference value for? */ #define DCNT 20 /* Correct value of polynomial evaluation for range of different degrees */ /* pval[i] contains evaluation for degree MAXDEGREE-i */ static int pval[DCNT]; /* fixval contains evaluation for degree FIXDEGREE */ static int fixval; static int fixval_const; static void init_const_poly(void); static void init(void); extern int const_poly_eval(int *not_use, int not_use2, int x); void run_fun_const(int degree); static double compute_score(double cmeas, double cref, double cbest); unsigned long rand1_h,rand1_l,rand_div; void rand_step(unsigned long divv); void GenerateRandomNumber(unsigned long divv); extern void make_CPU_busy(void); double run_poly_perf_test(void); /* Reference implementation */ static int ref_poly_eval(int *a, int degree, int x) { int result = 0; int i; int xpwr = 1; /* Successive powers of x */ for (i = 0; i <= degree; i++) { result += a[i]*xpwr; xpwr *= x; } return result; } /* Initialize polynomial to constant values and compute reference values */ static void init_const_poly(void) { int i; for (i=0;i<4;i++) { GenerateRandomNumber(90); coeff_const[i] = rand_div+10; } printf("你需要修改poly.c的const_poly_eval函数,实现下面的常数多项式计算!\n"); printf("\tresult=%d+%d*x+%d*x^2+%d*x^3\n",coeff_const[0],coeff_const[1],coeff_const[2],coeff_const[3]); fixval_const = ref_poly_eval(coeff_const, 3, xval); // printf("x=%d, fixval_const=%d\n",xval,fixval_const); } void test_const_poly(void) { int i; double fix_time=0; int my_cal = const_poly_eval(coeff_const, 3, xval); if (fixval_const != my_cal) { printf("常系数多项式计算const_poly_eval实现错误(x=%d),预期结果是%d,但是计算得到的是%d\n",xval,fixval_const,my_cal); exit(0); } fix_time = 0; for (i=0;i 1.1*(sbest-1)+1) return 120; return 100*((smeas-1.0)/(sbest-1.0) + 0.1); } /* 产生一个0~divv-1之间的随机数,同时更新随机数种子 */ void GenerateRandomNumber(unsigned long divv) { unsigned long long x = rand1_h; x *= 0x6AC690C5; x += rand1_l; rand1_h = (unsigned long)x; rand1_l = (unsigned long)(x>>32); if (divv==0) return; rand_div = rand1_h % divv; } int main(int argc, char *argv[]) { int i; double cpe = cstandard[0].cref; double cfix = cstandard[1].cref; verbose = 0; srand((unsigned int)time(NULL)); // CPU_Factor(); // GetCpuClock(); printf("\t2015多项式优化实验,欢迎你!\n"); printf("============================\n"); if (argc == 1) { printf("使用方法:%s 学号后6位 [学号后6位] [学号后6位] ...\n",argv[0]); printf("你需要依据提示改写poly.c程序,实现一个常系数多项式的计算,尽可能快哦....\n"); printf("另外,你需要改写poly.c程序,实现任意阶的多项式计算和10阶的多项式计算,要快!\n"); return 0; } /*依据学号,初始化一个随机数发生器*/ rand1_h = (unsigned long)atoi(argv[1]); rand1_l=0x29A; GenerateRandomNumber(0); for (i=2;i