Forums Register Login

Performance with threads

+Pie Number of slices to send: Send
Hi,
I have a thread which counts from say 1 to 1 million and it takes 60 seconds to do so.
If i use four threads to do the same task , will the time be less or be the same ? According to me it should be the same since they are sharing the same CPU.
Now if I use four threads on four different CPUs, should the time reduce to 15 secs ? since all thread will run together (in the real sense, no sharing of CPU)
Can ne one please explain !!
Thanks
+Pie Number of slices to send: Send
Hey nobody for this Q ???
+Pie Number of slices to send: Send
If you were to create four threads, one which counted from 1 to a quarter million, one which counted from a quarter million to half a million, etc., then you are correct. Actually the multi-threaded on one CPU approach may take a bit longer than expected because of time spent switching from one thread to the next.
+Pie Number of slices to send: Send
Say you did have 4 CPUs, how could you tell each thread to run on a separate CPU?
+Pie Number of slices to send: Send
 

Originally posted by James Davis:
Say you did have 4 CPUs, how could you tell each thread to run on a separate CPU?


I don't know anything about internal OS and hardware stuff, but I think you just create threads and pray that it works out.
+Pie Number of slices to send: Send
It depends on your OS. There have been some Operating Systems which supported programmatic assignment of task to CPU. For example the Cray supercomputer version of UNIX, UNICOS would allow you to direct certain processes & threads to certain CPUs. However most popular OS's assign tasks to processors using their own scheduler and you have no control over this. If you think about it anyway the scheduler can do a much better job anyway since it knows the current CPU state.
[ November 30, 2002: Message edited by: Jim Baiter ]
Eat that pie! EAT IT! Now read this tiny ad. READ IT!
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com


reply
reply
This thread has been viewed 555 times.
Similar Threads
Executor runnable priority
Garbage collection thread belongs to which priority..min?normal?max?
Threads management for daemon programs
Problems with thread priority
Thread.sleep. What guarantees?
More...

All times above are in ranch (not your local) time.
The current ranch time is
Apr 16, 2024 10:04:28.