Compiles under g++, but not Cilk++

Compiles under g++, but not Cilk++

I have a program that compiles (after many tweaks) with g++. It is really a converted c programthat I changed to get it to compile and run like a c++ program.

I succeeded.

However, when I try to compile it with cilk++ after doing the following things:

adding cilk.h to the main program's include files
changing main(0 to cilk_main()
renaming the file to from *.c *.cilk this is a Cilk Arts compiler cilk+_ compiler.

I get the error:

thread.c: In function int cilk CreateThread(pthread_t*, void*, void*, size_t):

thread.c:54: error: invalid conversion from void* (cilk*)(void*) to void* (*)(void*)

thread.c:54: error: initializing argument 3 of int pthread_create(pthread_t*, const pthread_attr_t*,

void* (*)(void*), void*)

I am unsure as to what is wrong and how to correct it. As I said it compiles under g++, but what is causing the error when I compile it under cilk++?

I am attaching the file (thread.c)that has the relevant c code in it.

Any help appreciated. Thanks in advance.



PS I have takenforum advice andI have submitted a voucher for Intel Cilk++, but it must go throughmany governmentoffices to be zpproved and finalized.That will take awhile so I am using Cilk Arts Cilk++ for now. Ishould have no problem converting the code to Intel Cilk++ when that transactionis complete.

5 posts / 0 new
Last post
For more complete information about compiler optimizations, see our Optimization Notice.

The source is truncated, but I'm pretty sure that you're getting caught by cilk++ linkage.

Cilk++ allocates frames from the heap instead of from the stack. You can call C or C++ functions from Cilk++, but you must use cilk::context::run to transition fromC++ to Cilk++ functions. cilk_main() is hiding this bit of boilerplate from you. I believe the Cilk++ documentation explains the details in Chapter 11: Mixing C++ and Cilk++ code.

Note that each cilk::context you create will have its own set of worker threads. If you call cilk::context::run() from threads created by some other threading mechanism, you risk oversubscribing your system.

- Barry

I also think that I am getting caugt up in cilk++ linkage. However, I am not sure what is meant when you say

"cilk_main() is hiding this bit of boilerplate from you", explain.

Also,I only cilkified the main program. Now as stated cilk++ functions can call c++ functions, but not vice versa. Where did I go wrong, since cilk_main calls everything else, but what call cilk_main? It is the only cilk++ function. I am just going by the exampleon the middle og page 14 in the Cilk++ Programmers Guide.

I do not thnk that I am calling cilk++ functions from c++. At least not obviously.

Amy help appreciated. Thanks in advance.


I believe that this info is important. I only cilkified the main program. But I called the compiler with cilk++ which treats all files as cilk files. But, the only one now that is cilk is main. That may explain some of my program's compile behavior.

I do not know if this helps, but I mention it all the same.

I believe theerror message that indicates your problem is here:

thread.c: In function int cilk CreateThread(pthread_t*, void*, void*, size_t):
thread.c:54: error: invalid conversion from void* (cilk*)(void*) to void* (*)(void*)

It sounds like the compiler at thread.c:54, has detected a Cilk function where it really expected a normal C/C++ function. My guess is, that by defining all files with the .cilk extension, you also converted the function passed in to pthread_create from a C++ function into a Cilk function. Since the pthread library expects a normal C++ function, it will fail to compile.

One way to define a function with C++ linkage within a .cilk file is to wrap it within an appropriate extern block.

extern "C++" {
// Define C++ function.

If I recall correctly, you may also sometimes need to be careful with linkages when including certain header files.

Often, your Cilk++ code usually ends up simpler and more efficient if you can avoid mixing both pthread parallelismand Cilk parallelism in the same program. In case you need to do so, however, as Barry mentioned, the Cilk++ guide has more information on how you can mix C++ and Cilk code.


PS. It is good to hear that you are considering using Intel Cilk Plus. It turns out that one of the major improvements in Cilk Plus is that it no longer needs to make a distinction between C++ and Cilk linkages, thereby avoiding many of these issues. :)

Leave a Comment

Please sign in to add a comment. Not a member? Join today