- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hi there,
I have a question. I wrote code, but it generate runtime error.
[cpp] class A {
public:
float *x;
A() {
x = (float*)malloc(100 * sizeof(float));
int i;
for (i = 0; i < 100; i++) {
x = i + 100;
}
printf("x[0] %.3f\n", x[0]);
}
void fA() {
#pragma offload target(mic:0) \
in(x[0:10] : REUSE)
{
x[0] = -1;
}
}
~A() {
#pragma offload target (mic:0) \
out(x : length(100) FREE)
{
}
printf("x[0] %.3f\n", x[0]);
free(x);
}
};
int main( ) {
A a;
a.fA();
}
[/cpp]
I have field of class which is point to array. When create of class should allocation memory on Xeon Phi. Also class have function which copy data to Xeon Phi, but not all array, and part of array. How to do it right?
I was looking for how to do this, but found nothing.
Link Copied
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
The array x must have the offload attribute in order to be used in an offloaded section of your code. And not just any x but the particular instance - a.x. As far as I know, you cannot do that. But what you can do is use Cilk. You can declare the whole class to be _Cilk_shared and create a _Cilk_shared instance of that class. You would call fA using _Cilk_offload rather than doing an offload inside fA.
There are a number of examples showing how to used _Cilk_shared/_Cilk_offload in /opt/intel/composerxe/Samples/en_US/C++/mic_samples/shrd_sampleCPP
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
ok. Thanks for the answer.
As I know pragma offload faster than _Cilk_offload. But i don't know How much is it?
I use pragma offload because it let to get maximum perfomance.

- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page