#include #include #include //for multithreading #include #include //for sleep #include #define DOUBLEMODE 0 #define DOUBLEERRORMODE 1 #define RATIOMODE 2 #ifndef MODE #define MODE DOUBLEMODE #endif #define NUM_THREADS 6 #if MODE == DOUBLEERRORMODE #include "double-error.h" #define VALUETYPE double_error #define EXPTYPE double_error #elif MODE == RATIOMODE #include "ratio.h" #define VALUETYPE rational #define EXPTYPE unsigned int #else #include "double.h" #define VALUETYPE double #define EXPTYPE double #endif /*length of the support of f*/ static const int N=24; /*order of the derivative to consider.*/ static const int K=3; /*given function df[0] on domain [0,M-1], compute derivatives f' until f^{(K)} and store them in df[1] to df[K]*/ void differentiate(VALUETYPE* f, VALUETYPE* df, int D){ VALUETYPE df0[D]; /*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[N]; compute_maximalfunction(f,Mf,D); /*Allocate memory for derivatives.*/ VALUETYPE df[N]; VALUETYPE dMf[N]; /*Compute Kth derivative of f and Mf*/ differentiate(f,df,D); differentiate(Mf,dMf,D); /*Print derivatives*/ /* for(int k=0; k<=K; k++){ printf("f %d: ",k); for(int i=0; i.4997) //if(to_double(r)>=.58) if(to_double(r)>.53) { printf("f: "); for(int i=0; ip); int* D = args->D; int* s = args->t; while(*D <= N){ if(*s <= (1 << *D)-2){ int t = *s; *s = t+1; compute(p,t,*D); } else { *s = 0; *D = *D+1; } } return NULL; } int main() { /*exponent p of the L^p norm to consider*/ EXPTYPE p = to_exptype(1); /*Iterate over all strings of 0s and 1s with length N. Those will represent f.*/ int t = 1; int D = 1; //for(int t=1; t<=(1 << N)-1; t++){ //compute(N,K,D,p,t); //} struct Args args = {&p, &D, &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); usleep(1000*100); } // 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; }