Cilk functions calling c functions

Cilk functions calling c functions

newport_j's picture

I am looking for a simple example of a Cilk function calling a c function. I tried using the example of fibonacci numbers in the Cilk 5.4.6 Guide - it did not work.

A procedure call in a cilk function must be spawned (or so said the error when I compiled the progeram code).You cannot call a c function by spwaning it from a Cilk function. There is the problem.I am assuming it is something that is very easy, but I have seen no examples. You talk in the Guide about a c function calling a Cilk function using stubs. That is good. I just want it the other way around.

Iused the Cilk fibonacci main function and called the c function fib. It would not compile.I am not surpised because the c fib function is not a cilk function and cannot be spawned by the calling function. If I remove the word spawn from Cilk mainthen it says all procedure calls in cilk must be spawned. I cannot spawn a c function.

Any help appreciated. Thanks in advance.

Newport_j

4 posts / 0 new
Last post
For more complete information about compiler optimizations, see our Optimization Notice.
Jim Sukha (Intel)'s picture

From what I recall, I believe in Cilk 5.4.6, you should be able to call any C function from Cilk code. The issue you may be seeing is that because fib() is a recursive Cilk function, when it tries to recursively call fib(), the system thinks you are trying to call a Cilk function. Calling an explicit C function with a different name (e.g., fib_c())should work.

One of the improvements ofCilk++ over Cilk 5.4.6 is that Cilk++ allows Cilk functions to be called from any function that is compiled using Cilk++. Intel Cilk Plus further improves the situation, by allowing Cilk functions to be called fromC code, even if that C code is from a legacy binary that was not compiled for Cilk.

If possible, I would encourage you to use Intel Cilk Plus for your application. Cilk 5.4.6 is a research project from MIT, not a supported Intel product. The new functionality of Cilk Plus might make your life easier. :)

Jim

newport_j's picture

That is a good idea to go to Intel Cilk++. But, my legacy code is in c. I have moved some of it to c++, but it is not really object oriented, yet. I do not think Intel Cilk++ can handle basicc. Any ideas if it can, handle basic c that is?

Thanks in advance.

Newport_j

Barry Tannenbaum (Intel)'s picture

Cilk++ is strictly an extension of C++. The use of reducers requires templates.

While C++ allows for object oriented use, there are people who use it as "a better C". One of the applications we ported to Cilk++ was a neural network application named mikenet. I believe the developer simply renamed all of the files from .c to .cpp and then dealt with with (relatively minor) type-checking differences between C and C++. Things like needing to cast the address returned by malloc().

Of course, Intel Cilk Plus supports both C and C++.

- Barry

Login to leave a comment.