std::vector < T > Get_Data(const bool &noise_amplitude_is_known, const T &noise_amplitude) { T alpha = 1; T this_sigma = 1000; T prev_sigma = this_sigma; std::vector < T > a, b, c, f; Fill(alpha, a, c, b, f); solveMatrix(this->N + 1, a, c, b, f, this->Z); while (true) { _Z = Z; prev_sigma = this_sigma; alpha *= 0.5; Fill(alpha, a, c, b, f); solveMatrix(this->N + 1, a, c, b, f, this->Z); this_sigma = sigma(); if (noise_amplitude_is_known) { if (ro() - SQR(noise_amplitude) <= 0) { cerr << "alpha = " << alpha << endl; return this->Z; } } else { // if (this_sigma > prev_sigma) { if (alpha < noise_amplitude) { cerr << "alpha = " << alpha << ", sigma = " << this_sigma << endl; return this->Z; } } } }
void solveSplineDimension(IN int n /*numver of points*/, IN const double *y /*y[n]*/, OUT struct pol *p /*p[n-1]*/) //http://mathworld.wolfram.com/CubicSpline.html { double D[n], v[n]; double primdiag[n], supdiag[n], subdiag[n]; n--; for (int i = 0; i<=n; ++i) { primdiag[i] = 4.0; supdiag[i] = subdiag[i] = 1.0; if (i>0 && i<n) v[i] = 3*(y[i+1]-y[i-1]); } v[0] = 3*(y[1]-y[0]); v[n] = 3*(y[n]-y[n-1]); primdiag[0] = primdiag[n-1] = 2.0; solveMatrix(n, supdiag, primdiag, subdiag, v, D); for (int i = 0; i<n; ++i) { p[i].a = y[i]; p[i].b = D[i]; p[i].c = 3*(y[i+1]-y[i])-2*D[i]-D[i+1]; p[i].d = 2*(y[i]-y[i+1])+D[i]+D[i+1]; } }
void mexFunction(int nlhs, mxArray *plhs[], int nrhs, const mxArray *prhs[]) { double *a, *diag, *c, *V, *U; double *sub_diag, *hyp_diag; double **d, **rhs, b; int N, i, step, dims, j; /*can be replaced with mxGetM*/ int tid, nthreads; if( 0 == nlhs || nrhs < 5) mexErrMsgTxt("not enough input arguments"); plhs[0] =prhs[0]; U= mxGetPr(plhs[0]); sub_diag= mxGetPr(prhs[1]); diag= mxGetPr(prhs[2]); hyp_diag= mxGetPr(prhs[3]); V= mxGetPr(prhs[4]); N= mxGetM( prhs[0] ); d= (double *)mxMalloc(N*sizeof(double)); rhs= (double *)mxMalloc(N*sizeof(double)); #if 0 if( N==mxGetN(prhs[1]) ) ismatrix=1; else ismatrix=0; #endif nthreads = par_mat_init(&d, &rhs, N); dims = mxGetNumberOfDimensions( prhs[0] ); #pragma omp parallel shared(N, d, rhs, sub_diag, diag, hyp_diag, U)\ private(i, j, tid) { tid = omp_get_thread_num(); #pragma omp for schedule(guided) nowait for(i =0; i < N; ++i) { for( j =0; j < N; ++j) { init_param( d[tid], diag+ j*N +i*N*N, N); init_param( rhs[tid], V + j*N + i*N*N, N); solveMatrix(N, sub_diag+ j*N + i*N*N, d[tid], hyp_diag+j*N+i*N*N, rhs[tid], U + j*N + i*N*N); } } } par_mat_free(d, rhs, nthreads); return; }
void mexFunction(int nlhs, mxArray *plhs[], int nrhs, const mxArray *prhs[]){ double *a, *diag, *c, *V, *U; double *sub_diag, *hyp_diag; double *d, *rhs, b; int N, i, step, ismatrix; /*can be replaced with mxGetM*/ if( 0 == nlhs || nrhs < 5) mexErrMsgTxt("not enough input arguments"); plhs[0] =prhs[0]; U= mxGetPr(plhs[0]); sub_diag= mxGetPr(prhs[1]); diag= mxGetPr(prhs[2]); hyp_diag= mxGetPr(prhs[3]); V= mxGetPr(prhs[4]); N= mxGetM( prhs[0] ); d= (double *)mxMalloc(N*sizeof(double)); rhs= (double *)mxMalloc(N*sizeof(double)); if( N==mxGetN(prhs[1]) ) ismatrix=1; else ismatrix=0; for(i =0; i <N; ++i){ init_param( d, diag+i*N, N); init_param( rhs, V+i*N, N); solveMatrix(N, sub_diag+i*N*ismatrix, d, hyp_diag+i*N*ismatrix, rhs, U +i*N); } mxFree(d); mxFree(rhs); return; }
/***************************************************** * main function *****************************************************/ int main(int argc, char** argv) { freopen("i.txt", "r", stdin); freopen("o.txt", "w", stdout); // read input file if(input(stdin)) { printf("Read successfully!\n"); } putchar('\n'); // construct SDF graph constructSDF(); printMatrix(stdout); putchar('\n'); // solve vector q printf("==== Solve Matrix ====\n"); if(solveMatrix()) { printf("Solve Matrix successfully!\n"); printq(stdout); putchar('\n'); } else { printf("Can't solve Matrix...\n"); exit(1); } putchar('\n'); // translate SDF to DAG printf("======== DAG ========\n"); if(SDF2DAG()) { printDAG(stdout); } else { printf("DAG error!\n"); exit(2); } putchar('\n'); #ifndef NDEBUG // calc Static b-level printf("======== SBL ========\n"); calcBLevel(); printBLevel(stdout); putchar('\n'); #endif // calc shortest Message Route printf("====== NextHop ======\n"); calcNextHop(); printNextHop(stdout); putchar('\n'); // Schedules printf("===== Schedules =====\n"); if(doDLS()) { printSchedules(stdout); putchar('\n'); printf(" ---- Task ----\n"); printTaskSchedules(stdout); FILE *datafile = fopen("data.txt", "w"); if(datafile == NULL){ printf("Error open data.txt file!\n"); exit(3); } printScheduleData(datafile); fclose(datafile); } else { printf("Schedule failed...\n"); exit(4); } putchar('\n'); return 0; }