algorithm - Efficient way to see if a set of values appear in an array? -
i'm trying check if 1d array of integers a contains or not, @ every 1 of it's size(a) positions, of elements of set of integers s (also 1d array), general case of size(s) > 1 . the easy , obvious way following nested loop: do = 1, size(a) j = 1, size(s) if(a(i) == s(j)) ** ** enddo enddo the problem that, large arrays a , s , process inefficient. there intrinsic fortran subroutine or function faster? or other method? i've tried following, doesn't want compile: do = 1, nnodes if(a(i) == any(s)) ** ** enddo the error message appears following: " error #6362: data types of argument(s) invalid. " i'm using vs2010 intel parallel studio 2013. the expression a(i) == any(s) has integer on lhs , logical on rhs . we'll have none of c-inspired nonsense of regarding comparable types in fortran thank much. actually, it's worse that, any returns logical takes array of logicals on input, any(array_of_int) ...