|
| View previous topic :: View next topic |
| Author |
Message |
paokara
Joined: 06 Feb 2011 Posts: 19
|
Posted: Wed Feb 27, 2013 2:52 am Post subject: Updating an array |
|
|
Hi,
I have a problem with an array inside a double loop. I want to update this array but i don't know if it is possible to do this in parallel.
| Code: |
!$acc kernels reduction(+:k)
do j=1,N
do i= 1,M
!In the beginning SOME INDEPENDENT CALCULATIONS
!and now the part with the reduction variable and the array
k = k +1
array(1,k) = i
array(2,k) = j
enddo
enddo
|
After the 2D loop my array should look like
k = 4
array(1,1) = 2 | array(1,2) = 3 | array(1,3) = 5 | array(1,4) = 5
array(2,1) = 3 | array(2,2) = 4 | array(2,3) = 160 | array(2,4) = 300
The problem is that with openACC my results are like
k=4 (CORRECT RESULT)
array(1,1) = 5 | array(1,2) = 0 | array(1,3) = 0 | array(1,4) = 0
array(2,1) = 160 | array(2,2) = 0 | array(2,3) = 0 | array(2,4) = 0
I'm familiar with the reason of this behaviour but i want to know if there is a way to solve this.
In CUDA i solved this problem using ATOMIC operations.
Thank you,
Sotiris |
|
| Back to top |
|
 |
Alexey A. Romanenko
Joined: 17 Feb 2012 Posts: 31
|
Posted: Wed Feb 27, 2013 3:32 am Post subject: |
|
|
Hi, Sotiris!
Your problem is in "k" variable.
Try to substitute "k = k+1" with "k = j*M + i" and remove reduction clause.
Alexey |
|
| Back to top |
|
 |
paokara
Joined: 06 Feb 2011 Posts: 19
|
Posted: Wed Feb 27, 2013 5:18 am Post subject: |
|
|
Thanks for the reply Alexey,
I did what you told me and now i have an array full of zeros and the pairs that i want in the positions k=j*M+i.
array(1,k) = SOMETHING
array(2,k) = SOMETHING ELSE
and in any other position array(1,l) = 0 and array(2,l) = 0
But now i want this pairs in the beginning of this array. For example if the total number of pairs is 5, i want the first 5 positions of the array to be filled with this pairs and all the other positions to be zeros.
Thanks
Sotiris |
|
| Back to top |
|
 |
mkcolg
Joined: 30 Jun 2004 Posts: 4996 Location: The Portland Group Inc.
|
Posted: Wed Feb 27, 2013 10:55 am Post subject: |
|
|
Hi Sotiris,
| Quote: | | In CUDA i solved this problem using ATOMIC operations. | You might want to revisit this since it will cause your code to slow down as the threads block on updating "k". Especially given, as Alexy points out, you can derive "k" from the index variables and loop bounds.
| Quote: | | But now i want this pairs in the beginning of this array. For example if the total number of pairs is 5, i want the first 5 positions of the array to be filled with this pairs and all the other positions to be zeros. | Sorry, I'm not entirely sure what you mean, but it seems you might just need an if statement.
- Mat |
|
| Back to top |
|
 |
paokara
Joined: 06 Feb 2011 Posts: 19
|
Posted: Thu Feb 28, 2013 1:35 am Post subject: |
|
|
Thanks for the reply Mat
| Quote: | Sorry, I'm not entirely sure what you mean, but it seems you might just need an if statement.
|
Ok, let me be more specific. I have a double loop and inside this loop i have an IF statement.Also i have a counter K which tells me how many times my program gets inside this IF statement.
| Code: |
!$acc kernels
do j=1,L
array(j) = 0
enddo
!$acc kernels reduction(+:k)
do j=1,N
do i= 1,M
!In the beginning SOME INDEPENDENT CALCULATIONS
If (condition) then
k = k +1
array(k) = i+j
end if
enddo
enddo
|
The dimendsion of the loop is M=1000 and N=1000. But after the execution my counter k is around to 10(so i get inside if statement 10 times). So i want only the first K positions of my array to be filled. For example if the dimension of ARRAY is L=1000, after the loop i want something like that:
K = 10
ARRAY(1) = value1, ARRAY(2) = value2,...,ARRAY(10) = value10, ARRAY(11)=0,...,ARRAY(1000) = 0
I used Alexey's way (k = j*M + i) and after the execution i had the correct results (value1,value2,...,value10) but i had them in the wrong positions of my ARRAY(for those i's and j's in k=j*M+i). So i want the correct results in the first K positions of the ARRAY, and i want this in parallel execution.
Thank you,
Sotiris |
|
| Back to top |
|
 |
|
|
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 © 2001, 2002 phpBB Group
|