-
Notifications
You must be signed in to change notification settings - Fork 1
/
common.cuh
180 lines (155 loc) · 7.27 KB
/
common.cuh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
#ifndef PTGRAPH_COMMON_CUH
#define PTGRAPH_COMMON_CUH
#include <iostream>
#include <chrono>
#include <fstream>
#include <math.h>
#include "gpu_kernels.cuh"
#include <thrust/host_vector.h>
#include <thrust/device_vector.h>
#include <thrust/functional.h>
#include <thrust/sort.h>
#include <algorithm>
#include <thread>
#include "ArgumentParser.cuh"
using namespace std;
#define gpuErrorcheck(ans) { gpuAssert((ans), __FILE__, __LINE__); }
inline void gpuAssert(cudaError_t code, const char *file, int line, bool abort = true) {
if (code != cudaSuccess) {
fprintf(stderr, "GPUassert: %s %s %d\n", cudaGetErrorString(code), file, line);
if (abort) exit(code);
}
}
const static uint fragment_size = 4096;
//string testGraphPath = "/home/gxl/labproject/subway/uk-2007-04/output.txt";
const static string converPath = "/home/gxl/labproject/subway/uk-2007-04/uk-2007-04.bcsr";
const static string testGraphPath = "/home/gxl/dataset/friendster/friendster.bcsr";
//string testGraphPath = "/home/gxl/labproject/subway/uk-2007Restruct.bcsr";
//const static string testGraphPath = "/home/gxl/labproject/subway/friendster.bcsr";
//string testGraphPath = "/home/gxl/labproject/subway/friendsterRestruct.bcsr";
const static string testWeightGraphPath = "/home/gxl/labproject/subway/sk-2005.bwcsr";
const static string randomDataPath = "/home/gxl/labproject/subway/friendsterChange.random";
const static string prGraphPath = "/home/gxl/dataset/friendster/friendster.bcsc";
const static string ssspGraphPath = "/home/gxl/dataset/friendster/friendster.bwcsr";
const static uint DIST_INFINITY = std::numeric_limits<unsigned int>::max() - 1;
const static uint trunk_size = 1 << 24;
struct CommonPartitionInfo {
uint startVertex;
uint endVertex;
uint nodePointerOffset;
uint partitionEdgeSize;
};
struct PartEdgeListInfo {
uint partActiveNodeNums;
uint partEdgeNums;
uint partStartIndex;
};
void
checkNeedTransferPartition(bool *needTransferPartition, CommonPartitionInfo *partitionInfoList, bool *isActiveNodeList,
int partitionNum, uint testNumNodes, uint &activeNum);
void checkNeedTransferPartitionOpt(bool *needTransferPartition, CommonPartitionInfo *partitionInfoList,
bool *isActiveNodeList,
int partitionNum, uint testNumNodes, uint &activeNum);
void getMaxPartitionSize(unsigned long &max_partition_size, unsigned long &totalSize, uint testNumNodes, float param,
int edgeSize, int nodeParamSize = 15);
void getMaxPartitionSize(unsigned long &max_partition_size, unsigned long &totalSize, uint testNumNodes, float param,
int edgeSize, uint edgeListSize, int nodeParamsSize = 15);
void caculatePartInfoForEdgeList(uint *overloadNodePointers, uint *overloadNodeList, uint *degree,
vector<PartEdgeListInfo> &partEdgeListInfoArr, uint overloadNodeNum,
uint overloadMemorySize, uint overloadEdgeNum);
static void fillDynamic(int tId,
int numThreads,
unsigned int overloadNodeBegin,
unsigned int numActiveNodes,
unsigned int *outDegree,
unsigned int *activeNodesPointer,
unsigned int *nodePointer,
unsigned int *activeNodes,
uint *edgeListOverload,
uint *edgeList) {
float waitToHandleNum = numActiveNodes - overloadNodeBegin;
float numThreadsF = numThreads;
unsigned int chunkSize = ceil(waitToHandleNum / numThreadsF);
unsigned int left, right;
left = tId * chunkSize + overloadNodeBegin;
right = min(left + chunkSize, numActiveNodes);
unsigned int thisNode;
unsigned int thisDegree;
unsigned int fromHere;
unsigned int fromThere;
for (unsigned int i = left; i < right; i++) {
thisNode = activeNodes[i];
thisDegree = outDegree[thisNode];
fromHere = activeNodesPointer[i];
fromThere = nodePointer[thisNode];
for (unsigned int j = 0; j < thisDegree; j++) {
edgeListOverload[fromHere + j] = edgeList[fromThere + j];
}
}
}
static void writeTrunkVistInIteration(vector<vector<uint>> recordData, const string& outputPath) {
ofstream fout(outputPath);
for (int i = 0; i < recordData.size(); i++) {
// output by iteration
for (int j = 0; j < recordData[i].size(); j++) {
fout << recordData[i][j] << "\t";
}
fout << endl;
}
fout.close();
}
static vector<uint> countDataByIteration(uint edgeListSize, uint nodeListSize, uint* nodePointers, uint* degree, int *isActive) {
uint partSizeCursor = 0;
uint partSize = trunk_size / sizeof(uint);
uint partNum = edgeListSize / partSize;
vector<uint> thisIterationVisit(partNum + 1);
for (uint i = 0; i < nodeListSize; i++) {
uint edgeStartIndex = nodePointers[i];
uint edgeEndIndex = nodePointers[i] + degree[i];
uint maxPartIndex = partSizeCursor * partSize + partSize;
if (edgeStartIndex < maxPartIndex && edgeEndIndex < maxPartIndex) {
if(isActive[i]) thisIterationVisit[partSizeCursor] += degree[i];
} else if (edgeStartIndex < maxPartIndex && edgeEndIndex >= maxPartIndex) {
if(isActive[i]) thisIterationVisit[partSizeCursor] += (maxPartIndex - edgeStartIndex);
partSizeCursor += 1;
if(isActive[i]) thisIterationVisit[partSizeCursor] += (edgeEndIndex - maxPartIndex);
} else {
partSizeCursor += 1;
if(isActive[i]) thisIterationVisit[partSizeCursor] += degree[i];
}
}
return thisIterationVisit;
}
static vector<uint> countDataByIteration(uint edgeListSize, uint nodeListSize, uint* nodePointers, uint* degree, uint *isActive) {
uint partSizeCursor = 0;
uint partSize = trunk_size / sizeof(uint);
uint partNum = edgeListSize / partSize;
vector<uint> thisIterationVisit(partNum + 1);
for (uint i = 0; i < nodeListSize; i++) {
uint edgeStartIndex = nodePointers[i];
uint edgeEndIndex = nodePointers[i] + degree[i];
uint maxPartIndex = partSizeCursor * partSize + partSize;
if (edgeStartIndex < maxPartIndex && edgeEndIndex < maxPartIndex) {
if(isActive[i]) thisIterationVisit[partSizeCursor] += degree[i];
} else if (edgeStartIndex < maxPartIndex && edgeEndIndex >= maxPartIndex) {
if(isActive[i]) thisIterationVisit[partSizeCursor] += (maxPartIndex - edgeStartIndex);
partSizeCursor += 1;
if(isActive[i]) thisIterationVisit[partSizeCursor] += (edgeEndIndex - maxPartIndex);
} else {
partSizeCursor += 1;
if(isActive[i]) thisIterationVisit[partSizeCursor] += degree[i];
}
}
return thisIterationVisit;
}
static void calculateDegree(uint nodesSize, uint* nodePointers, uint edgesSize, uint* degree) {
for (uint i = 0; i < nodesSize - 1; i++) {
if (nodePointers[i] > edgesSize) {
cout << i << " " << nodePointers[i] << endl;
break;
}
degree[i] = nodePointers[i + 1] - nodePointers[i];
}
degree[nodesSize - 1] = edgesSize - nodePointers[nodesSize - 1];
}
#endif //PTGRAPH_COMMON_CUH