Open main menu

CDOT Wiki β

Changes

Team Darth Vector

958 bytes added, 23:59, 13 December 2017
Code Implementation Comparison for STL and TBB
https://www.inf.ed.ac.uk/teaching/courses/ppls/TBBtutorial.pdf
==Code Implementation 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?===
One major aspect to look for when parallelizing a piece of code is the Cost- Benefit. Is it worth the time and effort to parallelize a part of your software only to get a small performance gain? Or is just faster to keep in serial? Many of these questions must be answered when deciding to parallelize your code or not.
One major aspect TBB helps to look for when parallelizing a piece lower the cost of code is the Cost- Benefitsmaller performance benefit. Is it worth the time and Due to TBB requiring less effort to parallelize a part of your software only implement. Compared to get a small performance gain?other multi-threading libraries
*If are just trying to parallelize a section of your code with a simple map, scan, or reduce pattern. Without much thought TBB has you covered. Also, when *When working with large collections of data TBB with it its use of block range coupled with it algorithms makes it simpler to come up with solutions for the collection
TBB helps enables you to lower specify logical parallelism instead of threads. It eliminates the cost of smaller performance benefittime needed when developing a backbone for your code when working with threads. For quick and easy solutions for parallelize your code TBB is the way to go. STL stands on its own right, with its well-designed serial features. Due When trying to have more control near hardware level, or you need to TBB requiring less effort work near hardware level, the STL library with the threading libraries is the way to implementgo. Though there are thread safety issues.  '''Conclusion'''
TBB enables only gives you parallel solutions, STL gives you to specify logical parallelism instead of threads. It eliminates the time needed when developing a backbone foundations for many serial algorithms for your code when working with threads. For quick sorting, searching, and easy solutions for parallelize your code TBB is the way to goa verity of containers.
When trying to fine tune performance, have more control near hardware level, or you need to work near hardware level, the STL library is the way to go.
If you are trying to create your own model / deeper threading solution STL gives you the foundations without the needless level of abstraction of other 3rd party’s software.
===Implementation Safety for TBB and STL ===
We are all human and we do make mistakes. Less mistakes done by developers will equal to less wasted time.
We are all human *TBB specifically makes concurrent_vector container not to support insert and we do make mistakeserase operations. Only new items can be pushed back, and cannot be shrunk.
Less mistakes done by ** This prevents developers to write bad code. If for example, we would allow insert and erase operations on concurrent_vector, it could cause a big performance hit. This performance hit can burden both iterating and growing operations which will equal to less wasted timenot only make the concurrent containers in TBB unless, but also your program inefficient.
*As already stated most of the STL containers are not thread safe. Though some operations in TBB specifically makes it concurrent_vector container containers are also not to support insert thread safe, like reserve() and erase operationsclear() in concurrent_vector. Only new items can only be pushed back, and cannot be shrunk;
This prevents developers to write bad code. If for example*Thread Creation, terminating, we would allow insert and erase operations on concurrent_vectorsynchronizing, partitioning is managed by TBB. It could cause This creates a big performance hitlayer of safety on the programmer’s end, burdening both iterating and growing operations. Which will has they do not only have to deal with the threads themselves, making a developer less prone to make the concurrent containers mistakes in TBB unless, but also your program inefficienttheir code.
As already stated most of the STL containers are not thread safe. Though some operations in TBB containers are also not thread safe, like reserve() and clear() in concurrent_vector.
=== Identifying the worries and responsibility when parallelizing code ===The increasing complexity of your code is a natural problem when working in parallel. Knowing the responsibilities as in what you must worry about as a developer is key. When trying quickly implement parallel regions in your code, or to just to keep your code serial.====STL===='''If you are going to try to parallelize your code using STL coupled with the threading libraries this is what you must worry'''*Thread Creation, terminating, and synchronizing, partitioning , thread creation, and management must be handled by you. This increases the work load and the complexity. *The thread creation and overall resource for STL is managed by TBBa combination of libraries. This creates a layer *Dividing collection of data is more of safety on the programmer’s end, has they do problem when using the STL containers. Also mentioning that is not thread safe.*C++11 does not have to deal with any parallel algorithms. So, any common parallel patterns such as; map, scan, reduce, must be implemented by yourself, or by another library. But the threads themselveslatest STL C++17, making a developer less prone to make mistakeswill have some parallel algorithms like scan, map, and reduce.
=== Identifying The benefit of STL is due to the worries fact that you must manage the thread/ resources yourself which give you more control on the code, and responsibility when parallelizing fine tuning optimizations. Nonetheless, managing the thread yourself can be a double edge sword since with more control, it will take time implementing the code ===and the level of complexity will increase.
The increasing complexity of your code is a natural problem when working in parallel. Knowing the responsibilities as in what '''What you must don’t need to worry about as a developer is key. When trying quickly implement parallel regions in your code''' *Making sorting, searching algorithms.
====STL====Thread Creation, terminating, and synchronizing, partitioning, thread creation, and management must be handled by the programmer*Partitioning data.
This increases the work load *Array algorithms; like copying, assigning, and the complexity. The thread creation and overall resource for STL is managed by a combination of libraries.checking data
Dividing collection *Types of data is more of the problem when using STL.storage
C++11 does not have any parallel algorithms. So, any common parallel patterns such as; map, scan, reduce, must be implemented by yourself, or by another library. But the latest STL C++17, will have some parallel algorithms like scan, map, and reduce.*Value pairing
The benefit of STL Note all algorithms is due to the fact that you must manage the thread/ resources yourself it give you more control on the codedone in serial, and fine tuning optimizations. Though this can may not be a double edge sword and with more control, it will take time implementing the code. Not also mentioning the increase in complexity. thread safe
====TBB====
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.
Thread Creation, terminating, and synchronizing, partitioning, thread creation, and management is managed by TBB. This make *Making a solution from close to hardware level allows you need not to worry about be flexible to the heavy constructs of threads which solution you are close wanting to make. But the major downside is the hardware level. Having it close requirement of implementing the foundations first to hardware level makes it less flexible and require writing more need less codemake your solution work. It also has the potential of making your program inefficient if not done correctly.
Like already stated TBB does have Parallel Algorithms support, that has been already mentioned.
The great benefit of TBB is that it is made in such a way that you as a programmer can only worry about one thing. How to parallelize your serial code, and need to not to worry about the resource management. '''Benefit'''
The benefit of TBB is that it is made in such a way that you as a programmer can only worry about one thing; how to parallelize your serial code. You do not need to worry about the resource management. The TBB model allows you to make quick parallel implementation solutions with less amount of effort. 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 allows you to do.
'''Downside'''
//Leo Note: WIPThe downside of TBB is since much of the close to hard hardware management is done be hide the scenes, maybe will make this look betterit makes you has a developer have less control on finetuning your program. Unlike how STL with the threading library allows you to do.
32
edits