voidtest1(){ char signal_var; //需要指定mic卡的编号 #pragma offload target(mic:0)signal(&signal_var) { longlong i; longlong t; for(i = 0; i < 1000000000; i++) { t += i; t += i * 2; t += i * 3; t +=i %2; t += i %3; } printf("t is %lld\n", t); }
int j = 0; for(j = 0; j < 100000; j++) {} printf("j is %d\n", j);
#pragma offload target(mic:0) { longlong i; longlong t; for(i = 0; i < 1000000000; i++) { t += i; t += i * 2; t += i * 3; t +=i %2; t += i %3; } printf("t is %lld\n", t); }
int j = 0; for(j = 0; j < 100000; j++) {} printf("j is %d\n", j); printf("after wait\n"); }
__ONMIC__ voidadd_inputs(int n, float *f1, float *f2){ int i; for( i =0; i < n; i++) { f2[i] += f1[i]; } }
voiddisplay_vals( int id, int n, float *f2){ printf("\nResults after Offload #%d:\n",id);
int i; for ( i = 0; i < n; i++) { printf("f2[%d] is %f\n", i, f2[i] ); } printf("====================\n"); } voidtest(){ float *f1 , *f2; int n = 10000; int i, j; f1 = (float*) malloc(sizeof(float) * n); f2 = (float*)malloc(sizeof(float) * n);
for(i = 0; i < n; i++) { f1[i] = i+1; f2[i] = 0.0; } // 这里只上传数据 #pragma offload_transfer target(mic:0) signal(f1) \ in (f1:length(n) alloc_if(1) free_if(0))\ in (f2:length(n) alloc_if(1) free_if(0))