# Thread: How can i determine the length of a quantum

1. ## How can i determine the length of a quantum

the topic is writing a program that determines the length of a quantum in the OS loaded in the computer.

I think, program is a simple program doing nothing but integer operations for a long time, say for 20secs. Let us run this program twice unless our computer is not dual core system the processes normally will run in 41 says.The one second delay is due to switching. From here, we may calculate how many quanta are used per process; then, we may calculate the duration of a quantum. Our program should measure the time in milliseconds for accuracy.

2. And your question would be?

3. how can be this program in c?can you give me some examples?

4. I don't think the description of the problem is accurate in the first post. You want to measure the amount of time of the overhead of running two processes instead of one, and from that determine the quanta? In my (computer) vocabulary, quanta means the amount of time a process may run continously before another runnable process gets switched in.

Now, lets say that we have a 20 second runtime, and we run the process twice at the same time, and it now take 41 seconds to complete. What does that tell us? Nothing. Because we do not know HOW LONG it takes to switch from one task to another, and we do not know how many times those two tasks switched.

It gets even worse if we have a modern processor, as modern processors are rather complex and not entirely predictable when it comes to cache-hitrate and other complicated matters that affect the overall time the application runs.

There may well be ways to determine how long the quanta is, but I doubt that it's as simple as what you describe.

--
Mats

5. i am asked to determine the length of a quantum in the operating system and writing a set of comp. progs in a high level of language C. One of the progs is a simple prog doing nothing but integer operations for a long time, say for 20secs. Let us run this program twice ( you may want to have another program to run it twice with the least possible delay) Unless your system is a dual core system, the two processes will run slightly longer than twice as they would normally run, say 41 secs. The one second delay is due to switching. From here we may calculate how many quanta are used per process, then we may calculate the duration of quantum. The program should measure the time in milliseconds for accuracy. You may have other ideas such as running more than two copies of program in parallel...

6. Feline, are you the same person as Aga, or just in the same class? Is there some part of my answer in post 3 that you do not understand the concept of.

Running two instances of the application will tell you the overhead of running two applications at once, but it will NOT tell you the scheduling quantum parameter - because you do not know either of how many task switches there are, or the amount of time that a schedule another task in itself takes. These values in themselves vary a bit depending on cache-hit-rate in the scheduler just to mention ONE of many parameters.

So you may know that the overhead of running two applications is 1.52 seconds. But if the OS task switched once, 100 times or 10000 times will not be something you know. And you also do not know how much overhead EACH task switch takes. That would vary depending on lots of things - try writing a program that sums all numbers 0..1000000 [to make sure it doesn't overflow, make the result a double] a few hundred times (enough to take 20 seconds, say). Then do the same task again, but instead of using a simple counter, fill a 1 million entry array [make the array a global variable] with with the values 0..1000000 in the array, and calculate the sum by reading the array instead of just adding a loop variable to the sum. This will use 4MB of memory instead of a few dozen bytes for each complete loop. Run both once and then two copies. I think you'll find that the overhead in the array case will be MUCH larger (as a proportion of the time taken).

There is probably a way to determine the scheduling of the processor (at least get some reasonable measure of the apparent values), such as reading a high precision timer in a tight loop in two different processes, and seeing if there are "gaps" in the time. If there is a gap, that's the amount of time another process ran for.

Of course, the next problem is that other processes than yours WILL run on a system - so you may receive a network package that requires the computer to do some sort of work, and that interferes with your current task. That's part of the overhead of a computer.

--
Mats

7. Code:
```#include <stdio.h>

int main()
{

double a=0;
double i;
double total;

for(i=0;i<1000000;i++)
{
a=a+i;
}

total=a;
printf("Sum of numbers %d :",total);

return 0;

}```
the output of this code is -1179123712 how can be this i can not understand.

8. Originally Posted by Aga^^
Code:
`	printf("Sum of numbers %d :",total);`
the output of this code is -1179123712 how can be this i can not understand.
Because you are printing a double as a integer value.

--
Mats

9. &#37;d is not what you meant to use, read the doc...

10. thanks for your helps
for 2 years i have not used c so i forgot some things
Code:
```#include <stdio.h>

int main()
{

double a=0;
double i;
double total;

for(i=0;i<1000000;i++)
{
a=a+i;
}

total=a;
printf("Sum of numbers %lf :",total);

return 0;

}```
now how can i measure the length of a quantum?

11. Like I said earlier, you can't with that type of code (unless I've been working with operating systems and task switching code for 15+ years and not understood how they work...)

--
Mats

12. hmm you are right. but a little part of the code about measuring the quantum is enough for me

13. Originally Posted by Aga^^
hmm you are right. but a little part of the code about measuring the quantum is enough for me
Like I said, measure time with reasonably high precision (QueryPerfomanceCounter on Windows, gettimeofday in Linux) in a tight loop, and see if there are "gaps". Run two of those processes at the same time, and the "gaps" should correspond to the quantum.

--
Mats

14. double needs &#37;f format in printf, %lf format is for scanf

15. i tried it and both &#37;f and %lf gives the same result. (i looked it from an document)

Popular pages Recent additions