Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9196075
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T21:46:15+00:00 2026-06-17T21:46:15+00:00

I have two lists, I need to match elements in one against the other

  • 0

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?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-17T21:46:16+00:00Added an answer on June 17, 2026 at 9:46 pm

    It might be faster to use the intrinsic ANY function something like this

    do i = 1,Nlistone
         if (any(B==A(i))) output(i) = A(i)
    end do
    

    but 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 DO construct since each element of output is only written to by one thread.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have two lists, one of contacts and the other of employees. I want
I have two lists: ask[] timeStamp[] I need to add the information in these
I have a list of two-item lists and need to search for things in
I have two different list types. I need to remove the elements from list1
I have two tables: Campaigns, Campaign_statistics. I need to output campaigns list with nested
I have two lists. Ex: List<string> expected = new List<string>(); expected.Add( a ); expected.Add(
We have two mailing lists that we need to combine, and then make sure
I have two different lists where one is a bunch of ID's as in
I have two lists, A and B, with an equal number of elements, although
I have two tables that I need to compare and update values in one

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.