Software Archive
Read-only legacy content
17061 Discussions

Using mkl/fftw in Cilk_shared functions

phik
Beginner
479 Views

Apologies if this is already asked and answered; the forum search isn't great...

What's involved in calling the MKL fftw wrappers from a _Cilk_shared function?

src/math/fft_mkl.c(238): error: illegal to call a non-shared function in a _Cilk_shared context
      fftwf_execute(fftobject->plan);
      ^

I feel like I'm missing something rather fundamental...

0 Kudos
6 Replies
Frances_R_Intel
Employee
480 Views

A function must be written as a _Cilk_shared function before it can be used in a _Cilk_shared context. There is nothing you as a user can do to change this. And in general, the fftw wrappers are not thread safe. Depending on what you are trying to do, the fftw wrappers might not be you best choice. Are you trying to port code that is already using fftw calls?

0 Kudos
phik
Beginner
480 Views

Hi Frances--

Thanks for your prompt reply!

I understand that I can't do it as a user, but Intel goes to such great lengths to tell us that the MKL libraries are provided both for the CPU and the MIC -- so it seemed inconceivable to me that these would not be _Cilk_shared functions?  Are you basically saying "sorry, if you use FFTs, then you can't use Cilk offload"?  That seems like a rather gaping hole in the model, doesn't it?

Or is it just the fftw wrappers?  If I use the MKL functions directly, should I expect to find that those are _Cilk_shared?

I think I've already decided that there are too many unanswered questions about the Cilk offload black box for me to use anyway, so I suppose it doesn't really matter.  But surely MKL FFTs and Cilk offload aren't actually mutually exclusive?

0 Kudos
Ravi_N_Intel
Employee
480 Views

You can invoke MKL functions from _Cilk_shared functions.
Make sure the header files are surrounded by push/pop _CIlk_shared attribute

eg:-
#pragma offload_attribute(push,_Cilk_shared)
#include  "mkl.h"
#pragma offload_attribute(pop)

0 Kudos
phik
Beginner
480 Views

Ah ha!  I had no idea that pragma offload_attribute could also be applied to function prototypes.

I'm still shocked that the headers don't ship with _Cilk_shared already applied, but that workaround makes sense.  Thanks very much.

0 Kudos
Ravi_N_Intel
Employee
480 Views

The CPU compiler uses the presence of _Cilk_shared to invoke the MIC compiler.  If the mkl libraries had _Cilk_shared in them then we would be always generating code for MIC even if the application does not do any offload.  

0 Kudos
王_子_
Beginner
480 Views

Ravi Narayanaswamy (Intel) wrote:

You can invoke MKL functions from _Cilk_shared functions.
Make sure the header files are surrounded by push/pop _CIlk_shared attribute

eg:-
#pragma offload_attribute(push,_Cilk_shared)
#include  "mkl.h"
#pragma offload_attribute(pop)

Thank you very much. I also meet the similar problem which the malloc or strlen can not use in _Cilk_shared functions.

I use this method and it works !

0 Kudos
Reply