32
edits
Changes
→Business Point of View Comparison for STL and TBB
'''GPU621 Darth Vector: C++11 STL vs TBB Case Studies'''
''Join me, and together we can fork the problem as master and thread''
</pre>
<u>'''parallel_invoke:'''</u> Provides support for parallel calling to functions provided in the arguments. It is defined within the header "'''tbb/parallel_invoke.h'''" and is coded as: <pre>
</pre>
===Allocaters===Handles memory allocation for concurrent containers. In particular is used to help resolve issues that affect parallel programming. Called '''scalable_allocater<type>''' and '''cache_aligned_allocater<type>'''. Defined in "'''#include <tbb/scalable_allocator.h>'''"
==TBB Memory Allocation & Fixing Issues from Parallel Programming==
To use a lock, you program must be working in parallel(ex #include <thread>) and should be completing something in parallel. You can find c++11 locks with #include <mutex>
Note that there can be problems with locks. If a thread is locked but it is never unlocked, any other threads will be forced to wait which may cause performance issues. Another problem is called "Dead Locking" where each thread may be waiting for another to unlock (and vice versa) and the program is forced to wait and wait .
Locks can solve the above issue but cause significant performance issues as the threads are forced to wait for each other before continuing. This performance hit is known as '''Lock Convoying'''.
[[File:DarthVector ThreadLock.PNG |thumb|center|400px600px| Performance issues inside STL]]
===Lock Convoying in TBB===
TBB attempts to mitigate the performance issue from parallel code when accessing or completing an operation on a container through its own containers such as concurrent_vector.
Through '''concurrent_vector''', every time an element is accessed/changed, a return of the index location is given. TBB promises that any time an element is pushed, it will always be in the same location, no matter if the size of the vector changes in memory. With a standard vector, when the size of the vector changes, the data is copied over. If any threads are currently traversing this vector when the size changes, any iterators may no longer be valid. This support also goes further for containers so that multiple threads can iterate through the container while another thread may be growing the container. An interesting catch though is that anything iterating may iterate over objects that are being constructed, ensuring construction and access remain synchronized.
[[File:Gpuconcur.PNG |thumb|center|600px| concurrent_vector use with multiple threads]]
TBB also provides its own versions of the mutex such as ''spin_mutex'' for when mutual exclusion is still required.
==Business Point of View Comparison for STL and TBB==
{| class="wikitable collapsible collapsed" style="text-align: left;margin:0px;"
===Which library is better depending the on the use case?===
The real question is when should you parallelize your code, or to just keep it serial? TBB helps to lower the cost of smaller performance benefitis for multi-threading and STL is for single threading workloads. Due The fastest known serial algorithm maybe difficult or impossible to TBB requiring less effort to implementparallelize. Compared Some aspects to other multi-threading librarieslook out for when parallelizing your code are; *Overhead whether it maybe in communication, idling, load imbalance, synchronization, and excess computation
*If are just trying to parallelize a section Efficiency which is the measure of your code with processor utilization in a simple map, scan, or reduce pattern. Without much thought TBB has you covered.*When working with large collections of data TBB with its use of block range coupled with it algorithms makes it simpler to come up with solutions for the collectionparallel program
===Implementation Safety for TBB Identifying the worries and STL responsibilities ===We are all human and we do make mistakes. Less mistakes done by developers will equal to less wasted time.
*Thread Creation, terminating, and synchronizing, partitioning is managed , and management must be handled by TBByou. This creates a layer of safety on increases the work load and the programmer’s endcomplexity, has they do not have to deal with the threads themselves, making thread creation and overall resource for STL is managed by a developer less prone to make mistakes in their codecombination of libraries.
*Dividing collection of data is more of the problem when using the STL containers.
'''What you don’t need to worry about'''
*Making sorting, searching algorithms.
*Partitioning data.
*Array algorithms; like copying, assigning, and checking data
Note all algorithms is done in serial, and may not be thread safe
====TBBWorries and Responsibilities====*Thread Creation, terminating, and synchronizing, partitioning, thread creation, and management is managed by TBB. This make you need not to worry about the heavy constructs of threads which are close to the hardware level.
*Making a solution from close to hardware level allows Own Parallel algorithms (makes you need not to be flexible to worry about the solution you heavy constructs of threads that are wanting to make. But present in the major downside is the requirement lower levels of implementing the foundations first to make your solution workprogramming. It also simple map, scan, pipeline, or reduce TBB has the potential of making your program inefficient if not done correctly.you covered
'''Benefit'''
The downside of TBB is since much of the close to hard hardware management is done be hide the scenes, it makes you has a developer have less control on finetuning your program. Unlike how STL with the threading library allows you to do.
===Licensing===
TBB is dual-licensed as of September 2016
*COM license as part of suites products. Offers one year of technical support and products updates
*Apache v2.0 license for Open source code. Allows the user of the software the freedom to use the software for any purpose, to distribute it, to modify it, and to distribute modified versions of the software, under the terms of the license, without concern for royalties.
===Companies and Products that uses TBB===
*DreamWorks (DreamWorks Fur Shader)
*Blue Sky Studios (animation and simulation software)
*Pacific Northwest National Laboratory (Ultrasound products)
*More: https://software.intel.com/en-us/intel-tbb/reviews