#include #include #include //for multithreading #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 /*maximum length of the support of f*/ static const int N=24; /*given function df[0] on domain [0,M-1], compute derivatives f' until f^{(K)} and store f^{(K)} in df*/ void differentiate(VALUETYPE* f, VALUETYPE* df, int D, int K){ VALUETYPE df0[D]; /*Set zeroth derivative to be f.*/ for(int i=0; i.9) //|| //(k==2 && t>=.5) //|| (k==3 && t>.53) //|| //(k==4 && t>=.5) || (k==5 && t>=.58) || (k==6 && t>=.58) || (k==7 && t>=.69) || (k==8 && t>=.83) || (k==9 && t>=.8699) || (k==10 && t>=.919) || (k==11 && t>=.97) || (k==12 && t>=.97) || (k==13 && t>=.98) || (k==14 && t>=.98) || (k==15 && t>=.9817) || (k==16 && t>=.9817) ){ printf("f: "); for(int i=0; i= powd){ s += powd; d++; } else { int t = i-s+1; /*Set f to the values encoded in bit string t which is a value between 1 and powd = (1<> n) & 1); return d; } } return -1; } /*Goes through all functions indexed by those numbers which equal the thread number module NUM_THREADS.*/ void* compute_chunk(void* arguments){ int i = *((int*)arguments); EXPTYPE p = int_to_exptype(1); VALUETYPE f[N]; int d = generate_function(f,i); while(d >= 0){ compute(p,d,f); i += NUM_THREADS; d = generate_function(f,i); } } int main() { /*exponent p of the L^p norm to consider*/ EXPTYPE p = int_to_exptype(1); pthread_t threads[NUM_THREADS]; int args[NUM_THREADS]; int result_code; for (int i = 0; i < NUM_THREADS; i++) { printf("In main: Creating thread %d.\n", i); args[i] = i; result_code = pthread_create(&threads[i], NULL, compute_chunk, args+i); } // wait for each thread to complete for (int i = 0; i < NUM_THREADS; i++) { result_code = pthread_join(threads[i], NULL); printf("In main: Thread %d has ended.\n", i); } return 0; }