int main(int argc, char **argv) { if (argc != 4) { fprintf(stderr, "Usage: %s <vector size in K> <sort size in K> <merge size in K>\n", argv[0]); return 1; } N = atol(argv[1]) * BLOCK_SIZE; MIN_SORT_SIZE = atol(argv[2]) * BLOCK_SIZE; MIN_MERGE_SIZE = atol(argv[3]) * BLOCK_SIZE; T *data = malloc(N*sizeof(T)); T *tmp = malloc(N*sizeof(T)); initialize(N, data); clear(N, tmp); tareador_ON(); multisort(N, data, tmp); tareador_OFF(); check_sorted (N, data); fprintf(stdout, "Multisort program finished\n"); return 0; }
int main(int argc, char **argv) { if (argc < 3) { fprintf(stderr, "Usage: %s <vector size in K> <sort size in K>\n", argv[0]); return 1; } N = atol(argv[1]) * BLOCK_SIZE; MIN_SORT_SIZE = atol(argv[2]) * BLOCK_SIZE; T *data = malloc(N*sizeof(T)); T *tmp = malloc(N*sizeof(T)); //Initialize the data vector with random natual values initialize(N, data); //Clear the tmp vector. clear(N, tmp); bombolla(N, data, tmp); check_sorted (N, data); fprintf(stdout, "Bombolla program finished\n"); return 0; }
int main(int argc, char** argv) { if (argc < 3) { print_usage(argv[0]); return 1; } cerr << "B :" << (double(em::block_size) / 1024 / 1024) << "\tmem_size: " << (double(em::mem_size) / 1024 / 1024) << endl; em::TFile parsed_log(argv[1], O_RDONLY); const em::door<LogEntry> in_door(parsed_log, 0, parsed_log.size()); em::TFile sorted_log(argv[2], O_RDWR | O_CREAT | O_TRUNC, 0); { em::door<LogEntry> out_door(sorted_log, 0, 0); // Копируем данные, чтобы не испортить исходник std::copy(in_door.begin(), in_door.end(), out_door.begin()); } // Сортируем файлик em::sort<LogEntry>(sorted_log, SortByCaller()); std::cout << "#========== IO stats ==========" << std::endl; em::TIOStat::print_stat(std::cout); if (0) { const em::door<LogEntry> in_door(sorted_log, 0, sorted_log.size()); if (!check_sorted(in_door.begin(), in_door.end(), SortByCaller())) { cerr << "Range not sorted" << endl; } } return 0; }
void do_sort(long n, T data[n], T tmp[n]) { #if _EXTRAE_ Extrae_event(PROGRAM, MULTISORT); #else double sort_time = omp_get_wtime(); #endif #pragma omp parallel #pragma omp single multisort(N, data, tmp); #if _EXTRAE_ Extrae_event(PROGRAM,END); #else sort_time = omp_get_wtime() - sort_time; fprintf(stdout, "%g\n", sort_time); #endif #if _EXTRAE_ Extrae_event(PROGRAM,CHECK); #endif check_sorted (N, data); #if _EXTRAE_ Extrae_event(PROGRAM,END); #endif }
/* * Test: sort array a then check whether it's sorted */ static void test_sort(void **a, uint32_t n) { printf("input: "); print_array(a, n); ptr_array_sort(a, n); printf("output: "); print_array(a, n); check_sorted(a, n); printf("\n"); }
int main() { int len = buf_len; int * in = malloc(sizeof(int) * len); int * out = malloc(sizeof(int) * len); initialize(in, len); initialize(out, len); mergesort(in, out, len); check_sorted(in, len); return 0; }
void sort_block_q(uint64_t* buffer, int count) { if ( count <= 1 ) return; if ( count <= 32 ) { sort_block(buffer,count); return; }; uint64_t z[2] = {buffer[0], buffer[1]}; int nel = -1; bool alleq = true; for ( int i = 1; i < count; i++ ) { uint64_t a[2] = {buffer[i*2], buffer[i*2+1]}; if ( !compareeq (a,z) ) { alleq = false; nel = i; break; } } if ( alleq ) return; if ( nel >= 0 ) { swap(buffer,0,nel); } z[0] = buffer[0]; z[1] = buffer[1]; int lc = 1; for ( int i = 1; i < count; i++ ) { uint64_t a[2] = {buffer[i*2], buffer[i*2+1]}; if ( compare (a,z) ) { swap(buffer, i,lc); lc++; } } swap(buffer,0,lc-1); sort_block_q(buffer, lc); sort_block_q(buffer+(lc*2), count-lc); if ( count < SORT_BLOCK_SIZE ) return; if ( !check_sorted(buffer, count) ) { printf( "Block sort has errors!\n" ); } }
int main(int argc, char **argv) { if (argc != 4) { fprintf(stderr, "Usage: %s <vector size in K> <sort size in K> <merge size in K>\n", argv[0]); return 1; } N = atol(argv[1]) * BLOCK_SIZE; MIN_SORT_SIZE = atol(argv[2]) * BLOCK_SIZE; MIN_MERGE_SIZE = atol(argv[3]) * BLOCK_SIZE; T *data = malloc(N*sizeof(T)); T *tmp = malloc(N*sizeof(T)); double stamp; START_COUNT_TIME; initialize(N, data); clear(N, tmp); STOP_COUNT_TIME("Initialization time in seconds"); START_COUNT_TIME; #pragma omp parallel #pragma omp single multisort(N, data, tmp); STOP_COUNT_TIME("Multisort execution time"); START_COUNT_TIME; check_sorted (N, data); STOP_COUNT_TIME("Check sorted data execution time"); fprintf(stdout, "Multisort program finished\n"); return 0; }
void SortingTester::test_all(int size, int num_tests, bool partial_sort){ std::cout << "Initializing contents.\n" << std::endl; initialize_contents(size); if (!data_){ std::cout << "ERROR: Data uninitialized." << std::endl; std::cout << "Stopping tests." << std::endl; return; } std::cout << "Beginning Tests." << std::endl; for (auto& sort : sorters_){ // Test each sort cur_sort = sort->name(); std::cout << "Testing " << cur_sort << std::endl; SortingTestSummary summary(cur_sort); for (int i = 0; i < num_tests; i++){ shuffle_contents(); start_timer(); sort->operator()(data_, size); int time_ms = stop_timer(); if (!check_sorted()){ std::cout << "ERROR: TEST FAILED!" << std::endl; } summary.add_result(size, time_ms, comparisons, swap_count); reset_test(); } summaries_.push_back(summary); } }
int main( int argc, char** argv ) { if ( argc < 2 ) { fprintf(stderr, "usage: %s [filename]\n", argv[0]); exit(1); } FILE* fin = fopen(argv[1], "rb"); if ( fin == NULL ) { fprintf(stderr, "Filename %s not found\n", argv[1]); exit(1); } uint64_t* block = (uint64_t*)malloc(sizeof(uint64_t)*2*SORT_BLOCK_SIZE); FILE* fout = fopen("temp_0.dat", "wb"); uint64_t block_count = 0; while ( !feof(fin) ) { size_t readcount = fread(block, sizeof(uint64_t)*2, SORT_BLOCK_SIZE, fin); if ( readcount == 0 ) break; printf( "Sorting block %ld (%ld)\n", block_count, readcount ); if ( !check_sorted( block, readcount ) ) { sort_block_q(block, readcount); } fwrite(block, sizeof(uint64_t)*2, readcount, fout); block_count ++; } fclose(fout); fclose(fin); printf("Initial block-level sorting finished!\n"); //uint64_t* blocka = (uint64_t*)malloc(sizeof(uint64_t)*2*SORT_BLOCK_SIZE); //uint64_t* blockb = (uint64_t*)malloc(sizeof(uint64_t)*2*SORT_BLOCK_SIZE); uint64_t merge_block_count = 1; char cur_in_filename[128]; char cur_out_filename[128]; // Mergesort stages for (int sort_stage = 0; ; sort_stage++) { sprintf(cur_in_filename, "temp_%d.dat", sort_stage); FILE* fin1 = fopen(cur_in_filename, "rb"); FILE* fin2 = fopen(cur_in_filename, "rb"); sprintf(cur_out_filename, "temp_%d.dat", sort_stage+1); printf("Sorting stage %d! %s\n", sort_stage, cur_in_filename); fout =fopen(cur_out_filename,"wb"); uint64_t cur_block_off = 0; // Mergesort blocks while (!feof(fin1) && !feof(fin2)) { uint64_t startoff1 = cur_block_off * SORT_BLOCK_SIZE*2*sizeof(uint64_t); uint64_t startoff2 = (cur_block_off + merge_block_count) * SORT_BLOCK_SIZE*2*sizeof(uint64_t); fseek(fin1, startoff1, SEEK_SET); fseek(fin2, startoff2, SEEK_SET); uint64_t buf1[2]; uint64_t buf2[2]; fread(buf1, sizeof(uint64_t)*2, 1, fin1); fread(buf2, sizeof(uint64_t)*2, 1, fin2); uint64_t off1 = 0; uint64_t off2 = 0; printf( "Sorting blocks %ld %ld (%ld)\n", startoff1,startoff2,merge_block_count ); while (1) { if ( compare(buf1,buf2) ) { fwrite(buf1,sizeof(uint64_t)*2,1,fout); if ( fread(buf1, sizeof(uint64_t)*2, 1, fin1) == 0 ) break; off1 ++; if (off1 >= merge_block_count*SORT_BLOCK_SIZE) { while(off2 < merge_block_count*SORT_BLOCK_SIZE) { fwrite(buf2,sizeof(uint64_t)*2,1,fout); if ( fread(buf2, sizeof(uint64_t)*2, 1, fin2) == 0 ) break; off2 ++; } break; } } else { fwrite(buf2,sizeof(uint64_t)*2,1,fout); off2 ++; if ( fread(buf2, sizeof(uint64_t)*2, 1, fin2) == 0 || off2 >= merge_block_count*SORT_BLOCK_SIZE) { while(off1 < merge_block_count*SORT_BLOCK_SIZE) { fwrite(buf1,sizeof(uint64_t)*2,1,fout); if ( fread(buf1, sizeof(uint64_t)*2, 1, fin1) == 0 ) break; off1 ++; } break; } } } cur_block_off += merge_block_count*2; } merge_block_count *= 2; fclose(fin1); fclose(fin2); fclose(fout); std::remove(cur_in_filename); if ( merge_block_count >= block_count ) break; } printf( "Checking final file, %s\n", cur_out_filename ); FILE* fchin = fopen(cur_out_filename, "rb"); uint64_t last[2] = {0,0}; uint64_t count = 0; while (!feof(fchin)) { uint64_t cur[2] = {0,0}; if ( fread(cur, sizeof(uint64_t)*2, 1, fchin) == 0 ) break; if ( !compare(last, cur) ) { printf( "Sort error @ %ld (%ld %ld) > (%ld %ld)\n", count, last[0], last[1], cur[0], cur[1]); } last[0] = cur[0]; last[1] = cur[1]; count++; } printf ( "Checked %ld samples\n", count ); }
int main() { int32_t *a; int32_t n, j; a = (int32_t *) safe_malloc(1000 * sizeof(int32_t)); constant_array(a, 20); printf("input: "); print_array(a, 20); insertion_sort(a, 20); printf("isort: "); print_array(a, 20); printf("\n"); increasing_array(a, 20); printf("input: "); print_array(a, 20); insertion_sort(a, 20); printf("isort: "); print_array(a, 20); printf("\n"); decreasing_array(a, 20); printf("input: "); print_array(a, 20); insertion_sort(a, 20); printf("isort: "); print_array(a, 20); printf("\n"); for (n=0; n<20; n++) { for (j=0; j<10; j++) { random_array(a, n); printf("input: "); print_array(a, n); insertion_sort(a, n); printf("isort: "); print_array(a, n); printf("\n"); check_sorted(a, n); } } total1 = 0.0; total2 = 0.0; total3 = 0.0; total4 = 0.0; total4var = 0.0; total4var2 = 0.0; itotal = 0.0; for (n=0; n<100; n ++) { time1 = 0.0; time2 = 0.0; time3 = 0.0; time4 = 0.0; time4var = 0.0; time4var2 = 0.0; itime = 0.0; printf("size %"PRId32"\n", n); fflush(stdout); for (j=0; j<100; j++) { random_array(a, n); compare(a, n); if (j % 10 == 9) { printf("."); fflush(stdout); } } printf("\nisort: %.3f s\n", itime); printf("sort1: %.3f s\n", time1); printf("sort2: %.3f s\n", time2); printf("sort3: %.3f s\n", time3); printf("sort4: %.3f s\n", time4); printf("sort4var: %.3f s\n", time4var); printf("sort4var2: %.3f s\n", time4var2); printf("\n"); total1 += time1; total2 += time2; total3 += time3; total4 += time4; total4var += time4var; total4var2 += time4var2; itotal += itime; } printf("Total time\n"); printf("isort: %.3f s\n", itotal); printf("sort1: %.3f s\n", total1); printf("sort2: %.3f s\n", total2); printf("sort3: %.3f s\n", total3); printf("sort4: %.3f s\n", total4); printf("sort4var: %.3f s\n", total4var); printf("sort4var2: %.3f s\n", total4var2); safe_free(a); return 0; }
void mexFunction(int nout, mxArray *out[], int nin, const mxArray *in[]) { enum {IN_I=0,IN_END} ; enum {OUT_FRAMES=0, OUT_DESCRIPTORS} ; int verbose = 0 ; int opt ; int next = IN_END ; mxArray const *optarg ; vl_sift_pix const *data ; int M, N ; int O = - 1 ; int S = 3 ; int o_min = 0 ; double edge_thresh = -1 ; double peak_thresh = -1 ; double norm_thresh = -1 ; double magnif = -1 ; double window_size = -1 ; mxArray *ikeys_array = 0 ; double *ikeys = 0 ; int nikeys = -1 ; vl_bool force_orientations = 0 ; vl_bool floatDescriptors = 0 ; VL_USE_MATLAB_ENV ; /* ----------------------------------------------------------------- * Check the arguments * -------------------------------------------------------------- */ if (nin < 1) { mexErrMsgTxt("One argument required.") ; } else if (nout > 2) { mexErrMsgTxt("Too many output arguments."); } if (mxGetNumberOfDimensions (in[IN_I]) != 2 || mxGetClassID (in[IN_I]) != mxSINGLE_CLASS ) { mexErrMsgTxt("I must be a matrix of class SINGLE") ; } data = (vl_sift_pix*) mxGetData (in[IN_I]) ; M = mxGetM (in[IN_I]) ; N = mxGetN (in[IN_I]) ; while ((opt = vlmxNextOption (in, nin, options, &next, &optarg)) >= 0) { switch (opt) { case opt_verbose : ++ verbose ; break ; case opt_octaves : if (!vlmxIsPlainScalar(optarg) || (O = (int) *mxGetPr(optarg)) < 0) { mexErrMsgTxt("'Octaves' must be a positive integer.") ; } break ; case opt_levels : if (! vlmxIsPlainScalar(optarg) || (S = (int) *mxGetPr(optarg)) < 1) { mexErrMsgTxt("'Levels' must be a positive integer.") ; } break ; case opt_first_octave : if (!vlmxIsPlainScalar(optarg)) { mexErrMsgTxt("'FirstOctave' must be an integer") ; } o_min = (int) *mxGetPr(optarg) ; break ; case opt_edge_thresh : if (!vlmxIsPlainScalar(optarg) || (edge_thresh = *mxGetPr(optarg)) < 1) { mexErrMsgTxt("'EdgeThresh' must be not smaller than 1.") ; } break ; case opt_peak_thresh : if (!vlmxIsPlainScalar(optarg) || (peak_thresh = *mxGetPr(optarg)) < 0) { mexErrMsgTxt("'PeakThresh' must be a non-negative real.") ; } break ; case opt_norm_thresh : if (!vlmxIsPlainScalar(optarg) || (norm_thresh = *mxGetPr(optarg)) < 0) { mexErrMsgTxt("'NormThresh' must be a non-negative real.") ; } break ; case opt_magnif : if (!vlmxIsPlainScalar(optarg) || (magnif = *mxGetPr(optarg)) < 0) { mexErrMsgTxt("'Magnif' must be a non-negative real.") ; } break ; case opt_window_size : if (!vlmxIsPlainScalar(optarg) || (window_size = *mxGetPr(optarg)) < 0) { mexErrMsgTxt("'WindowSize' must be a non-negative real.") ; } break ; case opt_frames : if (!vlmxIsMatrix(optarg, 4, -1)) { mexErrMsgTxt("'Frames' must be a 4 x N matrix.x") ; } ikeys_array = mxDuplicateArray (optarg) ; nikeys = mxGetN (optarg) ; ikeys = mxGetPr (ikeys_array) ; if (! check_sorted (ikeys, nikeys)) { qsort (ikeys, nikeys, 4 * sizeof(double), korder) ; } break ; case opt_orientations : force_orientations = 1 ; break ; case opt_float_descriptors : floatDescriptors = 1 ; break ; default : abort() ; } } /* ----------------------------------------------------------------- * Do job * -------------------------------------------------------------- */ { VlSiftFilt *filt ; vl_bool first ; double *frames = 0 ; void *descr = 0 ; int nframes = 0, reserved = 0, i,j,q ; /* create a filter to process the image */ filt = vl_sift_new (M, N, O, S, o_min) ; if (peak_thresh >= 0) vl_sift_set_peak_thresh (filt, peak_thresh) ; if (edge_thresh >= 0) vl_sift_set_edge_thresh (filt, edge_thresh) ; if (norm_thresh >= 0) vl_sift_set_norm_thresh (filt, norm_thresh) ; if (magnif >= 0) vl_sift_set_magnif (filt, magnif) ; if (window_size >= 0) vl_sift_set_window_size (filt, window_size) ; if (verbose) { mexPrintf("vl_sift: filter settings:\n") ; mexPrintf("vl_sift: octaves (O) = %d\n", vl_sift_get_noctaves (filt)) ; mexPrintf("vl_sift: levels (S) = %d\n", vl_sift_get_nlevels (filt)) ; mexPrintf("vl_sift: first octave (o_min) = %d\n", vl_sift_get_octave_first (filt)) ; mexPrintf("vl_sift: edge thresh = %g\n", vl_sift_get_edge_thresh (filt)) ; mexPrintf("vl_sift: peak thresh = %g\n", vl_sift_get_peak_thresh (filt)) ; mexPrintf("vl_sift: norm thresh = %g\n", vl_sift_get_norm_thresh (filt)) ; mexPrintf("vl_sift: window size = %g\n", vl_sift_get_window_size (filt)) ; mexPrintf("vl_sift: float descriptor = %d\n", floatDescriptors) ; mexPrintf((nikeys >= 0) ? "vl_sift: will source frames? yes (%d read)\n" : "vl_sift: will source frames? no\n", nikeys) ; mexPrintf("vl_sift: will force orientations? %s\n", force_orientations ? "yes" : "no") ; } /* ............................................................... * Process each octave * ............................................................ */ i = 0 ; first = 1 ; while (1) { int err ; VlSiftKeypoint const* keys = 0 ; int nkeys = 0 ; if (verbose) { mexPrintf ("vl_sift: processing octave %d\n", vl_sift_get_octave_index (filt)) ; } /* Calculate the GSS for the next octave .................... */ if (first) { err = vl_sift_process_first_octave (filt, data) ; first = 0 ; } else { err = vl_sift_process_next_octave (filt) ; } if (err) break ; if (verbose > 1) { mexPrintf("vl_sift: GSS octave %d computed\n", vl_sift_get_octave_index (filt)); } /* Run detector ............................................. */ if (nikeys < 0) { vl_sift_detect (filt) ; keys = vl_sift_get_keypoints (filt) ; nkeys = vl_sift_get_nkeypoints (filt) ; i = 0 ; if (verbose > 1) { printf ("vl_sift: detected %d (unoriented) keypoints\n", nkeys) ; } } else { nkeys = nikeys ; } /* For each keypoint ........................................ */ for (; i < nkeys ; ++i) { double angles [4] ; int nangles ; VlSiftKeypoint ik ; VlSiftKeypoint const *k ; /* Obtain keypoint orientations ........................... */ if (nikeys >= 0) { vl_sift_keypoint_init (filt, &ik, ikeys [4 * i + 1] - 1, ikeys [4 * i + 0] - 1, ikeys [4 * i + 2]) ; if (ik.o != vl_sift_get_octave_index (filt)) { break ; } k = &ik ; /* optionally compute orientations too */ if (force_orientations) { nangles = vl_sift_calc_keypoint_orientations (filt, angles, k) ; } else { angles [0] = VL_PI / 2 - ikeys [4 * i + 3] ; nangles = 1 ; } } else { k = keys + i ; nangles = vl_sift_calc_keypoint_orientations (filt, angles, k) ; } /* For each orientation ................................... */ for (q = 0 ; q < nangles ; ++q) { vl_sift_pix buf [128] ; vl_sift_pix rbuf [128] ; /* compute descriptor (if necessary) */ if (nout > 1) { vl_sift_calc_keypoint_descriptor (filt, buf, k, angles [q]) ; transpose_descriptor (rbuf, buf) ; } /* make enough room for all these keypoints and more */ if (reserved < nframes + 1) { reserved += 2 * nkeys ; frames = mxRealloc (frames, 4 * sizeof(double) * reserved) ; if (nout > 1) { if (! floatDescriptors) { descr = mxRealloc (descr, 128 * sizeof(vl_uint8) * reserved) ; } else { descr = mxRealloc (descr, 128 * sizeof(float) * reserved) ; } } } /* Save back with MATLAB conventions. Notice tha the input * image was the transpose of the actual image. */ frames [4 * nframes + 0] = k -> y + 1 ; frames [4 * nframes + 1] = k -> x + 1 ; frames [4 * nframes + 2] = k -> sigma ; frames [4 * nframes + 3] = VL_PI / 2 - angles [q] ; if (nout > 1) { if (! floatDescriptors) { for (j = 0 ; j < 128 ; ++j) { float x = 512.0F * rbuf [j] ; x = (x < 255.0F) ? x : 255.0F ; ((vl_uint8*)descr) [128 * nframes + j] = (vl_uint8) x ; } } else { for (j = 0 ; j < 128 ; ++j) { float x = 512.0F * rbuf [j] ; ((float*)descr) [128 * nframes + j] = x ; } } } ++ nframes ; } /* next orientation */ } /* next keypoint */ } /* next octave */ if (verbose) { mexPrintf ("vl_sift: found %d keypoints\n", nframes) ; } /* ............................................................... * Save back * ............................................................ */ { mwSize dims [2] ; /* create an empty array */ dims [0] = 0 ; dims [1] = 0 ; out[OUT_FRAMES] = mxCreateNumericArray (2, dims, mxDOUBLE_CLASS, mxREAL) ; /* set array content to be the frames buffer */ dims [0] = 4 ; dims [1] = nframes ; mxSetPr (out[OUT_FRAMES], frames) ; mxSetDimensions (out[OUT_FRAMES], dims, 2) ; if (nout > 1) { /* create an empty array */ dims [0] = 0 ; dims [1] = 0 ; out[OUT_DESCRIPTORS]= mxCreateNumericArray (2, dims, floatDescriptors ? mxSINGLE_CLASS : mxUINT8_CLASS, mxREAL) ; /* set array content to be the descriptors buffer */ dims [0] = 128 ; dims [1] = nframes ; mxSetData (out[OUT_DESCRIPTORS], descr) ; mxSetDimensions (out[OUT_DESCRIPTORS], dims, 2) ; } } /* cleanup */ vl_sift_delete (filt) ; if (ikeys_array) mxDestroyArray(ikeys_array) ; } /* end: do job */ }
static enum EvaluationCost get_pred_cost (const struct predicate *p) { enum EvaluationCost data_requirement_cost = NeedsNothing; enum EvaluationCost inherent_cost = NeedsUnknown; if (p->need_stat) { data_requirement_cost = NeedsStatInfo; } else if (p->need_inum) { data_requirement_cost = NeedsInodeNumber; } else if (p->need_type) { data_requirement_cost = NeedsType; } else { data_requirement_cost = NeedsNothing; } if (pred_is (p, pred_exec) || pred_is(p, pred_execdir)) { if (p->args.exec_vec.multiple) inherent_cost = NeedsEventualExec; else inherent_cost = NeedsImmediateExec; } else if (pred_is (p, pred_fprintf)) { /* the parser calculated the cost for us. */ inherent_cost = p->p_cost; } else { struct pred_cost_lookup key; void *entry; if (!pred_table_sorted) { qsort (costlookup, sizeof(costlookup)/sizeof(costlookup[0]), sizeof(costlookup[0]), cost_table_comparison); if (!check_sorted (costlookup, sizeof(costlookup)/sizeof(costlookup[0]), sizeof(costlookup[0]), cost_table_comparison)) { error (EXIT_FAILURE, 0, "failed to sort the costlookup array"); } pred_table_sorted = 1; } key.fn = p->pred_func; entry = bsearch (&key, costlookup, sizeof(costlookup)/sizeof(costlookup[0]), sizeof(costlookup[0]), cost_table_comparison); if (entry) { inherent_cost = ((const struct pred_cost_lookup*)entry)->cost; } else { /* This message indicates a bug. If we issue the message, we actually have two bugs: if find emits a diagnostic, its result should be nonzero. However, not having an entry for a predicate will not affect the output (just the performance) so I think it would be confusing to exit with a nonzero status. */ error (0, 0, _("warning: there is no entry in the predicate evaluation " "cost table for predicate %s; please report this as a bug"), p->p_name); inherent_cost = NeedsUnknown; } } if (inherent_cost > data_requirement_cost) return inherent_cost; else return data_requirement_cost; }
int main(int argc, char **argv) { if (argc != 4) { fprintf(stderr, "Usage: %s <vector size in K> <sort size in K> <merge size in K>\n", argv[0]); return 1; } N = atol(argv[1]) * BLOCK_SIZE; MIN_SORT_SIZE = atol(argv[2]) * BLOCK_SIZE; MIN_MERGE_SIZE = atol(argv[3]) * BLOCK_SIZE; T *data = malloc(N*sizeof(T)); T *tmp = malloc(N*sizeof(T)); #if _EXTRAE_ Extrae_init(); Extrae_event(PROGRAM, INITIALIZE); #else double stamp; START_COUNT_TIME; #endif initialize(N, data); clear(N, tmp); #if _EXTRAE_ Extrae_event(PROGRAM, END); #else STOP_COUNT_TIME("Initialization time in seconds"); #endif #if _EXTRAE_ Extrae_event(PROGRAM, MULTISORT); #else START_COUNT_TIME; #endif #pragma omp parallel #pragma omp single { multisort(N, data, tmp); } #if _EXTRAE_ Extrae_event(PROGRAM,END); #else STOP_COUNT_TIME("Multisort execution time"); #endif #if _EXTRAE_ Extrae_event(PROGRAM,CHECK); #else START_COUNT_TIME; #endif check_sorted (N, data); #if _EXTRAE_ Extrae_event(PROGRAM,END); Extrae_fini(); #else STOP_COUNT_TIME("Check sorted data execution time"); #endif fprintf(stdout, "Multisort program finished\n"); return 0; }
void mexFunction(int nout, mxArray *out[], int nin, const mxArray *in[]) { enum {IN_I=0,IN_END} ; enum {OUT_FRAMES=0, OUT_DESCRIPTORS} ; int verbose = 0 ; int opt ; int next = IN_END ; mxArray const *optarg ; vl_sift_pix const *data ; int M, N ; int O = - 1 ; int S = 3 ; int o_min = 0 ; double edge_thresh = -1 ; double peak_thresh = -1 ; double norm_thresh = -1 ; double magnif = -1 ; double window_size = -1 ; mxArray *ikeys_array = 0 ; double *ikeys = 0 ; int nikeys = -1 ; vl_bool force_orientations = 0 ; vl_bool floatDescriptors = 0 ; VL_USE_MATLAB_ENV ; /* ----------------------------------------------------------------- * Check the arguments * -------------------------------------------------------------- */ if (nin < 1) { mexErrMsgTxt("One argument required.") ; } else if (nout > 2) { mexErrMsgTxt("Too many output arguments."); } if (mxGetNumberOfDimensions (in[IN_I]) != 2 || mxGetClassID (in[IN_I]) != mxSINGLE_CLASS ) { mexErrMsgTxt("I must be a matrix of class SINGLE") ; } data = (vl_sift_pix*) mxGetData (in[IN_I]) ; M = mxGetM (in[IN_I]) ; N = mxGetN (in[IN_I]) ; while ((opt = vlmxNextOption (in, nin, options, &next, &optarg)) >= 0) { switch (opt) { case opt_verbose : ++ verbose ; break ; case opt_frames : if (!vlmxIsMatrix(optarg, 4, -1)) { mexErrMsgTxt("'Frames' must be a 4 x N matrix.") ; } ikeys_array = mxDuplicateArray (optarg) ; nikeys = mxGetN (optarg) ; ikeys = mxGetPr (ikeys_array) ; if (! check_sorted (ikeys, nikeys)) { qsort (ikeys, nikeys, 4 * sizeof(double), korder) ; } break ; default : mexPrintf("F**k you!"); abort() ; } } /* ----------------------------------------------------------------- * Do job * -------------------------------------------------------------- */ { VlSiftFilt *filt ; vl_bool first ; double *frames = 0 ; void *descr = 0 ; int nframes = 0, reserved = 0, i,j,q ; /* create a filter to process the image */ filt = vl_sift_new (M, N, O, S, o_min) ; //mexPrintf("%f %f %f \n%f %f %f %f %f\n",(float)O,(float)S,(float)o_min,(float)peak_thresh // ,(float)edge_thresh,(float)norm_thresh,(float)magnif,(float)window_size); /* ............................................................... * Process each octave * ............................................................ */ i = 0 ; first = 1 ; while (first == 1) { int err ; VlSiftKeypoint const *keys = 0 ; int nkeys = 0 ; err = vl_sift_process_first_octave (filt, data) ; first = 0 ; if (err) break ; /* Run detector ............................................. */ nkeys = nikeys ; //mexPrintf("Zhu: entering sweeping nkeys, nkeys = %d, i = %d \n", nkeys, i); /* For each keypoint ........................................ */ for (; i < nkeys ; ++i) { int h; vl_sift_pix buf[128]; vl_sift_pix rbuf[128]; double angle; VlSiftKeypoint ik ; VlSiftKeypoint const *k ; /* Obtain keypoint orientations ........................... */ vl_sift_keypoint_init (filt, &ik, ikeys [4 * i + 1] - 1, ikeys [4 * i + 0] - 1, ikeys [4 * i + 2]) ; //mexPrintf("ikeys: [%f, %f, %f]\n", (float)(ikeys [4 * i + 1] - 1), (float)(ikeys [4 * i + 0] - 1), (float)(ikeys [4 * i + 2]) ); k = &ik ; /* optionally compute orientations too */ angle = VL_PI / 2 - ikeys [4 * i + 3] ; q = 0; /* compute descriptor (if necessary) */ //int h; //mexPrintf("M = %d, N = %d.\n",M,N); //for (h = 0; h < 300; h++) //{ // mexPrintf("%f ",data[h]); // if (h % 8 == 7) mexPrintf("\n"); //} if (nout > 1) { //mexPrintf("angles = %f, x = %f(%d), y = %f(%d), s = %f(%d), o = %d, sigma = %f.\n buf = [", //angle,k->x,k->ix,k->y,k->iy,k->s,k->is,k->o,k->sigma); vl_sift_calc_keypoint_descriptor (filt, buf, k, angle) ; //for (h = 0; h < 128; h++) //{ // mexPrintf("%f ",(float)buf[h]); // if (h % 8 == 7) mexPrintf("\n"); //} //mexPrintf("...].\nrbuf = ["); transpose_descriptor (rbuf, buf) ; //for (h = 0; h < 128; h++) //{ // mexPrintf("%f ",(float)rbuf[h]); // if (h % 8 == 7) mexPrintf("\n"); //} //mexPrintf("...].\n"); } /* make enough room for all these keypoints and more */ if (reserved < nframes + 1) { reserved += 2 * nkeys ; frames = mxRealloc (frames, 4 * sizeof(double) * reserved) ; if (nout > 1) { if (! floatDescriptors) { descr = mxRealloc (descr, 128 * sizeof(vl_uint8) * reserved) ; } else { descr = mxRealloc (descr, 128 * sizeof(float) * reserved) ; } } } /* Save back with MATLAB conventions. Notice tha the input * image was the transpose of the actual image. */ frames [4 * nframes + 0] = k -> y + 1 ; frames [4 * nframes + 1] = k -> x + 1 ; frames [4 * nframes + 2] = k -> sigma ; frames [4 * nframes + 3] = VL_PI / 2 - angle; //mexPrintf("Zhu: %d\n", nframes); if (nout > 1) { if (! floatDescriptors) { for (j = 0 ; j < 128 ; ++j) { float x = 512.0F * rbuf [j] ; x = (x < 255.0F) ? x : 255.0F ; ((vl_uint8*)descr) [128 * nframes + j] = (vl_uint8) x ; } } else { for (j = 0 ; j < 128 ; ++j) { float x = 512.0F * rbuf [j] ; ((float*)descr) [128 * nframes + j] = x ; } } } ++ nframes ; /* next orientation */ } /* next keypoint */ //break; //mexPrintf("Zhu: skip subsequent octave\n"); } /* next octave */ //mexPrintf("nframes_tot = %d\n",nframes); /* ............................................................... * Save back * ............................................................ */ { mwSize dims [2] ; /* create an empty array */ dims [0] = 0 ; dims [1] = 0 ; out[OUT_FRAMES] = mxCreateNumericArray (2, dims, mxDOUBLE_CLASS, mxREAL) ; /* set array content to be the frames buffer */ dims [0] = 4 ; dims [1] = nframes ; mxSetPr (out[OUT_FRAMES], frames) ; mxSetDimensions (out[OUT_FRAMES], dims, 2) ; if (nout > 1) { /* create an empty array */ dims [0] = 0 ; dims [1] = 0 ; out[OUT_DESCRIPTORS]= mxCreateNumericArray (2, dims, floatDescriptors ? mxSINGLE_CLASS : mxUINT8_CLASS, mxREAL) ; /* set array content to be the descriptors buffer */ dims [0] = 128 ; dims [1] = nframes ; mxSetData (out[OUT_DESCRIPTORS], descr) ; mxSetDimensions (out[OUT_DESCRIPTORS], dims, 2) ; } } /* cleanup */ vl_sift_delete (filt) ; if (ikeys_array) mxDestroyArray(ikeys_array) ; } /* end: do job */ }