c++ - misusing OpenMP? -


I have a program to use Opanmpi, for the for-loop parallel within the I loop, shared thread Will write the variable, so I have to synchronize them. However, I can sometimes get a segment error or a double free or corruption error. Does anyone know what happens? Thanks and good luck! Here's the code:

  void KNNClassifier :: classify_various_k (int dim, double * feature, integer label, int * ks, double * errors, integer nb_ks, integer k_max) {ANNpoint queryPt = 0; ANNidxArray nnIdx = 0; Anisteare distances = 0; QueryPt = Feature; NnIdx = new [k_max]; Disks = new k_max]; If (SRCMP (_search_neighbors, "cruel") == 0) {// search_search_struct-> gt; Anchor search (queryPt, k_max, nnIdx, diskette, _p); } Else if (strcmp (_search_neighbors, "kdtree") == 0) {_search_struct-> AnnkSearch (queryPt, k_max, nnIdx, dists, _eps); // double free or corruption} (int j = 0; j & lt; nb_ks; j ++) {scalar_t result = 0.0; For (int i = 0; i  gt; nb_examples) {nb_try = i; Break;} error_validation [i] = 0; } Int i = 0; #pragma omp parallel shared (nb_examples_test, error_validation, features_test, labels_test, nb_try, S) personal (i) {#pragma omp (dynamic) (i = 0; i & LT; nb_examples_test; i ++) Schedule Do not wait {classify_various_k (dim, features_test [i], labels_test [i], ks, error_validation, nb_tree, ks [nb_tree-1]); // where there is an error}} for (i = 0; i & lt; nb_try; i ++) {error_validation [i] / = nb_examples_test; Update:  

runs like my last post, the code runs fine with a single thread but runtime errors vary gives error from time to time for the multi-thread if I give it time to go, a Segflt , And the second will be double free or corruption.

Let's take a look at your segmentation fault line:

  + = _ Labels [nnIdx [i]];  

Result is local - OK.

nnIdx is local - okay.

i is local - still fine.

_labels ... what is this?

Is this global? ? AnnkSearch (queryPt, k_max;

through
  _search_struct- & gt: You  #pragma share  

goes to a former Had defined access to it, NNIDX, Dist, DPS);

It seems that we have a problem here that is not easily resolved - _search_struct thread is not secure - perhaps the prices are modified by thread at a time You must do a dedicated _search_struct by per-thread, maybe allocating it in classify_various_k

Really bad news however that ANN is probably completely non-threadable

The library allocates a small amount of storage, which is shared by all the search strings created during the lifetime of the program. Since the data is shared, it is not delinked, even when all individual structures are destroyed.

As seen above, there will always be issues with parallel data modification, because the library has some shared data - so it is not self-threaded: /.


Comments

Popular posts from this blog

sql - dynamically varied number of conditions in the 'where' statement using LINQ -

asp.net mvc - Dynamically Generated Ajax.BeginForm -

Debug on symbian -