コード例 #1
0
ファイル: main.c プロジェクト: buharin/fastbuild_python
int main(int argc, char *argv[])
{
    SETUP_THE_NUMBERS;
    TEARDOWN_THE_NUMBERS;
    char *char_string = string("asdasd");
    int c;

    while ((c = getopt(argc, argv, "hv")) != -1) {
        switch (c) {
            case 'h':
                print_help_message();
                prepare_for_exit();
                return EXIT_FAILURE;
            case 'v':
                print_licence_message();
                prepare_for_exit();
                return EXIT_FAILURE;
        }
    }
    random_init();
    set_signals();
    init_windows();
    init_modes();

    loop();

    prepare_for_exit();
    free_memory();
    return EXIT_SUCCESS;
}
コード例 #2
0
int main (int argc, char **argv) {

    if (argc != 4) {
        print_help_message(argv);
        exit(1);
    }

    int n, choice;

    choice = atoi(argv[1]);
    n = atoi(argv[2]);

    validate_inputs(n, choice);

    int *A;
    A = (int *) malloc(n * sizeof(int));
    assert(A != 0);

    int input_type = atoi(argv[3]);
    assert(input_type >= 0);
    assert(input_type <= 4);

    gen_input(A, n, input_type);

    int num_iterations = 10;
   
    sort_routines(choice, A, n, num_iterations);
    //insertion_sort(A, n, num_iterations);

    free(A);

    return 0;
}
コード例 #3
0
ファイル: gsl-shell-jit.c プロジェクト: LuaDist/gsl-shell
static int pmain(lua_State *L)
{
    struct Smain *s = &smain;
    char **argv = s->argv;
    int script;
    int flags = 0;
    globalL = L;
    if (argv[0] && argv[0][0]) progname = argv[0];
    LUAJIT_VERSION_SYM();  /* linker-enforced version check */
    script = collectargs(argv, &flags);
    if (script < 0) {  /* invalid args? */
        print_usage();
        s->status = 1;
        return 0;
    }
    if ((flags & FLAGS_NOENV)) {
        lua_pushboolean(L, 1);
        lua_setfield(L, LUA_REGISTRYINDEX, "LUA_NOENV");
    }
    lua_gc(L, LUA_GCSTOP, 0);  /* stop collector during initialization */
    luaL_openlibs(L);  /* open libraries */
    gsl_shell_openlibs(L);
    lua_gc(L, LUA_GCRESTART, -1);
    dolibrary (L, "gslext");
    s->keep_windows = 1;
    if (!(flags & FLAGS_NOENV)) {
        s->status = handle_luainit(L);
        if (s->status != 0) return 0;
    }
    if (s->status != 0) return 0;
    if ((flags & FLAGS_VERSION)) print_version();
    s->status = runargs(L, argv, (script > 0) ? script : s->argc);
    if (s->status != 0) return 0;
    if (script) {
        s->status = handle_script(L, argv, script);
        if (s->status != 0) return 0;
    }
    if ((flags & FLAGS_INTERACTIVE)) {
        print_jit_status(L);
        dotty(L);
        s->keep_windows = 0;
    } else if (script == 0 && !(flags & (FLAGS_EXEC|FLAGS_VERSION))) {
        if (lua_stdin_is_tty()) {
            print_version();
            print_jit_status(L);
            print_help_message();
            dotty(L);
            s->keep_windows = 0;
        } else {
            dofile(L, NULL);  /* executes stdin as a file */
        }
    }
    return 0;
}
コード例 #4
0
ファイル: expand.c プロジェクト: rmascarenhas/ooo
int main(int argc, char *argv[]) {
    if (argc <= 1) {
        print_help_message();
        return 1;
    }

    char expanded[MAX_EXPANDED_SIZE];
    
    expand(argv[1], expanded);
    printf("%s\n", expanded);

    return 0;
}
コード例 #5
0
void
print_bad_usage_message (int rank)
{
    if (rank) return;

    if (bad_usage.optarg) {
        fprintf(stderr, "%s [-%c %s]\n\n", bad_usage.message,
                (char)bad_usage.opt, bad_usage.optarg);
    }

    else {
        fprintf(stderr, "%s [-%c]\n\n", bad_usage.message,
                (char)bad_usage.opt);
    }

    print_help_message(rank);
}
コード例 #6
0
ファイル: osu_gather.c プロジェクト: Cai900205/test
int
main (int argc, char *argv[])
{
    int i, numprocs, rank, size;
    int skip;
    double latency = 0.0, t_start = 0.0, t_stop = 0.0;
    double timer=0.0;
    double avg_time = 0.0, max_time = 0.0, min_time = 0.0;
    char * sendbuf = NULL, * recvbuf = NULL;
    int po_ret;
    size_t bufsize;

    set_header(HEADER);
    set_benchmark_name("osu_gather");
    enable_accel_support();
    po_ret = process_options(argc, argv);

    if (po_okay == po_ret && none != options.accel) {
        if (init_accel()) {
            fprintf(stderr, "Error initializing device\n");
            exit(EXIT_FAILURE);
        }
    }

    MPI_Init(&argc, &argv);
    MPI_Comm_rank(MPI_COMM_WORLD, &rank);
    MPI_Comm_size(MPI_COMM_WORLD, &numprocs);

    switch (po_ret) {
        case po_bad_usage:
            print_bad_usage_message(rank);
            MPI_Finalize();
            exit(EXIT_FAILURE);
        case po_help_message:
            print_help_message(rank);
            MPI_Finalize();
            exit(EXIT_SUCCESS);
        case po_version_message:
            print_version_message(rank);
            MPI_Finalize();
            exit(EXIT_SUCCESS);
        case po_okay:
            break;
    }

    if(numprocs < 2) {
        if (rank == 0) {
            fprintf(stderr, "This test requires at least two processes\n");
        }

        MPI_Finalize();
        exit(EXIT_FAILURE);
    }

    if ((options.max_message_size * numprocs) > options.max_mem_limit) {
        options.max_message_size = options.max_mem_limit / numprocs;
    }

    if (0 == rank) {
        bufsize = options.max_message_size * numprocs;
        if (allocate_buffer((void**)&recvbuf, bufsize, options.accel)) {
            fprintf(stderr, "Could Not Allocate Memory [rank %d]\n", rank);
            MPI_Abort(MPI_COMM_WORLD, EXIT_FAILURE);
        }
        set_buffer(recvbuf, options.accel, 1, bufsize);
    }

    if (allocate_buffer((void**)&sendbuf, options.max_message_size,
                options.accel)) {
        fprintf(stderr, "Could Not Allocate Memory [rank %d]\n", rank);
        MPI_Abort(MPI_COMM_WORLD, EXIT_FAILURE);
    }
    set_buffer(sendbuf, options.accel, 0, options.max_message_size);

    print_preamble(rank);

    for (size=1; size <= options.max_message_size; size *= 2) {
        if (size > LARGE_MESSAGE_SIZE) {
            skip = SKIP_LARGE;
            options.iterations = options.iterations_large;
        } else {
            skip = SKIP;
        }

        MPI_Barrier(MPI_COMM_WORLD);
        timer=0.0;

        for (i=0; i < options.iterations + skip ; i++) {
            t_start = MPI_Wtime();
            MPI_Gather(sendbuf, size, MPI_CHAR, recvbuf, size, MPI_CHAR, 0,
                    MPI_COMM_WORLD);
            t_stop = MPI_Wtime();

            if (i >= skip) {
                timer+=t_stop-t_start;
            }
            MPI_Barrier(MPI_COMM_WORLD);
        }
        latency = (double)(timer * 1e6) / options.iterations;

        MPI_Reduce(&latency, &min_time, 1, MPI_DOUBLE, MPI_MIN, 0,
                MPI_COMM_WORLD);
        MPI_Reduce(&latency, &max_time, 1, MPI_DOUBLE, MPI_MAX, 0,
                MPI_COMM_WORLD);
        MPI_Reduce(&latency, &avg_time, 1, MPI_DOUBLE, MPI_SUM, 0,
                MPI_COMM_WORLD);
        avg_time = avg_time/numprocs;

        print_stats(rank, size, avg_time, min_time, max_time);
        MPI_Barrier(MPI_COMM_WORLD);
    }

    if (0 == rank) {
        free_buffer(recvbuf, options.accel);
    }
    free_buffer(sendbuf, options.accel);

    MPI_Finalize();

    if (none != options.accel) {
        if (cleanup_accel()) {
            fprintf(stderr, "Error cleaning up device\n");
            exit(EXIT_FAILURE);
        }
    }

    return EXIT_SUCCESS;
}
コード例 #7
0
ファイル: osu_iscatterv.c プロジェクト: allevin/sst-macro
int main(int argc, char *argv[])
{
    setbuf(stdout, NULL);
    int i = 0, rank, size, disp;
    int numprocs;
    double latency = 0.0, t_start = 0.0, t_stop = 0.0;
    double tcomp = 0.0, tcomp_total=0.0, latency_in_secs=0.0;
    double test_time = 0.0, test_total = 0.0;
    double timer=0.0;
    double wait_time = 0.0, init_time = 0.0;
    double init_total = 0.0, wait_total = 0.0;
    char *sendbuf=NULL;
    char *recvbuf=NULL;
    int *sdispls=NULL, *sendcounts=NULL;
    int po_ret;
    size_t bufsize;

    set_header(HEADER);
    set_benchmark_name("osu_iscatterv");
    enable_accel_support();
    po_ret = process_options(argc, argv);

    if (po_okay == po_ret && none != options.accel) {
        if (init_accel()) {
            fprintf(stderr, "Error initializing device\n");
            exit(EXIT_FAILURE);
        }
    }

    MPI_Init(&argc, &argv);
    MPI_Comm_rank(MPI_COMM_WORLD, &rank);
    MPI_Comm_size(MPI_COMM_WORLD, &numprocs);
    MPI_Request request;
    MPI_Status status;

    switch (po_ret) {
        case po_bad_usage:
            print_bad_usage_message(rank);
            MPI_Finalize();
            exit(EXIT_FAILURE);
        case po_help_message:
            print_help_message(rank);
            MPI_Finalize();
            exit(EXIT_SUCCESS);
        case po_version_message:
            print_version_message(rank);
            MPI_Finalize();
            exit(EXIT_SUCCESS);
        case po_okay:
            break;
    }

    if(numprocs < 2) {
        if (rank == 0) {
            fprintf(stderr, "This test requires at least two processes\n");
        }

        MPI_Finalize();
        exit(EXIT_FAILURE);
    }

    if ((options.max_message_size * numprocs) > options.max_mem_limit) {
        options.max_message_size = options.max_mem_limit / numprocs;
    }
    
    if (0 == rank) {
        if (allocate_buffer((void**)&sendcounts, numprocs*sizeof(int), none)) {
            fprintf(stderr, "Could Not Allocate Memory [rank %d]\n", rank);
            MPI_Abort(MPI_COMM_WORLD, EXIT_FAILURE);
        }
        if (allocate_buffer((void**)&sdispls, numprocs*sizeof(int), none)) {
            fprintf(stderr, "Could Not Allocate Memory [rank %d]\n", rank);
            MPI_Abort(MPI_COMM_WORLD, EXIT_FAILURE);
        }

        bufsize = options.max_message_size * numprocs;
        if (allocate_buffer((void**)&sendbuf, bufsize, options.accel)) {
            fprintf(stderr, "Could Not Allocate Memory [rank %d]\n", rank);
            MPI_Abort(MPI_COMM_WORLD, EXIT_FAILURE);
        }
        set_buffer(sendbuf, options.accel, 1, bufsize);
    }

    if (allocate_buffer((void**)&recvbuf, options.max_message_size,
                options.accel)) {
        fprintf(stderr, "Could Not Allocate Memory [rank %d]\n", rank);
        MPI_Abort(MPI_COMM_WORLD, EXIT_FAILURE);
    }
    set_buffer(recvbuf, options.accel, 0, options.max_message_size);

    print_preamble_nbc(rank);

    for(size=options.min_message_size; size <=options.max_message_size; size *= 2) {
        if(size > LARGE_MESSAGE_SIZE) {
            options.skip = SKIP_LARGE;
            options.iterations = options.iterations_large;
        }
        else {
            options.skip = SKIP;
        }
        if (0 == rank) {
            disp =0;
            for ( i = 0; i < numprocs; i++) {
                sendcounts[i] = size;
                sdispls[i] = disp;
                disp += size;
            }
        }
	
        MPI_Barrier(MPI_COMM_WORLD);
        
        timer = 0.0;     
        
        for(i=0; i < options.iterations + options.skip ; i++) {
            t_start = MPI_Wtime();
            
            MPI_Iscatterv(sendbuf, sendcounts, sdispls, MPI_CHAR, recvbuf,
                      size, MPI_CHAR, 0, MPI_COMM_WORLD, &request);
            MPI_Wait(&request,&status);

            t_stop = MPI_Wtime();
            
            if(i>=options.skip){
                timer += t_stop-t_start;
            } 
            MPI_Barrier(MPI_COMM_WORLD);
        }  
        
        MPI_Barrier(MPI_COMM_WORLD);

        latency = (timer * 1e6) / options.iterations;
        
        latency_in_secs = timer/options.iterations;

        init_arrays(latency_in_secs);
        
        if (0 == rank) {
            disp =0;
            for ( i = 0; i < numprocs; i++) {
                sendcounts[i] = size;
                sdispls[i] = disp;
                disp += size;
            }
        }

        MPI_Barrier(MPI_COMM_WORLD);

        timer = 0.0; tcomp_total = 0; tcomp = 0;        
        init_total = 0.0; wait_total = 0.0;
        test_time = 0.0, test_total = 0.0;

        for(i=0; i < options.iterations + options.skip ; i++) {
            t_start = MPI_Wtime();

            init_time = MPI_Wtime();
            MPI_Iscatterv(sendbuf, sendcounts, sdispls, MPI_CHAR, recvbuf,
                      size, MPI_CHAR, 0, MPI_COMM_WORLD, &request);
            init_time = MPI_Wtime() - init_time;

            tcomp = MPI_Wtime();             
            test_time = dummy_compute(latency_in_secs, &request); 
            tcomp = MPI_Wtime() - tcomp;

            wait_time = MPI_Wtime();
            MPI_Wait(&request,&status);
            wait_time = MPI_Wtime() - wait_time;

            t_stop = MPI_Wtime();
            
            if(i>=options.skip){
                timer += t_stop-t_start;
                tcomp_total += tcomp;
                test_total += test_time;
                init_total += init_time;
                wait_total += wait_time;
            }
            MPI_Barrier(MPI_COMM_WORLD);
        }  
       
        MPI_Barrier (MPI_COMM_WORLD);
        
        calculate_and_print_stats(rank, size, numprocs,
                                  timer, latency,
                                  test_total, tcomp_total,
                                  wait_total, init_total);
    }  
    
    if (0 == rank) {
        free_buffer(sendcounts, none);
        free_buffer(sdispls, none);
        free_buffer(sendbuf, options.accel);
    }
    free_buffer(recvbuf, options.accel);

    MPI_Finalize();

    if (none != options.accel) {
        if (cleanup_accel()) {
            fprintf(stderr, "Error cleaning up device\n");
            exit(EXIT_FAILURE);
        }
    }
   
    return EXIT_SUCCESS;
}
コード例 #8
0
int main(int argc, char *argv[])
{
    int i, j, numprocs, rank, size;
    double latency = 0.0, t_start = 0.0, t_stop = 0.0;
    double timer=0.0;
    double avg_time = 0.0, max_time = 0.0, min_time = 0.0;
    float *sendbuf, *recvbuf;
    int po_ret;
    size_t bufsize;

    int64_t* problems = all_reduce_kernels_size;
    int64_t* numRepeats = all_reduce_kernels_repeat;

    set_header(HEADER);
#ifdef ENABLE_MLSL
    mlsl_comm_req request;
    set_benchmark_name("mlsl_osu_allreduce");
#else
    set_benchmark_name("osu_allreduce");
#endif
    enable_accel_support();
    po_ret = process_options(argc, argv);

    if (po_okay == po_ret && none != options.accel) {
        if (init_accel()) {
            fprintf(stderr, "Error initializing device\n");
            exit(EXIT_FAILURE);
        }
    }

#ifdef ENABLE_MLSL
    MLSL_CALL(mlsl_environment_get_env(&env));
    MLSL_CALL(mlsl_environment_init(env, &argc, &argv));
    size_t process_idx, process_count;
    MLSL_CALL(mlsl_environment_get_process_idx(env, &process_idx));
    MLSL_CALL(mlsl_environment_get_process_count(env, &process_count));
    rank = process_idx;
    numprocs = process_count;
    MLSL_CALL(mlsl_environment_create_distribution(env, process_count, 1, &distribution));
#else
    MPI_Init(&argc, &argv);
    MPI_Comm_rank(MPI_COMM_WORLD, &rank);
    MPI_Comm_size(MPI_COMM_WORLD, &numprocs);
#endif

    switch (po_ret) {
        case po_bad_usage:
            print_bad_usage_message(rank);
            FINALIZE();
            exit(EXIT_FAILURE);
        case po_help_message:
            print_help_message(rank);
            FINALIZE();
            exit(EXIT_SUCCESS);
        case po_version_message:
            print_version_message(rank);
            FINALIZE();
            exit(EXIT_SUCCESS);
        case po_okay:
            break;
    }

    if(numprocs < 2) {
        if (rank == 0) {
            fprintf(stderr, "This test requires at least two processes\n");
        }

        FINALIZE();
        exit(EXIT_FAILURE);
    }

    if (options.max_message_size > options.max_mem_limit) {
        options.max_message_size = options.max_mem_limit;
    }

    bufsize = sizeof(float)*(options.max_message_size/sizeof(float));
    if (allocate_buffer((void**)&sendbuf, bufsize, options.accel)) {
        fprintf(stderr, "Could Not Allocate Memory [rank %d]\n", rank);
        MPI_Abort(MPI_COMM_WORLD, EXIT_FAILURE);
    }
    set_buffer(sendbuf, options.accel, 1, bufsize);

    bufsize = sizeof(float)*(options.max_message_size/sizeof(float));
    if (allocate_buffer((void**)&recvbuf, bufsize, options.accel)) {
        fprintf(stderr, "Could Not Allocate Memory [rank %d]\n", rank);
        MPI_Abort(MPI_COMM_WORLD, EXIT_FAILURE);
    }
    set_buffer(recvbuf, options.accel, 0, bufsize);

    print_preamble(rank, numprocs);

    size = options.max_message_size/sizeof(float);

    for (j = 0; j < _NUMBER_OF_KERNELS_; j++)
    {
        size = problems[j];

        options.iterations = numRepeats[j];
        MPI_Barrier(MPI_COMM_WORLD);

        timer = 0.0;
        t_start = MPI_Wtime();
        for(i=0; i < options.iterations; i++) {
#ifdef ENABLE_MLSL
            MLSL_CALL(mlsl_distribution_all_reduce(distribution, sendbuf, recvbuf, size, DT_FLOAT, RT_SUM, GT_DATA, &request));
            MLSL_CALL(mlsl_environment_wait(env, request));
#else
            MPI_Allreduce(sendbuf, recvbuf, size, MPI_FLOAT, MPI_SUM, MPI_COMM_WORLD);
#endif
        }

        t_stop = MPI_Wtime();
        timer = t_stop-t_start;

        latency = (double)(timer * 1e3) / options.iterations;

        MPI_Reduce(&latency, &min_time, 1, MPI_DOUBLE, MPI_MIN, 0,
                MPI_COMM_WORLD);
        MPI_Reduce(&latency, &max_time, 1, MPI_DOUBLE, MPI_MAX, 0,
                MPI_COMM_WORLD);
        MPI_Reduce(&latency, &avg_time, 1, MPI_DOUBLE, MPI_SUM, 0,
                MPI_COMM_WORLD);
        avg_time = avg_time/numprocs;

        print_stats(rank, size, avg_time, min_time, max_time);
        MPI_Barrier(MPI_COMM_WORLD);
    }

    free_buffer(sendbuf, options.accel);
    free_buffer(recvbuf, options.accel);

    FINALIZE();

    if (none != options.accel) {
        if (cleanup_accel()) {
            fprintf(stderr, "Error cleaning up device\n");
            exit(EXIT_FAILURE);
        }
    }

    return EXIT_SUCCESS;
}
コード例 #9
0
ファイル: task_user.cpp プロジェクト: eddieruano/ME405
/**
 * @brief      This method runs when the 'task_user' is called.
 *
 * @details    This method runs inifitely when the task is called so all logic
 *             is contained in here. A for(;;) loop runs until it gets to the
 *             end where it delays for 1 ms to allow other lower level
 *             priority tasks a chance to run.
 */
void task_user::run (void)
{
    time_stamp a_time;             // Holds the time so it can be displayed
    number_entered = 0;            // Holds a number being entered by user

    //
    for (;;)
    {
        switch (state)
        {
        // Initialize first task where we wait for
        case (0):
            printMainMenu();
            // If the user typed a character, read
            if (hasUserInput())
            {
                // In this switch statement, we respond to different characters as commands typed in by the user
                switch (char_in)
                {
                // The 't' command asks what time it is right now
                case ('m'):
                    *p_serial << PMS("->Selected: ") << char_in;
                    *p_serial
                            << endl
                            << endl
                            << PMS ("\t->Switching to Motor Module..")
                            << endl
                            << PMS ("\t->Clearing Registers and Menus..")
                            << endl
                            << PMS ("\t->Intializing Motors..")
                            << endl;

                    // Reset the visible menu flag
                    resetMenus();
                    // Sets the variable to true so it doesn't go into single module yet
                    in_main_motor_module = true;
                    // go to case 1 over all
                    transition_to(1);
                    break;
                // Enter encoder test module
                case ('e'):
                    *p_serial << PMS("->Selected: ") << char_in;
                    *p_serial
                            << ATERM_CLEAR_SCREEN << ATERM_CURSOR_TO_YX(1, 1)
                            << PMS ("\t->Switching to Encoder Module..")
                            << endl
                            << PMS ("\t->Clearing Registers and Menus..")
                            << endl
                            << PMS ("\t->Intializing Encoder..")
                            << endl << endl;

                    // Reset the visible menu flag
                    resetMenus();
                    // Sets the variable to true so it doesn't go into single module yet
                    in_encoder_module = true;
                    // go to case 1 over all
                    transition_to(3);
                    break;
                // The 't' command asks what time it is right now
                // Enter encoder test module
                case ('i'):
                    *p_serial << PMS("->Selected: ") << char_in;
                    *p_serial
                            << ATERM_CLEAR_SCREEN << ATERM_CURSOR_TO_YX(1, 1)
                            << PMS ("\t->Switching to IMU Module..")
                            << endl
                            << PMS ("\t->Clearing Registers and Menus..")
                            << endl
                            << PMS ("\t->Intializing IMU..")
                            << endl << endl;

                    // Reset the visible menu flag
                    resetMenus();
                    // Sets the variable to true so it doesn't go into single module yet
                    in_imu_module = true;
                    // go to case 1 over all
                    transition_to(4);
                    break;
                // The 't' command asks what time it is right now
                case ('t'):
                    *p_serial << (a_time.set_to_now ()) << endl;
                    break;

                // The 's' command asks for version and status information
                case ('s'):
                    show_status ();
                    break;
                // The 'd' means drive control
                case ('d'):
                    *p_serial << PMS("->Selected: ") << char_in;
                    *p_serial
                            << ATERM_CLEAR_SCREEN << ATERM_CURSOR_TO_YX(1, 1)
                            << PMS ("\t->Switching to Drive Mode..")
                            << endl << endl;
                    transition_to(5);
                    in_drive_mode = true;
                    resetMenus();
                    break;
                //case ('d'):
                // The 'h' command is a plea for help; '?' works also
                case ('h'):
                case ('?'):
                    print_help_message ();
                    break;

                // The 'n' command runs a test of entering a number
                case ('n'):
                    while (char_in != 'q')
                    {
                        *p_serial << PMS ("Enter decimal numeric digits, "
                                          "then RETURN or ESC") << endl;
                        getNumberInput();
                        *p_serial << endl << endl << PMS("\t->You Entered: ") << number_entered << endl;
                    }
                    break;

                // A control-C character causes the CPU to restart
                case (3):
                    *p_serial << PMS ("Resetting AVR") << endl;
                    wdt_enable (WDTO_120MS);
                    for (;;);
                    break;

                // If character isn't recognized, ask What's That Function?
                default:
                    *p_serial << '"' << char_in << PMS ("\": WTF?") << endl;
                    break;
                }; // End switch for characters
            } // End if a character was received

            break; // End of state 0

        // Motor Control BASE module
        case (1):
            if (in_main_motor_module) //first time here run menu and get input
            {
                // prints the menu for this module
                printMotorMenu();

                // user is going to input motor number or q
                getNumberInput();

                if (char_in == 'q')
                {
                    *p_serial << PMS("->Selected: ") << char_in << endl
                              << endl
                              << endl
                              << PMS("\t->Returning to Mission Control.. ")
                              << endl
                              << PMS("\t->Releasing Motors..") << endl
                              << PMS("\t->Resetting AVR..") << endl;
                    //wdt_enable (WDTO_120MS);
                    //for (;;);
                    //break;
                    //release motors
                    //motor_select->put(1);

                    //motor_directive -> put(FREEWHEEL);
                    //
                    // no longer in this module, leaving
                    in_main_motor_module = false;
                    transition_to(0);
                    resetMenus();
                    break;
                    //reset menu flag
                    //resetMenus();
                    // set the transition & wait for break
                    //transition_to(0);

                }
                // if the number entered is valid
                else if (isValidMotor(number_entered))
                {
                    // re print user input and give them confirmation message.
                    *p_serial
                            << endl
                            << endl
                            << PMS("\t->Switching to Control of Motor ") << number_entered << dec << PMS(".") << endl
                            << PMS ("\t->Return to the Main Motor Module to swap Motors.") << endl;
                    // set local motor select value
                    local_motor_select = number_entered;
                    //reset menus
                    resetMenus();
                    //set flag to off so we can go into the single motor module
                    in_main_motor_module = false;
                    // go back to the top of this menu
                    // since in_main_motor_module flag is set off, we will go into single motor control when this state reloops
                    transition_to(1);
                }
                else
                {
                    *p_serial << PMS("Try Again. ") << endl;
                    in_main_motor_module = true;

                }

                break;
            }
            if (!in_main_motor_module) //already were here now we go deeper
            {


                printSingleMotorOptions();
                // They now select the motor task
                if (hasUserInput())
                {
                    switch (char_in)
                    {
                    case ('s'):
                        *p_serial
                                << PMS("->Selected: ") << char_in << endl;
                        *p_serial
                                << endl
                                << PMS ("Enter the Power Value (-255 to 255);")
                                << endl
                                << PMS("  *Note: Negative Values = Reverse")
                                << endl;

                        //motor_directive -> put(1);
                        getNumberInput();
                        //setPower(motor_select->get(), number_entered);
                        setMotor(local_motor_select, (int16_t)number_entered, SETPOWER);
                        *p_serial
                                << endl << endl
                                << PMS ("\tPower set at ") << number_entered
                                << PMS(". ") << endl;

                        resetMenus();
                        printDashBoard();

                        //now that operation is complete, ask for more
                        *p_serial
                                << endl << PMS("->Choose Motor ")
                                << local_motor_select << PMS(" operation: ")
                                << PMS("\t(Press 'o' for options)")
                                << endl;
                        break;
                    case ('b'):
                        *p_serial
                                << PMS("->Selected: ") << char_in
                                << endl;
                        *p_serial
                                << PMS ("\t->Enter the Brake Force(0 - 255)")
                                << endl;
                        getNumberInput();
                        *p_serial
                                << endl << endl
                                << PMS ("\tBrake set at ") << number_entered
                                << PMS(". ") << endl;

                        setMotor(local_motor_select, number_entered, BRAKE);
                        resetMenus();

                        printDashBoard();
                        //now that operation is complete, ask for more
                        *p_serial
                                << endl << PMS("->Choose Motor ")
                                << local_motor_select << PMS(" operation: ")
                                << PMS("\t(Press 'o' for options)")
                                << endl;
                        break;
                    case ('f'):
                        *p_serial
                                << PMS("->Selected: ") << char_in << endl;
                        *p_serial
                                << PMS ("\t->Releasing Motor..") << endl;
                        setMotor(0, 0, FREEWHEEL);
                        resetMenus();
                        printDashBoard();
                        //now that operation is complete, ask for more
                        *p_serial
                                << endl << PMS("->Choose Motor ")
                                << local_motor_select << PMS(" operation: ")
                                << PMS("\t(Press 'o' for options)")
                                << endl;

                        break;
                    case ('p'):
                        *p_serial
                                << endl << PMS("->Selected: ")
                                << char_in << endl
                                << PMS("\t->Entering Potentiometer Control... ") << endl;
                        *p_serial << PMS ("\t->Potentiometer Activated.") << endl << endl;
                        *p_serial << endl << endl
                                  << PMS ("\t->Press 'q' to return to the Motor ") << local_motor_select << PMS(" Control")
                                  << endl << PMS ("\t->Press 'r' to refresh the DashBoard ") << endl;
                        transition_to(2);
                        resetMenus();
                        break;
                    case ('o'):
                        resetMenus();
                        printSingleMotorOptions();
                        break;
                    case ('q'):
                        *p_serial
                                << PMS("->Selected: ") << char_in << endl
                                << PMS(" Returning to Main Motor Module.. ")
                                << endl;
                        transition_to(1);
                        resetMenus();

                        in_main_motor_module = true;
                        break;
                    default:
                        *p_serial
                                << endl << PMS("'") << char_in
                                << PMS ("' is not a valid entry.") << endl;
                        *p_serial
                                << endl << PMS("->Choose Motor ")
                                << local_motor_select
                                << PMS(" operation: ") << endl;
                        break;
                    }
                }
            }

            break;
        //Potentiometer Mode
        case (2):
            if (hasUserInput())
            {
                if (char_in  == 'q')
                {
                    *p_serial << endl << PMS("->Selected: ") << char_in << endl;
                    transition_to(1);
                    resetMenus();
                    break;
                    //
                }
                if (char_in == 'r')
                {
                    *p_serial << endl << PMS("->Selected: ") << char_in << endl;
                    resetMenus();
                    printDashBoard();
                    *p_serial << endl << endl
                              << PMS ("\t->Press 'q' to return to the Motor ") << local_motor_select << PMS(" Control")
                              << endl << PMS ("\t->Press 'r' to refresh the DashBoard ") << endl;

                }
            }

            setMotor(local_motor_select, motor_power -> get(), POTENTIOMETER);
            printDashBoard();
            break;
        //for use later [3,4]
        case (3):
            if (in_encoder_module)
            {
                printEncoderModuleOptions();
                if (hasUserInput())
                    switch (char_in)
                    {
                    case ('q'):
                        *p_serial << ATERM_CLEAR_SCREEN << ATERM_BKG_WHITE
                                  << PMS("->Selected: ") << char_in << endl
                                  << endl
                                  << endl
                                  << PMS("\t->Returning to Mission Control.. ")
                                  << endl
                                  << PMS("\t->Releasing Encoder..") << endl;
                        transition_to(0);
                        in_main_motor_module = true;
                        in_encoder_module = false;
                        resetMenus();
                        *p_serial
                                << ATERM_CLEAR_SCREEN
                                << ATERM_CURSOR_TO_YX(1, 1) << endl;

                        break;
                    case ('r'):
                        //constant refreshing already
                        transition_to(1)
                        in_imu_module = true;
                        break;
                    default:
                        
                        break;
                    }
            }
            break;
        case (4):
            if (in_imu_module)
            {
                printIMUModuleOptions();
                if (hasUserInput())
                    switch (char_in)
                    {
                    case ('q'):
                        *p_serial << ATERM_CLEAR_SCREEN
                                  << PMS("->Selected: ") << char_in << endl
                                  << endl
                                  << endl
                                  << PMS("\t->Returning to Mission Control.. ")
                                  << endl
                                  << PMS("\t->Releasing IMU..") << endl;
                        transition_to(0);

                        in_imu_module = false;
                        resetMenus();   

                        break;
                        default:
                        break;
                        *p_serial << ATERM_CLEAR_SCREEN;
                    }




                    case ('r'):
                        
                        break;
                    default:
                        break;
                    }
            }
            break;
        // Drive Mode
        case (5):
            if (in_drive_mode)
            {
                printDriveModeOptions();
                // printDashBoard();
                if (hasUserInput())
                    switch (char_in)
                    {
                    case ('q'):
                        *p_serial << ATERM_CLEAR_SCREEN
                                  << PMS("->Selected: ") << char_in << endl
                                  << endl
                                  << endl
                                  << PMS("\t->Returning to Mission Control.. ")
                                  << endl
                                  << PMS("\t->Releasing Drive Mode..") << endl;
                        transition_to(0);
                        in_drive_mode = false;
                        resetMenus();
                        break;
                    case ('s'):
                        *p_serial << endl
                                  << PMS("Input Power Value for Motor: ")
                                  << endl;
                        getNumberInput();
                        setMotor(0, (int16_t)number_entered, SETPOWER);
                        *p_serial
                                << endl << endl
                                << PMS ("\tPower set at ") << number_entered
                                << PMS (". ") << endl << endl
                                << PMS ("Printing DashBoard.. ") << endl
                                << endl;
                        resetMenus();
                        printDashBoard();
                        break;
                    case ('r'):
                        *p_serial
                                << PMS ("Printing DashBoard.. ")
                                << endl
                                << endl;
                        resetMenus();
                        printDashBoard();

                        break;
                    default:
                        break;
                    }
                int16_t x_direction = y_joystick -> get();
                int16_t map_x = x_direction - 526;
                if (x_direction > 526)
                {
                    map_x = 2 * (x_direction - 526);
                }
                else
                {
                    map_x = -2 * (526 - x_direction);
                }

                motor_setpoint -> put(map_x);

                motor_directive -> put(SETPOWER);

                // *p_serial
                //         << ATERM_CURSOR_TO_YX(19, 1)
                //         << ATERM_ERASE_IN_LINE(0)
                //         << gear_state -> get()
                //         << PMS ("\t\t")
                //         << motor_setpoint -> get()
                //         << PMS("\t")
                //         << PMS("\t")
                //         << motor_power -> get()
                //         << PMS("\t")
                //         << PMS("\t")
                //         << encoder_count -> get()
                //         << PMS("\t")
                //         << ATERM_CURSOR_TO_YX(23, 1)
                //         << ATERM_ERASE_IN_LINE(0)
                //         << steering_power -> get()
                //         << PMS("    \t")
                //         << encoder_ticks_per_task -> get()
                //         << PMS("\t")
                //         << PMS("\t")
                //         << x_joystick -> get()
                //         << PMS("\t")
                //         << PMS("\t")
                //         << y_joystick -> get()
                //         << PMS("\t");
                *p_serial << encoder_ticks_per_task -> get() << endl;

            }
            break;
        //JoyStick test
        case (6):
            break;
        default:
            *p_serial << PMS ("Illegal state! Resetting AVR") << endl;
            wdt_enable (WDTO_120MS);
            for (;;);
            break;

        } // End switch state

        runs++;                             // Increment counter for debugging

        // No matter the state, wait for approximately a millisecond before we
        // run the loop again. This gives lower priority tasks a chance to run
        delay_ms (5);
    }
コード例 #10
0
ファイル: osu_barrier.c プロジェクト: allevin/sst-macro
int main(int argc, char *argv[])
{
    int i = 0, rank;
    int numprocs;
    double avg_time = 0.0, max_time = 0.0, min_time = 0.0;
    double latency = 0.0, t_start = 0.0, t_stop = 0.0;
    double timer=0.0;
    int po_ret;

    set_header(HEADER);
    set_benchmark_name("osu_barrier");
    enable_accel_support();
    po_ret = process_options(argc, argv);

    if (po_okay == po_ret && none != options.accel) {
        if (init_accel()) {
            fprintf(stderr, "Error initializing device\n");
            exit(EXIT_FAILURE);
        }
    }

    options.show_size = 0;

    MPI_Init(&argc, &argv);
    MPI_Comm_rank(MPI_COMM_WORLD, &rank);
    MPI_Comm_size(MPI_COMM_WORLD, &numprocs);

    switch (po_ret) {
        case po_bad_usage:
            print_bad_usage_message(rank);
            MPI_Finalize();
            exit(EXIT_FAILURE);
        case po_help_message:
            print_help_message(rank);
            MPI_Finalize();
            exit(EXIT_SUCCESS);
        case po_version_message:
            print_version_message(rank);
            MPI_Finalize();
            exit(EXIT_SUCCESS);
        case po_okay:
            break;
    }

    if(numprocs < 2) {
        if(rank == 0) {
            fprintf(stderr, "This test requires at least two processes\n");
        }

        MPI_Finalize();

        return EXIT_FAILURE;
    }

    print_preamble(rank);

    options.skip = options.skip_large;
    options.iterations = options.iterations_large;
    timer = 0.0;

    for(i=0; i < options.iterations + options.skip ; i++) {
        t_start = MPI_Wtime();
        MPI_Barrier(MPI_COMM_WORLD);
        t_stop = MPI_Wtime();

        if(i>=options.skip){
            timer+=t_stop-t_start;
        }
    }

    MPI_Barrier(MPI_COMM_WORLD);

    latency = (timer * 1e6) / options.iterations;

    MPI_Reduce(&latency, &min_time, 1, MPI_DOUBLE, MPI_MIN, 0,
                MPI_COMM_WORLD);
    MPI_Reduce(&latency, &max_time, 1, MPI_DOUBLE, MPI_MAX, 0,
                MPI_COMM_WORLD);
    MPI_Reduce(&latency, &avg_time, 1, MPI_DOUBLE, MPI_SUM, 0,
                MPI_COMM_WORLD);
    avg_time = avg_time/numprocs;

    print_stats(rank, 0, avg_time, min_time, max_time);
    MPI_Finalize();

    return EXIT_SUCCESS;
}
コード例 #11
0
ファイル: taskfarmer.c プロジェクト: lohedges/taskfarmer
/* Parse arguments from command-line

   Arguments:

     int argc                  number of command-line arguments
     char **argv               array of command-line arguments
     int rank                  process id
     char *task_file           pointer to task file buffer
     bool *verbose             pointer to verbose flag
     bool *wait_on_idle        pointer to wait flag
     bool *retry               pointer to retry flag
     int *sleep_time           pointer to sleep duration variable
     int *max_retries          pointer to maximum retries variable
*/
void parse_command_line_arguments(int argc, char **argv, int rank, char *task_file,
    bool *verbose, bool *wait_on_idle, bool* retry, int *sleep_time, int *max_retries)
{
    int i = 1;
    bool file;

    if (argc < 2)
    {
        if (rank == 0)
        {
            print_help_message();
        }

        MPI_Finalize();
        exit(0);
    }

    else
    {
        if (argc == 2)
        {
            if (strcmp(argv[1],"-h") == 0 || strcmp(argv[1],"--help") == 0)
            {
                if (rank == 0)
                {
                    print_help_message();
                }

                MPI_Finalize();
                exit(0);
            }
        }

        else
        {
            while (i < argc)
            {
                if (strcmp(argv[i],"-f") == 0 || strcmp(argv[i],"--file") == 0)
                {
                    i++;
                    file = true;
                    strcpy(task_file, argv[i]);
                }

                else if (strcmp(argv[i],"-v") == 0 || strcmp(argv[i],"--verbose") == 0)
                {
                    *verbose = true;
                }

                else if (strcmp(argv[i],"-w") == 0 || strcmp(argv[i],"--wait-on-idle") == 0)
                {
                    *wait_on_idle = true;
                }

                else if (strcmp(argv[i],"-r") == 0 || strcmp(argv[i],"--retry") == 0)
                {
                    *retry = true;
                }

                else if (strcmp(argv[i],"-s") == 0 || strcmp(argv[i],"--sleep-time") == 0)
                {
                    i++;
                    *sleep_time = atof(argv[i]);
                }

                else if (strcmp(argv[i],"-m") == 0 || strcmp(argv[i],"--max-retries") == 0)
                {
                    i++;
                    *max_retries = atof(argv[i]);
                }

                else if (strcmp(argv[i],"-h") == 0 || strcmp(argv[i],"--help") == 0)
                {
                    if (rank == 0)
                    {
                        print_help_message();
                    }

                    MPI_Finalize();
                    exit(0);
                }

                else
                {
                    if (rank == 0)
                    {
                        fprintf(stderr, "[ERROR]: Unknown command-line option %s\n", argv[i]);
                        fprintf(stderr, "For help run \"taskfarmer -h\"\n");
                    }

                    MPI_Finalize();
                    exit(1);
                }

                i++;
            }
        }
    }

    if (!file)
    {
        if (rank == 0)
        {
            fprintf(stderr, "[ERROR]: A task file must be specified with \"-f/--file\"\n");
            fprintf(stderr, "For help run \"taskfarmer -h\"\n");
        }

        MPI_Finalize();
        exit(1);
    }

    // only attempt to launch tasks once if retry option is unset
    if (!*retry) *max_retries = 1;
    else
    {
        // make sure number of retries is a positive, non-zero integer
        if (*max_retries <= 0)
        {
            if (rank == 0)
            {
                fprintf(stderr, "[ERROR]: Maximum number of retries must be greater than zero!\n");
            }

            MPI_Finalize();
            exit(1);
        }
    }

    if (*wait_on_idle)
    {
        // make sure sleep time is a positive, non-zero integer
        if (*sleep_time <= 0)
        {
            if (rank == 0)
            {
                fprintf(stderr, "[ERROR]: Sleep time must be greater than zero!\n");
            }

            MPI_Finalize();
            exit(1);
        }
    }
}
コード例 #12
0
ファイル: params.c プロジェクト: toni-rmc/common
char *handle_arguments(int argc, char *argv[], char **f1, char **f2, int *arg_mode)
{
    int i, c, indexptr;

    /* Value to return: */
    static char *delimiter = NULL;

    while ((c = getopt_long(argc, argv, "123", long_options, &indexptr)) != -1)
    {
        switch (c)
        {
            case '1':
                /* Don't print 1st column. */
                *arg_mode |= NO_C1;
                break;

            case '2':
                /* Don't print 2nd column. */
                *arg_mode |= NO_C2;
                break;

            case '3':
                /* Don't print 3rd column. */
                *arg_mode |= NO_C3;
                break;

            case 't':
                /* Trim blanks from an end of lines. */
                *arg_mode |= TRIM;
                break;

            case 's':
                /* Suppress warnings. */
                *arg_mode |= NO_WARN;
                opterr = 0;
                break;

            case 'd':
                /* Take delimiter argument. */
                delimiter = optarg;
                break;

            case 'v':
                /* Print version and other information and exit. */
                print_version();
                break;

            case 'h':
                /* Print help message and exit. */
                print_help_message();
                break;

            case '?':
                /* Some error in parsing arguments occurred
                e.g., missing argument or unknown switch.
                Do nothing. getopt_long() will print the
                error on it's own if NO_WARN flag is not set. */
                break;

            default:
                /* Something totaly unexpected. */
                abort();
                break;
        }
    } /* end of WHILE loop */

    /* Look for non-switch arguments.
    Two valid file names expected */
    for (i = optind; i < argc; i++)
    {
        if (*f1 == NULL)
            *f1 = argv[i];
        else if (*f2 == NULL)
            *f2 = argv[i];
        else
            break;
    }

    return delimiter;
}
コード例 #13
0
ファイル: osu_get_acc_latency.c プロジェクト: Cai900205/test
int main (int argc, char *argv[])
{
    SYNC        sync_type=FLUSH; 
    int         rank,nprocs;
   
    int         page_size;
    int         po_ret = po_okay;
    WINDOW      win_type=WIN_ALLOCATE;
 
    MPI_CHECK(MPI_Init(&argc, &argv));
    MPI_CHECK(MPI_Comm_size(MPI_COMM_WORLD, &nprocs));
    MPI_CHECK(MPI_Comm_rank(MPI_COMM_WORLD, &rank));

    if(nprocs != 2) {
        if(rank == 0) {
            fprintf(stderr, "This test requires exactly two processes\n");
        }

        MPI_CHECK(MPI_Finalize());

        return EXIT_FAILURE;
    }

    po_ret = process_options(argc, argv, &win_type, &sync_type, rank);
    switch (po_ret) {
        case po_bad_usage:
            print_help_message(rank);
            MPI_CHECK(MPI_Finalize());
            return EXIT_FAILURE;
        case po_help_message:
            print_help_message(rank);
            MPI_CHECK(MPI_Finalize());
            return EXIT_SUCCESS;
    }

    page_size = getpagesize();
    assert(page_size <= MAX_ALIGNMENT);
    
    sbuf =
        (char *) (((unsigned long) sbuf_original + (page_size - 1)) /
                page_size * page_size);
    memset(sbuf, 0, MAX_SIZE);

    rbuf =
        (char *) (((unsigned long) rbuf_original + (page_size - 1)) /
                page_size * page_size);
    memset(rbuf, 0, MAX_SIZE);

    cbuf =
        (char *) (((unsigned long) cbuf_original + (page_size - 1)) /
                page_size * page_size);
    memset(cbuf, 0, MAX_SIZE);

    print_header(rank, win_type, sync_type);

    switch (sync_type){
        case LOCK:
            run_get_acc_with_lock(rank, win_type);
            break;
        case LOCK_ALL:
            run_get_acc_with_lock_all(rank, win_type);
            break;
        case PSCW:
            run_get_acc_with_pscw(rank, win_type);
            break;
        case FLUSH_LOCAL:
            run_get_acc_with_flush_local(rank, win_type);
            break;
        case FENCE: 
            run_get_acc_with_fence(rank, win_type);
            break;
        default: 
            run_get_acc_with_flush(rank, win_type);
            break;
    }

    MPI_CHECK(MPI_Finalize());

    return EXIT_SUCCESS;
}
コード例 #14
0
ファイル: aln2pattern.cpp プロジェクト: jakobmatthes/fragrep
/// parse command line options
// ==============================================================
void read_parameters(int argc, char** argv)
// ==============================================================
{
	params_good = true;
	make_matrices = false;
	sensitivity = .75;
	num_of_opts = 0;
	max_line_length=50.;
	int i;
	for (i=1; i<argc && argv[i][0]=='-'; i++)
	{
		num_of_opts++;
		switch (argv[i][1])
		{
			case '-' : {
				read_long_parameter(argc,argv,i);
				break;
			}
			case 's' : {
				if (strlen(argv[i])>3)
				{
					throw bbq_exception(std::string("Unknown option: ")+std::string(argv[i])+std::string("\n"));
				}
				if (i+1<argc)
				{
					if (argc<=i+1 || !is_flt(argv[i+1]))
					{
						throw bbq_exception("expected float specifying sensitivity.\n");
					}
					sensitivity = atof(argv[i+1]);
					i++;
					num_of_opts++;
				} else {
					params_good = false;
				}
				break;
			}
			case 'L' : {
				if (strlen(argv[i])>3)
				{
					throw bbq_exception(std::string("Unknown option: ")+std::string(argv[i])+std::string("\n"));
				}
				if (i+1<argc)
				{
					if (argc<=i+1 || !is_flt(argv[i+1]))
					{
						throw bbq_exception("expected float specifying line length scale factor\n (in percent, i.e., default is -L 100).\n");
					}
					max_line_length = atof(argv[i+1])/2.;
					i++;
					num_of_opts++;
				} else {
					params_good = false;
				}
				break;
			}
			case 'm' : {
				if (strlen(argv[i])>3)
				{
					throw bbq_exception(std::string("Unknown option: ")+std::string(argv[i])+std::string("\n"));
				}
				make_matrices = true;
				break;
			}
			case 'h' : {
				print_help_message();
				exit(0);
			}
		}
	}
}