Determining required flops to run C code

This is a discussion on Determining required flops to run C code within the C Programming forums, part of the General Programming Boards category; I apologize if this is not the appropriate place to ask this question, or if my query is too elementary ...

  1. #1
    Registered User
    Join Date
    Mar 2005
    Posts
    2

    Determining required flops to run C code

    I apologize if this is not the appropriate place to ask this question, or if my query is too elementary for this board, yet I am having difficulty determining the number of floating point operations that are required to run a program I wrote in MATLAB and compiled to C.

    Is there a simple way to determine the number of flops required to run my code?

    Thank you so much for any help and guidance.

    mollyann

  2. #2
    Gawking at stupidity
    Join Date
    Jul 2004
    Location
    Oregon, USA
    Posts
    3,163
    Well, you can tell your compile to spit out the assembly code for the program and then you can comb through that. For example, if you're using gcc as your compiler you just give it the -S switch and then it will create a <your program name>.s file that contains the assembly code.
    If you understand what you're doing, you're not learning anything.

  3. #3
    Registered User
    Join Date
    Jan 2005
    Posts
    847
    The only way I can think of to do this would be to examine the assembly code of your program (either by setting your compiler to output an assembly listing or by viewing the assembly window of your debugger) and then looking up each floating point instruction in the documentation of your processor to see how many clock cycles that instruction takes. There may be some profilling software available to automate this process.
    [edit]itsme86 you beat me too it[/edit]
    Last edited by Quantum1024; 03-29-2005 at 05:47 PM.

  4. #4
    and the hat of wrongness Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,506
    Except a static count of the number of instructions takes no account of the run-time behaviour (say instructions inside loops).
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.
    I support http://www.ukip.org/ as the first necessary step to a free Europe.

  5. #5
    Registered User
    Join Date
    Mar 2005
    Posts
    2
    Thank you all for taking the time to respond.

    Salem, true. Do you have any suggestions other than going over the assembly code? A program "Crystal Flow" was recommended to me to hlep determine the number of flops within loops, but I have not tried it yet and know nothing about it.

  6. #6
    Gawking at stupidity
    Join Date
    Jul 2004
    Location
    Oregon, USA
    Posts
    3,163
    Quote Originally Posted by Salem
    Except a static count of the number of instructions takes no account of the run-time behaviour (say instructions inside loops).
    I didn't mean to just count the number of assembly instructions. Loops and such usually depend on variable data that's determined at runtime. So if she just steps through the program for a given set of data as if she was processing each instruction himself, she could just keep a simple tally.
    If you understand what you're doing, you're not learning anything.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 23
    Last Post: 04-20-2009, 07:35 AM
  2. Enforcing Machine Code Restrictions?
    By SMurf in forum Tech Board
    Replies: 21
    Last Post: 03-30-2009, 07:34 AM
  3. Run A Program from within a cpp code
    By Hexxx in forum C++ Programming
    Replies: 6
    Last Post: 01-02-2006, 07:05 PM
  4. Replies: 4
    Last Post: 01-15-2002, 11:04 PM
  5. code to run (linux) programs WITH arguments
    By N8760 in forum C++ Programming
    Replies: 3
    Last Post: 12-27-2001, 02:35 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21