Open main menu

CDOT Wiki β

Changes

Team Darth Vector

3,001 bytes added, 22:27, 11 December 2017
Code Implementation Comparison for STL and TBB
==Code Implementation Comparison for STL and TBB==
{| class="wikitable collapsible collapsed" style="text-align: left;margin:0px;"
|-
! style="width:20em;" |COLUMN1
! style="width:20em;" |COLUMN2
|-
|ROW1
|ROW1/COL2
|-
|ROW2
|ROW2/COL2
|-
|}
====Parallel Algorithms support=Which library is better depending the on the use case?===
C++11 STL does not have much One major aspect to offer look for parallel algorithms natively unlike TBBwhen 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?
''Though there If are new 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 working with large collections of data TBB with it use of block range coupled with it algorithms makes it simpler to come up with solutions for parallelism in the C++17 standard''collection
''More: http://wwwTBB helps to lower the cost of smaller performance benefit.bfilipekDue to TBB requiring less effort to implement.com/2017/08/cpp17-details-parallel.html''
====Resource management====TBB enables you to specify logical parallelism instead of threads. It eliminates the time 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.
Overall partitioningWhen trying to fine tune performance, thread creationhave more control near hardware level, and management or you need to work near hardware level, the STL library is hidden in TBBthe 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.
Thread Creation, terminating, and synchronizing is handled by ===Implementation Safety for TBB===
The thread creation We are all human and overall resource for STL is managed by a combination of libraries;we do make mistakes.
-thread for creation and joiningLess mistakes done by developers will equal to less wasted time.
-mutex for mutual exclusion TBB specifically makes it concurrent_vector container not to support insert and lockserase operations. Only new items can only be pushed back, and cannot be shrunk;
-future This prevents developers to write bad code. If for accessing results of asynchronous example, we would allow insert and erase operationson concurrent_vector. It could cause a big performance hit, burdening both iterating and growing operations. Which will not only make the concurrent containers in TBB unless, but also your program inefficient.
''Details: http://enAs already stated most of the STL containers are not thread safe.cppreferenceThough some operations in TBB containers are also not thread safe, like reserve() and clear() in concurrent_vector.com/w/cpp/thread''
====Implementation Safety====Thread Creation, terminating, and synchronizing, partitioning is managed by TBB specifically makes concurrent vector not to support insert and erase operations. Only new items can only be pushed back, and cannot be shrunk; -This prevents devs to write bad code -Allowing this could cause creates a mistake layer of safety on implementing parallel code. Which will cause a big performance hitthe programmer’s end, burdening both iterating and growing operations. Which will make has they do not have to deal with the concurrent containers in TBB unless due threads themselves, making a developer less prone to this riskmake mistakes.
'''Note for TBB (to trash less on STL)'''=== Identifying the worries and responsibility when parallelizing code ===
-Some operations The increasing complexity of your code is a natural problem when working in TBB containers are not thread safe, like reserve() and clear() parallel. Knowing the responsibilities as in concurrent vectorwhat you must worry about as a developer is key. When trying quickly implement parallel regions in your code.
-Complexity on concurrent containers ====STL====Thread Creation, terminating, and synchronizing, partitioning, thread creation, and management must be handled by the programmer.  This increases the work load and the complexity. The thread creation and overall resource for STL is managed by a combination of libraries. Dividing collection of data is more of the problem when using STL. 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. The benefit of STL is higher compared due to STLthe fact that you must manage the thread/ resources yourself it give you more control on the code, and fine tuning optimizations. For layouts Though this can be a double edge sword and implementationwith more control, it will take time implementing the code. Not also mentioning the increase in complexity.  ====TBB==== Thread Creation, terminating, and synchronizing, partitioning, thread creation, and management is managed by TBB. This due make you need not to worry about the heavy constructs of threads which are close to the hardware level. Having it close to hardware level makes it less flexible and require writing more need less code. It also has the nature potential of running making your program inefficient if not done correctly. Like already stated TBB does have Parallel Algorithms support.  The great benefit of TBB is that it is made in parallel such a way that you as a programmer can only worry about one thing. How to parallelize your serial code, and how need to not to worry about the resource management.  The TBB model allows you to make quick parallel implementation solutions with less amount of effort. implements The downside of TBB is since much of the close to hard hardware management is done be hide the scenes, itmakes you has a developer have less control on finetuning your program. Unlike how STL allows you to do.  //Leo Note: WIP, maybe will make this look better.
32
edits