Changes

Jump to: navigation, search

Team Darth Vector

1,792 bytes added, 22:06, 14 December 2017
List of TBB containers
tbb:concurrent_vector<typename> name; </pre>
 
 
<nowiki>
#include <iostream>
#include <tbb/tbb.h>
#include <tbb/concurrent_vector.h>
#include <vector>
#include <fstream>
#include <cstring>
#include <chrono>
#include <string>
 
using namespace std::chrono;
 
// define a stl and tbb vector
tbb::concurrent_vector<std::string> con_vector_string;
std::vector<std::string> s_vector_string;
 
tbb::concurrent_vector<int> con_vector_int;
std::vector<int> s_vector_int;
 
 
 
void reportTime(const char* msg, steady_clock::duration span) {
auto ms = duration_cast<milliseconds>(span);
std::cout << msg << " - took - " <<
ms.count() << " milliseconds" << std::endl;
}
 
int main(int argc, char** argv){
if(argc != 2) { return 1; }
int size = std::atoi(argv[1]);
 
steady_clock::time_point ts, te;
/*
TEST WITH STRING OBJECT
*/
ts = steady_clock::now();
// serial for loop
for(int i = 0; i < size; ++i)
s_vector_string.push_back(std::string());
te = steady_clock::now();
reportTime("Serial vector speed - STRING: ", te-ts);
 
ts = steady_clock::now();
// concurrent for loop
tbb::parallel_for(0, size, 1, [&](int i){
con_vector_string.push_back(std::string());
});
te = steady_clock::now();
 
reportTime("Concurrent vector speed - STRING: ", te-ts);
 
/*
TEST WITH INT DATA TYPE
*/
 
std::cout<< "\n\n";
ts = steady_clock::now();
// serial for loop
for(int i = 0; i < size; ++i)
s_vector_int.push_back(i);
te = steady_clock::now();
reportTime("Serial vector speed - INT: ", te-ts);
 
ts = steady_clock::now();
// concurrent for loop
tbb::parallel_for(0, size, 1, [&](int i){
con_vector_int.push_back(i);
});
te = steady_clock::now();
 
reportTime("Concurrent vector speed - INT: ", te-ts);
 
}
 
</nowiki>
 
 
'''<u>concurrent_hash_map</u>''' : A container class that supports hashing in parallel. The generated keys are not ordered and there will always be at least 1 element for a key. Defined within "'''tbb/concurrent_hash_map.h'''"
20
edits

Navigation menu