C versus C++ regarding the time for scientific computation

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • CarryFlag
    New Member
    • Jul 2008
    • 2

    C versus C++ regarding the time for scientific computation

    Hi

    I want to write functions for basic matrix calculations. Since I will call these functions several times, the working time of them is important. While searching the internet, I seen that some Fortran77 code may be faster than C++ code. I don't want to use Fortran however I want to decide using C or C++. Which one is suitable?
  • JosAH
    Recognized Expert MVP
    • Mar 2007
    • 11453

    #2
    Originally posted by CarryFlag
    Hi

    I want to write functions for basic matrix calculations. Since I will call these functions several times, the working time of them is important. While searching the internet, I seen that some Fortran77 code may be faster than C++ code. I don't want to use Fortran however I want to decide using C or C++. Which one is suitable?
    If your priority is on speed, google for 'linpack' and 'lapack'; they're a bunch of
    highly optimized functions dealing with matrix operations. If you have to deal
    with sparse matrixes the world is not so nice anymore but quite a few libraries
    exist for sparse matrix manipulations as well and again: google is your friend.

    kind regards,

    Jos

    Comment

    • arnaudk
      Contributor
      • Sep 2007
      • 425

      #3
      Well written C++ code will be as fast as the C or FORTRAN equivalent. You will probably find most scientists use C to do serious number crunching (or Fortran, if they have particularly long beards) but that's not because C++ is any slower, it's because they only write relatively small and simple programs and don't need the organisational advantages of objects. That's not to say the algorithms used are simple, but there's no question of writing thousands of lines of reusable code, working in a team, writing a GUI or anything like that - most often their code is written for a very narrow purpose and they are the only ones who will ever need to understand it.

      However, I believe there is a lot to be gained in productivity and transparency for yourself if you use objects and adhere to good programming practices. To this end, check out Blitz++ and boost.

      Bear in mind that you can also call Fortran routines from C/C++; Lapack (which largely supercedes linpack) is written in Fortran.

      Comment

      • arnaudk
        Contributor
        • Sep 2007
        • 425

        #4
        I should add that the de facto standard of numerical routines in C is GSL.

        Comment

        • CarryFlag
          New Member
          • Jul 2008
          • 2

          #5
          I have a good starting point now. Thank you for your help.

          Comment

          Working...