/* Prepare the matrices for the lcp call pA = [-M -1 q] */ PT_Matrix lcp_Matrix_Init(ptrdiff_t m, double *M, double *q) { ptrdiff_t i,n,incx; double tmp; PT_Matrix pA; /* Build column-major matrix A = [-M -1 q] */ pA = Matrix_Init(m,m+2,"A"); /* A(:,1:m) = M */ memcpy(pMAT(pA), M, m*m*sizeof(double)); /* A(:,1:m) = -A(:,1:m) */ tmp = -1.0; incx = 1; n = m*m; dscal(&n, &tmp, pMAT(pA), &incx); /* A(:,m+1) = -1 */ for(i=0;i<m;i++) C_SEL(pA,i,m) = -1.0; /* A(:,m+2) = q */ memcpy(&(C_SEL(pA,0,m+1)),q,m*sizeof(double)); return pA; }
/* Function: mdlStart ======================================================= * Abstract: * allocate memory for work vectors */ static void mdlStart(SimStruct *S) { ssGetPWork(S)[0] = calloc(NSTATES(S)*NSTATES(S), sizeof(double)); /* Mn */ ssGetPWork(S)[1] = calloc(NSTATES(S), sizeof(double)); /* qn */ ssGetPWork(S)[2] = calloc(NSTATES(S), sizeof(double)); /* r */ ssGetPWork(S)[3] = calloc(NSTATES(S), sizeof(double)); /* c */ ssGetPWork(S)[4] = calloc(NSTATES(S), sizeof(double)); /* x */ ssGetPWork(S)[5] = Matrix_Init(NSTATES(S),NSTATES(S)+2,"A"); /* pA */ ssGetPWork(S)[6] = Basis_Init(NSTATES(S)); /* pB */ }
void count_new(Value* cb, int lanes[NLANES][L],int filaments,int noconsts){ //clock_t t1 = clock(); Polyhedron *A; int i,j; Matrix *M; //printf("inside count we have the following lanes for %d filaments and %d noconsts:\n",filaments,noconsts); //dump_lanes(lanes); M=Matrix_Alloc(noconsts,filaments+2); //lock_t t2 = clock(); int** constraints; constraints= malloc(noconsts*sizeof(int *)); //clock_t t3 = clock(); //printf("%lu\n",(filaments+2)*(noconsts)); for (i=0;i<noconsts;i++){ constraints[i]=(int*)malloc(sizeof(int)*(filaments+2)); for(j=0;j<filaments+2;j++){ constraints[i][j]=0; //printf("%d %d %d\n",i,j,constraints[i][j]); } } //clock_t t4 = clock(); //printf("from count: fils %d noconsts %d\n",filaments,noconsts); gen_constraints(constraints,lanes,filaments,noconsts); //clock_t t5 = clock(); struct barvinok_options *options = barvinok_options_new_with_defaults(); Matrix_Init(M,constraints); //clock_t t6 = clock(); A=Constraints2Polyhedron(M,options->MaxRays); //clock_t t7 = clock(); barvinok_count_with_options(A, cb, options); //clock_t t8 = clock(); //printf("timings at count: t2=%f, t3=%f, t4=%f, t5=%f, t6=%f, t7=%f, t8=%f\n",(double)(t2-t1)/CLOCKS_PER_SEC,(double)(t3-t1)/CLOCKS_PER_SEC,(double)(t4-t1)/CLOCKS_PER_SEC,(double)(t5-t1)/CLOCKS_PER_SEC,(double)(t6-t1)/CLOCKS_PER_SEC,(double)(t7-t1)/CLOCKS_PER_SEC,(double)(t8-t1)/CLOCKS_PER_SEC); Polyhedron_Free(A); barvinok_options_free(options); Matrix_Free(M); for (i=0;i<noconsts;i++){ free(constraints[i]); } free(constraints); }
/* Initialize basis */ PT_Basis Basis_Init(ptrdiff_t m) { ptrdiff_t i; PT_Basis pB; pB = (PT_Basis)malloc(sizeof(T_Basis)); /* Initialize indices */ pB->pW = Index_Init(m,"W"); pB->pZ = Index_Init(m,"Z"); pB->pWc = Index_Init(m,"Wc"); pB->pP = Index_Init(m,"P"); /* Initial basis is I = [1:m] */ /* or W = [1:m], Z = [], Wc = [] */ for(i=0;i<m;i++) (pB->pW)->I[i] = i; (pB->pZ)->len = 0; (pB->pWc)->len = 0; /* Reserve space for a G matrix of max size (m x m) */ pB->pG = Matrix_Init(m, m, "B.G"); /* G is of size |W|x|Z| */ (pB->pG)->rows = m; (pB->pG)->cols = 0; /* Reserve space for an X matrix of max size (m x m) */ /* this matrix is to be factored */ /* X = inv(LX)*UX */ pB->pX = Matrix_Init(m, m, "B.X"); (pB->pX)->rows = pB->pWc->len; (pB->pX)->cols = pB->pZ->len; /* Reserve space for factored matrix F = P*L*U of max size (m x m) */ pB->pF = Matrix_Init(m, m, "B.F"); (pB->pF)->rows = pB->pWc->len; (pB->pF)->cols = pB->pZ->len; /* Setup the initial decomposition of X for LUmod */ /* X starts empty - so just reserve space */ /* LUmod performs factorization of type L*X = U */ /* LX is row major, full */ /* UX is row major, upper triangular */ /* Ut is column major, full with upper triangular entries */ pB->pLX = Matrix_Init(m,m,"B.LX"); pB->pUX = Matrix_Init(m,m,"B.UX"); pB->pUt = Matrix_Init(m,m,"B.Ut"); pB->pLX->rows = pB->pWc->len; pB->pLX->cols = pB->pZ->len; pB->pUX->rows = pB->pWc->len; pB->pUX->cols = pB->pZ->len; pB->pUt->rows = pB->pWc->len; pB->pUt->cols = pB->pZ->len; /* Work vectors*/ /* allocate always 5 elements more because there were problems detected * when freeing vectors */ pB->y = (double *)calloc(m+5,sizeof(double)); pB->z = (double *)calloc(m+5,sizeof(double)); pB->w = (double *)calloc(m+5,sizeof(double)); pB->v = (double *)calloc(m+5,sizeof(double)); pB->r = (double *)calloc(m+5,sizeof(double)); pB->p = (ptrdiff_t *)calloc(m+5,sizeof(ptrdiff_t)); /* for dgesv, dgetrs routine */ pB->s = (double *)calloc(2*m+5,sizeof(double)); /* for dgels routine */ return pB; }