提问人:AwaitedOne 提问时间:3/7/2018 最后编辑:1201ProgramAlarmAwaitedOne 更新时间:3/10/2018 访问量:117
使用 TBB 插入到无序升压双映射中
Insert into an unordered boost bimap using TBB
问:
我对 .我正在尝试在无序的 bimap 中插入 pair,其中 is of type 和 is type .我尝试创建 ,它在文件中,看起来像TBB
<key, value>
key
uint64_t
value
string
loop object
TBB.h
void ParallelIndex(uint64_t &kmer_len, std::string &split_kmer, std::string &sequence_content,
uint64_t &sequence_length, size_t &kmer_position ) {
parallel_for( blocked_range<size_t>(0, sequence_length),
[&](const blocked_range<size_t>& r) {
for(i = r.begin(); i < r.end(); ++i ){
split_kmer = sequence_content.substr(i, kmer_len);
reference_index_vector.insert(position(kmer_position, split_kmer));
i += kmer_len-1;
kmer_position += kmer_len;
}
}
);
}
在函数中,我尝试调用该函数main
TBB.cpp
index.ParallelIndex(index.kmer_len, index.split_kmer, index.sequence_content,
index.sequence_length, index.kmer_position );
它从 0 开始,一直到 n。我试图增加 5(首先和 ,就像直到 n),但只增加了 1。i
++i
i +=kmer_len-1
i = 0, 5, 10, 15, ...
i
完整代码如下所示:
TBB.cpp
#include <iostream>
#include <string>
#include <algorithm>
#include <boost/bimap.hpp>
#include <boost/bimap/unordered_set_of.hpp>
#include <boost/bimap/unordered_multiset_of.hpp>
#include "tbb/parallel_for.h"
#include "TBB.h"
#include "tbb/tbb.h"
#include <tbb/blocked_range.h>
using namespace tbb;
namespace bimaps = boost::bimaps;
typedef boost::bimap<bimaps::unordered_set_of<uint64_t>,
bimaps::unordered_multiset_of<std::string> > bimap_reference;
typedef bimap_reference::value_type position;
bimap_reference reference_index_vector;
uint64_t thread_test::create_index::kmer_len = 5;
std::string thread_test::create_index::split_kmer = "";
std::string thread_test::create_index::sequence_content = "ABCDDBACDDDCBBAAACBDAADCBDAAADCBDADADACBDDCBBBCDCBCDAADCBBCDAAAD";
uint64_t thread_test::create_index::sequence_length = 0;
size_t thread_test::create_index::kmer_position = 0;
size_t thread_test::create_index::i = 0;
int main(){
thread_test::create_index index;
index.sequence_length = index.sequence_content.length();
index.ParallelIndex(index.kmer_len, index.split_kmer, index.sequence_content,
index.sequence_length, index.kmer_position );
for( bimap_reference::const_iterator iter = reference_index_vector.begin(), iend = reference_index_vector.end();
iter != iend; ++iter ) {
std::cout << iter->left << " <--> "<< iter->right <<std::endl;
}
}
待定
#ifndef TBB_H_
#define TBB_H_
#include<iostream>
#include <algorithm>
#include <utility>
#include <boost/bimap.hpp>
#include <boost/bimap/unordered_set_of.hpp>
#include <boost/bimap/unordered_multiset_of.hpp>
#include "tbb/tbb.h"
#include <tbb/parallel_for.h>
#include <tbb/blocked_range.h>
#include <tbb/mutex.h>
using namespace tbb;
namespace bimaps = boost::bimaps;
typedef boost::bimap<bimaps::unordered_set_of<uint64_t>,
bimaps::unordered_multiset_of<std::string > > bimap_reference;
typedef bimap_reference::value_type position;
extern bimap_reference reference_index_vector;
namespace thread_test{
class create_index{
public:
static uint64_t kmer_len;
static std::string split_kmer;
static std::string sequence_content;
static uint64_t sequence_length;
static size_t kmer_position;
static size_t i;
// using lambda function
void ParallelIndex(uint64_t &kmer_len, std::string &split_kmer, std::string &sequence_content,
uint64_t &sequence_length, size_t &kmer_position ) {
parallel_for( blocked_range<size_t>(0, sequence_length),
[&](const blocked_range<size_t>& r) {
for(i = r.begin(); i < r.end(); ++i ){
split_kmer = sequence_content.substr(i, kmer_len);
reference_index_vector.insert(position(kmer_position, split_kmer));
i += kmer_len-1;
kmer_position += kmer_len;
}
}
);
}
};
}
#endif /* TBB_H_ */
问题增加了 1,但我尝试如上所述将其增加 5。i
答:
1赞
Agaz Wani
3/9/2018
#1
更改为 .在第一种情况下,您正在重新初始化 .for(i = r.begin(); i < r.end(); ++i )
for(; i < r.end(); ++i )
i = r.begin()
评论
operator()
tbb::parallel_for
const
TBB.cpp:(.text._ZNK11thread_test12create_indexclERKN3tbb13blocked_rangeImEE[_ZNK11thread_test12create_indexclERKN3tbb13blocked_rangeImEE]+0x35): undefined reference to
static
main()
uint64_t thread_test::create_index::kmer_len = 5;