double Converter::calculate(const QVector<double> &res, const QVector<double> &pres, double val) const { /*double sum = 0.0,x1 = 0.0,y1 = 0.0,y0=0.0,x0=0.0; for(auto it = res.begin(); it != res.end(); ++it){ if(*it > val){ if(it == res.begin()){ x0 = *res.begin(); y0 = *pres.begin(); x1 = *(res.begin()+1); y1 = *(pres.begin()+1); break; } x1 = *it; y1 = pres[it - res.begin()]; x0 = *(it-1); y0 = pres[it - res.begin() - 1]; break; } if(it + 1 == res.end()){ x0 = *(it-1); y0 = pres[res.size()-2]; x1 = *it; y1 = pres[res.size()-1]; } } sum = y0 + (y1 - y0) * (val - x0) / ( x1 - x0);*/ /*double sum=0,l=1; for(int j = 0;j < res.size(); ++j){ for(int i = 0; i < res.size(); ++i){ if( j != i){ l*= (val - res[i])/(double)(res[j]-res[i]); } } sum += l*pres[j]; l = 1; }*/ auto p = leastsquares(res,pres); double sum = p.first * exp(p.second*val)-1.0; return sum; }
void bspbench(){ void leastsquares(int h0, int h1, double *t, double *g, double *l); int p, s, s1, iter, i, n, h, destproc[MAXH], destindex[MAXH]; double alpha, beta, x[MAXN], y[MAXN], z[MAXN], src[MAXH], *dest, time0, time1, time, *Time, mintime, maxtime, nflops, r, g0, l0, g, l, t[MAXH+1]; /**** Determine p ****/ bsp_begin(P); p= bsp_nprocs(); /* p = number of processors obtained */ s= bsp_pid(); /* s = processor number */ Time= vecallocd(p); bsp_push_reg(Time,p*SZDBL); dest= vecallocd(2*MAXH+p); bsp_push_reg(dest,(2*MAXH+p)*SZDBL); bsp_sync(); /**** Determine r ****/ for (n=1; n <= MAXN; n *= 2){ /* Initialize scalars and vectors */ alpha= 1.0/3.0; beta= 4.0/9.0; for (i=0; i<n; i++){ z[i]= y[i]= x[i]= (double)i; } /* Measure time of 2*NITERS DAXPY operations of length n */ time0=bsp_time(); for (iter=0; iter<NITERS; iter++){ for (i=0; i<n; i++) y[i] += alpha*x[i]; for (i=0; i<n; i++) z[i] -= beta*x[i]; } time1= bsp_time(); time= time1-time0; bsp_put(0,&time,Time,s*SZDBL,SZDBL); bsp_sync(); /* Processor 0 determines minimum, maximum, average30 INTRODUCTION computing rate */ if (s==0){ mintime= maxtime= Time[0]; for(s1=1; s1<p; s1++){ mintime= MIN(mintime,Time[s1]); maxtime= MAX(maxtime,Time[s1]); } if (mintime>0.0){ /* Compute r = average computing rate in flop/s */ nflops= 4*NITERS*n; r= 0.0; for(s1=0; s1<p; s1++) r += nflops/Time[s1]; r /= p; printf("n= %5d min= %7.3lf max= %7.3lf av= %7.3lf Mflop/s ", n, nflops/(maxtime*MEGA),nflops/ (mintime*MEGA), r/MEGA); fflush(stdout); /* Output for fooling benchmark-detecting compilers */ printf(" fool=%7.1lf\n",y[n-1]+z[n-1]); } else printf("minimum time is 0\n"); fflush(stdout); } } /**** Determine g and l ****/ for (h=0; h<=MAXH; h++){ /* Initialize communication pattern */ for (i=0; i<h; i++){ src[i]= (double)i; if (p==1){ destproc[i]=0; destindex[i]=i; } else { /* destination processor is one of the p-1 others */ destproc[i]= (s+1 + i%(p-1)) %p; /* destination index is in my own part of dest */ destindex[i]= s + (i/(p-1))*p; } } /* Measure time of NITERS h-relations */ bsp_sync(); time0= bsp_time(); for (iter=0; iter<NITERS; iter++){ for (i=0; i<h; i++) bsp_put(destproc[i],&src[i],dest,destindex[i]*SZDBL, SZDBL); bsp_sync(); } time1= bsp_time(); time= time1-time0; /* Compute time of one h-relation */ if (s==0){ t[h]= (time*r)/NITERS; printf("Time of %5d-relation= %lf sec= %8.0lf flops\n", h, time/NITERS, t[h]); fflush(stdout); } } if (s==0){ printf("size of double = %d bytes\n",(int)SZDBL); leastsquares(0,p,t,&g0,&l0); printf("Range h=0 to p : g= %.1lf, l= %.1lf\n",g0,l0); leastsquares(p,MAXH,t,&g,&l); printf("Range h=p to HMAX: g= %.1lf, l= %.1lf\n",g,l); printf("The bottom line for this BSP computer is:\n"); printf("p= %d, r= %.3lf Mflop/s, g= %.1lf, l= %.1lf\n", p,r/MEGA,g,l); fflush(stdout); } bsp_pop_reg(dest); vecfreed(dest); bsp_pop_reg(Time); vecfreed(Time); bsp_end(); } /* end bspbench */
void bspbench(){ void leastsquares(int h0, int h1, double *t, double *g, double *l); int p, s, s1, iter, i, n, h, destproc[MAXH], destindex[MAXH]; double alpha, beta, x[MAXN], y[MAXN], z[MAXN], src[MAXH], *dest, time0, time1, time, *Time, mintime, maxtime, nflops, r, g0, l0, g, l, t[MAXH+1]; size_t pin[100]; // Determine p // start: new code for pinning for (i=0; i< tnode->length; i++) pin[i] = tnode->sons[i]->index; mcbsp_set_pinning( pin, tnode->length ); bsp_begin(tnode->length); // end: new code for pinning p= bsp_nprocs(); // p = number of processors obtained s= bsp_pid(); // s = processor number Time= vecallocd(p); bsp_push_reg(Time,p*SZDBL); dest= vecallocd(2*(MAXH+p)); bsp_push_reg(dest,(2*(MAXH+p))*SZDBL); bsp_sync(); // Determine r for (n=1; n < MAXN; n *= 2){ // Initialize scalars and vectors alpha= 1.0/3.0; beta= 4.0/9.0; for (i=0; i<n; i++){ z[i]= y[i]= x[i]= (double)i; } // Measure time of 2*NITERS DAXPY operations of length n time0=bsp_time(); for (iter=0; iter<NITERS; iter++){ for (i=0; i<n; i++) y[i] += alpha*x[i]; for (i=0; i<n; i++) z[i] -= beta*x[i]; } time1= bsp_time(); time= time1-time0; bsp_put(0,&time,Time,s*SZDBL,SZDBL); bsp_sync(); // Processor 0 determines minimum, maximum, average computing rate if (s==0){ mintime= maxtime= Time[0]; for(s1=1; s1<p; s1++){ mintime= MIN(mintime,Time[s1]); maxtime= MAX(maxtime,Time[s1]); } if (mintime>0.0){ // Compute r = average computing rate in flop/s nflops= 4*NITERS*n; r= 0.0; for(s1=0; s1<p; s1++) r += nflops/Time[s1]; r /= p; //printf("n= %5d min= %7.3lf max= %7.3lf av= %7.3lf Mflop/s ", // n, nflops/(maxtime*MEGA),nflops/(mintime*MEGA), r/MEGA); //fflush(stdout); // Output for fooling benchmark-detecting compilers printf( "", y[n-1]+z[n-1] ); } } } // Determine g and l for (h=0; h<=MAXH; h++){ // Initialize communication pattern for (i=0; i<h; i++){ src[i]= (double)i; if (p==1){ destproc[i]=0; destindex[i]=i; } else { // destination processor is one of the p-1 others destproc[i]= (s+1 + i%(p-1)) %p; // destination index is in my own part of dest destindex[i]= s + (i/(p-1))*p; } } for (i=0; i<h; i++){ src[i]= (double)i; if (p==1){ destproc[i]=0; destindex[i]=i; } else { // destination processor is one of the p-1 others destproc[i]= (s+1 + i%(p-1)) %p; // destination index is in my own part of dest destindex[i]= s + (i/(p-1))*p; } } // Measure time of NITERS h-relations bsp_sync(); time0= bsp_time(); for (iter=0; iter<NITERS; iter++){ for (i=0; i<h; i++) { //bsp_get(0, dest, destindex[i]*SZDBL, &src[i] , SZDBL); //bsp_get(destproc[i], dest, destindex[i]*SZDBL, &src[i] , SZDBL); bsp_put(destproc[i], &src[i] , dest , destindex[i]*SZDBL, SZDBL); } //if (s == 0) // bsp_get(0, dest, destindex[i]*SZDBL, &src[i] , SZDBL); bsp_sync(); } time1= bsp_time(); time= time1-time0; // Compute time of one h-relation if (s==0){ t[h]= (time*r)/NITERS; //#define SEHLOC_BENCH_VERBOSE #ifdef SEHLOC_BENCH_VERBOSE char strnodes[256]; sprintf(strnodes, ""); for (i=0; i<tnode->length; i++) { sprintf(strnodes, "%s %d", strnodes, tnode->sons[i]->index); } printf("SEH# Level%d %5d %lf %8.0lf\n", tnode->level, h, time/NITERS, t[h]); fflush(stdout); #endif } } if (s==0){ leastsquares(0,p,t,&g0,&l0); printf("Range h=0 to p : g= %.1lf, l= %.1lf\n",g0,l0); leastsquares(p,MAXH,t,&g,&l); g=(g>0)? g: g0*2; printf("Range h=p to HMAX: g= %.1lf, l= %.1lf\n",g,l); //printf("plot# %d %.1lf %.1lf\n",tnode->level, g,l); printf("The bottom line for this MultiBSP component is:\n"); printf("<p= %d, r= %.3lf Mflop/s, g= %.1lf, l= %.1lf>\n", p,r/MEGA,g,l); fflush(stdout); } bsp_pop_reg(dest); vecfreed(dest); bsp_pop_reg(Time); vecfreed(Time); bsp_end(); } /* end bspbench */