微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

num_threads子句的用户错误1001参数必须为正

如何解决num_threads子句的用户错误1001参数必须为正

我正在使用vcpkg中的flann。代码给出正确的输出。但是,它也会打印此错误语句User Error 1001:num_threads子句的参数必须为正。我已经阅读过有关此内容的信息,人们只建议使用setNumberOfThreads(positive number),即为线程数提供一个正数。但是我的代码中没有OMP的实现或任何并行性,即使在flann库中找不到任何可以给正数分配线程数的地方。谁能帮我解决这个问题。预先感谢。

    Output -
    User Error 1001: argument to num_threads clause must be positive
     2 34
     3 34
     1 41

 CODE
 #define _CRT_SECURE_NO_WARNINGS
 #include <iostream>
 #include<fstream>
 #include<vector>
 #include"rapidcsv.h"
 #include<iomanip>
 #include "flann/flann.h"

 float* read_points(const char* filename,int rows,int cols) {
float* data;
float *p;
FILE* fin;
int i,j;

fin = fopen(filename,"r");
if (!fin) {
    printf("Cannot open input file.\n");
    exit(1);
}

data = (float*)malloc(rows*cols * sizeof(float));
if (!data) {
    printf("Cannot allocate memory.\n");
    exit(1);
}
p = data;

for (i = 0; i < rows; ++i) {
    for (j = 0; j < cols; ++j) {
        fscanf(fin,"%g ",p);
        p++;
    }
}

fclose(fin);

return data;
 }

 using namespace std;
 int main()
 {
int rows = 4,cols = 2,t_rows = 1,t_cols = 2;
double ds[8] = { 788674.31,6786348.08,788675.31,788676.31,6786348.08 };
ofstream dsq("dataset.dat");
dsq << setprecision(10) << ds[0] << " " << setprecision(10) << ds[1] << endl;
dsq << setprecision(10) << ds[2] << " " << setprecision(10) << ds[3] << endl;
dsq << setprecision(10) << ds[4] << " " << setprecision(10) << ds[5] << endl;
dsq << setprecision(10) << ds[6] << " " << setprecision(10) << ds[7] << endl;

double ts[2] = { 788679.31,6786343.08 };
ofstream tsq("testset.dat");
tsq << setprecision(10) << ts[0] << " " << setprecision(10) << ts[1] << endl;

// read dataset points from file dataset.dat
float* dataset = read_points("dataset.dat",rows,cols);
float* testset = read_points("testset.dat",t_rows,t_cols);

// points in dataset and testset should have the same dimensionality
assert(cols == t_cols);
// number of nearest neighbors to search
int nn = 3;
// allocate memory for the nearest-neighbors indices
int* result = new int[t_rows*nn];
// allocate memory for the distances
float* dists = new float[t_rows*nn];

// index parameters are stored here
struct FLANNParameters p = DEFAULT_FLANN_ParaMETERS;

// the rest of the parameters are automatically computed
//p.target_precision = 0.9;
p.algorithm = FLANN_INDEX_KMEANS;
p.centers_init = FLANN_CENTERS_KMEANSPP;
// compute the 3 nearest-neighbors of each point in the testset
//#pragma warning(push)
//#pragma warning(disable: 1001)
// here goes your code where the warning occurs
flann_find_nearest_neighbors(dataset,cols,testset,result,dists,nn,&p);
//#pragma warning(pop)
for (int i = 0; i < (t_rows*nn); i++) {
    cout << result[i] << " " << dists[i] << endl;
}
delete[] dataset;
delete[] testset;
delete[] result;
delete[] dists;

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。