int main(int argc, char** argv) { if (argc != 2) { printf("Usage: ./fileops1 <input text file> \n"); exit(1); } char *content; int size,size2; size = ae_load_file_to_memory(argv[1], &content); size2=size; if (size < 0) { puts("Error loading file"); return 1; } do { // putchar(content[size-1]); size--; } while(size > 0); do { putchar(content[size]); size2--; size++; } while(size2 > 0); return 0; }
int main( int argc, const char* argv[] ) { double start,end; double dif; char* file_name = "../data/file.txt"; char* result; char* search_key = "123123"; long long nr_bytes; long long i; long long nr_lines; int string_size = strlen(search_key); int block_size; int read_count; int line_size; start = omp_get_wtime(); // read file: nr_bytes = ae_load_file_to_memory(argv[1],&result); end = omp_get_wtime(); dif = end-start; printf("LoadFile core %i: %f\n",omp_get_thread_num(), dif); // assume each line in file is equally long. here we get the line size. for ( i=0 ; i<nr_bytes ; i++ ) { if ( result[i]=='\n' ) { line_size = i+1; break; } } // nr_lines = nr_bytes / line_size; block_size = 1.5*(nr_lines/pow(6,string_size)); read_count = 0; start = omp_get_wtime(); // search: read_count = read_file(result,search_key,block_size,nr_lines,line_size); end = omp_get_wtime(); dif = end - start; printf("Search core %i: %f\n",omp_get_thread_num(),dif); printf("result found: %i\n", read_count); }
int main( int argc, const char* argv[] ) { double start,end; double dif; //int data_size = 100000000; // int string_size = 6; // int block_size = 1.5*(data_size/pow(10,string_size)); // int read_count; char* file_name = "../data/file.txt"; char* result; long long nr_bytes; start = omp_get_wtime(); nr_bytes = ae_load_file_to_memory(argv[1],&result); end = omp_get_wtime(); dif = end-start; printf("load file %f\n",dif); int line_size; long long i; for ( i=0 ; i<nr_bytes ; i++ ){ if ( result[i]=='\n' ){ line_size = i+1; break; } } // assume that all the lines in the file have the same size long long data_size = nr_bytes / line_size; int string_size = 6; int block_size = 1.5*(data_size/pow(10,string_size)); int read_count; start = omp_get_wtime(); read_count = read_file(result,"123123",block_size,data_size,line_size); end = omp_get_wtime(); dif = end - start; printf("search: %f\n",dif); printf("result found: %i\n", read_count); }