void test_find_representatives() { static const string useful_columns[] = { cFirstname::static_get_class_name(), cMiddlename::static_get_class_name(), cLastname::static_get_class_name(), cLatitude::static_get_class_name(), cAssignee::static_get_class_name(), cCity::static_get_class_name(), cCountry::static_get_class_name() }; static const uint32_t numcols = sizeof(useful_columns)/sizeof(string); vector<uint32_t> indice = make_indice(useful_columns,numcols); Spec spec; spec.it("Indexing for find_representatives", [&indice](Description desc)->bool { vector<uint32_t> test = { 0, 2, 1, 7, 4, 10, 11 }; return (test == indice); }); const Record * r1 = rpv[1]; const Record * r2 = rpv[2]; const Record * r3 = rpv[3]; typedef std::pair<const Attribute *, uint32_t> AttCount; typedef map<const Attribute *, uint32_t> AttCounts; RecordPList m_fellows = { r1, r2, r3 }; vector<AttCounts> trace = make_trace(indice, m_fellows, numcols); #if 0 /// Save all this it's really useful for_each(begin(trace), end(trace), [](AttCounts acs) { for_each(begin(acs), end(acs), [](AttCount ac) { const vector<const string*> & data = ac.first->get_data(); for_each(begin(data), end(data), [](const string * s) { std::cout << "Att: " << s->c_str() << ", "; }); std::cout << "count: " << ac.second << std::endl; }); }); #endif vector<const Attribute *> most = get_most(trace, numcols); const Record * mp = get_record_with_most(most, m_fellows, indice, numcols); //mp->print(); spec.it("Unique record ID for cluster representative should be 06453319-4", [mp](Description desc)->bool { const string uid = mp->get_unique_record_id(); return (uid == string("06453319-4")); }); }
static bool make_tuple(compile_t* c, ast_t* ast, gentype_t* g) { // An anonymous structure with no functions and no vtable. if(setup_name(c, ast, g, false)) return true; setup_tuple_fields(g); dwarf_forward(&c->dwarf, g); bool ok = make_struct(c, g) && make_trace(c, g) && make_components(c, g); // Finalise debug symbols for tuple type. dwarf_composite(&c->dwarf, g); dwarf_finish(&c->dwarf); // Generate a descriptor. gendesc_init(c, g); free_fields(g); return ok; }
static bool make_nominal(compile_t* c, ast_t* ast, gentype_t* g, bool prelim) { assert(ast_id(ast) == TK_NOMINAL); ast_t* def = (ast_t*)ast_data(ast); token_id id = ast_id(def); // For traits, just return a raw object pointer. switch(id) { case TK_INTERFACE: case TK_TRAIT: g->underlying = id; g->use_type = c->object_ptr; dwarf_trait(&c->dwarf, g); return true; default: {} } // If we already exist or we're preliminary, we're done. if(setup_name(c, ast, g, prelim)) return true; if(g->primitive == NULL) { // Not a primitive type. Generate all the fields and a trace function. setup_type_fields(g); // Forward declare debug symbols for this nominal, if needed. // At this point, this can only be TK_STRUCT, TK_CLASS, TK_PRIMITIVE, or // TK_ACTOR ast nodes. TK_TYPE has been translated to any of the former // during reification. dwarf_forward(&c->dwarf, g); bool ok = make_struct(c, g); if(!g->done) ok = ok && make_trace(c, g) && make_components(c, g); if(!ok) { free_fields(g); return false; } // Finalise symbols for composite type. if(!g->done) dwarf_composite(&c->dwarf, g); } else { // Emit debug symbols for a basic type (U8, U16, U32...) dwarf_basic(&c->dwarf, g); // Create a box type. make_box_type(c, g); } if(!g->done) { // Generate a dispatch function if necessary. make_dispatch(c, g); // Create a unique global instance if we need one. make_global_instance(c, g); // Generate all the methods. if(!genfun_methods(c, g)) { free_fields(g); return false; } if(g->underlying != TK_STRUCT) gendesc_init(c, g); // Finish off the dispatch function. if(g->underlying == TK_ACTOR) { codegen_startfun(c, g->dispatch_fn, false); codegen_finishfun(c); } // Finish the dwarf frame. dwarf_finish(&c->dwarf); } free_fields(g); g->done = true; return true; }
bool gentypes(compile_t* c) { reach_type_t* t; size_t i; genprim_builtins(c); if(c->opt->verbosity >= VERBOSITY_INFO) fprintf(stderr, " Data prototypes\n"); i = HASHMAP_BEGIN; while((t = reach_types_next(&c->reach->types, &i)) != NULL) { if(!make_opaque_struct(c, t)) return false; gendesc_type(c, t); make_debug_info(c, t); make_box_type(c, t); make_dispatch(c, t); gentrace_prototype(c, t); } gendesc_table(c); if(c->opt->verbosity >= VERBOSITY_INFO) fprintf(stderr, " Data types\n"); i = HASHMAP_BEGIN; while((t = reach_types_next(&c->reach->types, &i)) != NULL) { if(!make_struct(c, t)) return false; make_global_instance(c, t); } if(c->opt->verbosity >= VERBOSITY_INFO) fprintf(stderr, " Function prototypes\n"); i = HASHMAP_BEGIN; while((t = reach_types_next(&c->reach->types, &i)) != NULL) { // The ABI size for machine words and tuples is the boxed size. if(t->structure != NULL) t->abi_size = (size_t)LLVMABISizeOfType(c->target_data, t->structure); make_debug_final(c, t); make_pointer_methods(c, t); if(!genfun_method_sigs(c, t)) return false; } if(c->opt->verbosity >= VERBOSITY_INFO) fprintf(stderr, " Functions\n"); i = HASHMAP_BEGIN; while((t = reach_types_next(&c->reach->types, &i)) != NULL) { if(!genfun_method_bodies(c, t)) return false; } if(c->opt->verbosity >= VERBOSITY_INFO) fprintf(stderr, " Descriptors\n"); i = HASHMAP_BEGIN; while((t = reach_types_next(&c->reach->types, &i)) != NULL) { if(!make_trace(c, t)) return false; if(!genserialise(c, t)) return false; gendesc_init(c, t); } return true; }
/** ** long-term TODO: * substitute assertions with error messages (only run time errors) * look for a clean printing structure * ** maybe TODO: * record where tir occured (in the particle variable) * record how much energy is lost during the propagation in the particles * handle the lists in OpenGL in an explicit function for a better overview * polarization density: change to compute the stokes vector * ** TODO: * check multiple scattering, as some error was detected in the main loop with uninitialized rays * problem with the tracing visualization: the start of a transmitted ray isn't stored properly * -> add make trace when updating i1 */ int main(int argc, char **argv) { //testing(); getchar(); exit(EXIT_SUCCESS); FP_ERR_CLEAR; { int i; for(i = 0; i < argc; i++) fprintf(stdout, "arg[%d]: %s\n", i, argv[i]); } #if RELEASE_BUILD print_intro(); #endif init_allocations(); const uchar use_ogl = 0; uint nors, ui, res_azim, res_rad, nprtcls, res_polar_bin, res_azim_bin; double max_rad, lambda, mu_prtcl; point3 init, fin, polarisation; sphere3 screen; sphrcl_prtcl *mat_prtcls; /**< set the detection screen: */ res_polar_bin = 91; res_azim_bin = 360; bin_hit_screen *b_htscrn = alloc_bin_hit_screen(1, 4., res_polar_bin, res_azim_bin); /**< set the rays and some detection containers: */ lambda = 632.8e-6; max_rad = 3.9e-1; res_rad = 5; /* 80 */ res_azim = 10; if(res_azim < MAX_NUMBER_OF_RAYS / res_rad) nors = res_azim * res_rad; else error_msg("there are too many rays to be created - change the data type.", ERR_ARG); ray *rs = alloc_ray(nors); hit_screen *htscrn = alloc_hit_screen(nors); /**< set the particles: */ nprtcls = 3; mu_prtcl = 1.; sphrcl_prtcl *prtcls = alloc_sphrcl_prtcl(nprtcls); //set_sphrcl_prtcl(&prtcls[0],rfrct_indx_h2o(lambda,"mm"),mu_prtcl,0.,0.,0.,.4); set_sphrcl_prtcl(&prtcls[0], 1.4 + 0.i, mu_prtcl, 0., 0., 0., .4); set_sphrcl_prtcl(&prtcls[1], n_vac, mu_prtcl, 0., 1., 0., .42); set_sphrcl_prtcl(&prtcls[2], n_vac, mu_prtcl, 0., 0., 1., .41); set_sphere3(&screen, 0., 0., 0., b_htscrn[0].rad); /**< initiate the bundle of rays: */ set_point3(&polarisation, 1., 0., 0.); set_point3(&init, -1., 0., 0.); set_point3(&fin, 0., 0., 0.); gen_startrays_straight(rs, lambda, nors, res_azim, res_rad, max_rad, &init, &fin, &polarisation); /**< initiate the drawing of rays: */ glray *glrays; if(use_ogl) { glrays = alloc_glray(1, nors); copy_ray_to_glray_s(rs, glrays[0].glrs, nors); for(ui = 0; ui < nors; ui++) make_trace(&rs[ui], &glrays[0], ui); } FP_ERR_CHECK; prog_of_rays(0, INIT_PROG); #if PARALLEL_PROCESSING #if OSID == ISWIN32 & RELEASE_BUILD #warning "on windows xp 32 bit and mingw32 with gcc 4.6.2 \ there have been found deviations when using the built - in openmp 3.0. \ deviations have been detected in about 20 percent of the results at the 4th decimal place." #endif /**< parallel start ==> */ #pragma omp parallel for default(shared) lastprivate(ui) schedule(guided,2) #endif for(ui = 0; ui < nors; ui++) { intrsec isec; double min_l; uint min_l_ind = 0, n_subrs = 256, n_subhtscrn = 512, uj, i1, i2, i3, i4, j1, j2, n_move, max_subhtscrn = 1 << 15; ray first, second; memcpy(&first, &rs[ui], sizeof(ray)); /** * first run through the system. the code can be easily shortened by * beginning with the inner loop, but if the ray hits no particle, * this procedure would cost unnecessary memory allocations. */ for(uj = 0, min_l = DBL_MAX; uj < nprtcls; uj++) /**< check for the nearest intersection with a particle */ { if(intersec_lin_sph(&prtcls[uj].s, &first.v, 0, &isec)) if(first.v.l < min_l) { min_l = first.v.l; min_l_ind = uj; } } if(intersec_lin_sph(&screen, &first.v, 1, &isec)) /**< check for the intersection with the screen */ { if(first.v.l < min_l) { propagate_ray(&first); if(use_ogl) make_trace(&first, &glrays[0], ui); #pragma omp critical(reg_hit) { reg_hit(&first, &htscrn[ui], isec.cangl, FIRSTTIME_HIT_STATE); } #pragma omp critical(prog_of_rays) { prog_of_rays(1, COUNT_PROG); } #pragma omp atomic global_ray_info.count_hit++; continue; /**< if the screen was hit, proceed with the next ray */ } } else { #pragma omp critical(reg_hit) {reg_hit(&first, &htscrn[ui], 0xDEAD, EXCEPTION_STATE);} #pragma omp atomic global_ray_info.count_lost++; fprintf(stderr, "ray %u:\n", ui); error_msg("direct loss of a ray", ERR_ARG); continue; } /**< if a particle has been hit by the ray before the screen, allocate memory and start the inner loop: */ ray *subrs = alloc_ray(n_subrs); hit_screen *subhtscrn = alloc_hit_screen(n_subhtscrn); /**< handle the first intersection: */ intersec_lin_sph(&prtcls[min_l_ind].s, &first.v, 1, &isec); #pragma omp atomic prtcls[min_l_ind].hits++; propagate_ray(&first); if(set_refr_index(&first, &isec, prtcls[min_l_ind].n, prtcls[min_l_ind].mu)) { if(isec.incdnc == OBLIQUE) orthogo_ray_at_intersec(&first, &isec); i2 = handle_reflntrans(&first, &second, &isec); if(i2) memcpy(&subrs[1], &second, sizeof(ray)); first.hits++; } else { i2 = 0; propagate_ray_eps(&first); } if(use_ogl) make_trace(&first, &glrays[0], ui); memcpy(&subrs[0], &first, sizeof(ray)); i4 = i2 + 1; subrs[i4].lam = 0xDEAD; /**< now, we have at maximum 2 rays from the initial one */ for(i1 = 0, i3 = n_subrs, j1 = 0, j2 = n_subhtscrn, n_move = 0; i1 <= i2;) /**< --> start inner loop */ { /** * i1: current ray index * i2: total rays to work out minus 1 * i3: allocated rays * i4: rays to work out and the next ray to be saved by handle_reflntrans * n_move: times of moving subrs by n_subrs * j1: current hit_screen index * j2: allocated hit_screen variables */ assert(subrs[i1].lam != 0.); if(i1 == n_subrs) /**< save precious memory by overwriting the already handled rays */ { assert(i1 <= i4 && (i1 + i4) <= i3); memmove(&subrs[0], &subrs[i1], i4 * sizeof(ray)); i1 = 0; i2 -= n_subrs; i4 -= n_subrs; n_move++; } if(i1 + i4 == i3) /**< check for memory re-allocation of rays */ { subrs = realloc_ray(subrs, 0., i3, n_subrs); i3 += n_subrs; } if(j1 == j2) /**< check for memory re-allocation of hit detection */ { if(j2 > max_subhtscrn - n_subhtscrn) { #pragma omp critical(sort_detection) {sort_detection(subhtscrn, j1, &b_htscrn[0], 0);} j1 = 0; } else { subhtscrn = realloc_hit_screen(subhtscrn, j2, n_subhtscrn); j2 += n_subhtscrn; } } if(get_ray_int(&subrs[i1]) < MINI_INTENSITY) /**< check boundary condition */ { if(use_ogl) make_trace(&subrs[i1], &glrays[0], ui); reg_hit(&subrs[i1], &subhtscrn[j1], 0xDEAD, EXHAUSTED_RAY_STATE); i1++; j1++; if(use_ogl) make_trace(&subrs[i1], &glrays[0], ui); #pragma omp atomic global_ray_info.count_exhstd++; continue; } /**< check for the nearest intersection with the particles: */ for(uj = 0, min_l = DBL_MAX; uj < nprtcls; uj++) { if(intersec_lin_sph(&prtcls[uj].s, &subrs[i1].v, 0, &isec)) if(subrs[i1].v.l < min_l) { min_l = subrs[i1].v.l; min_l_ind = uj; } } /**< check for a hit on the detector: */ if(intersec_lin_sph(&screen, &subrs[i1].v, 1, &isec)) if(subrs[i1].v.l < min_l) { propagate_ray(&subrs[i1]); if(use_ogl) make_trace(&subrs[i1], &glrays[0], ui); reg_hit(&subrs[i1], &subhtscrn[j1], isec.cangl, REGULAR_HIT_STATE); i1++; j1++; if(use_ogl) make_trace(&subrs[i1], &glrays[0], ui); #pragma omp atomic global_ray_info.count_hit++; continue; } if(min_l == DBL_MAX) { if(use_ogl) make_trace(&subrs[i1], &glrays[0], ui); reg_hit(&subrs[i1], &subhtscrn[j1], 0xDEAD, EXCEPTION_STATE); i1++; j1++; if(use_ogl) make_trace(&subrs[i1], &glrays[0], ui); #pragma omp atomic global_ray_info.count_lost++; continue; } /**< set the intersection: */ intersec_lin_sph(&prtcls[min_l_ind].s, &subrs[i1].v, 1, &isec); #pragma omp atomic prtcls[min_l_ind].hits++; /**< propagate the ray to the intersection: */ propagate_ray(&subrs[i1]); /**< check if ray is traveling into another medium: */ if(set_refr_index(&subrs[i1], &isec, prtcls[min_l_ind].n, prtcls[min_l_ind].mu)) { if(isec.incdnc == OBLIQUE) orthogo_ray_at_intersec(&subrs[i1], &isec); assert(i1 + i4 < i3); assert(subrs[i4].lam == 0xDEAD); if(handle_reflntrans(&subrs[i1], &subrs[i4], &isec)) { if(get_ray_int(&subrs[i4]) < MINI_INTENSITY) /**< this is just to increment the event-counter of the particle */ { #pragma omp atomic prtcls[min_l_ind].exhstds++; } i2++; i4++; assert(subrs[i4].lam == 0.); subrs[i4].lam = 0xDEAD; } subrs[i1].hits++; } else propagate_ray_eps(&subrs[i1]); if(use_ogl) make_trace(&subrs[i1], &glrays[0], ui); if(get_ray_int(&subrs[i1]) < MINI_INTENSITY) /**< this is just to increment the event-counter of the particle */ { #pragma omp atomic prtcls[min_l_ind].exhstds++; } } /**< end inner loop, all child rays from one starting rays are worked out <-- */ #pragma omp critical(sort_detection) { sort_detection(subhtscrn, j1, &b_htscrn[0], 0); } #pragma omp critical(count_gen_update) /**< this can be substituted by atomic capture with omp 3.1 */ { global_ray_info.count_gen += (i2 + n_move * n_subrs); } #pragma omp critical(prog_of_rays) { prog_of_rays(i2 + 1 + n_move * n_subrs, PRINT_PROG); /**< +1 due to the first ray */ } free(subrs); free(subhtscrn); } /**< <== parallel end */ sort_detection(htscrn, nors, &b_htscrn[0], 1); prog_of_rays(0, CLEAR_OUT); FP_ERR_CHECK; print_bin_hit_screen("tenet / opera", &b_htscrn[0], 10, 0, INTENSITY, "testing", 0); gnuplot_bin_hit_screen("plot / test", &b_htscrn[0], E_FIELD_AMPLITUDE, 0, 0, 1, (res_polar_bin >> 1) + 1); gnuplot_bin_hit_screen("plot / test", &b_htscrn[0], MOD_E_FIELD_AMPLITUDE, 0, 0, 1, (res_polar_bin >> 1) + 1); gnuplot_bin_hit_screen("plot / test", &b_htscrn[0], INTENSITY, 0, 0, 1, (res_polar_bin >> 1) + 1); gnuplot_bin_hit_screen("plot / test", &b_htscrn[0], POLARISATION_DENSITY, 0, 0, 1, (res_polar_bin >> 1) + 1); boundingbox bbox; line3 trans_prtcls; trans_prtcls = (line3) { .o = {0., 0., 0.}, .r = {1., 1., 0.}, .l = 0.
bool gentypes(compile_t* c) { reachable_type_t* t; size_t i; genprim_builtins(c); PONY_LOG(c->opt, VERBOSITY_INFO, (" Data prototypes\n")); i = HASHMAP_BEGIN; while((t = reachable_types_next(&c->reachable->types, &i)) != NULL) { if(!make_opaque_struct(c, t)) return false; gendesc_type(c, t); make_debug_info(c, t); make_box_type(c, t); make_dispatch(c, t); gentrace_prototype(c, t); } PONY_LOG(c->opt, VERBOSITY_INFO, (" Data types\n")); i = HASHMAP_BEGIN; while((t = reachable_types_next(&c->reachable->types, &i)) != NULL) { if(!make_struct(c, t)) return false; make_global_instance(c, t); } PONY_LOG(c->opt, VERBOSITY_INFO, (" Function prototypes\n")); i = HASHMAP_BEGIN; while((t = reachable_types_next(&c->reachable->types, &i)) != NULL) { make_debug_final(c, t); make_pointer_methods(c, t); if(!genfun_method_sigs(c, t)) return false; } PONY_LOG(c->opt, VERBOSITY_INFO, (" Functions\n")); i = HASHMAP_BEGIN; while((t = reachable_types_next(&c->reachable->types, &i)) != NULL) { if(!genfun_method_bodies(c, t)) return false; } PONY_LOG(c->opt, VERBOSITY_INFO, (" Descriptors\n")); i = HASHMAP_BEGIN; while((t = reachable_types_next(&c->reachable->types, &i)) != NULL) { if(!make_trace(c, t)) return false; gendesc_init(c, t); } return true; }
int main(int argc, char **argv) { destor_start(); int job = DESTOR_BACKUP; int revision = -1; int opt = 0; while ((opt = getopt_long(argc, argv, short_options, long_options, NULL)) != -1) { switch (opt) { case 'r': job = DESTOR_RESTORE; revision = atoi(optarg); break; case 's': destor_stat(); break; case 't': job = DESTOR_MAKE_TRACE; break; case 'h': usage(); break; case 'p': { sds param = sdsnew(optarg); load_config_from_string(param); break; } default: return 0; } } sds path = NULL; switch (job) { case DESTOR_BACKUP: if (argc > optind) { path = sdsnew(argv[optind]); } else { fprintf(stderr, "backup job needs a protected path!\n"); usage(); } do_backup(path); /* * The backup concludes. * GC starts * */ if(destor.backup_retention_time >= 0 && jcr.id >= destor.backup_retention_time){ NOTICE("GC is running!"); do_delete(jcr.id - destor.backup_retention_time); } sdsfree(path); break; case DESTOR_RESTORE: if (revision < 0) { fprintf(stderr, "A job id is required!\n"); usage(); } if (argc > optind) { path = sdsnew(argv[optind]); } else { fprintf(stderr, "A target directory is required!\n"); usage(); } do_restore(revision, path[0] == 0 ? 0 : path); sdsfree(path); break; case DESTOR_MAKE_TRACE: { if (argc > optind) { path = sdsnew(argv[optind]); } else { fprintf(stderr, "A target directory is required!\n"); usage(); } make_trace(path); sdsfree(path); break; } default: fprintf(stderr, "Invalid job type!\n"); usage(); } destor_shutdown(); return 0; }