PGI User Forum
 SearchSearch   MemberlistMemberlist     RegisterRegister   ProfileProfile    Log inLog in 

Free OpenACC Webinar

Reduction operation in C

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



Joined: 13 Mar 2011
Posts: 1

PostPosted: Wed Mar 16, 2011 3:34 pm    Post subject: Reduction operation in C Reply with quote

Hi,
I read that the reduction operation was supported by pgi. I tried running this in C with a simple loop like


Code:

for(i=0;i<n;i++)
    s=s+a[i];


But I get " Loop carried scalar dependence for 's' " info. I tried the same simple loop in fortran and it worked without hassle. Is reduction supported only on fortran? Thanks.
Back to top
View user's profile
mkcolg



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

PostPosted: Wed Mar 16, 2011 4:45 pm    Post subject: Reply with quote

Hi phoenix07p,

Sum reduction works for C as well. My guess is something else is inhibiting the accelerator region. Can you post an example of what you're seeing?

Thanks,
Mat

Code:
% cat testr.c
#include <stdio.h>
#include <malloc.h>

int main () {

   float s;
   float *a;
 
   a=malloc(sizeof(float)*1024);
   for (int i=0;i<1024;++i) {
      a[i]=i;
   }

#pragma acc region for
   for (int i=0;i<1024;++i) {
      s=s+a[i];
   }
 
  printf("S=%g\n", s);

}

   
 
% pgcc testr.c -ta=nvidia -Minfo -V11.3
main:
     14, Generating copyin(a[0:1023])
         Generating compute capability 1.0 binary
         Generating compute capability 1.3 binary
         Generating compute capability 2.0 binary
     15, Loop is parallelizable
         Accelerator kernel generated
         15, #pragma acc for parallel, vector(256) /* blockIdx.x threadIdx.x */
             CC 1.0 : 7 registers; 1064 shared, 16 constant, 0 local memory bytes; 100% occupancy
             CC 1.3 : 7 registers; 1064 shared, 16 constant, 0 local memory bytes; 100% occupancy
             CC 2.0 : 10 registers; 1032 shared, 52 constant, 0 local memory bytes; 100% occupancy
         16, Sum reduction generated for s
% a.out
S=523776
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