Software Archive
Read-only legacy content
17061 Discussions

Pointer to shared warnings

Mark_S_7
Beginner
378 Views

Hi when I compile the code below I get warnings stating that data1 and data2 are not pointers to shared data, how can I remove these warnings (the code seems to run correctly).

Here is the source code

[cpp]

#include <cilk/cilk.h>
#include <offload.h>
#include <omp.h>
#include <stdio.h>

_Cilk_shared double * _Cilk_shared data1;
_Cilk_shared double * _Cilk_shared data2;
_Cilk_shared int length = 100000;

class _Cilk_shared adder{
    public:
        void addArrays(double * a, double * b, int length);
};

void adder::addArrays(double * a, double * b, int length){
    if(_Offload_get_device_number() >= 0)
        printf("On mic\n");
    else
        printf("On host\n");
    #pragma omp parallel for default(none) shared(a,b,length)
    for(int i=0; i<length; i++){
        a += b;
    };
};

_Cilk_shared adder addObj;

int main(){
    data1 = (_Cilk_shared double * _Cilk_shared) _Offload_shared_malloc(sizeof(double)*length);
    data2 = (_Cilk_shared double * _Cilk_shared) _Offload_shared_malloc(sizeof(double)*length);
    for(int i=0; i<length; i++){
        data1 = i;
        data2 = i;
    }
    _Cilk_offload  addObj.addArrays(data1,data2,length);
    for(int i=0; i<length; i++){
        if(data1!=2*i){
            printf("Something has gone wrong\n");
            return 1;
        }
    }
    printf("Everything went okay\n");
    return 0;
}

 

[/cpp]

Here are the warnings I get when I compile

[plain]

main.cpp(35): warning #2707: pointer argument in _Cilk_offload function call is not pointer-to-shared
      _Cilk_offload  addObj.addArrays(data1,data2,length);
                                      ^

main.cpp(35): warning #2707: pointer argument in _Cilk_offload function call is not pointer-to-shared
      _Cilk_offload  addObj.addArrays(data1,data2,length);

[/plain]

0 Kudos
1 Reply
Kevin_D_Intel
Employee
378 Views

Development’s guidance is that the function addArrays is accepting a pointer to non-shared, so at the call-site, though data1 (and data2) was pointer-to-shared, there was an implicit cast added to make it match the argument type.  To correct this, make addArrays accept the appropriate type.

Change lines 17 and 20 in your code above to read as follows:

void addArrays( _Cilk_shared double * a, _Cilk_shared double * b, int length);

void adder::addArrays( _Cilk_shared double * a, _Cilk_shared double * b, int length){

 

0 Kudos
Reply