int bench(int argc, char **argv, bool main_bench) { for (int arg = 0; arg < argc; ++arg) { if (!strncmp("--batch=", argv[arg], 8)) SAFE(batch(argv[arg] + 8, bench), CRIT); else if (!strncmp("--cfg=", argv[arg], 6)) cfg = str2cfg(argv[arg] + 6); else if (!strncmp("--match=", argv[arg], 8)) pattern = argv[arg] + 8; else if (!strncmp("--mb=", argv[arg], 5)) mb = atoi(argv[arg] + 5); else if (!strncmp("--dir=", argv[arg], 6)) dir = str2dir(argv[arg] + 6); else if (!strncmp("--alg=", argv[arg], 6)) alg = str2alg(argv[arg] + 6); else if (!strncmp("--attr=", argv[arg], 7)) SAFE(str2attr(&attr, argv[arg] + 7), CRIT); else if (!strncmp("--skip-impl=", argv[arg], 12)) skip_impl = argv[arg] + 12; else if (!strncmp("--allow-unimpl=", argv[arg], 15)) allow_unimpl = str2bool(argv[arg] + 15); else if (!strncmp("--perf-template=", argv[arg], 16)) perf_template = argv[arg] + 16; else if (!strcmp("--reset", argv[arg])) reset_parameters(); else if (!strncmp("--mode=", argv[arg], 7)) bench_mode = str2bench_mode(argv[arg] + 7); else if (!strncmp("-v", argv[arg], 2)) verbose = atoi(argv[arg] + 2); else if (!strncmp("--verbose=", argv[arg], 10)) verbose = atoi(argv[arg] + 10); else { desc_t c; bool is_deconv = 0; if (str2desc(&c, argv[arg], is_deconv) == FAIL) { fprintf(stderr, "driver: unknown option: `%s`, exiting...\n", argv[arg]); exit(2); } check_correctness(&c); } } return OK; }
int bench(int argc, char **argv, bool main_bench) { for (int arg = 0; arg < argc; ++arg) { if (!strncmp("--batch=", argv[arg], 8)) SAFE(batch(argv[arg] + 8, bench), CRIT); else if (!strncmp("--dir=", argv[arg], 6)) dir = str2dir(argv[arg] + 6); else if (!strncmp("--dt=", argv[arg], 5)) dt = str2dt(argv[arg] + 5); else if (!strncmp("--tag=", argv[arg], 6)) tag = str2tag(argv[arg] + 6); else if (!strncmp("--axis=", argv[arg], 7)) axis = atoi(argv[arg] + 7); else if (!strncmp("--group=", argv[arg], 8)) group = atoi(argv[arg] + 8); else if (!strncmp("--match=", argv[arg], 8)) pattern = argv[arg] + 8; else if (!strncmp("--mode=", argv[0], 7)) bench_mode = str2bench_mode(argv[0] + 7); else if (!strcmp("--reset", argv[arg])) reset_parameters(); else if (!strncmp("-v", argv[arg], 2)) verbose = atoi(argv[arg] + 2); else if (!strncmp("--verbose=", argv[arg], 10)) verbose = atoi(argv[arg] + 10); else { if (!strncmp("--", argv[arg], 2)) { fprintf(stderr, "driver: unknown option: `%s`, exiting...\n", argv[arg]); exit(2); } dims = str2dims(argv[arg]); check_correctness(); } } return OK; }
// --------------------------------------------------------------------- // test_large // --------------------------------------------------------------------- void test_large(unsigned long long* count) { dc_profile init, end; #if VERBOSE dc_profile start; #endif printf("--making initial list of %d items\n", N); rlist* in = rlist_new_rand(N, MAX_VAL); rlist* out = rlist_new(); puts("--making sorter"); dc_fetch_profile_info(&init); sorter* q = _sorter(new)(in, out); if (q == NULL) { printf("error: cannot initialize sorter\n"); exit(0); } dc_fetch_profile_info(&end); dc_dump_profile_diff(stdout, &init, &end); check_correctness(in, out); puts("\n--making ins/rem operations on input list"); size_t num_updates = 0; int val; dc_fetch_profile_info(&init); #if VERBOSE dc_fetch_profile_info(&start); #endif val = rlist_val(rlist_first(in)); #if VERBOSE printf("<r"); fflush(stdout); #endif #if INS_REM == 1 rlist_remove_first(in); #else rlist_set_val(rlist_first(in), UPDATE(val)); #endif #if VERBOSE printf("><i"); fflush(stdout); #endif #if INS_REM == 1 rlist_insert_first(in, val); #else rlist_set_val(rlist_first(in), val); #endif num_updates += 2; #if VERBOSE printf(">"); fflush(stdout); printf("\n"); dc_fetch_profile_info(&end); printf("last session report:\n"); dc_dump_profile_diff(stdout, &start, &end); printf("all sessions report:\n"); debugging_dump(q, 0, &init, &end); #endif check_correctness(in, out); rnode *prev; for (prev = rlist_first(in); prev != NULL && rlist_next(prev) != NULL; prev = rlist_next(prev)) { #if VERBOSE dc_fetch_profile_info(&start); #endif val = rlist_val(rlist_next(prev)); #if VERBOSE printf("<r"); fflush(stdout); #endif #if INS_REM == 1 rlist_remove_next(in, prev); #else rlist_set_val(rlist_next(prev), UPDATE(val)); #endif #if VERBOSE printf("><i"); fflush(stdout); #endif #if INS_REM == 1 rlist_insert_next(in, prev, val); #else rlist_set_val(rlist_next(prev), val); #endif #if VERBOSE printf(">"); fflush(stdout); printf("\n"); dc_fetch_profile_info(&end); printf("last session report:\n"); dc_dump_profile_diff(stdout, &start, &end); printf("all sessions report:\n"); debugging_dump(q, 0, &init, &end); #endif check_correctness(in, out); num_updates += 2; } #if VERBOSE == 0 dc_fetch_profile_info(&end); dc_dump_profile_diff(stdout, &init, &end); #endif puts("\n--deleting sorter"); dc_fetch_profile_info(&init); _sorter(delete)(q); dc_fetch_profile_info(&end); dc_dump_profile_diff(stdout, &init, &end); puts("\n--deleting lists"); dc_fetch_profile_info(&init); rlist_delete(in); rlist_delete(out); dc_fetch_profile_info(&end); dc_dump_profile_diff(stdout, &init, &end); }
// --------------------------------------------------------------------- // test_small 3 // --------------------------------------------------------------------- void test_small(unsigned long long* count) { dc_profile init, start, end; rlist* in = rlist_new_rand(N, MAX_VAL); rlist* out = rlist_new(); printf("list length=%d\n", rlist_length(in)); puts("--initial list in/out"); dump(in, out, count); puts("--making sorter"); sorter* h = _sorter(new)(in, out); if (h == NULL) { printf("error: cannot initialize sorter\n"); exit(0); } dump(in, out, count); #if DEBUG > 0 _sorter(dump)(h); #endif puts("\n--making rnd insert operations on input list"); dc_fetch_profile_info(&init); int val; rnode *prev; size_t num_update, i, j; int updates[UPD]; srand(17); for (i=0; i<UPD; i++) updates[i] = rand(); for (num_update=0; num_update<UPD; num_update++) { i = updates[num_update] % rlist_length(in); if (i==0) { val = rand() % MAX_VAL; printf("\n--update %u: insert value %u in position %u\n", num_update+1, val, i+1); dc_fetch_profile_info(&start); rlist_insert_first(in, val); dc_fetch_profile_info(&end); debugging_dump(h, 1, &start, &end); check_correctness(in, out); continue; } // i>0: update is not on the first item prev = rlist_first(in); for (j=1; j<i; j++) prev = rlist_next(prev); val = rand() % MAX_VAL; printf("\n--update %u: insert value %u in position %u\n", num_update+1, val, i+1); dc_fetch_profile_info(&start); rlist_insert_next(in, prev, val); dc_fetch_profile_info(&end); debugging_dump(h, 1, &start, &end); check_correctness(in, out); } dc_fetch_profile_info(&end); printf("\n--sequence report\n"); debugging_dump(h, 0, &init, &end); check_correctness(in, out); puts("\n--disposing of sorter"); _sorter(delete)(h); dump(in, out, count); puts("\n--deleting lists"); rlist_delete(in); rlist_delete(out); }
// --------------------------------------------------------------------- // test_small 1 // --------------------------------------------------------------------- void test_small(unsigned long long* count) { dc_profile init, start, end; rlist* in = rlist_new_rand(N, MAX_VAL); rlist* out = rlist_new(); printf("list length=%d\n", rlist_length(in)); puts("--initial list in/out"); dump(in, out, count); puts("--making sorter"); dc_fetch_profile_info(&init); sorter* h = _sorter(new)(in, out); if (h == NULL) { printf("error: cannot initialize sorter\n"); exit(0); } dump(in, out, count); dc_fetch_profile_info(&end); debugging_dump(h, 1, &init, &end); check_correctness(in, out); #if DEBUG > 0 _sorter(dump)(h); #endif puts("\n--making ins/rem operations on input list"); size_t num_updates = 0, i = 1; dc_fetch_profile_info(&init); int val; printf("\n--remove item %u of %u\n", i, N); dc_fetch_profile_info(&start); val = rlist_val(rlist_first(in)); rlist_remove_first(in); #if DUMP == 1 dump(in, out, count); #endif dc_fetch_profile_info(&end); debugging_dump(h, 1, &start, &end); check_correctness(in, out); printf("\n--re-insert %u of %u\n", i, N); dc_fetch_profile_info(&start); rlist_insert_first(in, val); #if DUMP == 1 dump(in, out, count); #endif dc_fetch_profile_info(&end); debugging_dump(h, 1, &start, &end); check_correctness(in, out); rnode *prev; i++; for (prev = rlist_first(in); prev != NULL && rlist_next(prev) != NULL; prev = rlist_next(prev), i++) { val = rlist_val(rlist_next(prev)); printf("\n--remove item %u of %u\n", i, N); dc_fetch_profile_info(&start); rlist_remove_next(in, prev); #if DUMP == 1 dump(in, out, count); #endif dc_fetch_profile_info(&end); debugging_dump(h, 1, &start, &end); check_correctness(in, out); printf("\n--re-insert %u of %u\n", i, N); dc_fetch_profile_info(&start); rlist_insert_next(in, prev, val); #if DUMP == 1 dump(in, out, count); #endif dc_fetch_profile_info(&end); debugging_dump(h, 1, &start, &end); check_correctness(in, out); num_updates += 2; } dc_fetch_profile_info(&end); printf("\n--sequence report\n"); debugging_dump(h, 0, &init, &end); check_correctness(in, out); puts("\n--disposing of sorter"); _sorter(delete)(h); dump(in, out, count); puts("\n--deleting lists"); rlist_delete(in); rlist_delete(out); }
int load_graphs_codes(char *file_in, char *custom_file_name){ FILE *fp; int trivial = 0; int err=0; try{ if(first){ first = FALSE; if(temporary_files_creation() != 0){ safe_exit("Error allocating temporary files."); return -1; } } // memory allocation if(heapVariablesAllocation() != 0){ safe_exit("Error on heap allocation variables."); return -1; } /*************************************************************** * Building CPOG Part * ***************************************************************/ // loading scenarios if(loadScenarios(file_in, fp) != 0){ safe_exit("Loading scenarios failed."); return -1; } // looking for predicates if(predicateSearch() != 0){ safe_exit("Predicate searching failed."); return -1; } // looking for non-trivial constraints if( (fp = fopen(CONSTRAINTS_FILE,"w")) == NULL){ safe_exit("Error on opening constraints file for writing."); return -1; } if(nonTrivialConstraints(fp, &total, &trivial) != 0){ safe_exit("Non-trivial constraints searching failed."); return -1; } fclose(fp); // writing non-trivial constraints into a file if( (fp = fopen(TRIVIAL_ENCODING_FILE,"w")) == NULL){ safe_exit("Error on opening constraints file for writing."); return -1; } for(int i = 0; i < total; i++) if (!encodings[i].trivial) { fprintf(fp,"%s\n",encodings[i].constraint.c_str()); } fclose(fp); if(conflictGraph(&total) != 0){ safe_exit("Building conflict graph failed."); return -1; } /*************************************************************** * Reading encoding set by the user * ***************************************************************/ if(read_set_encoding(custom_file_name,n,&bits) != 0){ safe_exit("Error on reading encoding set."); return -1; } if(check_correctness(custom_file_name,n,tot_enc,bits) != 0){ safe_exit("Codes set by the user unfeasible."); return -1; } /*************************************************************** * Variable preparation for encoding * ***************************************************************/ file_cons = strdup(CONSTRAINTS_FILE); // reading non-trivial encoding file if( (err = read_file(TRIVIAL_ENCODING_FILE)) ){ safe_exit("Error occured while reading non-trivial encoding file."); return -1; } // seed for rand srand(time(NULL)); // difference matrix allocation opt_diff = (int**) calloc(n, sizeof(int*)); for(int i=0;i<n;i++) opt_diff[i] = (int*) calloc(n, sizeof(int)); if(encoding_memory_allocation() != 0){ safe_exit("Error on allocating space for encoding (graph loading phase)."); return -1; } // building difference matrix if( (err = difference_matrix(cpog_count)) ){ safe_exit("Error occurred while building difference matrix"); return -1; } } catch(...) { safe_exit("Undefined error during loading graphs and codes."); return -1; } return 0; }