PGI User Forum
 SearchSearch   MemberlistMemberlist     RegisterRegister   ProfileProfile    Log inLog in 

CUDA-x86.

compiles but crashes at run-time
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
WmBruce



Joined: 18 May 2009
Posts: 14

PostPosted: Mon Jul 26, 2010 11:31 am    Post subject: compiles but crashes at run-time Reply with quote

Hi,

Here's a short code that compiles very happily yet it crashes at run-time with no error at all.

Code:

program main
   integer :: nums(3,3), vals(3,3)
   
   do j = 1,3
      do jj = 1,3
         nums(i,ii) = (i - 1) * 3 + ii
      enddo
   enddo
   
   !$acc region
   do i = 1,3
      do ii = 1,3
         vals(i,ii) = nums(i,ii) * 3
      enddo
      do ii = 1,3
         nums(i,ii) = vals(i,ii)
      enddo
   enddo
   !$acc end region
   
   do j = 1,3
      do jj = 1,3
         print *, nums(j,jj)
      enddo
   enddo
end program


All it does is set up nums to values 1...9, have vals be the holder of 3*nums and send vals back to nums. I understand that changing the accelerator region to the following would fix the problem,

Code:

   !$acc region
   do i = 1,3
      do ii = 1,3
         nums(i,ii) = nums(i,ii) * 3
      enddo
   enddo
   !$acc end region


but I am mostly curious as to why the first program does not work.
Back to top
View user's profile
mkcolg



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

PostPosted: Mon Jul 26, 2010 11:56 am    Post subject: Reply with quote

Hi WmBruce,

You have an error in source. In the first loop you use "i" and "ii" for the array index, but "j" and "jj" for the loop index. Changing "i" and "ii" to "j" and "jj" fixes the issue.

- Mat
Back to top
View user's profile
WmBruce



Joined: 18 May 2009
Posts: 14

PostPosted: Mon Jul 26, 2010 1:12 pm    Post subject: Reply with quote

Wow, I apologize for the simple mistake. I was trying to simplify the problem by mimicking the code that crashed, and in my haste made that mistake.

So here is the portion of my actual code that caused the crash.

Code:

program main
   real :: particles(20,3), garbage(20,3)
   real, parameter :: PI = 4 * atan(1.0)
   
      do j = 1, 20
         particles(j,1) = 4000
         particles(j,2) = 0
         particles(j,3) = 0
      end do
   
   !$acc region
      do j = 1, 10
         do jj = 1, 20
            garbage(jj,1) = particles(jj,1) + 0.002
            garbage(jj,2) = particles(jj,2) + 2 * PI
            garbage(jj,3) = (particles(jj,1) + 1) * sin(particles(jj,2) * 1000)
         end do
         do jj = 1, 20
            particles(jj,1) = garbage(jj,1)
            particles(jj,2) = garbage(jj,2)
            particles(jj,3) = garbage(jj,3)
         end do
      enddo
   !$acc end region    
end program


also im running PGI Worstation 10.6 (64bit) on Windows7 x64 and the the device is a Tesla C2050
Back to top
View user's profile
mkcolg



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

PostPosted: Mon Jul 26, 2010 1:56 pm    Post subject: Reply with quote

Quote:
Wow, I apologize for the simple mistake. I was trying to simplify the problem by mimicking the code that crashed, and in my haste made that mistake.
Not a problem.

The code is seg faulting because of a 'copyin' and 'copyout' mismatch for the particle array.
Code:
pgf90 -V10.6 test2.f90 -Minfo=accel -ta=nvidia
main:
     11, Generating copyin(particles(1:20,1:2))
         Generating copyout(particles(1:20,1:3))
         Generating copyout(garbage(1:20,1:3))

The easy fix is to change "!$acc region" to "!$acc region copy(particle)" so the compiler will copy in all of particles.


While doesn't matter much for this program, for larger codes you might want to consider using data regions to help cut down on the number of data transfers. For example:
Code:
program main
   real :: particles(20,3), garbage(20,3)
   real, parameter :: PI = 4 * atan(1.0)

!$acc data region local(garbage), copyout(particles)

!$acc region
      do j = 1, 20
         particles(j,1) = 4000
         particles(j,2) = 0
         particles(j,3) = 0
      end do

      do j = 1, 10
         do jj = 1, 20
            garbage(jj,1) = particles(jj,1) + 0.002
            garbage(jj,2) = particles(jj,2) + 2 * PI
            garbage(jj,3) = (particles(jj,1) + 1) * sin(particles(jj,2) * 1000)
         end do
         do jj = 1, 20
            particles(jj,1) = garbage(jj,1)
            particles(jj,2) = garbage(jj,2)
            particles(jj,3) = garbage(jj,3)
         end do
      enddo
!$acc end region
!$acc end data region

print *, particles(1,1)

end program


Hope this helps,
Mat
Back to top
View user's profile
WmBruce



Joined: 18 May 2009
Posts: 14

PostPosted: Mon Jul 26, 2010 4:24 pm    Post subject: Reply with quote

I copy-pasted your program and compiled it and it still crashed.

Thanks for the data directive advice. It is actually going to be something I am going to be using a lot.
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