c++xeon-phicilk-plusoffloading

Using Cilk reducer inside Cilk shared function


Hi I am trying to offload some parallel work to MIC using _Cilk_Shared and _Cilk_offload.

I declare a Cilk shared function:

_Cilk_shared void somefun(int count)

In main I call this function using

_Cilk_offload somefun(12) ;

inside this function everything is expected to be offloaded to MIC;

I want to declare a Cilk reducer inside somefun, so I can then use cilk_for and append to a cilk reducer list,

but I get error:

error: illegal to declare an object of a class not marked _Cilk_shared, in a _Cilk_shared context
  cilk::reducer_list_append<int> rw;

I know I can do this with offload pragma so I should be able to this with cilk shared as well right?

I can't find concrete example of using _Cilk_shared and _Cilk_offload.

Thanks in advance


Solution

  • Basically, what the compiler is complaining about is that you never told it that it needed to create coprocessor code as well as host code for all the functions in the reducer_list_append class. It is necessary but not sufficient to declare the object rw as being needed on the coprocessor. You also need to say that the class can be used on the coprocessor.

    Because you are using shared memory programming, you probably already have something like the following in your program:

    #pragma offload_attribute (push, _Cilk_shared) 
    #include <vector> 
    #include <offload.h> 
    #pragma offload_attribute (pop) 
    

    If rw is going to in shared memory, try adding the headers for reducer_list_append between those pragma's as well and use the shared allocator. If you don't need rw to be in shared memory, you shouldn't need the shared allocator. In that case, you might also be able to put the header for the class in a simple offload_attribute region, instead of a _Cilk_shared offload_attribute region - assuming there are no dependencies - but as long as you already have a _Cilk_shared offload_attribute region you might as well use it. It won't hurt anything.