Intel® Moderncode for Parallel Architectures
Support for developing parallel programming applications on Intel® Architecture.

Get some problem with global variable declaration

哲_陈_
Beginner
1,071 Views

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

0 Kudos
1 Reply
TimP
Honored Contributor III
1,071 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.

0 Kudos
Reply