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

## Get some problem with global variable declaration Beginner
134 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>
float *A;
float *B;
float *C;

//__attribute__((target(mic))) float *A,*B,*C;

void noco (float *A,float *B,float *C,int j)
{
int i;
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;
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);
printf("%f",AA);
return 0;
}   