void update(const IndexedType& x) { size_type current_pos = index_array[ id[x] ]; c[current_pos] = x; Node node(c.begin(), c.end(), c.begin()+current_pos, id); update_heap(node, comp, index_array); }
// Each thread executes the operations from its own array void *dowork(void *threadid) { long id = (long)threadid; int i; char *ptr; struct trace tr = ttrace[id]; int ops = tr.num_ops; for (i = 0; i < ops; i++) { switch (tr.ops[i].type) { case MALLOC: ptr = mymalloc(tr.ops[i].size); debug_print("[%li]: malloc block %d addr %p size %d\n", id, tr.ops[i].index, ptr, tr.ops[i].size); update_heap(); if (!ptr) { error_print("[%li]: error on allocation %i size %d\n", id, i, tr.ops[i].size); break; } // Check for "heap overflow" if ((ptr < start_heap) || (ptr + tr.ops[i].size > max_heap)) { error_print("[%li]: malloc block %d addr %p size %d heap overflow\n", id, tr.ops[i].index, ptr, tr.ops[i].size); break; } // Check for non-aligned allocation if ((size_t)ptr % 8 != 0) { error_print("[%li]: malloc block %d addr %p size %d non-aligned\n", id, tr.ops[i].index, ptr, tr.ops[i].size); } tr.blocks[tr.ops[i].index] = ptr; touch_after_malloc(id, tr.ops[i].index, ptr, tr.ops[i].size); break; case FREE: debug_print("[%li]: free block %d\n", id, tr.ops[i].index); ptr = tr.blocks[tr.ops[i].index]; if (ptr) { touch_before_free(id, tr.ops[i].index, ptr, tr.ops[i].size); } if (myfree(ptr)) { error_print("[%li]: error on free block %d\n", id, i); } break; default: fprintf(stderr, "Error: bad instruction\n"); exit(1); } } pthread_exit(NULL); }
void SurfaceEdgeCollapse::update(int &red_tri, int v1, int v2, Star &star, pair *link, int num_link, float x_0, float y_0, float z_0) { // To be invoked to complete each edge collapsing iteration. // Removes the vertex v2 from the vertex list, updates the coordinates of v1 // as well as all affected structures in the program: // stars of vertices in link, tri_list, heap, stars[v1] int l; int tri[2]; int vert[MAXTRI]; int to_remove = 0; int to_update = 0; // tri = pair of triangles to remove find_neighbors(v1, v2, star, to_remove, tri); if (!((to_remove == 2) || (star.boundary && (to_remove == 1)))) Covise::sendInfo("Edge has wrong number of neighbors!"); // vert = array of vertices in the link (to be updated) extract_points(v1, v2, num_link, link, to_update, vert); // update stars around the link for (l = 0; l < to_update; l++) update_star(v1, v2, star, l, vert, to_remove, tri); // update coordinates and label v2 as removed coords_x[v1] = x_0; coords_y[v1] = y_0; coords_z[v1] = z_0; is_removed[v2] = 1; // update star and tri_list update_global_structures(v1, v2, star, to_remove, tri); if (to_remove == 2) red_tri -= 2; else red_tri--; // copy star to stars[v1] delete[] stars[v1].tri; stars[v1].tri = new int[star.num_tri]; for (l = 0; l < star.num_tri; l++) stars[v1].tri[l] = star.tri[l]; stars[v1].num_tri = star.num_tri; stars[v1].boundary = star.boundary; stars[v1].manifold = star.manifold; if (angle[v2] > angle[v1]) angle[v1] = angle[v2]; //angle[v1] = (angle[v1] || angle[v2]); // update heap and edge_array update_heap(v1, v2, star, to_remove, tri); delete[] star.tri; }