wsmoses / Tapir-LLVM

Tapir extension to LLVM for optimizing Parallel Programs
Other
132 stars 24 forks source link

Unable to compile fib example on website #75

Closed hq6 closed 6 years ago

hq6 commented 6 years ago

I installed Cilk using the instructions from the website.

sudo apt-add-repository ppa:wsmoses/tapir-toolchain
sudo apt-get update
sudo apt-get install tapirclang-5.0 libcilkrts5

I copied the following program from the Cilk documentation.

#include <stdio.h>
#include <stdint.h>

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

int main(){
   printf("%ld\n", fib(20));
}

I then compiled using the compiler flag that they specified.

clang-5.0 -fcilkplus Fib.c

Fib.c:7:9: error: use of undeclared identifier 'cilk_spawn'
    x = cilk_spawn fib(n - 1);
        ^
Fib.c:9:5: error: use of undeclared identifier 'cilk_sync'
    cilk_sync;
    ^

The desired output is a working executable that uses Cilk and prints 6765.

What magic incantations are needed to produce this executable?

I am running Ubuntu 18.04 with kernel 4.4.0-45-generic.

neboat commented 6 years ago

Thanks for reaching out.

You need to include the cilk/cilk.h header file to get the cilk_spawn and cilk_sync keywords. I think that's the only change to the code that you'll need.

Thanks for pointing out the issue. We should add a note about that header on the Cilk Hub website.

hq6 commented 6 years ago

Thanks! With the header, the program compiles and runs.