#include #include #include #include #include #ifndef EXACT #define EXACT false #endif #define NUM_THREADS 4 #if EXACT #include "ratio.h" #define VALUETYPE rational #define EXPTYPE unsigned int #else #include "double.h" #define VALUETYPE double #define EXPTYPE double #endif /*given function df[0] on domain [0,D-1], compute derivatives f' until f^{(K)} and store them in df[1] to df[K]*/ void differentiate(VALUETYPE* f, VALUETYPE* df, int D, int K){ /*Set zeroth derivative to be f.*/ for(int i=0; i> i) & 1); //if(i%3==0) f[2*N+i+K/2] = 1; } VALUETYPE* Mf = malloc(D*sizeof(VALUETYPE)); compute_maximalfunction(f, Mf, D); /*Allocate memory for derivatives.*/ VALUETYPE* df = malloc(D*sizeof(VALUETYPE)); VALUETYPE* dMf = malloc(D*sizeof(VALUETYPE)); /*Compute Kth derivative of f and Mf*/ differentiate(f,df,D,K); differentiate(Mf,dMf,D,K); /*Print derivatives*/ /* for(int k=0;k<=K;k++){ printf("f %d: ",k); for(int i=0;i.4997) if(to_double(r)>.6) { printf("f: "); for(int i=0;iN); int K = *(args->K); int D = *(args->D); EXPTYPE p = *(args->p); int* s = args->t; while(*s <= (1 << N)-1){ int t = *s; *s = t+1; compute(N,K,D,p,t); } return NULL; } int main() { /*length of the support of f*/ int N=16; /*order of the derivative to consider. Should not be larger than (D-N)/2 because then the support of f^{(K)} reaches outside of our domain.*/ int K=10; /*length of the domain, minimum N+K to make sure the support of f^{(k)} belongs to the domain*/ int D=N+K+N/2; /*exponent p of the L^p norm to consider*/ EXPTYPE p = 1; int t = 1; /*Iterate over all strings of 0s and 1s with length N. Those will represent f.*/ //for(int t=1; t<=(1 << N)-1; t++){ //compute(N,K,D,p,t); //} struct Args args = {&N, &K, &D, &p, &t}; pthread_t threads[NUM_THREADS]; int result_code; for (int i = 0; i < NUM_THREADS; i++) { printf("In main: Creating thread %d.\n", i); result_code = pthread_create(&threads[i], NULL, perform_work, &args); assert(!result_code); } // wait for each thread to complete for (int i = 0; i < NUM_THREADS; i++) { result_code = pthread_join(threads[i], NULL); assert(!result_code); printf("In main: Thread %d has ended.\n", i); } return 0; }