THCPropose.cu 1.13 KB
Newer Older
rusty1s's avatar
rusty1s committed
1
2
3
#include "common.cuh"

__global__ void proposeKernel(int64_t *color, int64_t *prop, int64_t *row, int64_t *col,
rusty1s's avatar
rusty1s committed
4
                              int64_t *degree, int64_t *cumDegree, ptrdiff_t nNodes) {
rusty1s's avatar
rusty1s committed
5
  KERNEL_LOOP(i, nNodes) {
rusty1s's avatar
rusty1s committed
6
    if (color[i] != -1) continue;  // Only visit blue nodes.
rusty1s's avatar
rusty1s committed
7
    ptrdiff_t c;
rusty1s's avatar
rusty1s committed
8
    for (ptrdiff_t e = cumDegree[i] - degree[i]; e < cumDegree[i]; e++) {
rusty1s's avatar
rusty1s committed
9
10
      c = col[e];
      if (color[c] == -2) {  // Red neighbor found.
rusty1s's avatar
rusty1s committed
11
        prop[i] = c;  // Propose neighbor.
rusty1s's avatar
rusty1s committed
12
13
14
15
16
17
18
19
        break;
      }
    }
    if (prop[i] < 0) color[i] = i;  // Mark node as dead.
  }
}

void THCGreedy_propose(THCState *state, THCudaLongTensor *color, THCudaLongTensor *prop,
rusty1s's avatar
rusty1s committed
20
21
22
23
24
25
                       THCudaLongTensor *row, THCudaLongTensor *col, THCudaLongTensor *degree,
                       THCudaLongTensor *cumDegree) {
  KERNEL_RUN(proposeKernel, THCudaLongTensor_nElement(state, color),
             THCudaLongTensor_data(state, color), THCudaLongTensor_data(state, prop),
             THCudaLongTensor_data(state, row), THCudaLongTensor_data(state, col),
             THCudaLongTensor_data(state, degree), THCudaLongTensor_data(state, cumDegree))
rusty1s's avatar
rusty1s committed
26
}