<div dir="ltr"><div>Hi Rcpp friends, </div><div><br></div><div>I have a question regarding to parallel my rcpp code for KNN querying. I used ANN c++ package and the following is a test code related to the code for the querying. I can run through the code when I don' use the openMP. But I get error like the following when I use it : </div><div><div><br></div><div> *** caught illegal operation ***</div><div>address 0x1128e667d, cause 'illegal opcode'</div></div><div><i><br></i></div><div>I have a few questions, 1. what are the potential errors I made in the following code?  2. do we need to require the annkSearch function be thread-safe in order to use openMP here? 3. If  we cannot use openMP here because annkSearch is not thread-safe, can we use RcppParallel here? </div><div><br></div><div>Thanks a lot, </div><div><br></div><div><i>ANNpoint pq;</i></div><div><i>  pq = annAllocPt(d);</i></div><div><i>  int i, j;</i></div><div><i>  nn_idx    = new ANNidx[k];    // Allocate near neigh indices</i></div><div><i>  dists    = new ANNdist[k];   // Allocate near neighbor dists</i></div><div><i>  omp_set_num_threads(3);</i></div><div><i>  for(j = 0; j < d; j++)</i></div><div><i>  {</i></div><div><i>    pq[j]=data[ d_ptr[j]++ ];</i></div><div><i>  }</i></div><div><i><br></i></div><div><i>  // ------------ test kdtree search loop:   ------------ </i></div><div><i>  Rcout << "before search 1" << std::endl;</i></div><div><i>  #pragma omp parallel for shared(the_tree, k, error_bound) private(i, pq, nn_idx, dists)</i></div><div><i>  for(i = 0; i < 3; i ++)</i></div><div><i>  { </i></div><div><i>    if(i == 2){</i></div><div><i>      the_tree->annkSearch( // search</i></div><div><i>          pq, // query point</i></div><div><i>          k,    // number of near neighbors</i></div><div><i>          nn_idx,   // nearest neighbors (returned)</i></div><div><i>          dists,    // distance (returned)</i></div><div><i>          error_bound); // error bound</i></div><div><i>    }</i></div><div><i>  }</i></div><div><i>  Rcout << "end search 1" << std::endl;</i></div><div><br></div><div><br></div></div>