Software Archive
Read-only legacy content
17061 Discussions

why this simple offload give Segmentation fault error

yongbei_ma_
New Contributor I
402 Views

this simple test code is this(testclass.cpp):

#include <iostream>

class TEST{
public:
    double *A;
public:
    TEST(double * _A){A = _A;}
    void run(){
        A[1] = 0;
        // double *B = A;
        std::cout<<A[1]<<std::endl;
        #pragma offload target (mic) inout(A:length(2*3))
        {
            A[1] = 1;
        }
        std::cout<<A[1]<<std::endl;
    }
};

int main()
{

    double *A = (double*)_mm_malloc(sizeof(double)*2*3,64);
    TEST test(A);
    test.run();

}

.............................................................................................

after complile and run ,this give me this error:

[root@localhost yb]# icpc testclass.cpp

[root@localhost yb]# ./a.out

0

Segmentation fault (core dumped)

......................................................................

thanks.

 

0 Kudos
1 Reply
Kevin_D_Intel
Employee
402 Views

It relates to the underlying "this" pointer. I need to check with someone more knowledgeable about the requirements for offload within the CLASS, but for now add the additional nocopy clause as shown below to create an instance of the underlying "this" pointer.

        #pragma offload target (mic) nocopy(this : alloc_if(1) free_if(0)) inout(A:length(2*3))

 

0 Kudos
Reply