PGI User Forum
 SearchSearch   MemberlistMemberlist     RegisterRegister   ProfileProfile    Log inLog in 

Free OpenACC Webinar

Unstructured data lifetimes with classes

 
Post new topic   Reply to topic    PGI User Forum Forum Index -> Accelerator Programming
View previous topic :: View next topic  
Author Message
xray



Joined: 21 Jan 2010
Posts: 85

PostPosted: Tue Feb 11, 2014 3:28 pm    Post subject: Unstructured data lifetimes with classes Reply with quote

Hi,
I am wondering whether unstructured data lifetimes are working with C++ classes and constructors/destructors.

I have a stupid class CArray:
Code:
  class CArray {
   public:
    CArray(int n) {
      a = new double[n];
      #pragma acc enter data create(CArray::a[0:n])
    }
    ~CArray() {
      #pragma acc exit data delete(CArray::a[0:n])
      delete(a);
    }
      double *a;
  };


and then I want to access ist data in a parallel region. Like this:

Code:
int na=120;
CArray myarray(na);
#pragma acc parallel loop  present(myarray[0:na])
     for(i=0; i<na; i++) {
      myarray.a[i] = i;
     }


However, I get the error message that "data in PRESENT clause was not found on device". If I omit the present clause, the compiler creates a present_or_copyin for that array. If I then kaunch the parallel region, I get a launch failure.

I appreciate any comments.
Thanks, Sandra
Back to top
View user's profile
mkcolg



Joined: 30 Jun 2004
Posts: 6208
Location: The Portland Group Inc.

PostPosted: Tue Feb 11, 2014 4:32 pm    Post subject: Reply with quote

Hi Sandra,

There's two problems here. First is we don't yet support class members in data clauses due the "this" pointer. It's actually one of the major features we're currently working on and expect it to be available in the next few months. You can work around it by creating temp variables which point to the members.

- Mat

Code:
#include <iostream>

  class CArray {
   public:
    CArray(int n) {
      a = new double[n];
      double * tmp = a;
      #pragma acc enter data create(tmp[0:n])
    }
    ~CArray() {
      double * tmp = a;
      #pragma acc exit data delete(tmp)
      delete(a);
    }
      double *a;
  };

int main () {

int na=120;
CArray myarray(na);
double *tmp;
tmp = myarray.a;
#pragma acc parallel loop copyout(tmp[0:na])
     for(int i=0; i<na; i++) {
      tmp[i] = i;
     }

   std::cout <<  myarray.a[0] << " " << myarray.a[na-1] << std::endl;
   exit(0);
}
Back to top
View user's profile
xray



Joined: 21 Jan 2010
Posts: 85

PostPosted: Wed Feb 12, 2014 1:28 am    Post subject: Reply with quote

Dear Mat,
Thanks a lot for your fast response. Your workaround is working.
You mentioned TWO problems. What is the other one?
Sandra
Back to top
View user's profile
mkcolg



Joined: 30 Jun 2004
Posts: 6208
Location: The Portland Group Inc.

PostPosted: Wed Feb 12, 2014 9:04 am    Post subject: Reply with quote

Sorry, I was going to mention that there as was typo in the present clause where you just had "myarray[0:na]" instead of "myarray.a[0:na]". However, it didn't matter after the workaround. Forgot to go back and edit.

- Mat
Back to top
View user's profile
Display posts from previous:   
Post new topic   Reply to topic    PGI User Forum Forum Index -> Accelerator Programming All times are GMT - 7 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © phpBB Group