Ejemplo n.º 1
0
MAIN(argc, argv)
{
    GOTO_REAL();

    SETUP_NUMBER_TASKS(10);

    /*
     * Tuple for Scalable Data Generation
     * stores startVertex, endVertex, long weight and other info
     */
    graphSDG* SDGdata;

    /*
     * The graph data structure for this benchmark - see defs.h
     */
    graph* G;

#ifdef ENABLE_KERNEL2
    /*
     * Kernel 2
     */
    edge* maxIntWtList;
    edge* soughtStrWtList;
    long maxIntWtListSize;
    long soughtStrWtListSize;

#endif /* ENABLE_KERNEL2 */

#ifdef ENABLE_KERNEL3

#  ifndef ENABLE_KERNEL2
#    error KERNEL3 requires KERNEL2
#  endif

    /*
     * Kernel 3
     */
    V*   intWtVList  = NULL;
    V*   strWtVList  = NULL;
    Vl** intWtVLList = NULL;
    Vl** strWtVLList = NULL;
    Vd*  intWtVDList = NULL;
    Vd*  strWtVDList = NULL;

#endif /* ENABLE_KERNEL3 */

    double totalTime = 0.0;

    /* -------------------------------------------------------------------------
     * Preamble
     * -------------------------------------------------------------------------
     */

    /*
     * User Interface: Configurable parameters, and global program control
     */

    getUserParameters(argc, (char** const) argv);

    SIM_GET_NUM_CPU(THREADS);
    TM_STARTUP(THREADS, 0);
    P_MEMORY_STARTUP(THREADS);
    SETUP_NUMBER_THREADS(THREADS);
    thread_startup(THREADS);

double time_total = 0.0;
int repeat = REPEATS;
for (; repeat > 0; --repeat) {

    SDGdata = (graphSDG*)malloc(sizeof(graphSDG));
    assert(SDGdata);

    genScalData_seq(SDGdata);

    G = (graph*)malloc(sizeof(graph));
    assert(G);

    computeGraph_arg_t computeGraphArgs;
    computeGraphArgs.GPtr       = G;
    computeGraphArgs.SDGdataPtr = SDGdata;

TIMER_T start;
    TIMER_READ(start);

    GOTO_SIM();
    thread_start(computeGraph, (void*)&computeGraphArgs);
    GOTO_REAL();
TIMER_T stop;
    TIMER_READ(stop);
double time_tmp = TIMER_DIFF_SECONDS(start, stop);
PRINT_STATS();
time_total += time_tmp;
}

totalTime += time_total;


#ifdef ENABLE_KERNEL2

    /* -------------------------------------------------------------------------
     * Kernel 2 - Find Max weight and sought string
     * -------------------------------------------------------------------------
     */

    printf("\nKernel 2 - getStartLists() beginning execution...\n");

    maxIntWtListSize = 0;
    soughtStrWtListSize = 0;
    maxIntWtList = (edge*)malloc(sizeof(edge));
    assert(maxIntWtList);
    soughtStrWtList = (edge*)malloc(sizeof(edge));
    assert(soughtStrWtList);

    getStartLists_arg_t getStartListsArg;
    getStartListsArg.GPtr                = G;
    getStartListsArg.maxIntWtListPtr     = &maxIntWtList;
    getStartListsArg.maxIntWtListSize    = &maxIntWtListSize;
    getStartListsArg.soughtStrWtListPtr  = &soughtStrWtList;
    getStartListsArg.soughtStrWtListSize = &soughtStrWtListSize;

    TIMER_READ(start);

    GOTO_SIM();
#ifdef OTM
#pragma omp parallel
    {
        getStartLists((void*)&getStartListsArg);
    }
#else
    thread_start(getStartLists, (void*)&getStartListsArg);
#endif
    GOTO_REAL();

TIMER_T stop;
    TIMER_READ(stop);

    time = TIMER_DIFF_SECONDS(start, stop);
    totalTime += time;

    printf("\n\tgetStartLists() completed execution.\n");
    printf("\nTime taken for kernel 2 is %9.6f sec.\n\n", time);

#endif /* ENABLE_KERNEL2 */

#ifdef ENABLE_KERNEL3

    /* -------------------------------------------------------------------------
     * Kernel 3 - Graph Extraction
     * -------------------------------------------------------------------------
     */

    printf("\nKernel 3 - findSubGraphs() beginning execution...\n");

    if (K3_DS == 0) {

        intWtVList = (V*)malloc(G->numVertices * maxIntWtListSize * sizeof(V));
        assert(intWtVList);
        strWtVList = (V*)malloc(G->numVertices * soughtStrWtListSize * sizeof(V));
        assert(strWtVList);

        findSubGraphs0_arg_t findSubGraphs0Arg;
        findSubGraphs0Arg.GPtr                = G;
        findSubGraphs0Arg.intWtVList          = intWtVList;
        findSubGraphs0Arg.strWtVList          = strWtVList;
        findSubGraphs0Arg.maxIntWtList        = maxIntWtList;
        findSubGraphs0Arg.maxIntWtListSize    = maxIntWtListSize;
        findSubGraphs0Arg.soughtStrWtList     = soughtStrWtList;
        findSubGraphs0Arg.soughtStrWtListSize = soughtStrWtListSize;

        TIMER_READ(start);

        GOTO_SIM();
#ifdef OTM
#pragma omp parallel
        {
            findSubGraphs0((void*)&findSubGraphs0Arg);
        }
#else
        thread_start(findSubGraphs0, (void*)&findSubGraphs0Arg);
#endif
        GOTO_REAL();

        TIMER_READ(stop);

    } else if (K3_DS == 1) {

        intWtVLList = (Vl**)malloc(maxIntWtListSize * sizeof(Vl*));
        assert(intWtVLList);
        strWtVLList = (Vl**)malloc(soughtStrWtListSize * sizeof(Vl*));
        assert(strWtVLList);

        findSubGraphs1_arg_t findSubGraphs1Arg;
        findSubGraphs1Arg.GPtr                = G;
        findSubGraphs1Arg.intWtVLList         = intWtVLList;
        findSubGraphs1Arg.strWtVLList         = strWtVLList;
        findSubGraphs1Arg.maxIntWtList        = maxIntWtList;
        findSubGraphs1Arg.maxIntWtListSize    = maxIntWtListSize;
        findSubGraphs1Arg.soughtStrWtList     = soughtStrWtList;
        findSubGraphs1Arg.soughtStrWtListSize = soughtStrWtListSize;

        TIMER_READ(start);

        GOTO_SIM();
#ifdef OTM
#pragma omp parallel
        {
            findSubGraphs1((void*)&findSubGraphs1Arg);
        }
#else
        thread_start(findSubGraphs1, (void*)&findSubGraphs1Arg);
#endif
        GOTO_REAL();

        TIMER_READ(stop);

        /*  Verification
        on_one_thread {
          for (i=0; i<maxIntWtListSize; i++) {
            printf("%ld -- ", i);
            currV = intWtVLList[i];
            while (currV != NULL) {
              printf("[%ld %ld] ", currV->num, currV->depth);
              currV = currV->next;
            }
            printf("\n");
          }

          for (i=0; i<soughtStrWtListSize; i++) {
            printf("%ld -- ", i);
            currV = strWtVLList[i];
            while (currV != NULL) {
              printf("[%ld %ld] ", currV->num, currV->depth);
              currV = currV->next;
            }
            printf("\n");
          }

        }
        */

    } else if (K3_DS == 2) {

        intWtVDList = (Vd *) malloc(maxIntWtListSize * sizeof(Vd));
        assert(intWtVDList);
        strWtVDList = (Vd *) malloc(soughtStrWtListSize * sizeof(Vd));
        assert(strWtVDList);

        findSubGraphs2_arg_t findSubGraphs2Arg;
        findSubGraphs2Arg.GPtr                = G;
        findSubGraphs2Arg.intWtVDList         = intWtVDList;
        findSubGraphs2Arg.strWtVDList         = strWtVDList;
        findSubGraphs2Arg.maxIntWtList        = maxIntWtList;
        findSubGraphs2Arg.maxIntWtListSize    = maxIntWtListSize;
        findSubGraphs2Arg.soughtStrWtList     = soughtStrWtList;
        findSubGraphs2Arg.soughtStrWtListSize = soughtStrWtListSize;

        TIMER_READ(start);

        GOTO_SIM();
#ifdef OTM
#pragma omp parallel
        {
            findSubGraphs2((void*)&findSubGraphs2Arg);
        }
#else
        thread_start(findSubGraphs2, (void*)&findSubGraphs2Arg);
#endif
        GOTO_REAL();

        TIMER_READ(stop);

        /* Verification */
        /*
        on_one_thread {
          printf("\nInt weight sub-graphs \n");
          for (i=0; i<maxIntWtListSize; i++) {
            printf("%ld -- ", i);
            for (j=0; j<intWtVDList[i].numArrays; j++) {
              printf("\n [Array %ld] - \n", j);
              for (k=0; k<intWtVDList[i].arraySize[j]; k++) {
                printf("[%ld %ld] ", intWtVDList[i].vList[j][k].num, intWtVDList[i].vList[j][k].depth);
              }

            }
            printf("\n");
          }

          printf("\nStr weight sub-graphs \n");
          for (i=0; i<soughtStrWtListSize; i++) {
            printf("%ld -- ", i);
            for (j=0; j<strWtVDList[i].numArrays; j++) {
              printf("\n [Array %ld] - \n", j);
              for (k=0; k<strWtVDList[i].arraySize[j]; k++) {
                printf("[%ld %ld] ", strWtVDList[i].vList[j][k].num, strWtVDList[i].vList[j][k].depth);
              }

            }
            printf("\n");
          }

        }
       */

    } else {

        assert(0);

    }

    time = TIMER_DIFF_SECONDS(start, stop);
    totalTime += time;

    printf("\n\tfindSubGraphs() completed execution.\n");
    printf("\nTime taken for kernel 3 is %9.6f sec.\n\n", time);

#endif /* ENABLE_KERNEL3 */

#ifdef ENABLE_KERNEL4

    /* -------------------------------------------------------------------------
     * Kernel 4 - Graph Clustering
     * -------------------------------------------------------------------------
     */

    printf("\nKernel 4 - cutClusters() beginning execution...\n");

    TIMER_READ(start);

    GOTO_SIM();
#ifdef OTM
#pragma omp parallel
    {
        cutClusters((void*)G);
    }
#else
    thread_start(cutClusters, (void*)G);
#endif
    GOTO_REAL();

    TIMER_READ(stop);

    time = TIMER_DIFF_SECONDS(start, stop);
    totalTime += time;

    printf("\n\tcutClusters() completed execution.\n");
    printf("\nTime taken for Kernel 4 is %9.6f sec.\n\n", time);

#endif /* ENABLE_KERNEL4 */

    printf("Time = %9.6f \n", totalTime);

    /* -------------------------------------------------------------------------
     * Cleanup
     * -------------------------------------------------------------------------
     */

    P_FREE(G->outDegree);
    P_FREE(G->outVertexIndex);
    P_FREE(G->outVertexList);
    P_FREE(G->paralEdgeIndex);
    P_FREE(G->inDegree);
    P_FREE(G->inVertexIndex);
    P_FREE(G->inVertexList);
    P_FREE(G->intWeight);
    P_FREE(G->strWeight);

#ifdef ENABLE_KERNEL3

    LONGINT_T i;
    LONGINT_T j;
    Vl* currV;
    Vl* tempV;

    if (K3_DS == 0) {
        P_FREE(strWtVList);
        P_FREE(intWtVList);
    }

    if (K3_DS == 1) {
        for (i = 0; i < maxIntWtListSize; i++) {
            currV = intWtVLList[i];
            while (currV != NULL) {
                tempV = currV->next;
                P_FREE(currV);
                currV = tempV;
            }
        }
        for (i = 0; i < soughtStrWtListSize; i++) {
            currV = strWtVLList[i];
            while (currV != NULL) {
                tempV = currV->next;
                P_FREE(currV);
                currV = tempV;
            }
        }
        P_FREE(strWtVLList);
        P_FREE(intWtVLList);
    }

    if (K3_DS == 2) {
        for (i = 0; i < maxIntWtListSize; i++) {
            for (j = 0; j < intWtVDList[i].numArrays; j++) {
                P_FREE(intWtVDList[i].vList[j]);
            }
            P_FREE(intWtVDList[i].vList);
            P_FREE(intWtVDList[i].arraySize);
        }
        for (i = 0; i < soughtStrWtListSize; i++) {
            for (j = 0; j < strWtVDList[i].numArrays; j++) {
                P_FREE(strWtVDList[i].vList[j]);
            }
            P_FREE(strWtVDList[i].vList);
            P_FREE(strWtVDList[i].arraySize);
        }
        P_FREE(strWtVDList);
        P_FREE(intWtVDList);
    }

    P_FREE(soughtStrWtList);
    P_FREE(maxIntWtList);

#endif /* ENABLE_KERNEL2 */

    P_FREE(SOUGHT_STRING);
    P_FREE(G);
    P_FREE(SDGdata);

    TM_SHUTDOWN();
    P_MEMORY_SHUTDOWN();

    GOTO_SIM();

    thread_shutdown();

    MAIN_RETURN(0);
}
Ejemplo n.º 2
0
int 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;
  
    /* Kernel 2 output */
    edge *maxIntWtList;
    INT_T maxIntWtListSize;

    /* Kernel 4 output */
    DOUBLE_T *BC;
    
    DOUBLE_T elapsed_time;

    int filter, cutshort;

#ifdef _OPENMP
    if (argc < 3) {
        
        fprintf(stderr, "Usage: ./SSCA2 <No. of threads> <SCALE>\n");
        exit(-1);
    }
    NUM_THREADS = atoi(argv[1]);
    SCALE = atoi(argv[2]);
    omp_set_num_threads(NUM_THREADS);
    filter = atoi(argv[3]);
    cutshort = atoi(argv[4]);
#else
    if (argc < 2) {
        fprintf(stderr, "Usage: ./SSCA2 <SCALE>\n");
        exit(-1);
    }
    SCALE = atoi(argv[1]);
    filter = atoi(argv[2]);
    cutshort = atoi(argv[3]);
#endif

    /* ------------------------------------ */
    /*  Initialization -- Untimed           */
    /* ------------------------------------ */

    fprintf(stderr, "\nHPCS SSCA Graph Analysis Benchmark v2.2\n");
    fprintf(stderr, "Running...\n\n");

    init(SCALE, cutshort);

#ifdef _OPENMP
    fprintf(stderr, "\nNo. of threads: %d\n", NUM_THREADS);
#endif
    fprintf(stderr, "SCALE: %d\n\n", SCALE);
 
    /* -------------------------------------------- */
    /*  Scalable Data Generator -- Untimed          */
    /* -------------------------------------------- */

#ifndef VERIFYK4
    fprintf(stderr, "Scalable Data Generator -- ");
    fprintf(stderr, "genScalData() beginning execution...\n");

    SDGdata  = (graphSDG *) malloc(sizeof(graphSDG));
    elapsed_time = genScalData(SDGdata);

    fprintf(stderr, "\n\tgenScalData() completed execution\n");
    fprintf(stderr, 
            "\nTime taken for Scalable Data Generation is %9.6lf sec.\n\n", 
            elapsed_time);
#else
    fprintf(stderr, "Generating 2D torus for Kernel 4 validation -- ");
    fprintf(stderr, "gen2DTorus() beginning execution...\n");

    SDGdata = (graphSDG *) malloc(sizeof(graphSDG));
    elapsed_time = gen2DTorus(SDGdata);

    fprintf(stderr, "\n\tgen2DTorus() completed execution\n");
    fprintf(stderr, 
            "\nTime taken for 2D torus generation is %9.6lf sec.\n\n", 
            elapsed_time);
#endif
    
    
    /* ------------------------------------ */
    /*  Kernel 1 - Graph Construction       */
    /* ------------------------------------ */
  
    /* From the SDG data, construct the graph 'G'  */
    fprintf(stderr, "\nKernel 1 -- 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, "\n\tcomputeGraph() completed execution\n");
    fprintf(stderr, "\nTime taken for Kernel 1 is %9.6lf sec.\n\n", 
            elapsed_time);
    
    free(SDGdata);

    /* ---------------------------------------------------- */
    /*  Kernel 2 - Find max edge weight                     */
    /* ---------------------------------------------------- */
  
    fprintf(stderr, "\nKernel 2 -- getStartLists() beginning execution...\n");
  
    /* Initialize vars and allocate temp. memory for the edge list */
    maxIntWtListSize = 0;
    maxIntWtList = (edge *) malloc(sizeof(edge));

    elapsed_time = getStartLists(G, &maxIntWtList, &maxIntWtListSize);

    fprintf(stderr, "\n\tgetStartLists() completed execution\n\n");
    fprintf(stderr, "Max. int wt. list size is %d\n", maxIntWtListSize);
    fprintf(stderr, "\nTime taken for Kernel 2 is %9.6lf sec.\n\n", 
            elapsed_time);

    /* ------------------------------------ */
    /*  Kernel 3 - Graph Extraction         */
    /* ------------------------------------ */
  
    fprintf(stderr, "\nKernel 3 -- findSubGraphs() beginning execution...\n");

    elapsed_time = findSubGraphs(G, maxIntWtList, maxIntWtListSize);

    fprintf(stderr, "\n\tfindSubGraphs() completed execution\n");
    fprintf(stderr, "\nTime taken for Kernel 3 is %9.6lf sec.\n\n", 
            elapsed_time);
     
    free(maxIntWtList);
       
    /* ------------------------------------------ */
    /*  Kernel 4 - Betweenness Centrality         */
    /* ------------------------------------------ */
  
    fprintf(stderr, "\nKernel 4 -- betweennessCentrality() "
            "beginning execution...\n");  
    
    BC = (DOUBLE_T *) calloc(N, sizeof(DOUBLE_T));
    elapsed_time = betweennessCentrality(G, BC, filter);
    fprintf(stderr, "\nTime taken for Kernel 4 is %9.6f sec.\n\n", 
            elapsed_time);
    fprintf(stderr, "TEPS score for Kernel 4 is %lf\n\n", 
            7*N*(1<<K4approx)/elapsed_time);
    free(BC);
    
    /* -------------------------------------------------------------------- */
    
    free(G->numEdges);
    free(G->endV);
    free(G->weight);
    free(G);

    return 0;
}