Skip to content

Commit

Permalink
remove unnecessary tracking
Browse files Browse the repository at this point in the history
  • Loading branch information
imilinovic committed Jan 16, 2024
1 parent 244bf5f commit 202473d
Show file tree
Hide file tree
Showing 13 changed files with 34 additions and 123 deletions.
11 changes: 3 additions & 8 deletions cpp/community_detection_module/algorithm/louvain.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ std::vector<std::int64_t> GrappoloCommunityDetection(GrappoloGraph &grappolo_gra
return result;
}

void LoadUndirectedEdges(const mg_graph::GraphView<> &memgraph_graph, GrappoloGraph &grappolo_graph, mgp_graph *graph) {
void LoadUndirectedEdges(const mg_graph::GraphView<> &memgraph_graph, GrappoloGraph &grappolo_graph) {
int num_threads = 1;
#pragma omp parallel
{ num_threads = omp_get_num_threads(); }
Expand Down Expand Up @@ -105,11 +105,8 @@ void LoadUndirectedEdges(const mg_graph::GraphView<> &memgraph_graph, GrappoloGr
for (std::size_t i = 0; i < number_of_vertices; i++) added[i] = 0;

// Build the edgeList from edgeListTmp:
#pragma omp parallel
{
[[maybe_unused]] const enum mgp_error tracking_error = mgp_track_current_thread_allocations(graph);

#pragma omp for
#pragma omp parallel for
for (std::size_t i = 0; i < number_of_edges; i++) {
auto head = tmp_edge_list[i].head;
auto tail = tmp_edge_list[i].tail;
Expand All @@ -126,8 +123,6 @@ void LoadUndirectedEdges(const mg_graph::GraphView<> &memgraph_graph, GrappoloGr
edge_list[index].weight = weight;
}

[[maybe_unused]] const enum mgp_error untracking_error = mgp_untrack_current_thread_allocations(graph);
}
// Define Grappolo graph structure
grappolo_graph.sVertices = number_of_vertices;
grappolo_graph.numVertices = number_of_vertices;
Expand All @@ -146,7 +141,7 @@ std::vector<std::int64_t> GetCommunities(const mg_graph::GraphView<> &memgraph_g
// The structure will be deleted in afterward calls in grappolo methods
auto grappolo_graph = (GrappoloGraph *)malloc(sizeof(GrappoloGraph));
// Create structure and load undirected edges
LoadUndirectedEdges(memgraph_graph, *grappolo_graph, graph);
LoadUndirectedEdges(memgraph_graph, *grappolo_graph);

return GrappoloCommunityDetection(*grappolo_graph, graph, coloring, min_graph_shrink, threshold, coloring_threshold);
}
Expand Down
2 changes: 1 addition & 1 deletion cpp/community_detection_module/algorithm/louvain.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ std::vector<std::int64_t> GrappoloCommunityDetection(GrappoloGraph &grappolo_gra
* @param memgraph_graph Memgraph graph instance
* @param grappolo_graph Grappolo graph instance
*/
void LoadUndirectedEdges(const mg_graph::GraphView<> &memgraph_graph, GrappoloGraph &grappolo_graph, mgp_graph *graph);
void LoadUndirectedEdges(const mg_graph::GraphView<> &memgraph_graph, GrappoloGraph &grappolo_graph);

} // namespace

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -129,10 +129,7 @@ double parallelLouvianMethodNoMap(graph *G, mgp_graph *mg_graph, long *C, int nT
cUpdate[i].size =0;
}

#pragma omp parallel
{
[[maybe_unused]] const enum mgp_error tracking_error = mgp_track_current_thread_allocations(mg_graph);
#pragma omp for
#pragma omp parallel for
for (long i=0; i<NV; i++) {
long adj1 = vtxPtr[i];
long adj2 = vtxPtr[i+1];
Expand Down Expand Up @@ -182,8 +179,7 @@ double parallelLouvianMethodNoMap(graph *G, mgp_graph *mg_graph, long *C, int nT
}//End of If()
//numClustSize = 0;
}//End of for(i)
[[maybe_unused]] const enum mgp_error untracking_error = mgp_untrack_current_thread_allocations(mg_graph);
}

time2 = omp_get_wtime();

time3 = omp_get_wtime();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -129,10 +129,7 @@ double parallelLouvianMethodNoMapFastTrackResistance(graph *G, mgp_graph *mg_gra
cUpdate[i].size =0;
}

#pragma omp parallel
{
[[maybe_unused]] const enum mgp_error tracking_error = mgp_track_current_thread_allocations(mg_graph);
#pragma omp for
#pragma omp parallel for
for (long i=0; i<NV; i++) {
long adj1 = vtxPtr[i];
long adj2 = vtxPtr[i+1];
Expand Down Expand Up @@ -175,8 +172,7 @@ double parallelLouvianMethodNoMapFastTrackResistance(graph *G, mgp_graph *mg_gra
cUpdate[currCommAss[i]].size -=1;
}//End of If()
}//End of for(i)
[[maybe_unused]] const enum mgp_error untracking_error = mgp_untrack_current_thread_allocations(mg_graph);
}

time2 = omp_get_wtime();

time3 = omp_get_wtime();
Expand Down Expand Up @@ -279,15 +275,11 @@ double parallelLouvianMethodNoMapFastTrackResistance(graph *G, mgp_graph *mg_gra

//Store back the community assignments in the input variable:
//Note: No matter when the while loop exits, we are interested in the previous assignment
#pragma omp parallel
{
[[maybe_unused]] const enum mgp_error tracking_error = mgp_track_current_thread_allocations(mg_graph);
#pragma omp for
#pragma omp parallel for
for (long i=0; i<NV; i++) {
C[i] = pastCommAss[i];
}
[[maybe_unused]] const enum mgp_error untracking_error = mgp_untrack_current_thread_allocations(mg_graph);
}

//Cleanup
free(pastCommAss);
free(currCommAss);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -154,16 +154,11 @@ int algoDistanceOneVertexColoringOpt(graph *G, mgp_graph *mg_graph, int *vtxColo
//two conflicting vertices, based on their random values
time2 = omp_get_wtime();

#pragma omp parallel
{
[[maybe_unused]] const enum mgp_error tracking_error = mgp_track_current_thread_allocations(mg_graph);
#pragma omp for
#pragma omp parallel for
for (long Qi=0; Qi<QTail; Qi++) {
long v = Q[Qi]; //Q.pop_front();
distanceOneConfResolution(G, v, vtxColor, randValues, &QtmpTail, Qtmp, freq, 0);
} //End of outer for loop: for each vertex
[[maybe_unused]] const enum mgp_error untracking_error = mgp_untrack_current_thread_allocations(mg_graph);
}

time2 = omp_get_wtime() - time2;
totalTime += time2;
Expand Down Expand Up @@ -193,10 +188,7 @@ int algoDistanceOneVertexColoringOpt(graph *G, mgp_graph *mg_graph, int *vtxColo

//Verify Results and Cleanup
int myConflicts = 0;
#pragma omp parallel
{
[[maybe_unused]] const enum mgp_error tracking_error = mgp_track_current_thread_allocations(mg_graph);
#pragma omp for
#pragma omp parallel for
for (long v=0; v < NVer; v++ ) {
long adj1 = verPtr[v];
long adj2 = verPtr[v+1];
Expand All @@ -209,8 +201,6 @@ int algoDistanceOneVertexColoringOpt(graph *G, mgp_graph *mg_graph, int *vtxColo
}
}//End of inner for loop: w in adj(v)
}//End of outer for loop: for each vertex
[[maybe_unused]] const enum mgp_error untracking_error = mgp_untrack_current_thread_allocations(mg_graph);
}
myConflicts = myConflicts / 2; //Have counted each conflict twice

//Clean Up:
Expand Down Expand Up @@ -293,10 +283,7 @@ int algoDistanceOneVertexColoring(graph *G, mgp_graph *mg_graph, int *vtxColor,
///////////////////////////////////////// PART 1 ////////////////////////////////////////
//Color the vertices in parallel - do not worry about conflicts
time1 = omp_get_wtime();
#pragma omp parallel
{
[[maybe_unused]] const enum mgp_error tracking_error = mgp_track_current_thread_allocations(mg_graph);
#pragma omp for
#pragma omp parallel for
for (long Qi=0; Qi<QTail; Qi++) {
long v = Q[Qi]; //Q.pop_front();
long StartIndex = v*MaxDegree; //Location in Mark
Expand Down Expand Up @@ -328,8 +315,7 @@ int algoDistanceOneVertexColoring(graph *G, mgp_graph *mg_graph, int *vtxColor,
myColor++; /* no available color with # less than cmax */
vtxColor[v] = myColor; //Color the vertex
} //End of outer for loop: for each vertex
[[maybe_unused]] const enum mgp_error untracking_error = mgp_untrack_current_thread_allocations(mg_graph);
}

time1 = omp_get_wtime() - time1;
totalTime += time1;

Expand All @@ -339,10 +325,7 @@ int algoDistanceOneVertexColoring(graph *G, mgp_graph *mg_graph, int *vtxColor,
//Conflicts are resolved by changing the color of only one of the
//two conflicting vertices, based on their random values
time2 = omp_get_wtime();
#pragma omp parallel
{
[[maybe_unused]] const enum mgp_error tracking_error = mgp_track_current_thread_allocations(mg_graph);
#pragma omp for
#pragma omp parallel for
for (long Qi=0; Qi<QTail; Qi++) {
long v = Q[Qi]; //Q.pop_front();
long adj1 = verPtr[v];
Expand All @@ -363,8 +346,7 @@ int algoDistanceOneVertexColoring(graph *G, mgp_graph *mg_graph, int *vtxColor,
} //End of if( vtxColor[v] == vtxColor[verInd[k]] )
} //End of inner for loop: w in adj(v)
} //End of outer for loop: for each vertex
[[maybe_unused]] const enum mgp_error untracking_error = mgp_untrack_current_thread_allocations(mg_graph);
}

time2 = omp_get_wtime() - time2;
totalTime += time2;
nConflicts += QtmpTail;
Expand All @@ -387,10 +369,7 @@ int algoDistanceOneVertexColoring(graph *G, mgp_graph *mg_graph, int *vtxColor,
/////////////////////////////////////////////////////////////////////////////////////////
//Verify Results and Cleanup
int myConflicts = 0;
#pragma omp parallel
{
[[maybe_unused]] const enum mgp_error tracking_error = mgp_track_current_thread_allocations(mg_graph);
#pragma omp for
#pragma omp parallel for
for (long v=0; v < NVer; v++ ) {
long adj1 = verPtr[v];
long adj2 = verPtr[v+1];
Expand All @@ -404,8 +383,7 @@ int algoDistanceOneVertexColoring(graph *G, mgp_graph *mg_graph, int *vtxColor,
}
}//End of inner for loop: w in adj(v)
}//End of outer for loop: for each vertex
[[maybe_unused]] const enum mgp_error untracking_error = mgp_untrack_current_thread_allocations(mg_graph);
}

myConflicts = myConflicts / 2; //Have counted each conflict twice
//Clean Up:
free(Q);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -118,10 +118,7 @@ int algoColoringMultiHashMaxMin(graph *G, mgp_graph *mg_graph, int *vtxColor, in
time1 = omp_get_wtime();
for (int ihash=0; ihash<nHash; ihash++) {
int currentColor = (2*itr*nHash + 2*ihash); //Color to be used in current itr-hash combination
#pragma omp parallel
{
[[maybe_unused]] const enum mgp_error tracking_error = mgp_track_current_thread_allocations(mg_graph);
#pragma omp for
#pragma omp parallel for
for (long v=0; v<NVer; v++) {
//Iterate over all the vertices:
//Check if this vertex has already been colored
Expand Down Expand Up @@ -155,8 +152,7 @@ int algoColoringMultiHashMaxMin(graph *G, mgp_graph *mg_graph, int *vtxColor, in
__sync_fetch_and_add(&iterFreq,1);
}
}//End of for(v)
[[maybe_unused]] const enum mgp_error untracking_error = mgp_untrack_current_thread_allocations(mg_graph);
}

}//End of for(ihash)
totalColored += iterFreq;
time2 = omp_get_wtime();
Expand All @@ -174,10 +170,7 @@ int algoColoringMultiHashMaxMin(graph *G, mgp_graph *mg_graph, int *vtxColor, in
//Verify Results and Cleanup
long myConflicts = 0;
long unColored = 0;
#pragma omp parallel
{
[[maybe_unused]] const enum mgp_error tracking_error = mgp_track_current_thread_allocations(mg_graph);
#pragma omp for
#pragma omp parallel for
for (long v=0; v < NVer; v++ ) {
long adj1 = verPtr[v];
long adj2 = verPtr[v+1];
Expand All @@ -194,8 +187,7 @@ int algoColoringMultiHashMaxMin(graph *G, mgp_graph *mg_graph, int *vtxColor, in
}
}//End of inner for loop: w in adj(v)
}//End of outer for loop: for each vertex
[[maybe_unused]] const enum mgp_error untracking_error = mgp_untrack_current_thread_allocations(mg_graph);
}

myConflicts = myConflicts / 2; //Have counted each conflict twice

#ifdef PRINT_DETAILED_STATS_
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -161,10 +161,7 @@ double algoLouvainWithDistOneColoringNoMap(graph* G, mgp_graph *mg_graph, long *
long coloradj1 = colorPtr[ci];
long coloradj2 = colorPtr[ci+1];

#pragma omp parallel
{
[[maybe_unused]] const enum mgp_error tracking_error = mgp_track_current_thread_allocations(mg_graph);
#pragma omp for
#pragma omp parallel for
for (long K = coloradj1; K<coloradj2; K++) {
long i = colorIndex[K];
long localTarget = -1;
Expand Down Expand Up @@ -209,8 +206,6 @@ double algoLouvainWithDistOneColoringNoMap(graph* G, mgp_graph *mg_graph, long *
currCommAss[i] = localTarget;
//clusterLocalMap.clear();
}//End of for(i)
[[maybe_unused]] const enum mgp_error untracking_error = mgp_untrack_current_thread_allocations(mg_graph);
}

// UPDATE
#pragma omp parallel for
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -146,10 +146,7 @@ double parallelLouvianMethodEarlyTerminate(graph *G, mgp_graph *mg_graph, long *
//long totalUniqueComm = 0;

//#pragma omp parallel for reduction(+:totalEdgeTravel), reduction(+:totalUniqueComm)
#pragma omp parallel
{
[[maybe_unused]] const enum mgp_error tracking_error = mgp_track_current_thread_allocations(mg_graph);
#pragma omp for
#pragma omp parallel for
for (long i=0; i<NV; i++) {
if(verT[i])
continue; //Check if the vertex has already been terminated
Expand Down Expand Up @@ -201,8 +198,7 @@ double parallelLouvianMethodEarlyTerminate(graph *G, mgp_graph *mg_graph, long *
cUpdate[currCommAss[i]].size -=1;
}//End of If()
}//End of for(i)
[[maybe_unused]] const enum mgp_error untracking_error = mgp_untrack_current_thread_allocations(mg_graph);
}

time2 = omp_get_wtime();

time3 = omp_get_wtime();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -125,10 +125,7 @@ double parallelLouvainMethodFullSync(graph *G, mgp_graph *mg_graph, long *C, int
long totalEdgeTravel= 0;
long totalUniqueComm = 0;

#pragma omp parallel
{
[[maybe_unused]] const enum mgp_error tracking_error = mgp_track_current_thread_allocations(mg_graph);
#pragma omp for reduction(+:totalEdgeTravel), reduction(+:totalUniqueComm)
#pragma omp parallel for reduction(+:totalEdgeTravel), reduction(+:totalUniqueComm)
for (long i=0; i<NV; i++) {
long adj1 = vtxPtr[i];
long adj2 = vtxPtr[i+1];
Expand All @@ -155,8 +152,6 @@ double parallelLouvainMethodFullSync(graph *G, mgp_graph *mg_graph, long *C, int
}
totalUniqueComm += numUniqueClusters;
}//End of for(i)
[[maybe_unused]] const enum mgp_error untracking_error = mgp_untrack_current_thread_allocations(mg_graph);
}
time2 = omp_get_wtime();

time3 = omp_get_wtime();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -142,10 +142,7 @@ double parallelLouvainMethodFullSyncEarly(graph *G, mgp_graph *mg_graph, long *C
long totalEdgeTravel= 0;
long totalUniqueComm = 0;

#pragma omp parallel
{
[[maybe_unused]] const enum mgp_error tracking_error = mgp_track_current_thread_allocations(mg_graph);
#pragma omp for reduction(+:totalEdgeTravel), reduction(+:totalUniqueComm)
#pragma omp parallel for reduction(+:totalEdgeTravel), reduction(+:totalUniqueComm)
for (long i=0; i<NV; i++) {
if(verT[i])
continue;
Expand Down Expand Up @@ -184,8 +181,6 @@ double parallelLouvainMethodFullSyncEarly(graph *G, mgp_graph *mg_graph, long *C
}
totalUniqueComm += numUniqueClusters;
}//End of for(i)
[[maybe_unused]] const enum mgp_error untracking_error = mgp_untrack_current_thread_allocations(mg_graph);
}
time2 = omp_get_wtime();

time3 = omp_get_wtime();
Expand Down
Loading

0 comments on commit 202473d

Please sign in to comment.