- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
hello, recently I want to use the global variable on MIC but find a strange problem:
At first, I write the code like this :
#include <stdio.h> #include <stdlib.h> __attribute__((target(mic))) double *test1; __attribute__((target(mic))) void initglobal() { test1=(double *)malloc(sizeof(double)*10); for (int i = 0; i < 10; i++) test1 = i; } int main() { #pragma offload target(mic:0) { initglobal(); printf("%f\n",test1[4]); } }
The compiler said :
error: pointer variable "test1" in this offload region must be specified in an in/out/inout/nocopy clause
And then I try the method to access the global variable :
#include <stdio.h> #include <stdlib.h> __attribute__((target(mic))) double *test1; __attribute__((target(mic))) void initglobal() { test1=(double *)malloc(sizeof(double)*10); for (int i = 0; i < 10; i++) test1 = i; } __attribute__((target(mic))) void printglobal() { printf("%f\n",test1[4]); } int main() { #pragma offload target(mic:0) { initglobal(); printglobal(); } }
This time it is worked and print the data.
So I have a question that the global variable is really calculated on MIC, but why I can not access directly?
Link Copied
0 Replies
Reply
Topic Options
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page