How can i determine the length of a quantum

This is a discussion on How can i determine the length of a quantum within the C Programming forums, part of the General Programming Boards category; Originally Posted by Aga^^ i tried it and both %f and %lf gives the same result. (i looked it from ...

  1. #16
    Kernel hacker
    Join Date
    Jul 2007
    Location
    Farncombe, Surrey, England
    Posts
    15,677
    Quote Originally Posted by Aga^^ View Post
    i tried it and both %f and %lf gives the same result. (i looked it from an document)
    %lf MAY work - depending on what compiler you are using, and what C runtime it is. %lf for printf() means "long double" in some cases.

    How are you getting on with the task itself?

    --
    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
    Registered User Aga^^'s Avatar
    Join Date
    Aug 2008
    Posts
    71
    i m using Microsoft Visual C++ 6.0

    there are changes for the topic about measuring the quantum of the process.Like you said before measuring the quantum is difficult for me.So, if i can measure how long does the for loop run and add an exe of the program into the code (i mean when the program starts it also starts the same program while running so there will 2 process) is enough for me.So i can run the same program at the same time (my computer is single processor thus there will be a difference between the running time of the 2 processes).

  3. #18
    Registered User
    Join Date
    Dec 2008
    Posts
    8
    in that problem, if we assume the switching process takes 1 milisecond, can we calculate the length of a quantum

  4. #19
    Kernel hacker
    Join Date
    Jul 2007
    Location
    Farncombe, Surrey, England
    Posts
    15,677
    Quote Originally Posted by gamze View Post
    in that problem, if we assume the switching process takes 1 milisecond, can we calculate the length of a quantum
    If you know the amount of time that a process switch takes, then you could theoretically calculate the number of context switches, yes, and there is no other overhead in the system. Just measure the time it takes to run one and two of those applications on a single core processor. The difference will be formed of overhead of process switching.

    However, I can guarantee that a process switch is MUCH faster than 1ms. On a reasonably modern machine, it's probably in the order of 1-20 microseconds, give or take a bit, and you can expect the quantum to be in the order of tens of milliseconds, so a 20 second run of your program will have about 1000 potential task-switches, so about 1 millisecond of extra time. Even if it is one millisecond per task switch, then you would have one second, which is about 5% on a single process. So you need to ensure that running the same process several times on it's own doesn't vary more than 10% of that (so less than 0.1 second per run), or you will not have any good measure at all.

    So, if we do not assume unrealistic task-switching times, the approach described above will be more influenced by other error factors (such as background processes, interrupts, and other interference).

    Edit: Am I right in assuming that this is a task given by a teacher at a school or some such? And the above suggestion of a computation intensive task being a way to find this number?


    --
    Mats
    Last edited by matsp; 12-01-2008 at 01:11 PM.
    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
    Dec 2008
    Posts
    8
    yes you are right but we know how to calculate it, but the teacher expects us to see that if I run a program twice, the running time of it(if there is a single cpu) should be twice more than its actual running time. let me explain it in that way, think that the running time of our program is 100 sec, when we run it twice at the same time, the running times become 205 sec and 206 sec so that 5+6=11 sec occurs because of the switching..our teacher said that we can assume the switching time 1 ms and then if i divide 11 sec by 1 ms, i am going to find the number of switches..but first of all how i am going to make that program run twice at the same time.?? the other is, i found some ways to do it (to make run them at the same time) but in that point there is another problem..my progrm runs 49 sec but when i run it twice, first program runs 77 secs and the other is 95 secs. but to be able to calculate the switching time, these values should be more than 98 sec..but it never happens so i cannot calculate..

    could i tell u y problem

  6. #21
    Kernel hacker
    Join Date
    Jul 2007
    Location
    Farncombe, Surrey, England
    Posts
    15,677
    So exactly what are you doing to take 100 seconds, and how are you starting the two applications?

    --
    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.

  7. #22
    Registered User
    Join Date
    Dec 2008
    Posts
    8
    Code:
    for(i=0;i<20000000;i++)
      {
              for(j=0;j<1000;j++)
    
              a=a+i;
      }
    i just wrote a for loop and i takes about 100 sec and i wrote a batch to make that process run twice ..but our teacher said that we can also click the execute of the program twice with a little delay.

  8. #23
    Registered User
    Join Date
    Dec 2008
    Posts
    8
    Code:
    for(i=0;i<20000000;i++)
      {
              for(j=0;j<1000;j++)
    
              a=a+i;
      }
    i just wrote a for loop and i takes about 100 sec and i wrote a batch to make that process run twice ..but our teacher said that we can also click the execute of the program twice with a little delay.

  9. #24
    Kernel hacker
    Join Date
    Jul 2007
    Location
    Farncombe, Surrey, England
    Posts
    15,677
    And what are you doing to measure the time?
    Also what does your batch file actually look like?

    A batch file should be fine, but you need to take care that you start both in separate processes.

    I wrote something for Windows that calculates the quantum, and it seems to give reasonable numbers - but not entirely consistent. I think part of it is that windows prioritizes the foreground (or background) processes. [My method doesn't use ANY form of approximations of number of task switches - it actively measures how long it is between two performance counter samples, and tries to determine the quantum length from that, by calculating the most common (and larger than a small amount, otherwise noise will be the most common quantum measurement).

    --
    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
    Registered User
    Join Date
    Dec 2008
    Posts
    8
    start D:\timer\Debug\timer.exe
    start D:\timer\Debug\timer.exe

    i just wrote these codesin my batch file sometimes it make them run at the same time but sometimes at different times..so i am not sure if batch make them run one and other or parallel..

    but the most important thing for me is that whenever i run them twice,the running times are not more than twice big of the actual program. so i am wondering is it true that like i said before, if the running time of a program is 100 sec, when we run them twice, it becomes 205 sec and 206 sec..

    whenever i try it didnt happen..always smaller than twice of the real run time

  11. #26
    Kernel hacker
    Join Date
    Jul 2007
    Location
    Farncombe, Surrey, England
    Posts
    15,677
    As a general rule, you can expect it to take double the time, yes. However, I ran your loop a few times (and I don't think for a second your loop is in itself a problem):
    Code:
    E:\Temp>a 8000
    a = 31999996000000728.000000, time = 52.546000
    
    E:\Temp>start a 8000 && a 8000
    a = 31999996000000728.000000, time = 103.906000
    
    E:\Temp>start a 8000 && a 8000
    a = 31999996000000728.000000, time = 108.859000
    (The 8000 is just so that I could vary how many outer loops it does without changing the code each time, as waiting 4 minutes is a bit beyond what I'm capable of). But as you can see, running twice takes approximately twice as long as running it once - but not exactly.

    This is one of the reasons I said "This method probably doesn't work" - trust me, I have been benchmarking OS's, including scheduling performance, quite a lot - and if it was that easy, I would do it that way...

    If you have a real-time OS, where you KNOW that there's nothing else running on the machine, no network, no background processes, etc, then yes, it would probably work. In a modern Windows XP or such, it would be much harder to do, because there is so much else involved that you have no control over.

    --
    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.

  12. #27
    Registered User
    Join Date
    Dec 2008
    Posts
    8
    thanks for all your helpings, really i appriciate it,thanks a lot..
    can i have one more question..system is dual core, so to see multitasking i need to execute the program four times..i try to write the batch file as you did,but wrote that code four times
    start D:\quantum\Debug\quantum.exe 8000 && D:\quantum\Debug\quantum.exe 8000
    but it always run twice not four do you know why

  13. #28
    Kernel hacker
    Join Date
    Jul 2007
    Location
    Farncombe, Surrey, England
    Posts
    15,677
    Quote Originally Posted by gamze View Post
    thanks for all your helpings, really i appriciate it,thanks a lot..
    can i have one more question..system is dual core, so to see multitasking i need to execute the program four times..i try to write the batch file as you did,but wrote that code four times
    start D:\quantum\Debug\quantum.exe 8000 && D:\quantum\Debug\quantum.exe 8000
    but it always run twice not four do you know why
    so do
    Code:
    start xx && start xx && start xx && xx
    That will run four copies of xx.

    Obviously, you do not need 8000 in your case, as the number of loops is hard-coded in your code [unless you have changed it].

    --
    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.

  14. #29
    Registered User
    Join Date
    Dec 2008
    Posts
    8
    thank you, thank you ,thank you a lot...you are genious finally i finished my homework by the great help of you and send it tomorrow..thnks again

  15. #30
    Kernel hacker
    Join Date
    Jul 2007
    Location
    Farncombe, Surrey, England
    Posts
    15,677
    Quote Originally Posted by gamze View Post
    thank you, thank you ,thank you a lot...you are genious finally i finished my homework by the great help of you and send it tomorrow..thnks again
    So, what result did you get? Just out of curiosity.

    I will post my code in the next couple of days - just for fun, of course.

    --
    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.

Page 2 of 3 FirstFirst 123 LastLast
Popular pages Recent additions subscribe to a feed

Similar Threads

  1. char Handling, probably typical newbie stuff
    By Neolyth in forum C Programming
    Replies: 16
    Last Post: 06-21-2009, 05:05 AM
  2. Strange string behavior
    By jcafaro10 in forum C Programming
    Replies: 2
    Last Post: 04-07-2009, 08:38 PM
  3. How to determine length of pointer array
    By Dr.Zoidburg in forum C Programming
    Replies: 12
    Last Post: 02-16-2009, 06:52 PM
  4. Determine length of an array
    By ulillillia in forum C Programming
    Replies: 7
    Last Post: 04-21-2007, 09:32 PM
  5. Replies: 3
    Last Post: 03-04-2005, 02:46 PM

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