如何提高我的双for循环,10000*10000,每循环一次内循序要3到4毫秒

内循环就是一个求两个距离再IF判断距离符合要求值么符合就记住。据说可以用C++AMP,但不怎么会这个,求指点!

这个得看你的需求,使用AMP的话, 得结合实际需求,比如:

#include
#include
using namespace concurrency;

const int size = 5;

void CppAmpMethod() {
int aCPP[] = {1, 2, 3, 4, 5};
int bCPP[] = {6, 7, 8, 9, 10};
int sumCPP[size];

// Create C++ AMP objects.
array_view<const int, 1> a(size, aCPP);
array_view<const int, 1> b(size, bCPP);
array_view<int, 1> sum(size, sumCPP);
sum.discard_data();

parallel_for_each( 
    // Define the compute domain, which is the set of threads that are created.
    sum.extent, 
    // Define the code to run on each thread on the accelerator.
    [=](index<1> idx) restrict(amp)
{
    sum[idx] = a[idx] + b[idx];
}
);

// Print the results. The expected output is "7, 9, 11, 13, 15".
for (int i = 0; i < size; i++) {
    std::cout << sum[i] << "\n";
}

}


http://blog.csdn.net/lee353086/article/details/39936923,看一下这篇文章就明白amp怎么用了!

这是代码

 Point2f centre;
    float radius;
    int max = m.size();//m为轮廓坐标点集
    int n = 3;
    int cout = 10000;
    //开始找轮廓距离圆心的距离,再跟对应的半径比较
    Point2f bj;//将轮廓中的坐标循环放到BJ中
    int sum = 0;//记录满足坐标的个数
    vector<Point3f> mb;//将满足的坐标放到mb中
    float b, b1;
    vector<Point2f> v1(3);
    vector<Point2f> ab;
    vector<float> ra;
    struct timeb startTime, endTime;

    for (int i = 0; i < cout; i++)//count为得到的三个点的个数,也就是圆的个数,此处count设为10000
    {
        //vector<Point2f> v1(3);

        ftime(&startTime);
        for (int i = 0; i < n; i++)//此循环为随机得到在m里面的三个点集
        {
            int u = rand() % max;
            v1[i] = m[u];//m为得到的轮廓的坐标集
        }
        IsPointInALine(v1[0], v1[1], v1[2]);//判断三点是否可以构成圆,是,返回true,不是,返回false
        FindCircle(v1[0], v1[1], v1[2], centre, radius);//得出三点的圆心坐标与半径
        sum = 0;
        if (!((IsPointInALine(v1[0], v1[1], v1[2])) && (70 < radius < 80) && (54 < radius < 60)))
            continue;//三点是否组成圆,是,则找与该圆心距离为其半径的点

        for (int j = 0; j < max; j++)//max为m点集的个数m.size()
        {
        bj = m[j];
        b1 = (float)(sqrt((bj.x - centre.x)*(bj.x - centre.x) + (bj.y - centre.y)*(bj.y - centre.y)));
        b = fabs(b1 - radius);
        if (b <= 1)
        sum += 1;
        float zc;//点数阈值
        zc = 4/3*PI*radius;
        if (sum>zc)
        {
        mb.push_back(Point3f(centre.x, centre.y, radius));
        circle(image, centre, radius, Scalar(155, 50,255));
        break;
        }
        }
    }