From f3129294bf92daae6ca72e2f8c456bdff97b8b3e Mon Sep 17 00:00:00 2001 From: Julian Weigt Date: Tue, 23 Dec 2025 19:27:46 +0000 Subject: Enable multithreading. --- charf.c | 62 +++++++++++++++++++++++++++++++++++++++++++++++++++++--------- 1 file changed, 53 insertions(+), 9 deletions(-) diff --git a/charf.c b/charf.c index a2d1ad8..f52d41e 100644 --- a/charf.c +++ b/charf.c @@ -2,11 +2,14 @@ #include #include #include +#include #ifndef EXACT #define EXACT false #endif +#define NUM_THREADS 4 + #if EXACT #include "ratio.h" #define VALUETYPE rational @@ -106,8 +109,8 @@ void compute(int N, int K, int D, EXPTYPE p, int t){ //for(int i=0;i> i) & 1); + /*Since we care about the Kth derivative, which in i depends on f on [i,i+K], shift f to the right by K so that the support of f^{(K)} stays within the domain.*/ + f[(D-(N+K))/2+K+i] = convert_int((t >> i) & 1); //if(i%3==0) f[2*N+i+K/2] = 1; } @@ -147,8 +150,9 @@ void compute(int N, int K, int D, EXPTYPE p, int t){ //printf("%.3d: %.3f \n",t,r); /*Print f and ||Mf^{(k)}||_p/||f^{(k)}||_p if the latter is close to 1/2.*/ - if(to_double(r)>.4997){ - //if(to_double(r)>.7) + //if(to_double(r)>.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=12; + 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=3; + int K=10; - /*length of the domain*/ - int D=N+K+1; + /*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); + + //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; } -- cgit v1.2.3