int main(int argc, char **argv) { struct timespec T; unsigned N = 42; unsigned histogram[NUM_HIST_BOXES] = {0}; star_array_t stars = star_array_initialize(N); star_array_t sorted_stars = star_array_initialize(N); sym_matrix_t matrix = sym_matrix_intitialize(N); if(!matrix){ report(FAIL, "Failed to allocate matrix: %s (%d)", strerror(errno), errno); return -1; } float_t *tally = malloc(sizeof(float_t)*triag_nr(N-2)); if(!tally){ report(FAIL, "Failed to allocate tally: %s (%d)", strerror(errno), errno); return -1; } create_random_array(stars, N); report(INFO, "starting sort"); optim_sort(stars, sorted_stars, N); report(INFO, "sorted"); print_stars(sorted_stars, N); fill_matrix(sorted_stars, matrix, N); //print_matrix(matrix, N); create_tally_matrix(matrix, tally, N); //print_tally_matrix(tally, N-2); hist_param_t histparams = generate_histogram(tally, histogram, N-2, NUM_HIST_BOXES); display_histogram(histogram, histparams); star_array_free(stars); star_array_free(sorted_stars); sym_matrix_free(matrix); free(tally); }
void demo(int size) { printf("Shuffling arrays of size %d \n",size); printf("Time reported in number of cycles per array element.\n"); printf("Tests assume that array is in cache as much as possible.\n"); int repeat = 500; uint32_t * testvalues = create_random_array(size); uint32_t * pristinecopy = malloc(size * sizeof(uint32_t)); memcpy(pristinecopy,testvalues,sizeof(uint32_t) * size); if(sortAndCompare(testvalues, pristinecopy, size)!=0) return; BEST_TIME(shuffle_pcg(testvalues,size), array_cache_prefetch(testvalues,size), repeat, size); if(sortAndCompare(testvalues, pristinecopy, size)!=0) return; BEST_TIME(shuffle_pcg_go(testvalues,size), array_cache_prefetch(testvalues,size), repeat, size); if(sortAndCompare(testvalues, pristinecopy, size)!=0) return; BEST_TIME(shuffle_pcg_java(testvalues,size), array_cache_prefetch(testvalues,size), repeat, size); if(sortAndCompare(testvalues, pristinecopy, size)!=0) return; BEST_TIME(shuffle_pcg_divisionless(testvalues,size), array_cache_prefetch(testvalues,size), repeat, size); if(sortAndCompare(testvalues, pristinecopy, size)!=0) return; BEST_TIME(shuffle_pcg_divisionless_with_slight_bias(testvalues,size), array_cache_prefetch(testvalues,size), repeat, size); if(sortAndCompare(testvalues, pristinecopy, size)!=0) return; free(testvalues); free(pristinecopy); printf("\n"); }
int main(int argc, const char * argv[]) { std::vector<int> array = create_random_array(); std::cout << " Before sorting: " << std::endl; printArray(array); bubble_sort(array); std::cout << " After sorting: " << std::endl; printArray(array); return 0; }
int main(int argc, char** argv){ // Creates an array with random values int* array = create_random_array(10, 10); // Prints the values of the array, e.g: // 3 6 7 5 3 5 6 2 9 1 print_array(array, 10); // Sorts the array sort(array, 10); // Prints the sorted array, e.g: // 1 2 3 3 5 5 6 6 7 9 print_array(array, 10); // Create another random array int* new_array = create_random_array(10,10); // Print the second array print_array(new_array, 10); // Create a tree with the values in the new array Node* root = create_tree(new_array, 10); // Print the tree print_tree(root, 0); // Search for the values 3 and 11 in the tree // and print the results int found_3 = search(root, 3); int found_11 = search(root, 11); printf("%d, %d\n", found_3, found_11); // Integrate x^2 and x^3 from 0 to 1. // Should be approx 1/3 and 1/4. printf("%f\n", integrate(&x_squared, 0, 1, 0.001)); printf("%f\n", integrate(&x_cubed, 0, 1, 0.001)); }
int main() { array t = create_random_array(size); visit_array(t, size, print); sep; qsort_sort(t, size, cmp); visit_array(t, size, print); sep; return 0; }
int main() { long array[LENGTH]; create_random_array(array, LENGTH); quicksort(array, 0, LENGTH); print_array(array, LENGTH); return 0; }
int main(int argc, char **argv) { int N, i; clock_t start, end; srand(0); if(argc < 2) { printf("usage: ./a.out N\n"); return 0; } N = atoi(argv[1]); star_t *stars; stars = (star_t *) malloc(N*sizeof(star_t)); printf("creating random stars: \t"); start = clock(); create_random_array(stars, N); end = clock(); printtime(start, end); // print_stars(stars, N); printf("sorting stars: \t"); start = clock(); sort(stars, N); end = clock(); printtime(start, end); // print_stars(stars, N); printf("allocating matrix: \t"); start = clock(); float_t **matrix; float_t *matrix_aux; matrix=malloc(N*sizeof(float_t*)); matrix_aux=calloc(N*N, sizeof(float_t)); for(int i=0; i<N; i++) matrix[i]=&matrix_aux[i*N]; end = clock(); printtime(start, end); printf("filling matrix: \t"); start = clock(); fill_matrix(stars, matrix, N); // print_matrix(matrix,N); end = clock(); printtime(start, end); printf("generating histogram: \t"); start = clock(); int *histogram = (int *)calloc(NUM_HIST_BOXES,sizeof(int)); hist_param_t *histparams; histparams = malloc(sizeof(hist_param_t)); generate_histogram(matrix, histogram, N, NUM_HIST_BOXES, histparams); end = clock(); printtime(start, end); display_histogram(histogram, *histparams); }
int main(int argc, char **argv) { int N, i, j; clock_t start, end; /* if(argc < 2) { printf("usage: ./a.out N\n"); return 0; } */ N = 1000;//atoi(argv[1]); printf("MAX INT: %d\n", INT_MAX); star_t *stars; stars = (star_t *) malloc(N*sizeof(star_t)); printf("creating random stars: \t"); start = clock(); create_random_array(stars, N); end = clock(); printtime(start, end); // print_stars(stars, N); printf("sorting stars: \t"); start = clock(); sort(stars, N); end = clock(); printtime(start, end); // print_stars(stars, N); printf("allocating matrix: \t"); start = clock(); //float_t **matrix; matrix* m; m = matrix_create(N, N); end = clock(); printtime(start, end); printf("filling matrix: \t"); start = clock(); fill_matrix(stars, m, N); //print_matrix(matrix,N); end = clock(); printtime(start, end); printf("generating histogram: \t"); start = clock(); int *histogram = (int *)calloc(NUM_HIST_BOXES,sizeof(int)); hist_param_t histparams = generate_histogram(m, histogram, N, NUM_HIST_BOXES); end = clock(); printtime(start, end); display_histogram(histogram, histparams); free(histogram); free(m->data); free(m); /* for (i=0; i<N; i++) { printf("%s: %f\n",stars[i].designation,stars[i].distanceFromOrigin); } */ /* for (i=0; i<N; i++) { for (j=0; j<N; j++) { printf("%.2f ",matrix_get(*m, i, j)); } printf("\n"); } */ }