Ejemplo n.º 1
0
static inline void perform_local_work(void)
{
# ifdef TIME_WORKLOAD
    qtimer_t work_timer = qtimer_create();
    qtimer_start(work_timer);
# endif // TIME_WORKLOAD
    volatile unsigned long work = workload;
    long rand_per = (long)qtimer_fastrand();
    long rand_var = (long)qtimer_fastrand();

    rand_per = (rand_per<0) ? (-rand_per)%100 : rand_per%100;
    if (rand_per < workload_per) {
        rand_var = (rand_var<0) ? (-rand_var)%100 : rand_var%100;
        work += (workload * (workload_var * 0.01)) * (rand_var * 0.01);
    }

    for (int i = 0; i < work; i++) {
        work = work % 1000000000;
    }
    work++;
# ifdef TIME_WORKLOAD
    qtimer_stop(work_timer);
    fprintf(stdout, "Worked for %f\n", qtimer_secs(work_timer));
    qtimer_destroy(work_timer);
# endif // TIME_WORKLOAD
}
Ejemplo n.º 2
0
static void autocorrelation(void)
{   /*{{{*/
    int    eye = 3, m = 5, M;
    int    k;
    double pim, sigmapim, Zzero;
    double A[ITER];

    iprintf("\nAutocorrelation:\n");
    for (size_t i = 0; i < ITER; ++i) {
        A[i] = qtimer_fastrand();
    }

    for (eye = 1; eye < 51; ++eye) {
        for (m = 1; m < 11; ++m) {
            M   = floor((ITER - eye) / (double)m) - 1;
            pim = 0.0;
            for (k = 0; k <= M; ++k) {
                pim += A[eye + k * m] * A[eye + (k + 1) * m];
            }
            pim     *= (1.0 / (M + 1.0));
            pim     -= 0.25;
            sigmapim = sqrt(13 * M + 7) / (12 * (M + 1));

            Zzero = pim / sigmapim;
            iprintf("i=%i, m=%i, M=%i: %s\n", eye, m, M, (Zzero >= -1.96 && Zzero <= 1.96) ? "Passed" : "Failed");
        }
    }
} /*}}}*/
Ejemplo n.º 3
0
static void ks_test(void)
{   /*{{{*/
    double  Dplus, Dminus, D, Dalpha1, Dalpha2, Dalpha3;
    double *A[2];

    iprintf("Kolmogorov-Smirnov test:\n");
    A[0] = malloc(sizeof(double) * ITER);
    A[1] = malloc(sizeof(double) * ITER);
    for (size_t i = 0; i < ITER; ++i) {
        A[0][i] = qtimer_fastrand();
        A[1][i] = (double)i / (double)ITER;
    }
    qsort(A[0], ITER, sizeof(double), dcmp);
    Dplus  = A[1][0] - A[0][0];
    Dminus = A[0][0] - (-1.0 / (double)ITER);
    for (size_t i = 1; i < ITER; ++i) {
        if (A[1][i] - A[0][i] > Dplus) {
            Dplus = A[1][i] - A[0][i];
        }
        if (A[0][i] - ((i - 1) / (double)ITER) > Dminus) {
            Dminus = A[0][i] - ((i - 1) / (double)ITER);
        }
    }
    if (Dplus > Dminus) {
        D = Dplus;
    } else {
        D = Dminus;
    }
    Dalpha1 = 1.22 / sqrt(ITER);
    Dalpha2 = 1.36 / sqrt(ITER);
    Dalpha3 = 1.63 / sqrt(ITER);
    iprintf("alpha of 0.10: %s\n", (D <= Dalpha1) ? "Passed" : "Failed");
    iprintf("alpha of 0.05: %s\n", (D <= Dalpha2) ? "Passed" : "Failed");
    iprintf("alpha of 0.01: %s\n", (D <= Dalpha3) ? "Passed" : "Failed");
    free(A[0]);
    free(A[1]);
} /*}}}*/
Ejemplo n.º 4
0
static void runs (void)
{   /*{{{*/
    unsigned int     a       = 0;
    int              n1      = 0, n2 = 0, meanruns = 0;
    int              lastdir = 0;
    double           mua, sigmaa2, Zzeroa, Zzerob, mub, sigmab2;
    double           sum    = 0.0, mean, chisquare;
    unsigned int     *runlengths, maxrun = 0;
    int             rl;
    double         **oi;
    size_t           i;
    double *restrict A = malloc(sizeof(double) * ITER);

    iprintf("\nRuns Test:\n");
    for (i = 0; i < ITER; ++i) {
        A[i] = qtimer_fastrand();
        sum += A[i];
        if (i > 0) {
            if (A[i] > A[i - 1]) {
                if (lastdir == -1) {
                    ++a;
                }
                lastdir = 1;
            } else {
                if (lastdir == 1) {
                    ++a;
                }
                lastdir = -1;
            }
        }
    }
    mean = sum / (double)ITER;
    for (i = 0; i < ITER; ++i) {
        if (A[i] > mean) {
            n1++;
        } else {
            n2++;
        }
    }
    lastdir = (A[0] > mean) ? 1 : -1;
    for (i = 1; i < ITER; ++i) {
        if (A[i] > mean) {
            if (lastdir == -1) {
                meanruns++;
            }
            lastdir = 1;
        } else {
            if (lastdir == 1) {
                meanruns++;
            }
            lastdir = -1;
        }
    }
    mua     = ((2.0 * ITER) - 1.0) / 3.0;
    sigmaa2 = ((16.0 * ITER) - 29.0) / 90.0;
    Zzeroa  = (a - mua) / sigmaa2;
    mub     = ((2.0 * n1 * n2) / (double)ITER) + 0.5;
    sigmab2 = (2.0 * n1 * n2 * ((2.0 * n1 * n2) - ITER)) / (double)(ITER * ITER * (ITER - 1));
    Zzerob  = (meanruns - mub) / sqrt(sigmab2);

    runlengths     = (unsigned int *)calloc(sizeof(unsigned int), ITER);
    rl             = 0;
    runlengths[rl] = 1;
    lastdir        = 1;
    maxrun         = 0;
    for (i = 1; i < ITER; ++i) {
        if (A[i] > A[i - 1]) {
            if (lastdir == -1) {
                if (maxrun < runlengths[rl]) {
                    maxrun = runlengths[rl];
                }
                rl++;
            }
            lastdir = 1;
            runlengths[rl]++;
        } else {
            if (lastdir == 1) {
                if (maxrun < runlengths[rl]) {
                    maxrun = runlengths[rl];
                }
                ++rl;
            }
            lastdir = -1;
            runlengths[rl]++;
        }
    }
    oi = malloc(sizeof(double *) * 3);
    assert(oi);
    oi[0] = calloc(sizeof(double), maxrun);
    oi[1] = calloc(sizeof(double), maxrun);
    oi[2] = calloc(sizeof(double), maxrun);
    /* count the observed runs */
    for (i = 0; i < a; ++i) {
        oi[0][runlengths[i] - 1]++;
    }
    /* expected run calculation */
    for (i = 0; i < maxrun; ++i) {
        if (i <= ITER - 2) {
            oi[1][i] = (2.0 / bang(i + 3.0)) * (ITER * (i * i + 3 * i + 1) - (i * i * i + 3 * i * i - i - 4));
        } else {
            oi[1][i] = 2.0 / bang(ITER);
        }
    }
    /* insert expectation value combining here, start from high-end */
    if (maxrun > 2) {
        for (i = maxrun - 1; i > 0; --i) {
            if (oi[1][i] < 5) {
                size_t j;
                oi[1][i - 1] += oi[1][i];
                // oi[2][i-1] += oi[2][i];
                for (j = i; j + 1 < maxrun; ++j) {
                    oi[1][j] = oi[1][j + 1];
                    // oi[2][j] = oi[1][j+1];
                }
                maxrun--;
            }
        }
    }
    /* calc chisquare parts */
    for (i = 0; i < maxrun; ++i) {
        oi[2][i] = ((oi[0][i] - oi[1][i]) * (oi[0][i] - oi[1][i])) / oi[1][i];
    }
    /* count up chisquare sum */
    chisquare = 0.0;
    for (i = 0; i < maxrun; ++i) {
        chisquare += oi[2][i];
    }

    iprintf("       runs with alpha 0.05: %s\n", (Zzeroa >= -1.96 && Zzeroa <= 1.96) ? "Passed" : "Failed");
    iprintf("  mean runs with alpha 0.05: %s\n", (Zzerob >= -1.96 && Zzerob <= 1.96) ? "Passed" : "Failed");
    iprintf("run lengths with alpha 0.05: %s\n", (chisquare < chisquare_alphafive(maxrun - 1)) ? "Passed" : "Failed");
    free(oi[2]);
    free(oi[1]);
    free(oi[0]);
    free(oi);
    free(runlengths);
    free(A);
} /*}}}*/