Running a console program with maximum speed

This is a discussion on Running a console program with maximum speed within the Linux Programming forums, part of the Platform Specific Boards category; Originally Posted by arno-nyme I did not realize that underscores are reserved. Does it lead to trouble or is it ...

  1. #16
    Kernel hacker
    Join Date
    Jul 2007
    Location
    Farncombe, Surrey, England
    Posts
    15,677
    Quote Originally Posted by arno-nyme View Post
    I did not realize that underscores are reserved. Does it lead to trouble or is it just a question od style. I am not really a programmer, I just write a msters thesis

    Davoud

    ATTACHMENT: JPG - generator
    It is a style issue - the problem comes when one of your symbols collide with one of the implementations.

    --
    Mats
    Compilers can produce warnings - make the compiler programmers happy: Use them!
    Please don't PM me for help - and no, I don't do help over instant messengers.

  2. #17
    Cat without Hat CornedBee's Avatar
    Join Date
    Apr 2003
    Posts
    8,893
    Does it lead to trouble
    It can, when the next version of the compiler decides it wants that symbol for its own purposes.
    All the buzzt!
    CornedBee

    "There is not now, nor has there ever been, nor will there ever be, any programming language in which it is the least bit difficult to write bad code."
    - Flon's Law

  3. #18
    Registered User
    Join Date
    May 2008
    Posts
    10
    I used the mypowf function, but my program became slower.
    Any explenations?

    I did not use "-ffast-math", as I did not know how. I am not a progammer, just an by exident scientist (not even that in my real live)

    Davoud

  4. #19
    Kernel hacker
    Join Date
    Jul 2007
    Location
    Farncombe, Surrey, England
    Posts
    15,677
    It is likely to run slower if you don't use -ffast-math. When you compile your code with gcc, you give it options, one of those would be -ffast-math - that will take some short cuts, but it's only really relevant when working in corner-cases - such as dealing with infinity as an input or result. For the use you have, -ffast-math should give the exact same result.

    I had already figured you weren't a proficient programmer - the code is not that good [just like you would probably spot something similar if I started discussing economics, trading and such].

    --
    Mats
    Compilers can produce warnings - make the compiler programmers happy: Use them!
    Please don't PM me for help - and no, I don't do help over instant messengers.

  5. #20
    Registered User
    Join Date
    May 2008
    Posts
    10
    :-)

    I tried to find it out myself, but how do I put compiler -ffast-math flags with gcc / code::Blocks?

    I implemented the memcp, and its faster now!
    Many thanks for the help and effort put.


    Davoud

  6. #21
    Captain Crash brewbuck's Avatar
    Join Date
    Mar 2007
    Location
    Portland, OR
    Posts
    7,237
    Quote Originally Posted by arno-nyme View Post
    I am programming a "agent based" computer simulation in gcc. It basically does vector operations and gives as output some text files. Its an console application. It is written for scientific purposes. I would like to find a way to running this program dedicating the complete (or like 80%) of my processing power to it. File is attached. (code is messy I am not a professional programmer)
    Under most non-real-time schedulers, there is no way to force a process to be scheduled exclusively so that it uses 100% of the CPU. However you can adjust its priority to make it more "attractive" to the scheduler, which will cause it to be scheduled more often. Of course the simplest way to give it as many cycles as possible is to make sure that nothing else is running on the machine.

    At least, that's how I interpreted your question. The others seem to have interpreted it in terms of optimization. Thought I'd give an answer orthogonal to those.

  7. #22
    Kernel hacker
    Join Date
    Jul 2007
    Location
    Farncombe, Surrey, England
    Posts
    15,677
    Quote Originally Posted by arno-nyme View Post
    :-)

    I tried to find it out myself, but how do I put compiler -ffast-math flags with gcc / code::Blocks?

    I implemented the memcp, and its faster now!
    Many thanks for the help and effort put.


    Davoud
    Not sure how code::Blocks deal with compiler settings, but I'm sure there is a way to add extra settings to the compile phase. There you do need to add -ffast-math.

    --
    Mats
    Compilers can produce warnings - make the compiler programmers happy: Use them!
    Please don't PM me for help - and no, I don't do help over instant messengers.

  8. #23
    Registered User
    Join Date
    Apr 2008
    Posts
    395
    ...you can adjust its priority to make it more "attractive" to the scheduler, which will cause it to be scheduled more often.
    ...and to do that, use the command "nice" ("man nice" for details).

  9. #24
    Kernel hacker
    Join Date
    Jul 2007
    Location
    Farncombe, Surrey, England
    Posts
    15,677
    Quote Originally Posted by root4 View Post
    ...and to do that, use the command "nice" ("man nice" for details).
    But you can only make your process HIGHER priority if you have superuser (root) privileges.

    --
    Mats
    Compilers can produce warnings - make the compiler programmers happy: Use them!
    Please don't PM me for help - and no, I don't do help over instant messengers.

  10. #25
    Cat without Hat CornedBee's Avatar
    Join Date
    Apr 2003
    Posts
    8,893
    And it's only of use if there actually is a less important application stealing CPU time. It won't make your program run faster.
    In other words, if your total CPU usage isn't at 100%, nice isn't going to help, since there is CPU power available; the program just doesn't use it.
    All the buzzt!
    CornedBee

    "There is not now, nor has there ever been, nor will there ever be, any programming language in which it is the least bit difficult to write bad code."
    - Flon's Law

  11. #26
    Registered User
    Join Date
    Apr 2008
    Posts
    395
    It won't make your program run faster.
    No one said the program would run faster, it was only said it would be less interrupted (scheduled more often & longer) which was one of the OP requests.

    if your total CPU usage isn't at 100%, nice isn't going to help, since there is CPU power available;
    Any reference about that? because as far as I know it does modify the scheduling policy of the process, the only 'unknown' parameter being when the new policy is applied (depending on the process current state).

    the program just doesn't use it.
    The program has no choice, this is managed by the O/S.

  12. #27
    Kernel hacker
    Join Date
    Jul 2007
    Location
    Farncombe, Surrey, England
    Posts
    15,677
    The system will always attempt to use the CPU to 100% - only if there is no runnable task will it be lower than that. nice does not change what happens to a process that is sleeping because it's waiting for data from the disk, for example.

    In this case, the application will use as much CPU-time as it can (it is doing some disk IO at the start and end, but it's marginal in the overall runtime). Unless there are other tasks running on the same machine, there will be little or no benefit from using nice.

    --
    Mats
    Compilers can produce warnings - make the compiler programmers happy: Use them!
    Please don't PM me for help - and no, I don't do help over instant messengers.

  13. #28
    Registered User
    Join Date
    May 2008
    Posts
    10
    Hi,

    I investigated the pow thing further. It appears that even using -ffast-math it is slower. I suppose the reason is that I use x<1 e.G. mypow(15,0.25) as exponents.
    The other things work well. Thank you.

    Davoud

Page 2 of 2 FirstFirst 12
Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Running a program
    By dingolay in forum C Programming
    Replies: 4
    Last Post: 10-01-2006, 09:03 PM
  2. Running a console application
    By maxorator in forum C++ Programming
    Replies: 4
    Last Post: 10-03-2005, 04:23 AM
  3. Replies: 3
    Last Post: 09-05-2005, 08:57 AM
  4. Get the PID of a console program
    By BianConiglio in forum Windows Programming
    Replies: 6
    Last Post: 05-24-2004, 05:24 AM
  5. C++ console program using Ms Visual Studio .NET
    By matheo917 in forum C++ Programming
    Replies: 4
    Last Post: 09-05-2002, 11:16 PM

Tags for this Thread


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