Software Archive
Read-only legacy content
17061 Discussões

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

Cui__liwei
Principiante
605 Visualizações

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 Solução
Rajiv_D_Intel
Funcionário
605 Visualizações

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;
}

Ver solução na publicação original

2 Respostas
Rajiv_D_Intel
Funcionário
606 Visualizações

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;
}

Cui__liwei
Principiante
605 Visualizações

Thank you Rajiv!

Responder