/* When done, free all memory */ void free_all() { int i; for (i = 0; i < popsize; i++) { free(oldpop[i].chrom); free(newpop[i].chrom); } free(oldpop); free(newpop); free_selection(); }
void TE_View::copy_selection(SelectionManager* s) { // copy selection into selection buffer int dot = text_editor_->Dot(); int mark = text_editor_->Mark(); if (dot == mark) return; // nothing to copy! int len = Math::abs(mark-dot); free_selection(s); selection_buffer_ = new char[len+1]; te_buffer_->Copy(dot, selection_buffer_, mark-dot); selection_buffer_[len] = '\0'; // printf("selection_buffer:%s\n", selection_buffer_); }
void list_free_read_request (read_request * h) { read_request * n; while (h) { n = h->next; free_selection (h->sel); if (h->priv) { free (h->priv); h->priv = 0; } free (h); h = n; } }
void adios_read_flexpath_release_step(ADIOS_FILE *adiosfile) { int i; flexpath_reader_file *fp = (flexpath_reader_file*)adiosfile->fh; for(i=0; i<fp->num_bridges; i++) { if(fp->bridges[i].created && !fp->bridges[i].opened) { send_open_msg(fp, i); } } free_evgroup(fp->gp); fp->gp = NULL; flexpath_var *tmpvars = fp->var_list; while(tmpvars){ if(tmpvars->num_dims > 0){ free(tmpvars->global_dims); tmpvars->num_dims = 0; } free_displacements(tmpvars->displ, tmpvars->num_displ); tmpvars->displ = NULL; if(tmpvars->sel){ free_selection(tmpvars->sel); } tmpvars->sel = NULL; for(i=0; i<tmpvars->num_chunks; i++){ flexpath_var_chunk *chunk = &tmpvars->chunks[i]; if(chunk->has_data){ free(chunk->data); chunk->data = NULL; chunk->has_data = 0; } free(chunk->local_bounds); free(chunk->global_offsets); free(chunk->global_bounds); chunk->global_offsets = NULL; chunk->global_bounds = NULL; chunk->local_bounds = NULL; chunk->rank = 0; } tmpvars = tmpvars->next; } }
int adios_read_flexpath_schedule_read_byid(const ADIOS_FILE *adiosfile, const ADIOS_SELECTION *sel, int varid, int from_steps, int nsteps, void *data) { fp_log("FUNC", "entering schedule_read_byid\n"); flexpath_reader_file * fp = (flexpath_reader_file*)adiosfile->fh; flexpath_var * var = fp->var_list; while(var){ if(var->id == varid) break; else var=var->next; } if(!var){ adios_error(err_invalid_varid, "Invalid variable id: %d\n", varid); return err_invalid_varid; } //store the user allocated buffer. flexpath_var_chunk *chunk = &var->chunks[0]; chunk->user_buf = data; var->start_position = 0; if(nsteps != 1){ adios_error (err_invalid_timestep, "Only one step can be read from a stream at a time. " "You requested % steps in adios_schedule_read()\n", nsteps); return err_invalid_timestep; } // this is done so that the user can do multiple schedule_read/perform_reads // within before doing release/advance step. Might need a better way to // manage the ADIOS selections. if(var->sel){ free_selection(var->sel); } var->sel = copy_selection(sel); switch(var->sel->type) { case ADIOS_SELECTION_WRITEBLOCK: { int writer_index = var->sel->u.block.index; if(writer_index > fp->num_bridges){ adios_error(err_out_of_bound, "No process exists on the writer side matching the index.\n"); return err_out_of_bound; } send_var_message(fp, writer_index, var->varname); break; } case ADIOS_SELECTION_BOUNDINGBOX: { free_displacements(var->displ, var->num_displ); var->displ = NULL; int j=0; int need_count = 0; array_displacements * all_disp = NULL; uint64_t pos = 0; double sched_start = MPI_Wtime(); for(j=0; j<fp->num_bridges; j++) { int destination=0; if(need_writer(fp, j, var->sel, fp->gp, var->varname)==1){ uint64_t _pos = 0; need_count++; destination = j; global_var *gvar = find_gbl_var(fp->gp->vars, var->varname, fp->gp->num_vars); // TODO: memory leak here. have to free these at some point. array_displacements *displ = get_writer_displacements(j, var->sel, gvar, &_pos); displ->pos = pos; _pos *= (uint64_t)var->type_size; pos += _pos; all_disp = realloc(all_disp, sizeof(array_displacements)*need_count); all_disp[need_count-1] = *displ; send_var_message(fp, j, var->varname); } } double sched_end = MPI_Wtime(); var->displ = all_disp; var->num_displ = need_count; break; } case ADIOS_SELECTION_AUTO: { adios_error(err_operation_not_supported, "ADIOS_SELECTION_AUTO not yet supported by flexpath."); break; } case ADIOS_SELECTION_POINTS: { adios_error(err_operation_not_supported, "ADIOS_SELECTION_POINTS not yet supported by flexpath."); break; } } fp_log("FUNC", "entering schedule_read_byid\n"); return 0; }
static int selection_command( struct ged *gedp, struct rt_db_internal *ip, int argc, const char *argv[]) { int i; struct rt_selection_set *selection_set; struct bu_ptbl *selections; struct rt_selection *new_selection; struct rt_selection_query query; const char *cmd, *solid_name, *selection_name; /* 0 1 2 3 * brep <solid_name> selection subcommand */ if (argc < 4) { return -1; } solid_name = argv[1]; cmd = argv[3]; if (BU_STR_EQUAL(cmd, "append")) { /* append to named selection - selection is created if it doesn't exist */ void (*free_selection)(struct rt_selection *); /* 4 5 6 7 8 9 10 * selection_name startx starty startz dirx diry dirz */ if (argc != 11) { bu_log("wrong args for selection append"); return -1; } selection_name = argv[4]; /* find matching selections */ query.start[X] = atof(argv[5]); query.start[Y] = atof(argv[6]); query.start[Z] = atof(argv[7]); query.dir[X] = atof(argv[8]); query.dir[Y] = atof(argv[9]); query.dir[Z] = atof(argv[10]); query.sorting = RT_SORT_CLOSEST_TO_START; selection_set = ip->idb_meth->ft_find_selections(ip, &query); if (!selection_set) { bu_log("no matching selections"); return -1; } /* could be multiple options, just grabbing the first and * freeing the rest */ selections = &selection_set->selections; new_selection = (struct rt_selection *)BU_PTBL_GET(selections, 0); free_selection = selection_set->free_selection; for (i = BU_PTBL_LEN(selections) - 1; i > 0; --i) { long *s = BU_PTBL_GET(selections, i); free_selection((struct rt_selection *)s); bu_ptbl_rm(selections, s); } bu_ptbl_free(selections); BU_FREE(selection_set, struct rt_selection_set); /* get existing/new selections set in gedp */ selection_set = ged_get_selection_set(gedp, solid_name, selection_name); selection_set->free_selection = free_selection; selections = &selection_set->selections; /* TODO: Need to implement append by passing new and * existing selection to an rt_brep_evaluate_selection. * For now, new selection simply replaces old one. */ for (i = BU_PTBL_LEN(selections) - 1; i >= 0; --i) { long *s = BU_PTBL_GET(selections, i); free_selection((struct rt_selection *)s); bu_ptbl_rm(selections, s); } bu_ptbl_ins(selections, (long *)new_selection); } else if (BU_STR_EQUAL(cmd, "translate")) { struct rt_selection_operation operation; /* 4 5 6 7 * selection_name dx dy dz */ if (argc != 8) { return -1; } selection_name = argv[4]; selection_set = ged_get_selection_set(gedp, solid_name, selection_name); selections = &selection_set->selections; if (BU_PTBL_LEN(selections) < 1) { return -1; } for (i = 0; i < (int)BU_PTBL_LEN(selections); ++i) { int ret; operation.type = RT_SELECTION_TRANSLATION; operation.parameters.tran.dx = atof(argv[5]); operation.parameters.tran.dy = atof(argv[6]); operation.parameters.tran.dz = atof(argv[7]); ret = ip->idb_meth->ft_process_selection(ip, gedp->ged_wdbp->dbip, (struct rt_selection *)BU_PTBL_GET(selections, i), &operation); if (ret != 0) { return ret; } } } return 0; }