#include "defs.h" double computeGraph(graph* G, graphSDG* SDGdata) { VERT_T* endV; LONG_T *degree, *numEdges, *pos, *pSums; WEIGHT_T* w; double elapsed_time; elapsed_time = get_seconds(); LONG_T i, j, u, n, m, tid, nthreads; tid = 0; nthreads = 1; n = N; m = M; if (tid == 0) { pos = (LONG_T *) malloc(m*sizeof(LONG_T)); assert(pos != NULL); degree = (LONG_T *) calloc(m, sizeof(LONG_T)); assert(degree != NULL); } for (i=0; istartVertex[i]; pos[i] = degree[u]++; } if (tid == 0) { numEdges = (LONG_T *) malloc((n+1)*sizeof(LONG_T)); pSums = (LONG_T *) malloc(nthreads*sizeof(LONG_T)); } prefix_sums(degree, numEdges, pSums, n); if (tid == 0) { free(degree); free(pSums); //w = (WEIGHT_T *) malloc(m*sizeof(WEIGHT_T)); endV = (VERT_T *) malloc(m* sizeof(VERT_T)); } for (i=0; istartVertex[i]; j = numEdges[u] + pos[i]; endV[j] = SDGdata->endVertex[i]; //w[j] = SDGdata->weight[i]; } if (tid == 0) { free(pos); G->n = n; G->m = m; G->numEdges = numEdges; G->endV = endV; //G->weight = w; G->weight = NULL; } /* Verification */ #if 0 fprintf(stderr, "SDG data:\n"); for (int i=0; im; i++) { fprintf(stderr, "[%ld %ld %ld] ", SDGdata->startVertex[i], SDGdata->endVertex[i], SDGdata->weight[i]); } fprintf(stderr, "\n"); for (int i=0; in + 1; i++) { fprintf(stderr, "[%ld] ", G->numEdges[i]); } fprintf(stderr, "\nGraph:\n"); for (int i=0; in; i++) { for (int j=G->numEdges[i]; jnumEdges[i+1]; j++) { fprintf(stderr, "[%ld %ld %ld] ", i, G->endV[j], G->weight[j]); } } #endif free(SDGdata->startVertex); free(SDGdata->endVertex); free(SDGdata->weight); elapsed_time = get_seconds() - elapsed_time; return elapsed_time; }