I need to generate a random array of indices, i.e. unique integers beginning from 1.
So far I have this sequential code in Fortran:
subroutine rperm3(N, p)
integer, intent(in) :: N
integer, dimension(:), intent(out) :: p
integer :: j, k, l
real :: u
call random_seed()
p = 0
do j=1,N
call random_number(u)
k = floor(j*u) + 1
p(j) = p(k)
p(k) = j
call sleep(2)
end do
end subroutine rperm3
Basically, in every iteration a random index gets generated, value from this index is assigned to the position of the current index and the old value is rewritten with the current index itself.
But is there any way to parallelize this with OpenMP? I see, that simply using !$omp parallel for is not possible, as we are using the previous values of the array, which don't have to be assigned at the time they're needed...
And if there is no way to do it, is there any other parallel algorithm doing the same thing, i.e. generating a random array of unique integers from some range?
Aucun commentaire:
Enregistrer un commentaire