Thread: How can i determine the length of a quantum

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    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

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

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

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

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

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

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

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

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, 04:05 AM
  2. Strange string behavior
    By jcafaro10 in forum C Programming
    Replies: 2
    Last Post: 04-07-2009, 07: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, 08:32 PM
  5. Replies: 3
    Last Post: 03-04-2005, 02:46 PM