|
-
April 17th, 2008, 09:10 PM
#1
is vector efficient with multiple thread?
If a vector is synchronized, will multiple thread be more efficient than a single thread?
What is other alterative to a vector in the context of multi-thread?
Thanks,
CR
-
April 17th, 2008, 09:13 PM
#2
Re: is vector efficient with multiple thread?
I don't see how the number of threads will have any effect on which data structure you choose, except insofar as the data structure is determined by the overall parallelness of the design.
-
April 17th, 2008, 09:18 PM
#3
Re: is vector efficient with multiple thread?
Suppose one thread accesses the first part of a vector and another thread operates on the second part of the vector.
If the vector can only be accessed by one thread at a time, one thread has to wait for the other one. Then, multiple thread is worse than a single thread taking into account additional threading overhead.
is that right?
Last edited by caperover2002; April 17th, 2008 at 09:26 PM.
-
April 17th, 2008, 09:21 PM
#4
Re: is vector efficient with multiple thread?
If the vector is syncronized with a mutex, then yes.
Typically multithreaded design should try to avoid such dependencies.
-
April 17th, 2008, 09:27 PM
#5
Re: is vector efficient with multiple thread?
I am using stl library.
I observed that four thread is slower than one single thread and I am trying to figure out why?
-
April 17th, 2008, 09:42 PM
#6
Re: is vector efficient with multiple thread?
The use of multiple threads should be a design choice, not an optimization choice. Yes, running with multiple threads may get you more cores, but that isn't guaranteed.
Unless of course you're doing GPU programming with OpenGL or CUDA, in which case, the point of the design is optimization, so they're really the same concern. But CUDA threads aren't really the same as CPU threads in any case, so don't concern yourself with that if you don't know what it means.....
Last edited by Lindley; April 17th, 2008 at 09:47 PM.
-
April 18th, 2008, 02:09 AM
#7
Re: is vector efficient with multiple thread?
As mentioned in the other thread, you need to synchronize access to any resource shared between threads.
Given that if the resource (like a vector) contains data that can manipulated from separate threads (meaning data at each index can be processed and written back to the same index), you can often improve performance during lengthy thread operations by locking the vector copying the data from and index and unlocking the data. When the thread has finished it's work it locks/unlocks to write the data back to the index.
But this is one strategy and there are others to help minimize lock time and improve performance.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|