- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
I try use an Intel PHI co-prococessor.But i got some problem with global variable declaration .I decline A,B,C as global variable.But the value of them are equal。Turn out to be,A=5,B=5,C=5.And AA=30.The right AA must be 17.Try to get some help here.Thanks.
#include <stdio.h>
#include <math.h>
#include <omp.h>
#pragma offload_attribute(push,target(mic))
float *A;
float *B;
float *C;
#pragma offload_attribute(pop)
//__attribute__((target(mic))) float *A,*B,*C;
void noco (float *A,float *B,float *C,int j)
{
int i;
#pragma offload target (mic)\
nocopy(A:length(j) alloc_if(1) free_if(0))\
nocopy(B:length(j) alloc_if(1) free_if(0))\
nocopy(C:length(j) alloc_if(1) free_if(0))
for(i=0;i<j;i++)
{
A=2;
B=3;
C=5;
}
}
void add (float *A,float *B,float *C,float *AA,int j)
{
int i;
#pragma offload target (mic)\
nocopy(A:length(j) alloc_if(0) free_if(1))\
nocopy(B:length(j) alloc_if(0) free_if(1))\
nocopy(C:length(j) alloc_if(0) free_if(1))\
out(AA:length(j) alloc_if(1) free_if(1))
for(i=0;i<j;i++)
{
AA=A+B*C;
}
}
int main()
{
float *AA =NULL;
float j=11;
AA = (float *) malloc(j*sizeof(float));
noco(A,B,C,j);
add(A,B,C,AA,j);
printf("%f",AA[1]);
return 0;
}
- Tags:
- Parallel Computing
Link Copied
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
There is a specific moderated forum for MIC, while you have no guarantee that the right people will see your questions on this apparently un-moderated forum.

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