Quantcast
Channel: Intel® Cilk™ Plus
Viewing all articles
Browse latest Browse all 77

Why calculation of fibonacci with cilk took longer?

$
0
0

I'm running on Linux (ubuntu) Intel I7 1600Mhz, with 4 cores. I'm using Intel compiler V14 I measured the time it tooks to calculate fibonacci with or without cilk:

 

 

int fib(int n) {

    if (n < 2) {
        return n;
    }
    else {
        int x = cilk_spawn fib(n-1);
        int y = fib(n-2);
        cilk_spawn;
        return (x+y);
    }
}


inf seqFib(int n) {

    if (n < 2) {
        return n;
    }
    else {
        int x = fib(n-1);
        int y = fib(n-2);
        return (x+y);
    }

}


long long getNanoTime() {

    struct timespec currTod;
    long long curT = 0;
    long long billion = 1000000000;

    clock_gettime(CLOCK_REALTIME, &currTod);
    curT  = currTod.tv_sec * billion ;
    curT += currTod.tv_nsec;

    return curT;


}


int main() {
    int x = 40;
    long long start = getNanoTime();
    int res = fib(x);
    long long end = getNanoTime();
    cout << "\n cilk: "<< res;


    start = getNanoTime();
    res = seqFib(x);
    end = getNanoTime();
    cout << "\n seq:"<< res;

    return 0;


}

 

But the results are weired: With cilk the result is 427 nano and without cilk it tooks 281 nano

I run it for several times, and same results ...


Viewing all articles
Browse latest Browse all 77

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>