static void test_hmatrix_system(const char *apprxtype, pcamatrix Vfull, pcamatrix KMfull, pblock block, pbem2d bem_slp, phmatrix V, pbem2d bem_dlp, phmatrix KM, bool exterior) { pavector x, b; real errorV, errorKM, error_solve, eps_solve; uint steps; eps_solve = 1.0e-12; steps = 1000; printf("Testing: %s Hmatrix %s\n" "====================================\n\n", (exterior == true ? "exterior" : "interior"), apprxtype); assemble_bem2d_hmatrix(bem_slp, block, V); assemble_bem2d_hmatrix(bem_dlp, block, KM); errorV = norm2diff_amatrix_hmatrix(V, Vfull) / norm2_amatrix(Vfull); printf("rel. error V : %.5e\n", errorV); errorKM = norm2diff_amatrix_hmatrix(KM, KMfull) / norm2_amatrix(KMfull); printf("rel. error K%c0.5*M : %.5e\n", (exterior == true ? '-' : '+'), errorKM); x = new_avector(Vfull->rows); b = new_avector(KMfull->cols); printf("Solving Dirichlet problem:\n"); projectl2_bem2d_const_avector(bem_dlp, eval_dirichlet_quadratic_laplacebem2d, x); clear_avector(b); addeval_hmatrix_avector(1.0, KM, x, b); solve_cg_bem2d(HMATRIX, V, b, x, eps_solve, steps); if (exterior == true) { scale_avector(-1.0, x); } error_solve = L2gamma_c_diff_norm2(bem_slp, x, eval_neumann_quadratic_laplacebem2d); clear_avector(x); error_solve = error_solve / L2gamma_c_diff_norm2(bem_slp, x, eval_neumann_quadratic_laplacebem2d); printf("rel. error neumann : %.5e %s\n", error_solve, (IS_IN_RANGE(3.0e-3, error_solve, 4.0e-3) ? " okay" : "NOT okay")); if (!IS_IN_RANGE(3.0e-3, error_solve, 4.0e-3)) problems++; printf("\n"); del_avector(x); del_avector(b); }
static gboolean in_image4(gint x, gint y) {/*判断位置(x,y)是否在image4图片范围内*/ if(IS_IN_RANGE(x,IMAGE4_XPOS,IMAGE4_XPOS+IMAGE_WIDTH) && IS_IN_RANGE(y,IMAGE4_YPOS,IMAGE4_YPOS+IMAGE_HEIGHT)) { return TRUE; } else { return FALSE; } }
void weifu_Init(void) { clock_Init(); axle_Init(0); op_Init(0); vss_Init(); wss_Init(); pwmin1_Init(); counter2_Init(); eng_speed_timer = time_get(1000); wtout_timer = time_get(1000); mcamos_init_ex(&lcm); cfg_data.eng_speed = 0; cfg_data.wtout = 0; phase_diff = 2; eng_factor = 10; op_factor = 10; //vss = 0; vss = 0; tim_dc = 0; tim_frq = 0; hfmsig = 0; hfmref = 0; /* for(index_result = 0;index_result < 120;index_result ++ ) { result_axle[index_result] = 0; result_op_37[index_result] = 0; result_op_120[index_result] = 0; result_axle[index_result] = IS_IN_RANGE(index_result, 58, 59) | IS_IN_RANGE(index_result, 118, 119); result_op_37[index_result] = IS_IN_RANGE(index_result, 36, 36); result_op_120[index_result] = IS_IN_RANGE(index_result, 28, 29) | IS_IN_RANGE(index_result, 58, 59) \ | IS_IN_RANGE(index_result, 88, 89) | IS_IN_RANGE(index_result, 118, 119); }*/ for(index_result = 0;index_result < 3840;index_result ++ ) { gear32_120[index_result] = gear32_1[index_result%32]; op32_120[index_result] = gear32_1[index_result%32]; if(IS_IN_RANGE(index_result, axle_min1, axle_max1) | IS_IN_RANGE(index_result, axle_min2, axle_max2)) { gear32_120[index_result] = gear32_1[0]; } if(IS_IN_RANGE(index_result, op_min1, op_max1) | IS_IN_RANGE(index_result, op_min2, op_max2) | IS_IN_RANGE(index_result, op_min3, op_max3) | IS_IN_RANGE(index_result, op_min4, op_max4)) { op32_120[index_result] = gear32_1[0]; } } simulator_Start(); }
void weifu_Update(void) { //communication update weifu_ConfigData(); if (eng_rpm != cfg_data.eng_rpm) { #if SAMPLE_DENSITY_HIGH clock_SetFreq(cfg_data.eng_rpm << 5); #else clock_SetFreq(cfg_data.eng_rpm << 4); #endif eng_rpm = cfg_data.eng_rpm; op_rpm = eng_rpm >> 1; if (IS_IN_RANGE(eng_rpm, 0, 500)) { eng_factor = WAVE_FACTOR_3; } else if (IS_IN_RANGE(eng_rpm, 500, 1000)) { eng_factor = WAVE_FACTOR_5; } else if (IS_IN_RANGE(eng_rpm, 1000, 1500)) { eng_factor = WAVE_FACTOR_7; } else { eng_factor = WAVE_FACTOR_10; } if (IS_IN_RANGE(op_rpm, 0, 500)) { op_factor = WAVE_FACTOR_3; } else if (IS_IN_RANGE(op_rpm, 500, 1000)) { op_factor = WAVE_FACTOR_5; } else if (IS_IN_RANGE(op_rpm, 1000, 1500)) { op_factor = WAVE_FACTOR_7; } else { op_factor = WAVE_FACTOR_10; } }
void myInterrupt0 (void) { int i; //Update frequency freq = (int)getFreq(0); //Is this car one? if (IS_IN_RANGE(freq, 100, OFFSET)) { if (count[0] >= 0) count[0] += 2; } //Is this car two? else if (IS_IN_RANGE(freq, 500, OFFSET)) { if (count[1] >= 0) count[1] += 2; } //Have any of the cars triggered a lap? for (i = 0; i < 2; i++) if (count[i] > 5) { if (timeval_diff(¤tTime[0], &lastLap[i]) > 1000000) pythonCallback(i); count[i] = 0; gettimeofday(&lastLap[i], NULL); } if (count[i] > 0) count[i]--; }
void st_lowcase_string(char* buf) { while(*buf != '\0') { //ascii 字符 if(UTF8_CHAR_LEN(*buf) == 1) { if(IS_IN_RANGE(*buf, 0x41, 0x5a)) *buf = *buf | 0x20; buf += 1; continue; } // 多字符 buf += UTF8_CHAR_LEN(*buf); } }
PObsNode getNextNode ( PObsNode node, RU8 value ) { PObsNode next = NULL; if( rpal_memory_isValid( node ) && IS_IN_RANGE( node, value ) ) { next = node->elements[ EFFECTIVE_INDEX( node, value ) ]; } return next; }
int main(int argc, char **argv) { ptet3d *gr; ptet3dp1 *dc; ptet3dref *rf; psparsematrix A, Af; pavector xd, b, x; uint L; real error; pstopwatch sw; real runtime; uint i; real eps; uint steps; uint iter; init_h2lib(&argc, &argv); sw = new_stopwatch(); L = 5; eps = 1e-12; steps = 2500; (void) printf("----------------------------------------\n" "Creating mesh hierarchy\n"); gr = (ptet3d *) allocmem(sizeof(ptet3d) * (L + 1)); rf = (ptet3dref *) allocmem(sizeof(ptet3dref) * L); gr[0] = new_unitcube_tet3d(); (void) printf(" Level %2u: %u vertices, %u edges, %u faces, %u tetrahedra\n", 0, gr[0]->vertices, gr[0]->edges, gr[0]->faces, gr[0]->tetrahedra); for (i = 0; i < L; i++) { gr[i + 1] = refine_tet3d(gr[i], rf + i); (void) printf(" Level %2u: %u vertices, %u edges, %u faces, %u tetrahedra\n", i + 1, gr[i + 1]->vertices, gr[i + 1]->edges, gr[i + 1]->faces, gr[i + 1]->tetrahedra); } (void) printf("Creating discretizations\n"); dc = (ptet3dp1 *) allocmem(sizeof(ptet3dp1) * (L + 1)); for (i = 0; i <= L; i++) { dc[i] = new_tet3dp1(gr[i]); (void) printf(" Level %2u: %u degrees of freedom, %u fixed\n", i, dc[i]->ndof, dc[i]->nfix); } for (i = 2; i <= L; i++) { (void) printf("Testing level %u\n" " Setting up matrix\n", i); start_stopwatch(sw); A = build_tet3dp1_sparsematrix(dc[i]); Af = build_tet3dp1_interaction_sparsematrix(dc[i]); assemble_tet3dp1_laplace_sparsematrix(dc[i], A, Af); runtime = stop_stopwatch(sw); (void) printf(" %.1f seconds\n" " %.1f MB (interaction %.1f MB)\n" " %.1f KB/DoF (interaction %.1f KB/DoF)\n" " %u non-zero entries (interaction %u)\n", runtime, getsize_sparsematrix(A) / 1048576.0, getsize_sparsematrix(Af) / 1048576.0, getsize_sparsematrix(A) / 1024.0 / dc[i]->ndof, getsize_sparsematrix(Af) / 1024.0 / dc[i]->ndof, A->nz, Af->nz); (void) printf(" Setting up Dirichlet data\n"); xd = new_avector(dc[i]->nfix); assemble_tet3dp1_dirichlet_avector(dc[i], sin_solution, 0, xd); (void) printf(" Setting up right-hand side\n"); b = new_avector(dc[i]->ndof); assemble_tet3dp1_functional_avector(dc[i], sin_rhs, 0, b); (void) printf(" Starting iteration\n"); x = new_avector(dc[i]->ndof); random_real_avector(x); start_stopwatch(sw); iter = solve_cg_sparsematrix_avector(A, b, x, eps, steps); runtime = stop_stopwatch(sw); (void) printf(" %u CG iterations\n", iter); (void) printf("\n" " %.1f seconds\n" " %.1f seconds per step\n", runtime, runtime / iter); error = norml2_tet3dp1(dc[i], sin_solution, 0, x, xd); (void) printf(" rel. L^2 error %.4e %s\n", error, (IS_IN_RANGE(1.0e-3, error, 9.0e-2) ? " okay" : "NOT okay")); if (!IS_IN_RANGE(1.0e-3, error, 9.0e-2)) problems++; del_avector(x); del_avector(b); del_avector(xd); del_sparsematrix(Af); del_sparsematrix(A); } (void) printf("----------------------------------------\n" "Cleaning up\n"); for (i = 0; i <= L; i++) del_tet3dp1(dc[i]); freemem(dc); for (i = 0; i < L; i++) del_tet3dref(rf[i]); freemem(rf); for (i = 0; i <= L; i++) del_tet3d(gr[i]); freemem(gr); del_stopwatch(sw); uninit_h2lib(); return problems; }
static void check_triangularsolve(bool lower, bool unit, bool atrans, pcamatrix a, bool xtrans) { uint n = a->rows; amatrix xtmp, btmp; pamatrix x, b; avector xvtmp, bvtmp; pavector xv, bv; real error; assert(n == a->cols); /* * amatrix */ x = init_amatrix(&xtmp, n, n); random_amatrix(x); b = init_zero_amatrix(&btmp, n, n); if (xtrans) addmul_amatrix(1.0, false, x, !atrans, a, b); else addmul_amatrix(1.0, atrans, a, false, x, b); triangularsolve_amatrix(lower, unit, atrans, a, xtrans, b); add_amatrix(-1.0, false, x, b); error = norm2_amatrix(b) / norm2_amatrix(x); (void) printf("Checking amatrix triangularsolve\n" " (lower=%s, unit=%s, atrans=%s, xtrans=%s)\n" " Accuracy %g, %sokay\n", (lower ? "tr" : "fl"), (unit ? "tr" : "fl"), (atrans ? "tr" : "fl"), (xtrans ? "tr" : "fl"), error, (IS_IN_RANGE(0.0, error, 1.0e-14) ? "" : " NOT ")); if (!IS_IN_RANGE(0.0, error, 1.0e-14)) problems++; copy_amatrix(false, x, b); triangulareval_amatrix(lower, unit, atrans, a, xtrans, b); triangularsolve_amatrix(lower, unit, atrans, a, xtrans, b); add_amatrix(-1.0, false, x, b); error = norm2_amatrix(b) / norm2_amatrix(x); (void) printf("Checking amatrix triangulareval/triangularsolve\n" " (lower=%s, unit=%s, atrans=%s, xtrans=%s):\n" " Accuracy %g, %sokay\n", (lower ? "tr" : "fl"), (unit ? "tr" : "fl"), (atrans ? "tr" : "fl"), (xtrans ? "tr" : "fl"), error, (IS_IN_RANGE(0.0, error, 1.0e-14) ? "" : " NOT ")); if (!IS_IN_RANGE(0.0, error, 1.0e-14)) problems++; /* * avector */ xv = init_avector(&xvtmp, n); random_avector(xv); bv = init_avector(&bvtmp, n); clear_avector(bv); if (atrans) { addevaltrans_amatrix_avector(1.0, a, xv, bv); } else { addeval_amatrix_avector(1.0, a, xv, bv); } triangularsolve_amatrix_avector(lower, unit, atrans, a, bv); add_avector(-1.0, xv, bv); error = norm2_avector(bv) / norm2_avector(xv); (void) printf("Checking avector triangularsolve\n" " (lower=%s, unit=%s, atrans=%s)\n" " Accuracy %g, %sokay\n", (lower ? "tr" : "fl"), (unit ? "tr" : "fl"), (atrans ? "tr" : "fl"), error, (IS_IN_RANGE(0.0, error, 1.0e-14) ? "" : " NOT ")); if (!IS_IN_RANGE(0.0, error, 1.0e-14)) problems++; copy_avector(xv, bv); triangulareval_amatrix_avector(lower, unit, atrans, a, bv); triangularsolve_amatrix_avector(lower, unit, atrans, a, bv); add_avector(-1.0, xv, bv); error = norm2_avector(bv) / norm2_avector(xv); (void) printf("Checking avector triangulareval/triangularsolve\n" " (lower=%s, unit=%s, atrans=%s):\n" " Accuracy %g, %sokay\n", (lower ? "tr" : "fl"), (unit ? "tr" : "fl"), (atrans ? "tr" : "fl"), error, (IS_IN_RANGE(0.0, error, 1.0e-14) ? "" : " NOT ")); if (!IS_IN_RANGE(0.0, error, 1.0e-14)) problems++; uninit_amatrix(b); uninit_amatrix(x); uninit_avector(bv); uninit_avector(xv); }
static void test_h2matrix_system(const char *apprxtype, pcamatrix Vfull, pcamatrix KMfull, pblock block, pbem3d bem_slp, ph2matrix V, pbem3d bem_dlp, ph2matrix KM, bool linear, bool exterior, real low, real high) { struct _eval_A eval; helmholtz_data hdata; pavector x, b; real errorV, errorKM, error_solve, eps_solve; uint steps; boundary_func3d rhs = (boundary_func3d) rhs_dirichlet_point_helmholtzbem3d; eps_solve = 1.0e-12; steps = 1000; printf("Testing: %s H2matrix %s\n" "====================================\n\n", (exterior == true ? "exterior" : "interior"), apprxtype); assemble_bem3d_h2matrix_row_clusterbasis(bem_slp, V->rb); assemble_bem3d_h2matrix_col_clusterbasis(bem_slp, V->cb); SCHEDULE_OPENCL(0, 1, assemble_bem3d_h2matrix, bem_slp, block, V); assemble_bem3d_h2matrix_row_clusterbasis(bem_dlp, KM->rb); assemble_bem3d_h2matrix_col_clusterbasis(bem_dlp, KM->cb); SCHEDULE_OPENCL(0, 1, assemble_bem3d_h2matrix, bem_dlp, block, KM); eval.V = V; eval.Vtype = H2MATRIX; eval.KM = KM; eval.KMtype = H2MATRIX; eval.eta = REAL_SQRT(ABSSQR(bem_slp->kvec[0]) + ABSSQR(bem_slp->kvec[1]) + ABSSQR(bem_slp->kvec[2])); hdata.kvec = bem_slp->kvec; hdata.source = allocreal(3); if (exterior) { hdata.source[0] = 0.0, hdata.source[1] = 0.0, hdata.source[2] = 0.2; } else { hdata.source[0] = 0.0, hdata.source[1] = 0.0, hdata.source[2] = 5.0; } errorV = norm2diff_amatrix_h2matrix(V, Vfull) / norm2_amatrix(Vfull); printf("rel. error V : %.5e\n", errorV); errorKM = norm2diff_amatrix_h2matrix(KM, KMfull) / norm2_amatrix(KMfull); printf("rel. error K%c0.5*M : %.5e\n", (exterior == true ? '-' : '+'), errorKM); x = new_avector(Vfull->rows); b = new_avector(KMfull->cols); printf("Solving Dirichlet problem:\n"); integrate_bem3d_const_avector(bem_dlp, rhs, b, (void *) &hdata); solve_gmres_bem3d(HMATRIX, &eval, b, x, eps_solve, steps); error_solve = max_rel_outer_error(bem_slp, &hdata, x, rhs); printf("max. rel. error : %.5e %s\n", error_solve, (IS_IN_RANGE(low, error_solve, high) ? " okay" : "NOT okay")); if (!IS_IN_RANGE(low, error_solve, high)) problems++; printf("\n"); del_avector(x); del_avector(b); freemem(hdata.source); }
int main() { ph2matrix h2, h2copy, L, R; pclusterbasis rb, cb, rbcopy, cbcopy, rblow, cblow, rbup, cbup; pclusteroperator rwf, cwf, rwflow, cwflow, rwfup, cwfup, rwfh2, cwfh2; ptruncmode tm; pavector x, b; uint n; real error; pcurve2d gr2; pbem2d bem2; pcluster root2; pblock block2; uint clf, m; real tol, eta, delta, eps_aca; n = 579; tol = 1.0e-13; clf = 16; eta = 1.0; m = 4; delta = 1.0; eps_aca = 1.0e-13; gr2 = new_circle_curve2d(n, 0.333); bem2 = new_slp_laplace_bem2d(gr2, 2, BASIS_CONSTANT_BEM2D); root2 = build_bem2d_cluster(bem2, clf, BASIS_CONSTANT_BEM2D); block2 = build_strict_block(root2, root2, &eta, admissible_max_cluster); rb = build_from_cluster_clusterbasis(root2); cb = build_from_cluster_clusterbasis(root2); setup_h2matrix_aprx_greenhybrid_bem2d(bem2, rb, cb, block2, m, 1, delta, eps_aca, build_bem2d_rect_quadpoints); (void) printf("----------------------------------------\n" "Check %u x %u Cholesky factorization\n", n, n); (void) printf("Creating laplacebem2d SLP matrix\n"); assemble_bem2d_h2matrix_row_clusterbasis(bem2, rb); assemble_bem2d_h2matrix_col_clusterbasis(bem2, cb); h2 = build_from_block_h2matrix(block2, rb, cb); assemble_bem2d_h2matrix(bem2, block2, h2); (void) printf("Creating random solution and right-hand side\n"); x = new_avector(n); random_avector(x); b = new_avector(n); clear_avector(b); mvm_h2matrix_avector(1.0, false, h2, x, b); (void) printf("Copying matrix\n"); rbcopy = clone_clusterbasis(h2->rb); cbcopy = clone_clusterbasis(h2->cb); h2copy = clone_h2matrix(h2, rbcopy, cbcopy); (void) printf("Computing Cholesky factorization\n"); tm = new_releucl_truncmode(); rblow = build_from_cluster_clusterbasis(root2); cblow = build_from_cluster_clusterbasis(root2); L = build_from_block_lower_h2matrix(block2, rblow, cblow); rwflow = prepare_row_clusteroperator(L->rb, L->cb, tm); cwflow = prepare_col_clusteroperator(L->rb, L->cb, tm); rwf = NULL; cwf = NULL; init_cholesky_h2matrix(h2, &rwf, &cwf, tm); choldecomp_h2matrix(h2, rwf, cwf, L, rwflow, cwflow, tm, tol); (void) printf("Solving\n"); cholsolve_h2matrix_avector(L, b); add_avector(-1.0, x, b); error = norm2_avector(b) / norm2_avector(x); (void) printf(" Accuracy %g, %sokay\n", error, IS_IN_RANGE(2.0e-13, error, 3.0e-12) ? "" : " NOT "); if (!IS_IN_RANGE(2.0e-13, error, 3.0e-12)) problems++; rwfh2 = prepare_row_clusteroperator(h2copy->rb, h2copy->cb, tm); cwfh2 = prepare_col_clusteroperator(h2copy->rb, h2copy->cb, tm); (void) printf("Checking factorization\n"); error = norm2_h2matrix(h2copy); addmul_h2matrix(-1.0, L, true, L, h2copy, rwfh2, cwfh2, tm, tol); error = norm2_h2matrix(h2copy) / error; (void) printf(" Accuracy %g, %sokay\n", error, IS_IN_RANGE(4.0e-15, error, 4.0e-14) ? "" : " NOT "); if (!IS_IN_RANGE(4.0e-15, error, 4.0e-14)) problems++; del_h2matrix(h2copy); del_h2matrix(h2); del_h2matrix(L); del_avector(b); del_avector(x); del_truncmode(tm); del_clusteroperator(rwflow); del_clusteroperator(cwflow); del_clusteroperator(rwf); del_clusteroperator(cwf); del_clusteroperator(rwfh2); del_clusteroperator(cwfh2); rb = build_from_cluster_clusterbasis(root2); cb = build_from_cluster_clusterbasis(root2); setup_h2matrix_aprx_greenhybrid_bem2d(bem2, rb, cb, block2, m, 1, delta, eps_aca, build_bem2d_rect_quadpoints); (void) printf("----------------------------------------\n" "Check %u x %u LR factorization\n", n, n); (void) printf("Creating laplacebem2d SLP matrix\n"); assemble_bem2d_h2matrix_row_clusterbasis(bem2, rb); assemble_bem2d_h2matrix_col_clusterbasis(bem2, cb); h2 = build_from_block_h2matrix(block2, rb, cb); assemble_bem2d_h2matrix(bem2, block2, h2); (void) printf("Creating random solution and right-hand side\n"); x = new_avector(n); random_avector(x); b = new_avector(n); clear_avector(b); mvm_h2matrix_avector(1.0, false, h2, x, b); (void) printf("Copying matrix\n"); rbcopy = clone_clusterbasis(h2->rb); cbcopy = clone_clusterbasis(h2->cb); h2copy = clone_h2matrix(h2, rbcopy, cbcopy); (void) printf("Computing LR factorization\n"); rblow = build_from_cluster_clusterbasis(root2); cblow = build_from_cluster_clusterbasis(root2); L = build_from_block_lower_h2matrix(block2, rblow, cblow); rbup = build_from_cluster_clusterbasis(root2); cbup = build_from_cluster_clusterbasis(root2); R = build_from_block_upper_h2matrix(block2, rbup, cbup); tm = new_releucl_truncmode(); rwf = prepare_row_clusteroperator(h2->rb, h2->cb, tm); cwf = prepare_col_clusteroperator(h2->rb, h2->cb, tm); rwflow = prepare_row_clusteroperator(L->rb, L->cb, tm); cwflow = prepare_col_clusteroperator(L->rb, L->cb, tm); rwfup = prepare_row_clusteroperator(R->rb, R->cb, tm); cwfup = prepare_col_clusteroperator(R->rb, R->cb, tm); lrdecomp_h2matrix(h2, rwf, cwf, L, rwflow, cwflow, R, rwfup, cwfup, tm, tol); (void) printf("Solving\n"); lrsolve_h2matrix_avector(L, R, b); add_avector(-1.0, x, b); error = norm2_avector(b) / norm2_avector(x); (void) printf(" Accuracy %g, %sokay\n", error, IS_IN_RANGE(2e-13, error, 2e-12) ? "" : " NOT "); if (!IS_IN_RANGE(2e-13, error, 2e-12)) problems++; rwfh2 = prepare_row_clusteroperator(h2copy->rb, h2copy->cb, tm); cwfh2 = prepare_col_clusteroperator(h2copy->rb, h2copy->cb, tm); (void) printf("Checking factorization\n"); error = norm2_h2matrix(h2copy); addmul_h2matrix(-1.0, L, false, R, h2copy, rwfh2, cwfh2, tm, tol); error = norm2_h2matrix(h2copy) / error; (void) printf(" Accuracy %g, %sokay\n", error, IS_IN_RANGE(4.0e-15, error, 5.0e-14) ? "" : " NOT "); if (!IS_IN_RANGE(4.0e-15, error, 5.0e-14)) problems++; /* Final clean-up */ (void) printf("Cleaning up\n"); del_h2matrix(h2); del_h2matrix(h2copy); del_h2matrix(L); del_h2matrix(R); del_clusteroperator(rwf); del_clusteroperator(cwf); del_clusteroperator(rwflow); del_clusteroperator(cwflow); del_clusteroperator(rwfup); del_clusteroperator(cwfup); del_clusteroperator(rwfh2); del_clusteroperator(cwfh2); del_avector(b); del_avector(x); del_truncmode(tm); freemem(root2->idx); del_bem2d(bem2); del_block(block2); del_cluster(root2); del_curve2d(gr2); (void) printf("----------------------------------------\n" " %u matrices and\n" " %u vectors still active\n" " %u errors found\n", getactives_amatrix(), getactives_avector(), problems); return problems; }
void urx_remove(rhdtyp *rtnhdr) { urx_rtnref *rtn, *rtnprev; urx_labref *lab, *labprev; urx_addr *addr, *addrprev, *savaddr; unsigned char *regstart, *regend; int deletes; DEBUG_ONLY(deletes = 0); #ifdef USHBIN_SUPPORTED /* All unresolved addresses will point into the linkage section */ regstart = (unsigned char *)rtnhdr->linkage_adr; regend = regstart + (SIZEOF(lnk_tabent) * rtnhdr->linkage_len); #else /* All unresolved addresses will point into the code section */ regstart = PTEXT_ADR(rtnhdr); regend = PTEXT_END_ADR(rtnhdr); #endif rtnprev = &urx_anchor; rtn = rtnprev->next; while (rtn) { /* For each unresolved routine.. */ addrprev = NULL; addr = rtn->addr; while (addr) { /* Run list of resolve addrs for this routine */ if (IS_IN_RANGE(regstart, regend, addr->addr)) { /* We will be deleting an element so addrprev will not be changing */ if (NULL == addrprev) rtn->addr = addr->next; /* First element being removed */ else addrprev->next = addr->next; savaddr = addr->next; free(addr); addr = savaddr; DEBUG_ONLY(++deletes); continue; } addrprev = addr; addr = addr->next; } /* Note that the structure of the urx_labref and urx_rtnref is critical here. The urx_rtnref serves as an anchor for the urx_labref chain by virtue of urx_rtnref's "lab" pointer being at the same offset as urx_labref's "next" pointer. */ labprev = (urx_labref *)rtn; lab = rtn->lab; while (lab) { addrprev = NULL; addr = lab->addr; while (addr) { if (IS_IN_RANGE(regstart, regend, addr->addr)) { /* We will be deleting an element so addrprev will not be changing */ if (NULL == addrprev) lab->addr = addr->next; /* First element being removed */ else addrprev->next = addr->next; savaddr = addr->next; free(addr); addr = savaddr; DEBUG_ONLY(++deletes); continue; } addrprev = addr; addr = addr->next; } if (NULL == lab->addr) { /* No references to this label left .. remove from unresolved chain */ labprev->next = lab->next; free(lab); lab = labprev->next; DEBUG_ONLY(++deletes); continue; } labprev = lab; lab = lab->next; } /* Note that it is possible to have a routine on the unresolved chain with no addr chain of unresolves for it yet there are labels unresolved. This would be the case if a routine contained a call to a non-existent label. It is not an error until/unless the call call is executed. The reverse is also true, it is possible to have an unresolved addr chain for the routine with no labels. This occurs when a call using indirection such as DO @LBL^RTN. In this case, there will be no unresolved label but there will be an unresolved routine. */ if (NULL == rtn->addr && NULL == rtn->lab) { /* This node has no reason to keep living */ rtnprev->next = rtn->next; free(rtn); rtn = rtnprev->next; DEBUG_ONLY(++deletes); continue; } rtnprev = rtn; rtn = rtn->next; } #ifdef DEBUG_URX PRINTF("urx_remove: Deleted %d entries\n", deletes); #endif }
PObsNode addTransition ( PObsNode parent, PObsNode node, PObsNode to, RU8 onValue ) { PObsNode retNode = NULL; RU32 currentNodeSize = 0; RU8 numElemToAdd = 0; RU8 indexToInsert = 0; PObsNode originalNode = node; RU32 i = 0; if( rpal_memory_isValid( node ) ) { currentNodeSize = sizeof( ObsNode ) + ( node->nElements * sizeof( RPVOID ) ); if( !IS_IN_RANGE( node, onValue ) ) { if( onValue >= node->startOffset + node->nElements ) { numElemToAdd = onValue - ( node->startOffset + node->nElements ) + 1; } else { numElemToAdd = node->startOffset - onValue; } if( node->nAllocated < node->nElements + numElemToAdd ) { node = rpal_memory_realloc( node, currentNodeSize + ( numElemToAdd * sizeof( RPVOID ) ) ); rpal_memory_zero( node->elements + node->nElements, numElemToAdd * sizeof( RPVOID ) ); node->nAllocated = node->nElements + numElemToAdd; } if( onValue < node->startOffset && 0 < node->nElements ) { rpal_memory_memmove( node->elements + numElemToAdd, node->elements, node->nElements * sizeof( RPVOID ) ); node->startOffset = node->startOffset - (RU8)numElemToAdd; } node->nElements += numElemToAdd; // The above realloc may have changed the pointer so we need // to update it in the parent, if it exists... if( NULL != parent && originalNode != node ) { for( i = 0; i < parent->nElements; i++ ) { if( originalNode == parent->elements[ i ] ) { parent->elements[ i ] = node; } } } } indexToInsert = EFFECTIVE_INDEX( node, onValue ); if( NULL == node->elements[ indexToInsert ] ) { node->elements[ indexToInsert ] = to; retNode = node; } } return retNode; }