示例#1
0
/* =============================================================================
 * main
 * =============================================================================
 */
MAIN(argc, argv)
{
    GOTO_REAL();

    /*
     * Initialization
     */
    parseArgs(argc, (char** const)argv);
    long numThread = global_params[PARAM_THREAD];
    SIM_GET_NUM_CPU(numThread);
    TM_STARTUP(numThread);
    P_MEMORY_STARTUP(numThread);
    thread_startup(numThread);
    maze_t* mazePtr = maze_alloc();
    assert(mazePtr);
    long numPathToRoute = maze_read(mazePtr, global_inputFile);
    router_t* routerPtr = router_alloc(global_params[PARAM_XCOST],
                                       global_params[PARAM_YCOST],
                                       global_params[PARAM_ZCOST],
                                       global_params[PARAM_BENDCOST]);
    assert(routerPtr);
    list_t* pathVectorListPtr = list_alloc(NULL);
    assert(pathVectorListPtr);

    /*
     * Run transactions
     */
    router_solve_arg_t routerArg = {routerPtr, mazePtr, pathVectorListPtr};
    TIMER_T startTime;
    TIMER_READ(startTime);
    GOTO_SIM();
#ifdef OTM
#pragma omp parallel
    {
        router_solve((void *)&routerArg);
    }
#else
    thread_start(router_solve, (void*)&routerArg);
#endif
    GOTO_REAL();
    TIMER_T stopTime;
    TIMER_READ(stopTime);

    long numPathRouted = 0;
    list_iter_t it;
    list_iter_reset(&it, pathVectorListPtr);
    while (list_iter_hasNext(&it, pathVectorListPtr)) {
        vector_t* pathVectorPtr = (vector_t*)list_iter_next(&it, pathVectorListPtr);
        numPathRouted += vector_getSize(pathVectorPtr);
    }
    printf("Paths routed    = %li\n", numPathRouted);
    printf("Elapsed time    = %f seconds\n", TIMER_DIFF_SECONDS(startTime, stopTime));

    /*
     * Check solution and clean up
     */
    assert(numPathRouted <= numPathToRoute);
    bool_t status = maze_checkPaths(mazePtr, pathVectorListPtr, global_doPrint);
    assert(status == TRUE);
    puts("Verification passed.");
    maze_free(mazePtr);
    router_free(routerPtr);

    TM_SHUTDOWN();
    P_MEMORY_SHUTDOWN();

    GOTO_SIM();

    thread_shutdown();


    MAIN_RETURN(0);
}
示例#2
0
/* =============================================================================
 * main
 * =============================================================================
 */
MAIN(argc, argv)
{
    /*
     * Initialization
     */
    parseArgs(argc, (char** const)argv);
    long numThread = global_params[PARAM_THREAD];
    SIM_GET_NUM_CPU(numThread);
    TM_STARTUP(numThread);
    P_MEMORY_STARTUP(numThread);
    thread_startup(numThread);
    maze_t* mazePtr = maze_alloc();
    assert(mazePtr);
    long numPathToRoute = maze_read(mazePtr, global_inputFile);
    router_t* routerPtr = router_alloc(global_params[PARAM_XCOST],
                                       global_params[PARAM_YCOST],
                                       global_params[PARAM_ZCOST],
                                       global_params[PARAM_BENDCOST]);
    assert(routerPtr);
    list_t* pathVectorListPtr = list_alloc(NULL);
    assert(pathVectorListPtr);

    /*
     * Run transactions
     */
    router_solve_arg_t routerArg = {routerPtr, mazePtr, pathVectorListPtr};
    // NB: Since ASF/PTLSim "REAL" is native execution, and since we are using
    //     wallclock time, we want to be sure we read time inside the
    //     simulator, or else we report native cycles spent on the benchmark
    //     instead of simulator cycles.
    GOTO_SIM();
    TIMER_T startTime;
    TIMER_READ(startTime);
#ifdef OTM
#pragma omp parallel
    {
        router_solve((void *)&routerArg);
    }
#else
    thread_start(router_solve, (void*)&routerArg);
#endif
    TIMER_T stopTime;
    TIMER_READ(stopTime);
    // NB: As above, timer reads must be done inside of the simulated region
    //     for PTLSim/ASF
    GOTO_REAL();

    long numPathRouted = 0;
    list_iter_t it;
    list_iter_reset(&it, pathVectorListPtr);
    while (list_iter_hasNext(&it, pathVectorListPtr)) {
        vector_t* pathVectorPtr = (vector_t*)list_iter_next(&it, pathVectorListPtr);
        numPathRouted += vector_getSize(pathVectorPtr);
    }
    printf("Paths routed    = %li\n", numPathRouted);
    printf("Elapsed time    = %f seconds\n", TIMER_DIFF_SECONDS(startTime, stopTime));

    /*
     * Check solution and clean up
     */
    assert(numPathRouted <= numPathToRoute);
    bool status = maze_checkPaths(mazePtr, pathVectorListPtr, global_doPrint);
    assert(status);
    puts("Verification passed.");
    maze_free(mazePtr);
    router_free(routerPtr);

    TM_SHUTDOWN();
    P_MEMORY_SHUTDOWN();

    thread_shutdown();


    MAIN_RETURN(0);
}
示例#3
0
文件: kmeans.c 项目: HPDCS/stmF2C2
/* =============================================================================
 * main
 * =============================================================================
 */
MAIN(argc, argv)
{
    int     max_nclusters = 13;
    int     min_nclusters = 4;
    char*   filename = 0;
    float*  buf;
    float** attributes;
    float** cluster_centres = NULL;
    int     i;
    int     j;
    int     best_nclusters;
    int*    cluster_assign;
    int     numAttributes;
    int     numObjects;
    int     use_zscore_transform = 1;
    char*   line;
    int     isBinaryFile = 0;
    int     nloops;
    int     len;
    int     nthreads;
    float   threshold = 0.001;
    int     opt;

    GOTO_REAL();

    line = (char*)malloc(MAX_LINE_LENGTH); /* reserve memory line */

    nthreads = 1;
    while ((opt = getopt(argc,(char**)argv,"p:i:m:n:t:bz")) != EOF) {
        switch (opt) {
            case 'i': filename = optarg;
                      break;
            case 'b': isBinaryFile = 1;
                      break;
            case 't': threshold = atof(optarg);
                      break;
            case 'm': max_nclusters = atoi(optarg);
                      break;
            case 'n': min_nclusters = atoi(optarg);
                      break;
            case 'z': use_zscore_transform = 0;
                      break;
            case 'p': nthreads = atoi(optarg);
                      break;
            case '?': usage((char*)argv[0]);
                      break;
            default: usage((char*)argv[0]);
                      break;
        }
    }

    if (filename == 0) {
        usage((char*)argv[0]);
    }

    if (max_nclusters < min_nclusters) {
        fprintf(stderr, "Error: max_clusters must be >= min_clusters\n");
        usage((char*)argv[0]);
    }

    SIM_GET_NUM_CPU(nthreads);

    numAttributes = 0;
    numObjects = 0;

    /*
     * From the input file, get the numAttributes and numObjects
     */
    if (isBinaryFile) {
        int infile;
        if ((infile = open(filename, O_RDONLY, "0600")) == -1) {
            fprintf(stderr, "Error: no such file (%s)\n", filename);
            exit(1);
        }
        read(infile, &numObjects, sizeof(int));
        read(infile, &numAttributes, sizeof(int));

        /* Allocate space for attributes[] and read attributes of all objects */
        buf = (float*)malloc(numObjects * numAttributes * sizeof(float));
        assert(buf);
        attributes = (float**)malloc(numObjects * sizeof(float*));
        assert(attributes);
        attributes[0] = (float*)malloc(numObjects * numAttributes * sizeof(float));
        assert(attributes[0]);
        for (i = 1; i < numObjects; i++) {
            attributes[i] = attributes[i-1] + numAttributes;
        }
        read(infile, buf, (numObjects * numAttributes * sizeof(float)));
        close(infile);
    } else {
        FILE *infile;
        if ((infile = fopen(filename, "r")) == NULL) {
            fprintf(stderr, "Error: no such file (%s)\n", filename);
            exit(1);
        }
        while (fgets(line, MAX_LINE_LENGTH, infile) != NULL) {
            if (strtok(line, " \t\n") != 0) {
                numObjects++;
            }
        }
        rewind(infile);
        while (fgets(line, MAX_LINE_LENGTH, infile) != NULL) {
            if (strtok(line, " \t\n") != 0) {
                /* Ignore the id (first attribute): numAttributes = 1; */
                while (strtok(NULL, " ,\t\n") != NULL) {
                    numAttributes++;
                }
                break;
            }
        }

        /* Allocate space for attributes[] and read attributes of all objects */
        buf = (float*)malloc(numObjects * numAttributes * sizeof(float));
        assert(buf);
        attributes = (float**)malloc(numObjects * sizeof(float*));
        assert(attributes);
        attributes[0] = (float*)malloc(numObjects * numAttributes * sizeof(float));
        assert(attributes[0]);
        for (i = 1; i < numObjects; i++) {
            attributes[i] = attributes[i-1] + numAttributes;
        }
        rewind(infile);
        i = 0;
        while (fgets(line, MAX_LINE_LENGTH, infile) != NULL) {
            if (strtok(line, " \t\n") == NULL) {
                continue;
            }
            for (j = 0; j < numAttributes; j++) {
                buf[i] = atof(strtok(NULL, " ,\t\n"));
                i++;
            }
        }
        fclose(infile);
    }

    TM_STARTUP(nthreads);
    thread_startup(nthreads);

    /*
     * The core of the clustering
     */
    cluster_assign = (int*)malloc(numObjects * sizeof(int));
    assert(cluster_assign);

    nloops = 1;
    len = max_nclusters - min_nclusters + 1;

#ifdef STM_ENERGY_MONITOR
	startEnergy();
#endif /* STM_ENERGY_MONITOR */

    for (i = 0; i < nloops; i++) {
        /*
         * Since zscore transform may perform in cluster() which modifies the
         * contents of attributes[][], we need to re-store the originals
         */
        memcpy(attributes[0], buf, (numObjects * numAttributes * sizeof(float)));

        cluster_centres = NULL;
        cluster_exec(nthreads,
                     numObjects,
                     numAttributes,
                     attributes,           /* [numObjects][numAttributes] */
                     use_zscore_transform, /* 0 or 1 */
                     min_nclusters,        /* pre-define range from min to max */
                     max_nclusters,
                     threshold,
                     &best_nclusters,      /* return: number between min and max */
                     &cluster_centres,     /* return: [best_nclusters][numAttributes] */
                     cluster_assign);      /* return: [numObjects] cluster id for each object */

    }

#ifdef GNUPLOT_OUTPUT
    {
        FILE** fptr;
        char outFileName[1024];
        fptr = (FILE**)malloc(best_nclusters * sizeof(FILE*));
        for (i = 0; i < best_nclusters; i++) {
            sprintf(outFileName, "group.%d", i);
            fptr[i] = fopen(outFileName, "w");
        }
        for (i = 0; i < numObjects; i++) {
            fprintf(fptr[cluster_assign[i]],
                    "%6.4f %6.4f\n",
                    attributes[i][0],
                    attributes[i][1]);
        }
        for (i = 0; i < best_nclusters; i++) {
            fclose(fptr[i]);
        }
        free(fptr);
    }
#endif /* GNUPLOT_OUTPUT */

#ifdef OUTPUT_TO_FILE
    {
        /* Output: the coordinates of the cluster centres */
        FILE* cluster_centre_file;
        FILE* clustering_file;
        char outFileName[1024];

        sprintf(outFileName, "%s.cluster_centres", filename);
        cluster_centre_file = fopen(outFileName, "w");
        for (i = 0; i < best_nclusters; i++) {
            fprintf(cluster_centre_file, "%d ", i);
            for (j = 0; j < numAttributes; j++) {
                fprintf(cluster_centre_file, "%f ", cluster_centres[i][j]);
            }
            fprintf(cluster_centre_file, "\n");
        }
        fclose(cluster_centre_file);

        /* Output: the closest cluster centre to each of the data points */
        sprintf(outFileName, "%s.cluster_assign", filename);
        clustering_file = fopen(outFileName, "w");
        for (i = 0; i < numObjects; i++) {
            fprintf(clustering_file, "%d %d\n", i, cluster_assign[i]);
        }
        fclose(clustering_file);
    }
#endif /* OUTPUT TO_FILE */

#ifdef OUTPUT_TO_STDOUT
    {
        /* Output: the coordinates of the cluster centres */
        for (i = 0; i < best_nclusters; i++) {
            //printf("%d ", i);
            for (j = 0; j < numAttributes; j++) {
                //printf("%f ", cluster_centres[i][j]);
            }
            //printf("\n");
        }
    }
#endif /* OUTPUT TO_STDOUT */


#ifdef STM_ENERGY_MONITOR
    float joule=endEnergy();
	printf("Threads: %i\tElapsed time: %f Energy: %f",nthreads, global_time, joule);
#else
	printf("Threads: %i\tElapsed time: %f", nthreads, global_time);
#endif /* STM_ENERGY_MONITOR */

    free(cluster_assign);
    free(attributes);
    free(cluster_centres[0]);
    free(cluster_centres);
    free(buf);

    TM_SHUTDOWN();
	if (getenv("STM_STATS") != NULL) {
		unsigned long u;
		if (stm_get_global_stats("global_nb_commits", &u) != 0){
			printf("\tThroughput: %f\n",u/global_time);
		}
	}

    GOTO_SIM();

    thread_shutdown();

    MAIN_RETURN(0);
}
示例#4
0
int main(int argc, char **argv)
{
    char logpath[FILENAME_MAX];
    int log;

    if (argc != 2) 
    {
        fprintf(stderr, PACKAGE_STRING "\n"
                "  (c) Copyright 2001-2004 The IceS Development Team <*****@*****.**>\n"
                "        Michael Smith <*****@*****.**>\n"
                "        Karl Heyes    <*****@*****.**>\n"
                "        and others\n"
                "\n"
                "Usage: \"ices config.xml\"\n");
        return 1;
    }

    config_initialize();

    if (config_read(argv[1]) <= 0) 
    {
        fprintf(stderr, "Failed to read config file \"%s\"\n", argv[1]);
        goto fail;
    }
	
    if (ices_config->background)
    {
#ifndef _WIN32		
        int ret = 0;
        /* Start up new session, to lose old session and process group */
        switch (fork())
        {
        case 0: break; /* child continues */
        case -1: perror ("fork"); ret = -1;
        default:
            exit (ret);
        }

        /* Disassociate process group and controlling terminal */ 
        setsid();

        /* Become a NON-session leader so that a */
        /* control terminal can't be reacquired */
        switch (fork())
        {
        case 0: break; /* child continues */
        case -1: perror ("fork"); ret = -1;
        default:
            exit (ret);
        }
#else
        FreeConsole();
#endif    		
    }

    log_initialize();
    thread_initialize();
    shout_init();
    encode_init();
#ifndef _WIN32	
    signals_setup();
#endif

    snprintf(logpath, FILENAME_MAX, "%s/%s", ices_config->logpath, 
            ices_config->logfile);
    if(ices_config->log_stderr)
        log = log_open_file(stderr);
    else
    {
        log = log_open(logpath);
        if (log < 0)
            fprintf (stderr, "unable to open log %s\n", logpath);
        log_set_trigger (log, ices_config->logsize);
    }
    /* Set the log level, if requested - defaults to 2 (WARN) otherwise */
    if (ices_config->loglevel)
        log_set_level(log, ices_config->loglevel);

    ices_config->log_id = log;

    LOG_INFO0(PACKAGE_STRING " started...");
    if (ices_config->pidfile != NULL)
    {
        FILE *f = fopen (ices_config->pidfile, "w");
        if (f)
        {
            fprintf (f, "%i", getpid());
            fclose (f);
        }
        else
        {
            LOG_WARN1("pidfile \"%s\" cannot be written to", ices_config->pidfile);
            xmlFree (ices_config->pidfile);
            ices_config->pidfile = NULL;
        }
    }

    /* Start the core streaming loop */
    input_loop();

    if (ices_config->pidfile)
        remove (ices_config->pidfile);

    LOG_INFO0("Shutdown complete");

    log_close(log);

 fail:
    encode_close();
    shout_shutdown();
    config_shutdown();
    thread_shutdown();
    log_shutdown();

    return 0;
}
示例#5
0
/* =============================================================================
 * main
 * =============================================================================
 */
int main (int argc, char** argv)
{
    int result = 0;
    TIMER_T start;
    TIMER_T stop;

    /* Initialization */
    parseArgs(argc, (char** const)argv);

    printf("Creating gene and segments... ");
    fflush(stdout);

    long geneLength = global_params[PARAM_GENE];
    long segmentLength = global_params[PARAM_SEGMENT];
    long minNumSegment = global_params[PARAM_NUMBER];
    long numThread = global_params[PARAM_THREAD];

    thread_startup(numThread);

    random_t* randomPtr = random_alloc();
    assert(randomPtr != NULL);
    random_seed(randomPtr, 0);

    gene_t* genePtr = gene_alloc(geneLength);
    assert( genePtr != NULL);
    gene_create(genePtr, randomPtr);
    char* gene = genePtr->contents;

    segments_t* segmentsPtr = segments_alloc(segmentLength, minNumSegment);
    assert(segmentsPtr != NULL);
    segments_create(segmentsPtr, genePtr, randomPtr);
    sequencer_t* sequencerPtr = sequencer_alloc(geneLength, segmentLength, segmentsPtr);
    assert(sequencerPtr != NULL);

    puts("done.");
    printf("Gene length     = %li\n", genePtr->length);
    printf("Segment length  = %li\n", segmentsPtr->length);
    printf("Number segments = %li\n", vector_getSize(segmentsPtr->contentsPtr));
    fflush(stdout);

    /* Benchmark */
    printf("Sequencing gene... ");
    fflush(stdout);
    TIMER_READ(start);
#ifdef OTM
#pragma omp parallel
    {
        sequencer_run(sequencerPtr);
    }
#else
    thread_start(sequencer_run, (void*)sequencerPtr);
#endif
    TIMER_READ(stop);
    puts("done.");
    printf("Time = %lf\n", TIMER_DIFF_SECONDS(start, stop));
    fflush(stdout);

    /* Check result */
    {
        char* sequence = sequencerPtr->sequence;
        result = strcmp(gene, sequence);
        printf("Sequence matches gene: %s\n", (result ? "no" : "yes"));
        if (result) {
            printf("gene     = %s\n", gene);
            printf("sequence = %s\n", sequence);
        }
        fflush(stdout);
        assert(strlen(sequence) >= strlen(gene));
    }

    /* Clean up */
    printf("Deallocating memory... ");
    fflush(stdout);
    sequencer_free(sequencerPtr);
    segments_free(segmentsPtr);
    gene_free(genePtr);
    random_free(randomPtr);
    puts("done.");
    fflush(stdout);

    thread_shutdown();

    return result;
}
示例#6
0
文件: genome.c 项目: takayuki/al
/* =============================================================================
 * main
 * =============================================================================
 */
MAIN (argc,argv)
{
    TIMER_T start;
    TIMER_T stop;

    GOTO_REAL();

    /* Initialization */
    parseArgs(argc, (char** const)argv);
    SIM_GET_NUM_CPU(global_params[PARAM_THREAD]);

    printf("Creating gene and segments... ");
    fflush(stdout);

    long geneLength = global_params[PARAM_GENE];
    long segmentLength = global_params[PARAM_SEGMENT];
    long minNumSegment = global_params[PARAM_NUMBER];
    long numThread = global_params[PARAM_THREAD];

    TM_STARTUP(numThread);
    P_MEMORY_STARTUP(numThread);

    random_t* randomPtr = random_alloc();
    assert(randomPtr != NULL);
    random_seed(randomPtr, 0);

    gene_t* genePtr = gene_alloc(geneLength);
    assert( genePtr != NULL);
    gene_create(genePtr, randomPtr);
    char* gene = genePtr->contents;

    segments_t* segmentsPtr = segments_alloc(segmentLength, minNumSegment);
    assert(segmentsPtr != NULL);
    segments_create(segmentsPtr, genePtr, randomPtr);
    sequencer_t* sequencerPtr = sequencer_alloc(geneLength, segmentLength, segmentsPtr);
    assert(sequencerPtr != NULL);

    puts("done.");
    printf("Gene length     = %li\n", genePtr->length);
    printf("Segment length  = %li\n", segmentsPtr->length);
    printf("Number segments = %li\n", vector_getSize(segmentsPtr->contentsPtr));
    fflush(stdout);

    /* Benchmark */
    printf("Sequencing gene... ");
    fflush(stdout);
    TIMER_READ(start);
    GOTO_SIM();
    thread_startup(numThread, sequencer_run, (void*)sequencerPtr);
    thread_start();
    GOTO_REAL();
    TIMER_READ(stop);
    puts("done.");
    printf("Time = %lf\n", TIMER_DIFF_SECONDS(start, stop));
    fflush(stdout);

    /* Check result */
    {
        char* sequence = sequencerPtr->sequence;
        int result = strcmp(gene, sequence);
        printf("Sequence matches gene: %s\n", (result ? "no" : "yes"));
        if (result) {
            printf("gene     = %s\n", gene);
            printf("sequence = %s\n", sequence);
        }
        fflush(stdout);
        assert(strlen(sequence) >= strlen(gene));
    }

    /* Clean up */
    printf("Deallocating memory... ");
    fflush(stdout);
    sequencer_free(sequencerPtr);
    segments_free(segmentsPtr);
    gene_free(genePtr);
    random_free(randomPtr);
    puts("done.");
    fflush(stdout);

    al_dump(&sequencerLock);

    TM_SHUTDOWN();
    P_MEMORY_SHUTDOWN();

    GOTO_SIM();

    thread_shutdown();

    MAIN_RETURN(0);
}
示例#7
0
/* =============================================================================
 * main
 * =============================================================================
 */
MAIN(argc, argv)
{
    char exitmsg[1024];

    GOTO_REAL();

    load_syncchar_map("sync_char.map.yada");

    /*
     * Initialization
     */

    parseArgs(argc, (char** const)argv);
    sprintf(exitmsg, "END BENCHMARK %s-parallel-phase\n", argv[0]);

    SIM_GET_NUM_CPU(global_numThread);
    TM_STARTUP(global_numThread);
    P_MEMORY_STARTUP(global_numThread);
    thread_startup(global_numThread);
    global_meshPtr = mesh_alloc();
    assert(global_meshPtr);
    printf("Angle constraint = %lf\n", global_angleConstraint);
    printf("Reading input... ");
    long initNumElement = mesh_read(global_meshPtr, global_inputPrefix);
    puts("done.");
    global_workHeapPtr = heap_alloc(1, &element_heapCompare);
    assert(global_workHeapPtr);
    long initNumBadElement = initializeWork(global_workHeapPtr, global_meshPtr);

    printf("Initial number of mesh elements = %li\n", initNumElement);
    printf("Initial number of bad elements  = %li\n", initNumBadElement);
    printf("Starting triangulation...");
    fflush(stdout);

    /*
     * Run benchmark
     */

    TIMER_T start;
    TIMER_READ(start);
    OSA_PRINT("entering parallel phase\n",0);
    START_INSTRUMENTATION();
    GOTO_SIM();
#ifdef OTM
#pragma omp parallel
    {
        process();
    }
#else
    thread_start(process, NULL);
#endif
    GOTO_REAL();
    OSA_PRINT("exiting parallel phase\n",0);
    OSA_PRINT(exitmsg,0);
    STOP_INSTRUMENTATION();
    TIMER_T stop;
    TIMER_READ(stop)

    puts(" done.");
    printf("Elapsed time                    = %0.3lf\n",
           TIMER_DIFF_SECONDS(start, stop));
    fflush(stdout);

    /*
     * Check solution
     */

    long finalNumElement = initNumElement + global_totalNumAdded;
    printf("Final mesh size                 = %li\n", finalNumElement);
    printf("Number of elements processed    = %li\n", global_numProcess);
    fflush(stdout);

#if 0
    bool_t isSuccess = mesh_check(global_meshPtr, finalNumElement);
#else
    bool_t isSuccess = TRUE;
#endif
    printf("Final mesh is %s\n", (isSuccess ? "valid." : "INVALID!"));
    fflush(stdout);
    assert(isSuccess);

    /*
     * TODO: deallocate mesh and work heap
     */

    TM_SHUTDOWN();
    P_MEMORY_SHUTDOWN();

    GOTO_SIM();

    thread_shutdown();

    MAIN_RETURN(0);
}
示例#8
0
文件: ssca2.c 项目: HPDCS/htmMCATS
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);
}
示例#9
0
/* =============================================================================
 * main
 * =============================================================================
 */
MAIN(argc, argv)
{
    GOTO_REAL();

    /*
     * Initialization
     */

    parseArgs(argc, (char** const)argv);
    long numThread     = global_params[PARAM_THREAD];
    long numVar        = global_params[PARAM_VAR];
    long numRecord     = global_params[PARAM_RECORD];
    long randomSeed    = global_params[PARAM_SEED];
    long maxNumParent  = global_params[PARAM_NUMBER];
    long percentParent = global_params[PARAM_PERCENT];
    global_insertPenalty = global_params[PARAM_INSERT];
    global_maxNumEdgeLearned = global_params[PARAM_EDGE];
    SIM_GET_NUM_CPU(numThread);
    TM_STARTUP(numThread);
    P_MEMORY_STARTUP(numThread);
    thread_startup(numThread);

    printf("Random seed                = %li\n", randomSeed);
    printf("Number of vars             = %li\n", numVar);
    printf("Number of records          = %li\n", numRecord);
    printf("Max num parents            = %li\n", maxNumParent);
    printf("%% chance of parent         = %li\n", percentParent);
    printf("Insert penalty             = %li\n", global_insertPenalty);
    printf("Max num edge learned / var = %li\n", global_maxNumEdgeLearned);
    printf("Operation quality factor   = %f\n", global_operationQualityFactor);
    fflush(stdout);

    /*
     * Generate data
     */

    printf("Generating data... ");
    fflush(stdout);

    random_t* randomPtr = random_alloc();
    assert(randomPtr);
    random_seed(randomPtr, randomSeed);

    data_t* dataPtr = data_alloc(numVar, numRecord, randomPtr);
    assert(dataPtr);
    net_t* netPtr = data_generate(dataPtr, -1, maxNumParent, percentParent);
    puts("done.");
    fflush(stdout);

    /*
     * Generate adtree
     */

    adtree_t* adtreePtr = adtree_alloc();
    assert(adtreePtr);

    printf("Generating adtree... ");
    fflush(stdout);

    TIMER_T adtreeStartTime;
    TIMER_READ(adtreeStartTime);

    adtree_make(adtreePtr, dataPtr);

    TIMER_T adtreeStopTime;
    TIMER_READ(adtreeStopTime);

    puts("done.");
    fflush(stdout);
    printf("Adtree time = %f\n",
           TIMER_DIFF_SECONDS(adtreeStartTime, adtreeStopTime));
    fflush(stdout);

    /*
     * Score original network
     */

    float actualScore = score(netPtr, adtreePtr);
    net_free(netPtr);

    /*
     * Learn structure of Bayesian network
     */

    learner_t* learnerPtr = learner_alloc(dataPtr, adtreePtr, numThread);
    assert(learnerPtr);
    data_free(dataPtr); /* save memory */

    printf("Learning structure...");
    fflush(stdout);

    TIMER_T learnStartTime;
    TIMER_READ(learnStartTime);
    GOTO_SIM();

    learner_run(learnerPtr);

    GOTO_REAL();
    TIMER_T learnStopTime;
    TIMER_READ(learnStopTime);

    puts("done.");
    fflush(stdout);
    printf("Time = %f\n",
           TIMER_DIFF_SECONDS(learnStartTime, learnStopTime));
    fflush(stdout);

    /*
     * Check solution
     */

    bool_t status = net_isCycle(learnerPtr->netPtr);
    assert(!status);

#ifndef SIMULATOR
    float learnScore = learner_score(learnerPtr);
    printf("Learn score  = %f\n", learnScore);
#endif
    printf("Actual score = %f\n", actualScore);

    /*
     * Clean up
     */

    fflush(stdout);
    random_free(randomPtr);
#ifndef SIMULATOR
    adtree_free(adtreePtr);
#  if 0    
    learner_free(learnerPtr);
#  endif    
#endif

    TM_SHUTDOWN();
    P_MEMORY_SHUTDOWN();

    GOTO_SIM();

    thread_shutdown();

    MAIN_RETURN(0);
}
示例#10
0
/****** run_ijs_server() *******************************************************
*  NAME
*     run_ijs_server() -- The servers main loop
*
*  SYNOPSIS
*     int run_ijs_server(u_long32 job_id, int nostdin, int noshell,
*                        int is_rsh, int is_qlogin, int force_pty,
*                        int *p_exit_status)
*
*  FUNCTION
*     The main loop of the commlib server, handling the data transfer from
*     and to the client.
*
*  INPUTS
*     COMM_HANDLE *handle - Handle of the COMM server
*     u_long32 job_id    - SGE job id of this job
*     int nostdin        - The "-nostdin" switch
*     int noshell        - The "-noshell" switch
*     int is_rsh         - Is it a qrsh with commandline?
*     int is_qlogin      - Is it a qlogin or qrsh without commandline?
*     int suspend_remote - suspend_remote switch of qrsh
*     int force_pty      - The user forced use of pty by the "-pty yes" switch
*
*  OUTPUTS
*     int *p_exit_status - The exit status of qrsh_starter in case of
*                          "qrsh <command>" or the exit status of the shell in
*                          case of "qrsh <no command>"/"qlogin".
*                          If the job was signalled, the exit code is 128+signal.
*
*  RESULT
*     int - 0: Ok.
*           1: Invalid parameter
*           2: Log list not initialized
*           3: Error setting terminal mode
*           4: Can't create tty_to_commlib thread
*           5: Can't create commlib_to_tty thread
*           6: Error shutting down commlib connection
*           7: Error resetting terminal mode
*
*  NOTES
*     MT-NOTE: run_ijs_server is not MT-safe
*******************************************************************************/
int run_ijs_server(COMM_HANDLE *handle, const char *remote_host,
                   u_long32 job_id,
                   int nostdin, int noshell,
                   int is_rsh, int is_qlogin, ternary_t force_pty,
                   ternary_t suspend_remote,
                   int *p_exit_status, dstring *p_err_msg)
{
   int               ret = 0, ret_val = 0;
   THREAD_HANDLE     *pthread_tty_to_commlib = NULL;
   THREAD_HANDLE     *pthread_commlib_to_tty = NULL;
   THREAD_LIB_HANDLE *thread_lib_handle = NULL;
   cl_raw_list_t     *cl_com_log_list = NULL;

   DENTER(TOP_LAYER, "run_ijs_server");

   if (handle == NULL || p_err_msg == NULL || p_exit_status == NULL || remote_host == NULL) {
      return 1;
   }
   g_comm_handle = handle;
   g_hostname    = strdup(remote_host);

   cl_com_log_list = cl_com_get_log_list();
   if (cl_com_log_list == NULL) {
      return 2;
   }

   g_nostdin = nostdin;
   g_noshell = noshell;
   g_pid = getpid();
   g_is_rsh = is_rsh;

   if (suspend_remote == UNSET || suspend_remote == NO) {
      g_suspend_remote = 0;
   } else {
      g_suspend_remote = 1;
   }

   /*
    * qrsh without command and qlogin both have is_rsh == 0 and is_qlogin == 1
    * qrsh with command and qsh don't need to set terminal mode.
    * If the user requested a pty we also have to set terminal mode.
    * But only if stdout is still connected to a tty and not redirected
    * to a file or a pipe.
    */
   if (isatty(STDOUT_FILENO) == 1 &&
      ((force_pty == UNSET && is_rsh == 0 && is_qlogin == 1) || force_pty == YES)) {
      /*
       * Set this terminal to raw mode, just output everything, don't interpret
       * it. Let the pty on the client side interpret the characters.
       */
      ret = terminal_enter_raw_mode();
      if (ret != 0) {
         sge_dstring_sprintf(p_err_msg, "can't set terminal to raw mode: %s (%d)",
            strerror(ret), ret);
         return 3;
      } else {
        g_raw_mode_state = 1;
      }
   }

   /*
    * Setup thread list and create two worker threads
    */
   thread_init_lib(&thread_lib_handle);
   /*
    * From here on, we have to cleanup the list in case of errors, this is
    * why we "goto cleanup" in case of error.
    */

   DPRINTF(("creating worker threads\n"));
   DPRINTF(("creating tty_to_commlib thread\n"));
   ret = create_thread(thread_lib_handle, &pthread_tty_to_commlib, cl_com_log_list,
      "tty_to_commlib thread", 1, tty_to_commlib);
   if (ret != CL_RETVAL_OK) {
      sge_dstring_sprintf(p_err_msg, "can't create tty_to_commlib thread: %s",
         cl_get_error_text(ret));
      ret_val = 4;
      goto cleanup;
   }

   DPRINTF(("creating commlib_to_tty thread\n"));
   ret = create_thread(thread_lib_handle, &pthread_commlib_to_tty, cl_com_log_list,
      "commlib_to_tty thread", 1, commlib_to_tty);
   if (ret != CL_RETVAL_OK) {
      sge_dstring_sprintf(p_err_msg, "can't create commlib_to_tty thread: %s",
         cl_get_error_text(ret));
      ret_val = 5;
      goto cleanup;
   }

   /*
    * From here on, the two worker threads are doing all the work.
    * This main thread is just waiting until the client closes the 
    * connection to us, which causes the commlib_to_tty thread to 
    * exit. Then it closes the tty_to_commlib thread, too, and 
    * cleans up everything.
    */
   DPRINTF(("waiting for end of commlib_to_tty thread\n"));
   thread_join(pthread_commlib_to_tty);

   DPRINTF(("shutting down tty_to_commlib thread\n"));
   thread_shutdown(pthread_tty_to_commlib);

   /*
    * Close stdin to awake the tty_to_commlib-thread from the select() call.
    * thread_shutdown() doesn't work on all architectures.
    */
   close(STDIN_FILENO);

   DPRINTF(("waiting for end of tty_to_commlib thread\n"));
   thread_join(pthread_tty_to_commlib);
cleanup:
   /*
    * Set our terminal back to 'unraw' mode. Should be done automatically
    * by OS on process end, but we want to be sure.
    */
   ret = terminal_leave_raw_mode();
   DPRINTF(("terminal_leave_raw_mode() returned %s (%d)\n", strerror(ret), ret));
   if (ret != 0) {
      sge_dstring_sprintf(p_err_msg, "error resetting terminal mode: %s (%d)", strerror(ret));
      ret_val = 7; 
   }

   *p_exit_status = g_exit_status;

   thread_cleanup_lib(&thread_lib_handle);
   DRETURN(ret_val);
}
示例#11
0
/* =============================================================================
 * main
 * =============================================================================
 */
MAIN (argc,argv)
{
    TIMER_T start;
    TIMER_T stop;

    /* Initialization */
    parseArgs(argc, (char** const)argv);
    SIM_GET_NUM_CPU(global_params[PARAM_THREAD]);

    printf("Creating gene and segments... ");
    fflush(stdout);

    long geneLength = global_params[PARAM_GENE];
    long segmentLength = global_params[PARAM_SEGMENT];
    long minNumSegment = global_params[PARAM_NUMBER];
    long numThread = global_params[PARAM_THREAD];


    random_t* randomPtr;
    gene_t* genePtr;
    char* gene;
    segments_t* segmentsPtr;
    sequencer_t* sequencerPtr;

    TM_STARTUP(numThread);
    P_MEMORY_STARTUP(numThread);
    TM_THREAD_ENTER();

    //    TM_BEGIN();
    randomPtr= random_alloc();
    assert(randomPtr != NULL);
    random_seed(randomPtr, 0);

    genePtr = gene_alloc(geneLength);
    assert( genePtr != NULL);
    gene_create(genePtr, randomPtr);
    gene = genePtr->contents;

    segmentsPtr = segments_alloc(segmentLength, minNumSegment);
    assert(segmentsPtr != NULL);
    segments_create(segmentsPtr, genePtr, randomPtr);
    sequencerPtr = sequencer_alloc(geneLength, segmentLength, segmentsPtr);
    assert(sequencerPtr != NULL);
    //TM_END();
    thread_startup(numThread);
    puts("done.");
    printf("Gene length     = %li\n", genePtr->length);
    printf("Segment length  = %li\n", segmentsPtr->length);
    printf("Number segments = %li\n", vector_getSize(segmentsPtr->contentsPtr));
    fflush(stdout);

    /* Benchmark */
    printf("Sequencing gene... ");
    fflush(stdout);
    // NB: Since ASF/PTLSim "REAL" is native execution, and since we are using
    //     wallclock time, we want to be sure we read time inside the
    //     simulator, or else we report native cycles spent on the benchmark
    //     instead of simulator cycles.
    GOTO_SIM();
    TIMER_READ(start);
#ifdef OTM
#pragma omp parallel
    {
        sequencer_run(sequencerPtr);
    }
#else
    thread_start(sequencer_run, (void*)sequencerPtr);
#endif
    TIMER_READ(stop);
    // NB: As above, timer reads must be done inside of the simulated region
    //     for PTLSim/ASF
    GOTO_REAL();
    puts("done.");
    printf("Time = %lf\n", TIMER_DIFF_SECONDS(start, stop));
    fflush(stdout);

    /* Check result */
    {
      char* sequence;
      int result;
      //TM_BEGIN();
      sequence= sequencerPtr->sequence;
      result = strcmp(gene, sequence);
      //TM_END();
        printf("Sequence matches gene: %s\n", (result ? "no" : "yes"));
        if (result) {
            printf("gene     = %s\n", gene);
            printf("sequence = %s\n", sequence);
        }
        fflush(stdout);
        assert(strlen(sequence) >= strlen(gene));
    }

    /* Clean up */
    printf("Deallocating memory... ");
    fflush(stdout);
    sequencer_free(sequencerPtr);
    segments_free(segmentsPtr);
    gene_free(genePtr);
    random_free(randomPtr);
    puts("done.");
    fflush(stdout);

    TM_SHUTDOWN();
    P_MEMORY_SHUTDOWN();

    thread_shutdown();

    MAIN_RETURN(0);
}
示例#12
0
文件: yada.c 项目: jaingaurav/rstm
/* =============================================================================
 * main
 * =============================================================================
 */
MAIN(argc, argv)
{
    /*
     * Initialization
     */

    parseArgs(argc, (char** const)argv);
    SIM_GET_NUM_CPU(global_numThread);
    TM_STARTUP(global_numThread);
    P_MEMORY_STARTUP(global_numThread);
    thread_startup(global_numThread);
    global_meshPtr = mesh_alloc();
    assert(global_meshPtr);
    printf("Angle constraint = %lf\n", global_angleConstraint);
    printf("Reading input... ");
    long initNumElement = mesh_read(global_meshPtr, (char*)global_inputPrefix);
    puts("done.");
    global_workHeapPtr = heap_alloc(1, &yada_heapcompare);
    assert(global_workHeapPtr);
    long initNumBadElement = initializeWork(global_workHeapPtr, global_meshPtr);

    printf("Initial number of mesh elements = %li\n", initNumElement);
    printf("Initial number of bad elements  = %li\n", initNumBadElement);
    printf("Starting triangulation...");
    fflush(stdout);

    /*
     * Run benchmark
     */

    // NB: Since ASF/PTLSim "REAL" is native execution, and since we are using
    //     wallclock time, we want to be sure we read time inside the
    //     simulator, or else we report native cycles spent on the benchmark
    //     instead of simulator cycles.
    GOTO_SIM();
    TIMER_T start;
    TIMER_READ(start);
#ifdef OTM
#pragma omp parallel
    {
        process();
    }
#else
    thread_start((void(*)(void*))process, NULL);
#endif
    TIMER_T stop;
    TIMER_READ(stop);
    // NB: As above, timer reads must be done inside of the simulated region
    //     for PTLSim/ASF
    GOTO_REAL();

    puts(" done.");
    printf("Elapsed time                    = %0.3lf\n",
           TIMER_DIFF_SECONDS(start, stop));
    fflush(stdout);

    /*
     * Check solution
     */

    long finalNumElement = initNumElement + global_totalNumAdded;
    printf("Final mesh size                 = %li\n", finalNumElement);
    printf("Number of elements processed    = %li\n", global_numProcess);
    fflush(stdout);

#if 1
    bool isSuccess = mesh_check(global_meshPtr, finalNumElement);
#else
    bool isSuccess = true;
#endif
    printf("Final mesh is %s\n", (isSuccess ? "valid." : "INVALID!"));
    fflush(stdout);
    assert(isSuccess);

    /*
     * TODO: deallocate mesh and work heap
     */
    TM_SHUTDOWN();
    P_MEMORY_SHUTDOWN();

    GOTO_SIM();

    thread_shutdown();

    MAIN_RETURN(0);
}
示例#13
0
/* =============================================================================
 * main
 * =============================================================================
 */
MAIN(argc, argv)
{
    GOTO_REAL();

    /*
     * Initialization
     */

    parseArgs(argc, (char** const)argv);
    long numThread = global_params[PARAM_THREAD];
    SIM_GET_NUM_CPU(numThread);
    TM_STARTUP(numThread);
    P_MEMORY_STARTUP(numThread);
    thread_startup(numThread);

    long percentAttack = global_params[PARAM_ATTACK];
    long maxDataLength = global_params[PARAM_LENGTH];
    long numFlow       = global_params[PARAM_NUM];
    long randomSeed    = global_params[PARAM_SEED];
    printf("Percent attack  = %li\n", percentAttack);
    printf("Max data length = %li\n", maxDataLength);
    printf("Num flow        = %li\n", numFlow);
    printf("Random seed     = %li\n", randomSeed);

    dictionary_t* dictionaryPtr = dictionary_alloc();
    assert(dictionaryPtr);
    stream_t* streamPtr = stream_alloc(percentAttack);
    assert(streamPtr);
    long numAttack = stream_generate(streamPtr,
                                     dictionaryPtr,
                                     numFlow,
                                     randomSeed,
                                     maxDataLength);
    printf("Num attack      = %li\n", numAttack);

    decoder_t* decoderPtr = decoder_alloc();
    assert(decoderPtr);

    vector_t** errorVectors = (vector_t**)malloc(numThread * sizeof(vector_t*));
    assert(errorVectors);
    long i;
    for (i = 0; i < numThread; i++) {
        vector_t* errorVectorPtr = vector_alloc(numFlow);
        assert(errorVectorPtr);
        errorVectors[i] = errorVectorPtr;
    }

    arg_t arg;
    arg.streamPtr    = streamPtr;
    arg.decoderPtr   = decoderPtr;
    arg.errorVectors = errorVectors;

    /*
     * Run transactions
     */

    TIMER_T startTime;
    TIMER_READ(startTime);
    GOTO_SIM();
#ifdef OTM
#pragma omp parallel
    {
        processPackets((void*)&arg);
    }
    
#else
    thread_start(processPackets, (void*)&arg);
#endif
    GOTO_REAL();
    TIMER_T stopTime;
    TIMER_READ(stopTime);
    printf("\nTime = %lf\n", TIMER_DIFF_SECONDS(startTime, stopTime));

    /*
     * Check solution
     */

    /*long numFound = 0;
    for (i = 0; i < numThread; i++) {
        vector_t* errorVectorPtr = errorVectors[i];
        long e;
        long numError = vector_getSize(errorVectorPtr);
        numFound += numError;
        for (e = 0; e < numError; e++) {
            long flowId = (long)vector_at(errorVectorPtr, e);
            bool_t status = stream_isAttack(streamPtr, flowId);
            assert(status);
        }
    }*/
    /*printf("Num found       = %li\n", numFound);
    assert(numFound == numAttack);*/

    /*
     * Clean up
     */

    for (i = 0; i < numThread; i++) {
        vector_free(errorVectors[i]);
    }
    free(errorVectors);
    decoder_free(decoderPtr);
    stream_free(streamPtr);
    dictionary_free(dictionaryPtr);

    TM_SHUTDOWN();
    P_MEMORY_SHUTDOWN();

    GOTO_SIM();

    thread_shutdown();

    MAIN_RETURN(0);
}
示例#14
0
文件: intruder.c 项目: HPDCS/htmMCATS
/* =============================================================================
 * main
 * =============================================================================
 */
MAIN(argc, argv)
{
    GOTO_REAL();

    /*
     * Initialization
     */
    SETUP_NUMBER_TASKS(3);

    parseArgs(argc, (char** const)argv);
    long numThread = global_params[PARAM_THREAD];
    SETUP_NUMBER_THREADS(numThread);
    SIM_GET_NUM_CPU(numThread);
    TM_STARTUP(numThread, 0);
    P_MEMORY_STARTUP(numThread);
    thread_startup(numThread);

    long percentAttack = global_params[PARAM_ATTACK];
    long maxDataLength = global_params[PARAM_LENGTH];
    long numFlow       = global_params[PARAM_NUM];
    long randomSeed    = global_params[PARAM_SEED];
/*    printf("Percent attack  = %li\n", percentAttack);
    printf("Max data length = %li\n", maxDataLength);
    printf("Num flow        = %li\n", numFlow);
    printf("Random seed     = %li\n", randomSeed); */

double time_total = 0.0;
int repeats = global_params[PARAM_REPEAT];
for (; repeats > 0; --repeats) {

    dictionary_t* dictionaryPtr = dictionary_alloc();
    assert(dictionaryPtr);
    stream_t* streamPtr = stream_alloc(percentAttack);
    assert(streamPtr);
    long numAttack = stream_generate(streamPtr,
                                     dictionaryPtr,
                                     numFlow,
                                     randomSeed,
                                     maxDataLength);
//    printf("Num attack      = %li\n", numAttack);

    decoder_t* decoderPtr = decoder_alloc();
    assert(decoderPtr);

    vector_t** errorVectors = (vector_t**)malloc(numThread * sizeof(vector_t*));
    assert(errorVectors);
    long i;
    for (i = 0; i < numThread; i++) {
        vector_t* errorVectorPtr = vector_alloc(numFlow);
        assert(errorVectorPtr);
        errorVectors[i] = errorVectorPtr;
    }

    arg_t arg;
    arg.streamPtr    = streamPtr;
    arg.decoderPtr   = decoderPtr;
    arg.errorVectors = errorVectors;

    /*
     * Run transactions
     */

    TIMER_T startTime;
    TIMER_READ(startTime);
    tm_time_t start_clock=TM_TIMER_READ();
    GOTO_SIM();
    thread_start(processPackets, (void*)&arg);
    GOTO_REAL();
    TIMER_T stopTime;
    tm_time_t end_clock=TM_TIMER_READ();
    TIMER_READ(stopTime);
    double time_tmp = TIMER_DIFF_SECONDS(startTime, stopTime);
	time_total += time_tmp;
    PRINT_STATS();
    PRINT_CLOCK_THROUGHPUT(end_clock-start_clock);

    /*
     * Check solution
     */

    long numFound = 0;
    for (i = 0; i < numThread; i++) {
        vector_t* errorVectorPtr = errorVectors[i];
        long e;
        long numError = vector_getSize(errorVectorPtr);
        numFound += numError;
        for (e = 0; e < numError; e++) {
            long flowId = (long)vector_at(errorVectorPtr, e);
            bool_t status = stream_isAttack(streamPtr, flowId);
            assert(status);
        }
    }
//    printf("Num found       = %li\n", numFound);
    assert(numFound == numAttack);

    /*
     * Clean up
     */

    for (i = 0; i < numThread; i++) {
        vector_free(errorVectors[i]);
    }
    free(errorVectors);
    decoder_free(decoderPtr);
    stream_free(streamPtr);
    dictionary_free(dictionaryPtr);

}

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

    TM_SHUTDOWN();
    P_MEMORY_SHUTDOWN();

    GOTO_SIM();

    thread_shutdown();

    MAIN_RETURN(0);
}
示例#15
0
/* =============================================================================
 * main
 * =============================================================================
 */
int main (int argc, char** argv)
{
    /*
     * Initialization
     */

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

    thread_startup(global_numThread);
    global_meshPtr = mesh_alloc();
    assert(global_meshPtr);
    printf("Angle constraint = %lf\n", global_angleConstraint);
    printf("Reading input... ");
    long initNumElement = mesh_read(global_meshPtr, global_inputPrefix);
    puts("done.");
    global_workHeapPtr = heap_alloc(1, &element_heapCompare);
    assert(global_workHeapPtr);
    long initNumBadElement = initializeWork(global_workHeapPtr, global_meshPtr);

    printf("Initial number of mesh elements = %li\n", initNumElement);
    printf("Initial number of bad elements  = %li\n", initNumBadElement);
    printf("Starting triangulation...");
    fflush(stdout);

    /*
     * Run benchmark
     */

    TIMER_T start;
    TIMER_READ(start);
#ifdef OTM
    #pragma omp parallel
    {
        process();
    }
#else
    thread_start(process, NULL);
#endif
    TIMER_T stop;
    TIMER_READ(stop);

    puts(" done.");
    printf("Time                            = %0.3lf\n",
           TIMER_DIFF_SECONDS(start, stop));
    fflush(stdout);

    /*
     * Check solution
     */

    long finalNumElement = initNumElement + global_totalNumAdded;
    printf("Final mesh size                 = %li\n", finalNumElement);
    printf("Number of elements processed    = %li\n", global_numProcess);
    fflush(stdout);

#if 0
    bool_t isSuccess = mesh_check(global_meshPtr, finalNumElement);
#else
    bool_t isSuccess = TRUE;
#endif
    printf("Final mesh is %s\n", (isSuccess ? "valid." : "INVALID!"));
    fflush(stdout);
    assert(isSuccess);

    /*
     * TODO: deallocate mesh and work heap
     */

    thread_shutdown();

    return 0;
}
示例#16
0
/* =============================================================================
 * main
 * =============================================================================
 */
MAIN(argc, argv)
{
  int i;
  //FILE * wfile;

#  ifdef SIMULATOR
  printf("SIMULATOR is defined\n");
#  else
  printf("SIMULATOR is not defined\n");
#  endif /* !SIMULATOR */

#if defined(STM)
  printf("STM is defined\n");
#  else
  printf("STM is not defined\n");
#  endif /* !SIMULATOR */



    GOTO_REAL();

    /*
     * Initialization
     */

   if(argc !=3)
     printf("needs two input arguments, \"max_count, num_threads\",argc=%d\n\n", argc);

   max_count = atoi(argv[1]);
   long numThread = atoi(argv[2]);

   if(numThread > MAX_NUM_OF_THREADS)
     printf("num_threads can be at most %d\n\n", MAX_NUM_OF_THREADS);
   //else
   //printf("numThread = %d\n\n", (int)numThread);

   for(i=0; i<MAX_NUM_OF_THREADS; i++)
     threads_arg[i]=i;
 

    SIM_GET_NUM_CPU(numThread);
    TM_STARTUP(numThread);
    P_MEMORY_STARTUP(numThread);
    thread_startup(numThread);


    /*
     * Run transactions
     */
    //router_solve_arg_t routerArg = {routerPtr, mazePtr, pathVectorListPtr};
    TIMER_T startTime;
    TIMER_READ(startTime);
    GOTO_SIM();
    thread_start(func_count, (void*)threads_arg);
    GOTO_REAL();
    TIMER_T stopTime;
    TIMER_READ(stopTime);


    //printf("Elapsed time    = %f seconds\n", TIMER_DIFF_SECONDS(startTime, stopTime));

    /*
     * Check solution and clean up
     */


    TM_SHUTDOWN();
    P_MEMORY_SHUTDOWN();

    GOTO_SIM();

    thread_shutdown();

    //wfile = fopen ("exe_time.txt","a");
    //fprintf(wfile, "Elapsed time    = %f, Aborts/starts=%f, Aborts=%f, starts=%f\n", TIMER_DIFF_SECONDS(startTime, stopTime), (float)((float)(AbortTally*100)/((float)StartTally)), (float)AbortTally, (float)StartTally);
    //fclose(wfile);

    //printf("final value of counter=%d\n\n", my_counter); 



    MAIN_RETURN(0);
}