最近,我使用OpenMP
Parallel For
来加速计算。在OMP
代码运行之前,我使用 OMP
函数为每个vector resize
个线程准备了独立的存储空间。
问题在于:当我使用vector< vector<> >
类型时,程序会在几个小时内导致core dump
,但使用vector< vector<>* >
则不会。我对OpenMP
不太熟悉,无法理解这个问题。非常感谢任何帮助。
以下是代码:
//near_geohash_vec.size() == 9
std::vector< std::vector<mtads_frame::PoiInfo* > > poi_info_vec_vec;
poi_info_vec_vec.resize(near_geohash_vec.size());
std::vector< std::vector< DealRespRet* > > deal_ret_vec_vec;
deal_ret_vec_vec.resize(near_geohash_vec.size());
#pragma omp parallel for
for (size_t i = 0; i < near_geohash_vec.size(); i++)
{
std::vector<mtads_frame::PoiInfo*> &poi_info_vec = poi_info_vec_vec[i];
item_deal_mgr->QueryInfo(near_geohash_vec[i],
deal_front_cids_map,
poi_info_vec,
FLAGS_retrieval_result_length);
CalcDistance(request,poi_info_vec_vec[i],
reco_result_pool_mgr,deal_ret_vec_vec[i]);
if (ad_rank_.get() != NULL)
{
ad_rank_->Work(deal_ret_vec_vec[i], request->curr_hour());
}
else if (rank_.get() != NULL)
{
rank_->Work(deal_ret_vec_vec[i]);
}
}
这是没有问题的代码:
//near_geohash_vec.size() == 9
std::vector< std::vector< mtads_frame::PoiInfo* >* > poi_info_vec_vec;
std::vector< std::vector< DealRespRet* >* > deal_ret_vec_vec;
for (size_t i = 0; i < near_geohash_vec.size(); ++i)
{
poi_info_vec_vec.push_back(new std::vector< mtads_frame::PoiInfo* >());
deal_ret_vec_vec.push_back(new std::vector< DealRespRet* >());
}
#pragma omp parallel for
for (size_t i = 0; i < near_geohash_vec.size(); i++)
{
std::vector< mtads_frame::PoiInfo* > &poi_info_vec = *(poi_info_vec_vec[i]);
std::vector< DealRespRet* > &deal_ret_vec = *(deal_ret_vec_vec[i]);
item_deal_mgr->QueryInfo(near_geohash_vec[i],
deal_front_cids_map,
poi_info_vec,
FLAGS_retrieval_result_length);
CalcDistance(request, poi_info_vec, reco_result_pool_mgr, deal_ret_vec);
if (ad_rank_.get() != NULL)
{
ad_poi_rank_->Work(deal_ret_vec, request->curr_hour());
}
else if (rank_.get() != NULL)
{
rank_->Work(deal_ret_vec);
}
}