The following C code is available:
#include <stdio.h> #include <stdlib.h> #include <math.h> #define Te 52.0 #define Ts 2196.0 #define Tc 2196.0 #define Traw_max 246140.0 #define RL 7 const int W[] = {16, 32, 64, 128, 256, 512, 1024}; double mod = 0.0; double lambda(int N, double Traw); int round_p(double x); int main() { FILE *fp; int i; fp = fopen("D:\\data_a.txt", "w"); for(i = 1; i <= 100; i++) {printf("%d\n", i); fprintf(fp, "%d %.9f\n", i, lambda(1, Traw_max / i));} fclose(fp); return 0; } double lambda(int N, double Traw) { if(Traw < Ts) return 0.0; if(N <= 0) return 0.0; printf("mark0\n"); int t = 0, i, j; int max_t = round_p(Traw / Te) + 1; printf("%d\n", max_t); double *Pold[W[0]], *Pnew[W[0]], lambda = 0.0; printf("mark0.5\n"); for(i = 0; i < W[0]; i++) { Pold[i] = calloc(max_t, sizeof(double)); Pnew[i] = calloc(max_t, sizeof(double)); } printf("mark0.7\n"); for(i = 0; i < W[0]; i++) {printf("%d\n", i); Pold[i][0] = 1.0 / W[0]; printf("%e\n", Pold[i][0]);} printf("mark1\n"); while(t < max_t) { for(i = 1; i < W[0]; i++) for(j = 0; j < max_t; j++) Pnew[i - 1][j] = Pold[i][j]; for(j = 0; j < max_t; j++) for(i = 0; i < W[0]; i++) Pnew[i][j + 1] = Pold[0][j] * (1.0 / W[0]); for(i = 0; i < W[0]; i++) for(j = 0; j < max_t; j++) Pold[i][j] = Pnew[i][j]; for(i = 0; i < W[0]; i++) for(j = 0; j < max_t; j++) if((t + 1 - j >= 0) && (j * Ts + (t + 1 - j) * Te > Traw - Ts) && (j * Ts + (t + 1 - j) * Te <= Traw)) { lambda += j * Pold[i][j]; Pold[i][j] = 0.0; } t++; } printf("mark2\n"); for(i = 0; i < W[0]; i++) { free(Pold[i]); free(Pnew[i]); } return lambda; } int round_p(double x) { int i; for(i = 0; i <= x; i++); i++; return i; } Which is successfully compiled. However, when you try to start the program crashes. In the task manager, everything is fine - the process eats up the standard 25% of processor time, eats little memory. In some places in the code I placed the labels of the console output, and noticed two of the most frequent cases:
The
lambdafunction is called once, reaches the mark2 mark and the program crashes.The
lambdafunction is called exactly 61 times (the number of the beast, not otherwise), and the program crashes when trying to assign an element of the arrayPold[0][0]in the loop. If you first try to assign a value to an array element outside the loop, then a crash also occurs.
What's the matter? What should be done to understand the cause of the error?
round_p(double x)function. I haven't laughed like that for a long time And in fact I want to say that I can’t understand why you callcallocandfree. Second, it would not hurt to wrap the construction in atry catchand then it will become clear what the matter is - ArchDemon