#include "defs.h" #ifdef CILKPAR #include #include #else #define cilk_for for #define cilk_main main #define cilk_spawn #define cilk_sync #endif #define MAX_THREADS 320 double betweennessCentrality_parallel(graph* G, double* BC) { double elapsed_time; return elapsed_time; } /* * Serial Version * */ double betweennessCentrality_serial(graph* G, double* BC) { int *S; /* stack of vertices in order of distance from s. Also, implicitly, the BFS queue */ plist* P; /* predecessors of vertex v on shortest paths from s */ double* sig; /* No. of shortest paths */ int* d; /* Length of the shortest path between every pair */ double* del; /* dependency of vertices */ int *in_degree, *numEdges; int *pListMem; int* Srcs; int *start, *end; int seed = 2387; double elapsed_time; int i, j, k, p, count, myCount; int v, w, vert; int numV, num_traversals, n, m, phase_num; /* numV: no. of vertices to run BFS from = 2^K4approx */ //numV = 1<nv; m = G->ne; numV = n; /* Permute vertices */ Srcs = (int *) malloc(n*sizeof(int)); for (i=0; inbr[i]; in_degree[v]++; } prefix_sums(in_degree, numEdges, n); pListMem = (int *) malloc(m*sizeof(int)); for (i=0; ifirstnbr[i+1] - G->firstnbr[i] == 0) { continue; } else { num_traversals++; } if (num_traversals == numV + 1) { break; } sig[i] = 1; d[i] = 0; S[0] = i; start[0] = 0; end[0] = 1; count = 1; phase_num = 0; while (end[phase_num] - start[phase_num] > 0) { myCount = 0; // BFS to destination, calculate distances, for ( int vert = start[phase_num]; vert < end[phase_num]; vert++ ) { v = S[vert]; for ( int j=G->firstnbr[v]; jfirstnbr[v+1]; j++ ) { w = G->nbr[j]; if (v != w) { /* w found for the first time? */ if (d[w] == -1) { //printf("n=%d, j=%d, start=%d, end=%d, count=%d, vert=%d, w=%d, v=%d\n",n,j,start[phase_num],end[phase_num],myCount,vert,w,v); S[end[phase_num] + myCount] = w; myCount++; d[w] = d[v] + 1; sig[w] = sig[v]; P[w].list[P[w].count++] = v; } else if (d[w] == d[v] + 1) { sig[w] += sig[v]; P[w].list[P[w].count++] = v; } } } } /* Merge all local stacks for next iteration */ phase_num++; start[phase_num] = end[phase_num-1]; end[phase_num] = start[phase_num] + myCount; count = end[phase_num]; } phase_num--; while (phase_num > 0) { for (j=start[phase_num]; j