0

I have declared some global variables to be _Cilk_shared. They are used in the functions that I want to offload They are used in some functions I do not want to be offloaded as well.

So initially I only declared those functions that I need to offload as _Cilk_shared and call those function using _Cilk_offload.

It compiles fine. And when I run it on host only it gives correct result.

Then I run it with MIC. it gives me runtime error about can not load library blablabla undefined symbol followed by function names that I did not declare as _cilk_shared. Those functions are not needed to be _cilk_shared as well.

So I have to change those functions to _cilk_shared. Run it again. This time MIC gives correct result.

And I checked whether those functions (which I did not want to offload and did not declare as _cilk_shared initially ) are offloaded or not, by Using

#ifdef __MIC__
    printf(" Running on MIC\n");
#else
    printf("No MIC\n");
#endif

The result is that they are not offloaded....

So I am wondering why it wants me to declare those functions as _Cilk_shared?

yidiyidawu
  • 303
  • 1
  • 3
  • 12

1 Answers1

0

When a function is declared for offloading - if the function is defined in that file, the compiler generates object code that will run on the processor and object code that will run on the coprocessor. if the function is used in that file, it generates object code that will call the processor version and code that will call the coprocessor version (unless the call is inside an area that is protected by '"ifdef MIC"

So why might the loader want a function to have been declared for offload even if you never call it in an offloaded region? Well if the function is part of a class, then the entire class needs to be declared for offload because the class 'knows' what functions are part of it. When you load the object code for a class, you load in the whole class. In this case if you are going to share objects of that class, it should be declared as _Cilk_shared.

You can get into similar problems if the functions are in a dynamically linked library. The dynamically linked library 'knows' what functions are part of it and it 'knows' what functions are required by it. So, when you run your code, the loader wants to find all the files the library 'knows' it needs. In this case, the simplest thing is to just make offloaded versions of all the libraries. Other things you can try - try either statically linking the library containing those files or try creating libraries that don't 'know' they need things they really don't - break your library into pieces or try explicitly create separate host and coprocessor version of the library as you would for code you are going to run natively on the coprocessor.

If this doesn't explain what you are seeing, let me know.

froth
  • 319
  • 1
  • 6
  • None of the functions I wrote are dynamically linked or member function in a shared class. They are just declared in a header file.. – yidiyidawu Apr 19 '15 at 02:56
  • Sigh, Is it possible for you to put together a small test case that shows this behavior? It looks like it may take some more digging to figure out. – froth Apr 20 '15 at 22:48