Community
cancel
Showing results for 
Search instead for 
Did you mean: 
Highlighted
Beginner
21 Views

The strange method access to the global variable on MIC

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?

0 Kudos
0 Replies