Software Archive
Read-only legacy content
17061 Discussions

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

Cui__liwei
Beginner
278 Views

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
278 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

0 Kudos
2 Replies
Rajiv_D_Intel
Employee
279 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;
}

0 Kudos
Cui__liwei
Beginner
278 Views

Thank you Rajiv!

0 Kudos
Reply