diff options
Diffstat (limited to 'charf.c')
| -rw-r--r-- | charf.c | 15 |
1 files changed, 11 insertions, 4 deletions
@@ -110,7 +110,7 @@ void compute_maximalfunction(VALUETYPE* f, VALUETYPE* Mf, int D){ /*Because it simplifies code later on we also assign the average on twice the circle, starting in 0.*/ Af[0][2*D] = Af[0][D]; - /*Finding the maximal average actually looks like the most costly computation, in the whole algorithm, being of order D^3. + /*Finding the maximal average actually looks like the most costly computation, in the whole algorithm, being of order D^2. Hence we put effort into making it efficient. The strategy is to go trough all possible intervals, starting with those of largest length. For each [i,i+l) that we encounter we check for each n∈[i,i+l) if the average on [i,i+l) beats the current best average that we have so far computed for intervals containing n. @@ -273,6 +273,7 @@ int generate_function(VALUETYPE* f, index_t i){ #define FORMAT_TEXT 0 #define FORMAT_LATEX 1 +/*Write into pointer s the function corresponding to an index, and that the ratio of the L^p norms of the kth derivative of the maximal function and the function equals r.*/ void format_result(char* s, index_t index, int k, EXPTYPE p, VALUETYPE r, int format){ VALUETYPE f[N]; int d = generate_function(f,index); @@ -340,6 +341,8 @@ void format_result(char* s, index_t index, int k, EXPTYPE p, VALUETYPE r, int fo } } +/*Given an index compute the ratio of the L^p norms of derivatives up to order k of the maximal function and the function for a given range of exponents p. +If for any order of derivative or exponent p the latest record for that ratio is broken, update the value of the record and the index of the witnessing function.*/ int compute(index_t index, EXPTYPE exponents[P], VALUETYPE (*records_ratio)[K+1][P], index_t (*records_index)[K+1][P]){ VALUETYPE f[N]; int D = generate_function(f,index); @@ -407,6 +410,7 @@ int compute(index_t index, EXPTYPE exponents[P], VALUETYPE (*records_ratio)[K+1] return D; } +/*Save formatted string of current records into pointer text. Each entry is formatted using format_result.*/ void format_results(char* text, EXPTYPE exponents[P], VALUETYPE ratios[K+1][P], index_t indeces[K+1][P], int format){ char beginning[1024]; char end[1024]; @@ -481,9 +485,10 @@ void print_latex_records_to_file(EXPTYPE exponents[P], VALUETYPE ratios[K+1][P], fclose(fptr); } +/*information given to each thread*/ typedef struct { EXPTYPE exponents[P]; VALUETYPE (*records_ratio)[K+1][P]; index_t (*records_index)[K+1][P]; int num_thread; int* domain_current; int* cont; } Args; -/*Goes through all functions indexed by those numbers which equal the thread number module NUM_THREADS.*/ +/*Goes through all functions indexed by those numbers which equal the thread number mod NUM_THREADS.*/ void* compute_chunk(void* arguments){ Args* args = arguments; int i = args -> num_thread; @@ -518,6 +523,7 @@ int main() { int domain_current = 0; int cont = 0; + /*Start threads that do the computation.*/ for (int i = 0; i < NUM_THREADS; i++) { printf("In main: Creating thread %d.\n", i); memcpy(args[i].exponents,exponents,sizeof exponents); @@ -529,6 +535,7 @@ int main() { pthread_create(&threads[i], NULL, compute_chunk, args+i); } + /*Capture user input.*/ size_t sz = 1024; char prmpt[] = "To exit enter q, quit or exit.\nTo print current records to terminal enter r.\nTo print current records to a file enter p.\nTo do so with tex formatting enter t.\n"; char buff[sz]; @@ -543,9 +550,9 @@ int main() { getLine("Enter file name:\n", buff, sz); print_latex_records_to_file(exponents,records_ratio,records_index,buff); } - } while(cont < NUM_THREADS); + } while(cont < NUM_THREADS); //Stop once all threads have finished. - // wait for each thread to complete + /*Wait for each thread to complete.*/ for (int i = 0; i < NUM_THREADS; i++) { pthread_join(threads[i], NULL); printf("In main: Thread %d has ended.\n", i); |
