Changes

Jump to: navigation, search

GPU621/Distributed Workload

2,881 bytes added, 03:59, 3 December 2018
no edit summary
== Overview ==
'''==== TBB''': <br />====
Is a template library developed by Intel to provide methods to facilitate parallel programming. This is done by dividing a computation into tasks that can be scheduled to run in parallel threads on multi-core processors <br />
Threading Building Blocks includes algorithms, concurrent containers, locks and memory allocation tools. <br />
TBB is designed to work with any C++ compiler. <br />
'''STL''': <br pre>#include <tbb/tbb.h> blocked_range<int> range0(0 ,40);for (auto i = range.begin(); i != range.end(); i++) { b[i] = 2 * a[i] + b[i];}</pre>==== STL ====
The Standard Template Library also extends useful functionality, including generic data structures, containers, iterators and algorithms that can be used to write clean efficient code. <br />
The person who in 1979 was initially interested with ideas of generic programming, his work at AT&T and Bell Laboratories eventually lead to a proposal to the ANSI/ISO for the standardization of STL into the C++ standard.
[[File<pre>#include <iostream>#include <vector>int main () { std::vector<int> myvector; for (int i=0; i < 6; i++) myvector.push_back(i);  for (std::vector<int>::iterator it = myvector.begin(); it != myvector.end(); ++it) std::cout << ' ' << *it; std::cout << '/n';}</pre> == Comparison ==Both libraries use C++ templates to provide generic programming structures. The libraries do overlap when it comes to the functionality they provide, however STL is designed to be more general use and TBB specializes on parallel programming with threads. <br />==== Iterators ==== Both libraries use random access iterators to ease navigation of containers. TBB follows the standard set by STL and the ISO C++ standard, but they also extend them so that <code>tbb::concurrent_vector<T></code> can be used safely in parallel threads. <br />==== Containers ==== '''STL''' implements the following common containers* vector* list* queue* stack* map'''TBB''' does not implement as many containers however it does include some that are useful in parallel programming and extends their functionality.* blocked_range<T>* concurrent_hash_map<T>* cuncurrent_vector<T>* concurrent_queue<T> ==== Algorithms ====Some serial algorithms exist for STL that can preform tasks such like searching and sorting. These functions are typically used to operate on the containers like <code>std::merge()</code> and <code>std::Parallel_forsort()</code> <br />The algorithms in '''TBB''' are much more vital to the usefulness of the library.PNG|344px|thumb|left|'''TBB ''' uses templated functions like* parallel_for(range, body [, partitioner]);* parallel_scan(range, body [, partitioner]); * parallel_reduce(range, body [, partitioner]);These functions operate on the <code> blocked_range </code> container class in '''TBB''' to preform operations in parallel as described in the <code> body </code> object, typically by overloading the <code>() operator</code>. The following code snippet will demonstrate a simple <code>parallel_reduce</code> implementation.<pre>#include "tbb/parallel_reduce.h"#include "tbb/blocked_range.h" using namespace tbb; struct Sum { float value; Sum() : value(0) {} Sum( Sum& s, split ) {value = 0;} void operator()( const blocked_range<float*>& r ) { float temp = value; for( float* a=r.begin(); a!=r.end(); ++a ) { temp += *a; } value = temp; } void join( Sum& rhs ) {value += rhs.value;}}; float ParallelSum( float array[[File:Vector_iter], size_t n ) { Sum total; parallel_reduce( blocked_range<float*>( array, array+n ), total ); return total.value;}</pre>Some things to notice about this code are as follows. All of the reduce operations are done in the overloaded () operator.PNG|500px|thumb|right|STL Vector The <code>join()</code> and Iterators]]<code>Sum(Sum& s, split)</code> split constructor are needed to split the blocked_range
24
edits

Navigation menu