Community
cancel
Showing results for 
Search instead for 
Did you mean: 
哲_陈_
Beginner
62 Views

Get some problem with global variable declaration

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;
}

 

QQ截图20150409213434.png

Tags (1)
0 Kudos
1 Reply
TimP
Black Belt
62 Views

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.

Reply