user515000
user515000

Reputation: 31

CUDA on Thrust: how to implement priority queue

my plan is to calculate a distance matrix using Pearsons's correlation and get q- nearest neighbors for each nodes (q=ln(n)) from the distance matrix and put them in a result vector. I did it in C++ using STL priority queue inside the loop of correlation function.

But do you think, there is any way to do it in GPU?

  1. Can anyone help me, how can I do the same in GPU (probably Thrust will be easier for me!)
  2. How to implement priority queue in GPU?

Here is my CPU(C++ STL) code:

For example,

      distance matrix
-----------------------
 0 3 2 4
 3 0 4 5
 2 4 0 6
 .....

output in a object vector
=================

    source  target  weight
--------------------------------
0 2 2
0 1 3  ....    (sorted by Edge weight)

1 0 3
1 2 4

2 0 2
.....


calculatePearsonCorrelation(float  vector1[], float vector2[], int m) {
               // float distancePearson(vector vector1, vector vector2){

                            int i;
                            float a=0,b=0,c=0,d=0, e = 0, sumX=0, sumY=0;

                            //m = vector1.size();

                            for(i=0;iq){
                        MIN=pqx.top().get_corr();
                        if(corr::iterator it = qNNVector.begin(); it!=qNNVector.end(); ++it) {
            fout 

Upvotes: 3

Views: 2733

Answers (1)

peakxu
peakxu

Reputation: 6675

Have you tried using Thrust's sort? You can just read out the first q elements. If there are enough elements, you'll likely see a decent speedup.

Upvotes: 1

Related Questions