#include "defs.h" int cilk_main(int argc, char** argv) { /* Data structure for storing generated tuples in the * Scalable Data Generation Stage -- see defs.h */ graphSDG* SDGdata; /* The graph data structure -- see defs.h */ graph* G; /* BC output */ double *BC, *BC_serial; double elapsed_time; /* whether to run the parallel or the serial implementation */ int run_serial = 0; int i; if (argc != 2 && argc != 3) { fprintf(stderr, "Usage: ./BC \n" " is the order of magnitude for the number of nodes in the graph. n = 2^SCALE. 2 = tiny graph, 27 = huge graph.\n" "If is nonempty then the serial calculation of betweenness centrality will be run instead of your parallel one. Use this to see how much faster your parallel version is.\n"); exit(-1); } SCALE = atoi(argv[1]); if (argc == 3) { run_serial = 1; } /* ------------------------------------ */ /* Initialization -- Untimed */ /* ------------------------------------ */ init(SCALE); fprintf(stderr, "SCALE: %d\n\n", SCALE); /* -------------------------------------------- */ /* Torus Graph Generator -- Untimed */ /* -------------------------------------------- */ fprintf(stderr, "Generating 2D torus -- "); fprintf(stderr, "gen2DTorus() beginning execution...\n"); SDGdata = (graphSDG *) malloc(sizeof(graphSDG)); elapsed_time = gen2DTorus(SDGdata); fprintf(stderr, "\tgen2DTorus() completed execution\n"); fprintf(stderr, "Time taken for 2D torus generation is %9.6lf sec.\n", elapsed_time); /* ------------------------------------ */ /* Graph Construction */ /* ------------------------------------ */ /* From the SDG data, construct the graph 'G' */ fprintf(stderr, "computeGraph() beginning execution...\n"); G = (graph *) malloc(sizeof(graph)); /* Store the SDG edge lists in a compact representation * which isn't modified in subsequent Kernels */ elapsed_time = computeGraph(G, SDGdata); fprintf(stderr, "\tcomputeGraph() completed execution\n"); fprintf(stderr, "Time taken for computeGraph() is %9.6lf sec.\n\n", elapsed_time); free(SDGdata); /* ------------------------------------------ */ /* Betweenness Centrality */ /* ------------------------------------------ */ BC = (double *) calloc(N, sizeof(double)); if (!run_serial) { fprintf(stderr, "\nbetweennessCentrality()\n"); elapsed_time = betweennessCentrality(G, BC); fprintf(stderr, "Time taken for BC is %9.6f sec.\n", elapsed_time); fprintf(stderr, "TEPS score for BC is %lf\n\n", 7*((double)N)*((double)(1<n; i++) { if (round(BC[i] - BCval) != 0) { failed = 1; break; } } if (failed) { fprintf(stderr, "BC validation: FAILED!\n"); } else { fprintf(stderr, "BC validation successful!\n"); } free(BC); /* -------------------------------------------------------------------- */ free(G->numEdges); free(G->endV); free(G); return 0; }