c++ - Multithread performance drops down after a few operations -


i encountered weird bug in c++ multithread program on linux. multithreaded part executes loop. 1 single iteration first loads sift file containing features. , queries these features against tree. since have lot of images, used multiple threads querying. here code snippets.

struct multimatchparam {     int thread_id;     float *scores;     double *scores_d;     int *perm;     size_t db_image_num;     std::vector<std::string> *query_filenames;     int start_id;     int num_query;     int dim;     vocabtree *tree;     file *file; };  // multi-thread normalization anyway void multimatch(multimatchparam &param) {     // clear scores     for(size_t t = param.start_id; t < param.start_id + param.num_query; t++)     {         (size_t = 0; < param.db_image_num; i++)             param.scores[i] = 0.0;          dtype *keys;         int num_keys;          keys = readkeys_sfm((*param.query_filenames)[t].c_str(), param.dim, num_keys);          int normalize = true;         double mag = param.tree->multiscorequerykeys(num_keys, normalize, keys, param.scores);          delete [] keys;     } } 

i run on 8-core cpu. @ first runs , cpu usage 100% on 8 cores. after each thread has queried several images (about 20 images), of sudden performance (cpu usage) drops drastically, down 30% across 8 cores.

i doubt key bug concerned line of code.

double mag = param.tree->multiscorequerykeys(num_keys, normalize, keys, param.scores); 

since if replace costly operations (e.g., large for-loop containing sqrt). cpu usage 100%. multiscorequerykeys function complex operation on tree. since 8 cores may read same tree (no write operation tree), wonder whether read operation has kind of blocking effect. shouldn't have effect because don't have write operations in function. operations in loop same. if block cpu usage, happen in first few iterations. if need see details of function or other part of project, please let me know.

use std::async() instead of zeta::simplelock lock


Comments

Popular posts from this blog

facebook - android ACTION_SEND to share with specific application only -

python - Creating a new virtualenv gives a permissions error -

javascript - cocos2d-js draw circle not instantly -