From 81161ff6d77367b86181b49a07d43a86a1c809ee Mon Sep 17 00:00:00 2001 From: Julian Weigt Date: Wed, 7 Jan 2026 14:35:24 +0000 Subject: Make more flexible by assigning indeces to threads in advance and generating functions thread agnostically. --- charf.c | 83 +++++++++++++++++++++++++++++++++-------------------------------- 1 file changed, 42 insertions(+), 41 deletions(-) (limited to 'charf.c') diff --git a/charf.c b/charf.c index 7d12037..032fd89 100644 --- a/charf.c +++ b/charf.c @@ -4,8 +4,6 @@ //for multithreading #include #include -//for sleep -#include #define DOUBLEMODE 0 #define DOUBLEERRORMODE 1 @@ -32,7 +30,7 @@ #endif /*length of the support of f*/ -static const int N=24; +static const int N=16; /*order of the derivative to consider.*/ static const int K=3; @@ -120,16 +118,7 @@ void compute_maximalfunction(VALUETYPE* f, VALUETYPE* Mf, int D){ } } -void compute(EXPTYPE p, int t, int D){ - /*allocate memory for f*/ - VALUETYPE f[N]; - /*Initiate f to be zero everywhere.*/ - for(int i=0; i> i) & 1); - //if(i%3==0) f[2*N+i+K/2] = 1; - +void compute(EXPTYPE p, int D, VALUETYPE* f){ VALUETYPE Mf[N]; compute_maximalfunction(f,Mf,D); @@ -178,50 +167,62 @@ void compute(EXPTYPE p, int t, int D){ } } -struct Args {EXPTYPE* p; int* D; int* t; }; - -void* perform_work(void* arguments){ - struct Args *args = arguments; - EXPTYPE p = *(args->p); - 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); +/*Writes into f the values of the function indexed by i. Returns the size of the support of f, or -1 if there is no function with that index.*/ +int generate_function(VALUETYPE* f, int i){ + int s=0; + int d=1; + while(d <= N){ + /*number of strings of length d that are not all 0s or all 1s*/ + int powd = (1<= powd){ + s += powd; + d++; } else { - *s = 0; - *D = *D+1; + 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 NULL; + return -1; + } -int main() { - /*exponent p of the L^p norm to consider*/ - EXPTYPE p = to_exptype(1); +typedef struct { + EXPTYPE p; + VALUETYPE** f; + int i; +}Args; - /*Iterate over all strings of 0s and 1s with length N. Those will represent f.*/ - int t = 1; - int D = 1; +/*Goes through all functions indexed by those numbers which equal the thread number module NUM_THREADS.*/ +void* compute_chunk(void* arguments){ + Args *args = arguments; + EXPTYPE p = args->p; + int i = args->i; - //for(int t=1; t<=(1 << N)-1; t++){ - //compute(N,K,D,p,t); - //} + VALUETYPE f[N]; + int d = generate_function(f,i); + while(d >= 0){ + compute(p,d,f); + i += NUM_THREADS; + d = generate_function(f,i); + } +} - struct Args args = {&p, &D, &t}; +int main() { + /*exponent p of the L^p norm to consider*/ + EXPTYPE p = to_exptype(1); pthread_t threads[NUM_THREADS]; + Args args[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); + args[i] = (Args){.p=p, .i=i}; + result_code = pthread_create(&threads[i], NULL, compute_chunk, &(args[i])); assert(!result_code); - usleep(1000*100); } // wait for each thread to complete -- cgit v1.2.3