PGI User Forum
 SearchSearch   MemberlistMemberlist     RegisterRegister   ProfileProfile    Log inLog in 

CUDA-x86.

Tuning a Monte Carlo Algorithm on GPUs: basic question

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



Joined: 17 Jun 2013
Posts: 1

PostPosted: Mon Jun 17, 2013 4:35 am    Post subject: Tuning a Monte Carlo Algorithm on GPUs: basic question Reply with quote

I am a complete novice with CUDA and so I am probably overlooking something basic here with scoping or something. As I was reading over the first listing in the tutorial I see:
Code:

do i=1,N
    tempVal = X(i)*X(i) + Y(i)*Y(i)
if (tempVal < 1) then
temp(i) = 1
      else
    temp(i) = 0
      endif


So now temp(i) equals either 0 or 1 for all i in 1,N. Right?

Then later we see:

Code:
   do i=1,N
     sumA = sumA + temp(i)
     sumSq = sumSq + (temp(i)*temp(i))


Since each value of temp(i) is either 0 or 1, temp(i)*temp(i) is just 0*0=0 or 1*1=1 for each value of i. So sumA is equal to sumSq. Right? And what is the point of independently calculating the same value? And later:

Code:
    meanA = sumA / real(N);
    meanSq = sumSq / real(N);


Then doesn't meanA equal meanSq? And how does that help compute the variance? So what is wrong with my understanding?
Back to top
View user's profile
mkcolg



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

PostPosted: Mon Jun 17, 2013 11:55 am    Post subject: Reply with quote

No, you're correct. I considered removing the variance portion from the code since it didn't matter in this case. But, it's part of a Monte Carlo algorithm I was using, so decide to leave it in.

- 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