From 4840c8847aaad207f613742a65440e824c47a8e2 Mon Sep 17 00:00:00 2001 From: Julian Weigt Date: Fri, 2 Jan 2026 11:52:45 +0000 Subject: Do computations on circle, run through domains of all lengths, and add small sleep to threads to avoid overlap for small domains. --- charf.c | 129 ++++++++++++++++++++++++++++++++-------------------------------- 1 file changed, 64 insertions(+), 65 deletions(-) (limited to 'charf.c') diff --git a/charf.c b/charf.c index 670e4d0..7d12037 100644 --- a/charf.c +++ b/charf.c @@ -1,8 +1,11 @@ #include #include #include +//for multithreading #include #include +//for sleep +#include #define DOUBLEMODE 0 #define DOUBLEERRORMODE 1 @@ -29,31 +32,23 @@ #endif /*length of the support of f*/ -static const int N=16; +static const int N=24; -/*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.*/ -static const int K=12; +/*order of the derivative to consider.*/ +static const int K=3; -/*length of the domain, minimum N+2*K to make sure the support of f^{(k)} belongs to the domain*/ -static const int D=N+2*K; - - -/*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){ +/*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; - } + for(int i=0; i> i) & 1); + //if(i%3==0) f[2*N+i+K/2] = 1; - VALUETYPE Mf[D]; - compute_maximalfunction(f, Mf); + VALUETYPE Mf[N]; + compute_maximalfunction(f,Mf,D); /*Allocate memory for derivatives.*/ - VALUETYPE df[D]; - VALUETYPE dMf[D]; + VALUETYPE df[N]; + VALUETYPE dMf[N]; /*Compute Kth derivative of f and Mf*/ - differentiate(f,df); - differentiate(Mf,dMf); + differentiate(f,df,D); + differentiate(Mf,dMf,D); /*Print derivatives*/ /* - for(int k=0;k<=K;k++){ + for(int k=0; k<=K; k++){ printf("f %d: ",k); - for(int i=0;i.4997) - if(to_double(r)>.65) - //if(to_double(r)>.30) + //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(*s <= (1 << N)-1){ - int t = *s; - *s = t+1; - compute(p,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; } @@ -209,12 +206,13 @@ int main() { /*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, &t}; + struct Args args = {&p, &D, &t}; pthread_t threads[NUM_THREADS]; int result_code; @@ -223,6 +221,7 @@ int main() { 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 -- cgit v1.2.3