Community
cancel
Showing results for 
Search instead for 
Did you mean: 
Cui__liwei
Beginner
68 Views

Error: (pointer to array) may not be used in a subscript operation. How could I solve it?

Jump to solution

Hello everybody.

I have a pointer like this:

float **p = ...;
...
#pragma offload target(mic) in(p[0]:length(...))
_FUNCITON_

Then I got error info: ` "p" may not be used in a subscript operation.` when compiling it.

So how could I pass a one-dimensional array like this to mic? any advice and suggestions will be greatly appreciated!

0 Kudos
1 Solution
Rajiv_D_Intel
Employee
68 Views

Declarations like float **p; are not supported. However, float *p; is supported. p is an array of float pointers. There is a special syntax for transferring pointer arrays:

__declspec(target(mic)) float *p[4];

int main()
{
        p[0] = malloc(4*sizeof(float));
        p[1] = malloc(4*sizeof(float));
        p[0][0] = 55.0;
        p[0][1] = 66.0;
        p[0][2] = 77.0;
        p[0][3] = 88.0;

        #pragma offload target(mic) in(p[0:1] : extent(0:4))
        {
                printf("p[0][0] = %f\n", p[0][0]);
                printf("p[0][1] = %f\n", p[0][1]);
                printf("p[0][2] = %f\n", p[0][2]);
                printf("p[0][3] = %f\n", p[0][3]);
        }
        return 0;
}

View solution in original post

2 Replies
Rajiv_D_Intel
Employee
69 Views

Declarations like float **p; are not supported. However, float *p; is supported. p is an array of float pointers. There is a special syntax for transferring pointer arrays:

__declspec(target(mic)) float *p[4];

int main()
{
        p[0] = malloc(4*sizeof(float));
        p[1] = malloc(4*sizeof(float));
        p[0][0] = 55.0;
        p[0][1] = 66.0;
        p[0][2] = 77.0;
        p[0][3] = 88.0;

        #pragma offload target(mic) in(p[0:1] : extent(0:4))
        {
                printf("p[0][0] = %f\n", p[0][0]);
                printf("p[0][1] = %f\n", p[0][1]);
                printf("p[0][2] = %f\n", p[0][2]);
                printf("p[0][3] = %f\n", p[0][3]);
        }
        return 0;
}

View solution in original post

Cui__liwei
Beginner
68 Views

Thank you Rajiv!

Reply