-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathunionFindLib.h
174 lines (149 loc) · 5.55 KB
/
unionFindLib.h
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
#ifndef UNION_FIND_LIB
#define UNION_FIND_LIB
#include "unionFindLib.decl.h"
#include <NDMeshStreamer.h>
struct unionFindVertex {
long int vertexID;
long int parent;
long int componentNumber = -1;
std::vector<long int> need_boss_requests; //request queue for processing need_boss requests
long int findOrAnchorCount = 0;
void pup(PUP::er &p) {
p|vertexID;
p|parent;
p|componentNumber;
p|need_boss_requests;
}
};
struct componentCountMap {
long int compNum;
int count;
void pup(PUP::er &p) {
p|compNum;
p|count;
}
};
/* global variables */
/*readonly*/ extern CkGroupID libGroupID;
// declaration for custom reduction
extern CkReduction::reducerType mergeCountMapsReductionType;
// class definition for library chares
class UnionFindLib : public CBase_UnionFindLib {
unionFindVertex *myVertices;
int numMyVertices;
int pathCompressionThreshold = 5;
int componentPruneThreshold;
std::pair<int, int> (*getLocationFromID)(long int vid);
int myLocalNumBosses;
int totalNumBosses;
CkCallback postComponentLabelingCb;
public:
UnionFindLib() {}
UnionFindLib(CkMigrateMessage *m) { }
static CProxy_UnionFindLib unionFindInit(CkArrayID clientArray, int n);
void register_phase_one_cb(CkCallback cb);
void initialize_vertices(unionFindVertex *appVertices, int numVertices);
#ifndef ANCHOR_ALGO
void union_request(long int vid1, long int vid2);
void find_boss1(int arrIdx, long int partnerID, long int senderID);
void find_boss2(int arrIdx, long int boss1ID, long int senderID);
#else
void union_request(long int v, long int w);
void anchor(int w_arrIdx, long int v, long int path_base_arrIdx);
#endif
void local_path_compression(unionFindVertex *src, long int compressedParent);
bool check_same_chares(long int v1, long int v2);
void short_circuit_parent(shortCircuitData scd);
void compress_path(int arrIdx, long int compressedParent);
unionFindVertex* return_vertices();
void registerGetLocationFromID(std::pair<int, int> (*gloc)(long int v));
// functions and data structures for finding connected components
public:
void find_components(CkCallback cb);
void boss_count_prefix_done(int totalCount);
void start_component_labeling();
void insertDataNeedBoss(const uint64_t & data);
void insertDataFindBoss(const findBossData & data);
#ifdef ANCHOR_ALGO
void insertDataAnchor(const anchorData & data);
#endif
void need_boss(int arrIdx, long int fromID);
void set_component(int arrIdx, long int compNum);
void prune_components(int threshold, CkCallback appReturnCb);
void perform_pruning();
int get_total_num_bosses() {
return totalNumBosses;
}
//void merge_count_results(CkReductionMsg *msg);
//void merge_count_results(int* totalCounts, int numElems);
#ifdef PROFILING
void profiling_count_max(long int maxCount);
#endif
};
// library group chare class declarations
class UnionFindLibGroup : public CBase_UnionFindLibGroup {
bool map_built;
int* component_count_array;
int thisPeMessages; //for profiling
public:
UnionFindLibGroup() {
map_built = false;
thisPeMessages = 0;
}
void build_component_count_array(int* totalCounts, int numComponents);
int get_component_count(long int component_id);
void increase_message_count();
void contribute_count();
void done_profiling(int);
};
#define CK_TEMPLATES_ONLY
#include "unionFindLib.def.h"
#undef CK_TEMPLATES_ONLY
#endif
/// Some old functions for backup/reference ///
/*
void UnionFindLib::
start_boss_propagation() {
// iterate over local bosses and send messages to requestors
CkPrintf("Should never get executed!\n");
std::vector<int>::iterator iter = local_boss_indices.begin();
while (iter != local_boss_indices.end()) {
int bossIdx = *iter;
long int bossID = myVertices[bossIdx].vertexID;
std::vector<long int>::iterator req_iter = myVertices[bossIdx].need_boss_requests.begin();
while (req_iter != myVertices[bossIdx].need_boss_requests.end()) {
long int requestorID = *req_iter;
std::pair<int,int> requestor_loc = appPtr->getLocationFromID(requestorID);
this->thisProxy[requestor_loc.first].set_component(requestor_loc.second, bossID);
// done with requestor, delete from requests queue
req_iter = myVertices[bossIdx].need_boss_requests.erase(req_iter);
}
// done with this local boss, delete from vector
iter = local_boss_indices.erase(iter);
}
}*/
/*
void UnionFindLib::
merge_count_results(CkReductionMsg *msg) {
componentCountMap *final_map = (componentCountMap*)msg->getData();
int numComps = msg->getSize();
numComps = numComps/ sizeof(componentCountMap);
if (this->thisIndex == 0) {
CkPrintf("Number of components found: %d\n", numComps);
}
// convert custom map back to STL, for easier lookup
std::map<long int,int> quick_final_map;
for (int i = 0; i < numComps; i++) {
if (this->thisIndex == 0) {
//CkPrintf("Component %ld : Total vertices count = %d\n", final_map[i].compNum, final_map[i].count);
}
quick_final_map[final_map[i].compNum] = final_map[i].count;
}
for (int i = 0; i < numMyVertices; i++) {
if (quick_final_map[myVertices[i].componentNumber] <= componentPruneThreshold) {
// vertex belongs to a minor component, ignore by setting to -1
myVertices[i].componentNumber = -1;
}
}
delete msg;
}*/