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

  • SEARCH
  • Home
  • 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 7690095
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T20:19:05+00:00 2026-05-31T20:19:05+00:00

as it is so common with Fortran, I’m writing a massively parallel scientific code.

  • 0

as it is so common with Fortran, I’m writing a massively parallel scientific code. In the beginning of my code I read my configuration file which tells me which type of solver I want to use. Now that means that in a subroutine (during the main run) I have

if(solver.eq.1)then
  call solver1()
elseif(solver.eq.2)then
  call solver2()
else
  call solver3()
endif

Edit to avoid some confusion: This if is inside my time integration loop and I have one that is inside 3 nested loops.

Now my question is, wouldn’t it be more efficient to use function pointers instead as the solver variable will not change during execution, except at the initialisation procedure.

Obviously function pointers are F2003. That shouldn’t be a problem as long as I use gfortran 4.6. But I’m mainly using a BlueGene P, there is a f2003 compiler, so I suppose it’s going to work there as well although I couldn’t find any conclusive evidence on the web.

  • 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-05-31T20:19:06+00:00Added an answer on May 31, 2026 at 8:19 pm

    Knowing nothing about Fortran, this is my answer: The main problem with branching is that a CPU potentially cannot speculatively execute code across them. To mitigate this problem, branch prediction was introduced (which is very sophisticated in modern CPUs).

    Indirect calls through a function pointer can be a problem for the prediction unit of the CPU. If it can’t predict where the call will actually go, this will stall the pipeline.

    I am quite sure that the CPU will correctly predict that your branch will always be taken or not taken because it is a trivial case of prediction.

    Maybe the CPU can speculate across the indirect call, maybe it can’t. This is why you need to test which is better.

    If it cannot, you will certainly notice in your benchmark.

    In addition, maybe you can hoist the if test out of your inner loop so it won’t be called often. This will make the actual performance of the branch irrelevant.

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

Sidebar

Related Questions

A common mistake when writing code that reads text from a stream in Java
I've been tasked with maintaing some legacy fortran code, and I'm having trouble getting
Many common filesystems do not offer atomic operations, yet writing files in an atomic
I'm dealing with some legacy code that uses COMMON blocks extensively and sometimes uses
Common image questions in regards to developing WP7 applications which are all related to
Common problem which I know the SQL gurus out there will be able to
The common sense tells that the Doxygen comment blocks have to be put in
A common (i assume?) type of query: I have two tables ('products', 'productsales'). Each
The common solution to preventing deadlock in code is to make sure the sequence
CTE (Common Table Expression) vs Temp tables or Table variables , which is faster?

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.