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.
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).
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.
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
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.
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.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.Code:for(i=0;i<20000000;i++) { for(j=0;j<1000;j++) a=a+i; }
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.
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
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):
(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.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
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.
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
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.
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
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.