I have two lists, I need to match elements in one against the other and output those elements into a new matrix (output). What is the fastest way to this in Fortran? Brute force so far:
do i = 1,Nlistone
do j = 1,Nlisttwo
if A(i).eq.B(j) then
output(i) = B(j)
end if
end do
end do
openmp version:
!$OMP PARALLEL PRIVATE(i,j)
do i = 1,NA
do j = 1,NB
if A(i).eq.B(j) then
filtered(i) = A(j)
end if
end do
end do
!$OMP END PARALLEL DO
There are definitely better ways to do this and sorting is not an option here sorry (+ the vector elements are not in any particular order). Is there a boolean argument similar to mask in python?
It might be faster to use the intrinsic
ANYfunction something like thisbut I wouldn’t bet on this improving performance, I’d test both versions. You should be able to safely wrap this inside an
!$OMP PARALLEL DOconstruct since each element ofoutputis only written to by one thread.