• Post Reply Bookmark Topic Watch Topic
  • New Topic

Performance with threads

 
Shilpa Bhargava
Ranch Hand
Posts: 39
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
Shilpa Bhargava
Ranch Hand
Posts: 39
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hey nobody for this Q ???
 
David Weitzman
Ranch Hand
Posts: 1365
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Chris Stewart
Ranch Hand
Posts: 184
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Say you did have 4 CPUs, how could you tell each thread to run on a separate CPU?
 
David Weitzman
Ranch Hand
Posts: 1365
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Jim Baiter
Ranch Hand
Posts: 532
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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 ]
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!