From b43f9d38196080333680681766b6f23f024c0cb0 Mon Sep 17 00:00:00 2001 From: Julian Weigt Date: Tue, 23 Dec 2025 17:14:54 +0000 Subject: Reorganize mallocs to get ready for multithreading. --- charf.c | 166 ++++++++++++++++++++++++++++++---------------------------------- 1 file changed, 78 insertions(+), 88 deletions(-) (limited to 'charf.c') diff --git a/charf.c b/charf.c index 97f9e34..a2d1ad8 100644 --- a/charf.c +++ b/charf.c @@ -1,6 +1,7 @@ #include #include #include +#include #ifndef EXACT #define EXACT false @@ -18,13 +19,20 @@ /*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** df, int D, int K){ - int i; +void differentiate(VALUETYPE* f, VALUETYPE* df, int D, int K){ + /*Set zeroth derivative to be f.*/ + for(int i=0; i> i) & 1); + //if(i%3==0) f[2*N+i+K/2] = 1; + } - /*Convert integer valued f to float valued df[0]*/ - df[0] = f; - - compute_maximalfunction(f, Sf, Af, Mf, D); - - /*Compute 0th until Kth derivative of f and Mf*/ - differentiate(df,D,K); - differentiate(dMf,D,K); + VALUETYPE* Mf = malloc(D*sizeof(VALUETYPE)); + compute_maximalfunction(f, Mf, D); + + /*Allocate memory for derivatives.*/ + VALUETYPE* df = malloc(D*sizeof(VALUETYPE)); + VALUETYPE* dMf = malloc(D*sizeof(VALUETYPE)); + + /*Compute Kth derivative of f and Mf*/ + differentiate(f,df,D,K); + differentiate(Mf,dMf,D,K); /*Print derivatives*/ /* @@ -101,88 +133,46 @@ VALUETYPE compute_derivatives(VALUETYPE* f, VALUETYPE** Sf, VALUETYPE** Af, VALU printf("\n"); } */ - - //for(int k=0;k<=K;k++){ - + /*Compute L^p norm of derivatives*/ - int k=K; - intdfp[k] = integratep(df[k],p,D); - intdMfp[k] = integratep(dMf[k],p,D); + VALUETYPE intdfp = integratep(df,p,D); + VALUETYPE intdMfp = integratep(dMf,p,D); //printf("%d: %f / %f = %f\n",k,intdMfp[k],intdfp[k],intdMfp[k]/intdfp[k]); - //} - - /*Return ratio of L^p norms*/ - return ratio(intdMfp[k], intdfp[k]); -} - -int main() { - -/*length of the support of f*/ -int N=14; - -/*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=14; -/*length of the domain*/ -int D=N+K+1; - -/*exponent p of the L^p norm to consider*/ -EXPTYPE p = 1; - -/*allocate memory for f*/ -VALUETYPE* f = malloc(D*sizeof(VALUETYPE)); - -/*allocate memory for temporary variables, such as averages*/ -VALUETYPE** Sf = malloc(D*sizeof(VALUETYPE*)); -VALUETYPE** Af = malloc(D*sizeof(VALUETYPE*)); -VALUETYPE* Mf = malloc(D*sizeof(VALUETYPE)); -for(int i=0;i> i) & 1); - //if(i%3==0) f[2*N+i+K/2] = 1; - } - /*Compute ||Mf^{(k)}||_p/||f^{(k)}||_p.*/ - r = compute_derivatives(f, Sf, Af, Mf, df, dMf, p, intdfp, intdMfp, D, K); //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) printf("f: "); for(int i=0;i