diff options
| author | Julian Weigt <juw@posteo.de> | 2026-01-07 19:56:16 +0000 |
|---|---|---|
| committer | Julian Weigt <juw@posteo.de> | 2026-02-04 15:55:50 +0100 |
| commit | c599e6b5c5bb1890311caf169d58eea97a12c9d6 (patch) | |
| tree | 986d494d1eacdf7c8a1e5aa055e11897cf3d5520 | |
| parent | 0f7bfd3a8fdd0e566bb2ad93a8a71556a2933717 (diff) | |
Kinda add flexibility to vary K or p within one call.
| -rw-r--r-- | charf.c | 35 |
1 files changed, 13 insertions, 22 deletions
@@ -31,11 +31,8 @@ /*length of the support of f*/ static const int N=16; -/*order of the derivative to consider.*/ -static const int K=3; - -/*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){ +/*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<D; i++){ @@ -70,7 +67,7 @@ void compute_maximalfunction(VALUETYPE* f, VALUETYPE* Mf, int D){ //VALUETYPE Sf[N][N]; /*Af[i][j] will be the average of f on [min(i,j),max(i,j)]*/ //VALUETYPE Af[N][N]; - /*Apparently may become too big for stack or something.*/ + /*Apparently may become too big for stack or something so have to use malloc instead.*/ VALUETYPE* Sf[N]; VALUETYPE* Af[N]; for(int i=0; i<D;i++){ @@ -117,7 +114,7 @@ void compute_maximalfunction(VALUETYPE* f, VALUETYPE* Mf, int D){ } } -void compute(EXPTYPE p, int D, VALUETYPE* f){ +void compute(int K, EXPTYPE p, int D, VALUETYPE* f){ VALUETYPE Mf[N]; compute_maximalfunction(f,Mf,D); @@ -126,8 +123,8 @@ void compute(EXPTYPE p, int D, VALUETYPE* f){ VALUETYPE dMf[N]; /*Compute Kth derivative of f and Mf*/ - differentiate(f,df,D); - differentiate(Mf,dMf,D); + differentiate(f,df,D,K); + differentiate(Mf,dMf,D,K); /*Print derivatives*/ /* @@ -188,22 +185,16 @@ int generate_function(VALUETYPE* f, int i){ } -typedef struct { - EXPTYPE p; - VALUETYPE** f; - int i; -}Args; - /*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; + int i = *((int*)arguments); + int K = 3; + EXPTYPE p = to_exptype(1); VALUETYPE f[N]; int d = generate_function(f,i); while(d >= 0){ - compute(p,d,f); + compute(K,p,d,f); i += NUM_THREADS; d = generate_function(f,i); } @@ -214,13 +205,13 @@ int main() { EXPTYPE p = to_exptype(1); pthread_t threads[NUM_THREADS]; - Args args[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] = (Args){.p=p, .i=i}; - result_code = pthread_create(&threads[i], NULL, compute_chunk, &(args[i])); + args[i] = i; + result_code = pthread_create(&threads[i], NULL, compute_chunk, args+i); } // wait for each thread to complete |
