PGI User Forum
 SearchSearch   MemberlistMemberlist     RegisterRegister   ProfileProfile    Log inLog in 

CUDA-x86.

Reduction results in wrong results. Bug?
Goto page 1, 2  Next
 
Post new topic   Reply to topic    PGI User Forum Forum Index -> Accelerator Programming
View previous topic :: View next topic  
Author Message
PaulPa



Joined: 02 Aug 2012
Posts: 35

PostPosted: Sun Nov 25, 2012 5:40 am    Post subject: Reduction results in wrong results. Bug? Reply with quote

Hi,

I'm currentliy working on this little piece of code:

Code:

#pragma acc parallel loop gang private(i,j) copy(force[0:DIM][0:N]) copyin(pos[0:DIM][0:N])
   for(i=0;i < num_particles ; ++i){
      double tmp_x = 0.0;
      double tmp_y = 0.0;
      double tmp_z = 0.0;
#pragma acc loop //reduction(+:tmp_x,tmp_z,tmp_z)
      for(j=0;j < num_particles; ++j){
         double dx = (pos[0][j] - pos[0][i]);
         double dy = (pos[1][j] - pos[1][i]);
         double dz = (pos[2][j] - pos[2][i]);
         double r = dx * dx + dy * dy + dz * dz;
         double tmp_f;
         if(r != 0.0){
            double s = 1.0 / r;
            s = s * s * s;
            tmp_f = 100.0 * s/r * (1.0 - 2.0 * s);
         }else{
            tmp_f = 0.0;
         }
         tmp_x += tmp_f * dx;
         tmp_y += tmp_f * dy;
         tmp_z += tmp_f * dz;
      }
      force[0][i] += tmp_x;
      force[1][i] += tmp_y;
      force[2][i] += tmp_z;
   }
}


If I compile this code as it is here, it is working perfectly (same results as sequential C code) and I receive the following compiler feedback:

Code:

    472, Accelerator kernel generated
        472, CC 2.0 : 47 registers; 16 shared, 96 constant, 0 local memory bytes
        476, #pragma acc loop gang /* blockIdx.x */
        481, #pragma acc loop vector(256) /* threadIdx.x */


However, I think that a reduction for tmp_x, tmp_y and tmp_z would be required. So if I uncomment the reduction I receive the exact same compiler feedback (i.e. nothing about added reductions) but the results are wrong.

What am I missing here?

Thanks.
Best,
Paul
Back to top
View user's profile
mkcolg



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

PostPosted: Mon Nov 26, 2012 12:27 pm    Post subject: Reply with quote

Hi Paul,

In order the parallelize the inner loop, the compiler must be automatically generating the reductions, otherwise you'd be getting wrong answers without the reduction clause. I'm not sure why adding the reduction clause would then yield wrong answers. Seems like a compiler error.

Can you either post or send to PGI Customer Support (trs@pgroup.com) a reproducing example?

Thanks,
Mat
Back to top
View user's profile
PaulPa



Joined: 02 Aug 2012
Posts: 35

PostPosted: Mon Nov 26, 2012 12:52 pm    Post subject: Reply with quote

thanks for the quick reply, I'll file a bug-report shortly.

Do you know why I don't see any compiler feedback which tells me that a reduction clause has been generated (in both cases)?

Best,
Paul
Back to top
View user's profile
mkcolg



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

PostPosted: Mon Nov 26, 2012 2:50 pm    Post subject: Reply with quote

Hi Paul,

I just found the error:
Code:
#pragma acc loop reduction(+:tmp_x,tmp_z,tmp_z)

Changing one of the "tmp_z" to "tmp_y" fixes the problem.

I'll need to talk with one of our compiler engineers about why we're not printing a message for inner loop reductions.

- Mat
Back to top
View user's profile
PaulPa



Joined: 02 Aug 2012
Posts: 35

PostPosted: Mon Nov 26, 2012 11:43 pm    Post subject: Reply with quote

ups :) thanks for catching that. Yes, a compiler feedback would be nice.

Maybe another question:
I'm curious if the private(i,j) clause is really necessary. In OpenMP it would be, at least private(j), is it true for OpenACC as well?
Because if I don't use the private clause my programm runs 15% faster and still gives the same results.

Best,
Paul
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
Goto page 1, 2  Next
Page 1 of 2

 
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