Thread: Determining required flops to run C code

  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,218
    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 06:47 PM.

  4. #4
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,660
    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.

  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,218
    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, 08:05 PM
  4. Replies: 4
    Last Post: 01-16-2002, 12:04 AM
  5. code to run (linux) programs WITH arguments
    By N8760 in forum C++ Programming
    Replies: 3
    Last Post: 12-27-2001, 03:35 PM