コード例 #1
0
int main(int argc, char * argv[]) {
    mtype_t * matrix = NULL ;
    int i, MAX_SIZE;
    double avg_time;
    support_init();
    
    MAX_ITERS = 100;
    
    if(argc==2)
        if(atoi(argv[1])>=2)
            MAX_SIZE = atoi(argv[1]);
        else{
        printf("The argument must be an integer and larger than or equal to 2");
        return -1;
        }
    else if(argc>2){
        printf("This program takes one or no arguments, you entered too many.");
        return -1;
    }
    else MAX_SIZE = 1024;
    for ( i = 2; i <= MAX_SIZE; i = i * 2 ) {
        // Allocate a matrix of size : buffer_side x buffer_side
        allocate_matrix (& matrix , i );
        // Clear / Initialize the matrix
        clear_matrix (matrix , i );
        
        avg_time = run_experiment_ij (matrix, 5.0, i);
        printf("The average time to do scalar multiplication ij on a %d x %d matrix is %lf \n", i, i, avg_time);
    }
    printf("------------------------------------------------------------------------------\n");
    for ( i = 2; i <= MAX_SIZE; i = i * 2 ) {
        // Allocate a matrix of size : buffer_side x buffer_side
        allocate_matrix (& matrix , i );
        // Clear / Initialize the matrix
        clear_matrix (matrix , i );
        
        avg_time = run_experiment_ji (matrix, 5.0, i);
        printf("The average time to do scalar multiplication ji on a %d x %d matrix is %lf \n", i, i, avg_time);
    }

    support_finalize();
    
    return 0;
}
コード例 #2
0
ファイル: scalarmult.c プロジェクト: GitPS/Project4
int main(int argc, char * argv[]) {    
    int N;
    int max_N = 1024;
    double time;
    mtype_t *matrix = NULL;
    mtype_t scalar = 1;
    
    // Initialize the support library
    support_init();
    
    /* Command line argument handling */
    if(argc >= 2) {
        if(is_valid_int(argv[1]) == 0){
            max_N = (int)strtol(argv[1], NULL, 10);
        }
    }
    
    /* run_experiment_ij */
    printf("\n---------------------------\n\n");
    printf("Executing: run_experiment_ij()\n\n");
    for(N = 2; N <= max_N;){
        allocate_matrix(&matrix, N);
        time = run_experiment_ij(matrix, scalar, N);
        printf("Matrix Size in bytes: %lu\n", sizeof(mtype_t) * N * N);
        printf("megaFLOPS = %f\n\n", (1 * N * N) / time / 1000000);
        N = N*2;
        
        /* Cleanup */
        if(matrix != NULL){
            free(matrix);
            matrix = NULL;
        }
    }
    
    /* run_experiment_ji */
    printf("\n---------------------------\n\n");
    printf("Executing: run_experiment_ji()\n\n");
    for(N = 2; N <= max_N;){
        allocate_matrix(&matrix, N);
        time = run_experiment_ji(matrix, scalar, N);
        printf("Matrix Size in bytes: %lu\n", sizeof(mtype_t) * N * N);
        printf("megaFLOPS = %f\n\n", (1 * N * N) / time / 1000000);
        N = N*2;
        
        /* Cleanup */
        if(matrix != NULL){
            free(matrix);
            matrix = NULL;
        }
    }
    
    /* Cleanup */
    if(matrix != NULL){
        free(matrix);
        matrix = NULL;
    }

    // Finalize the support library
    support_finalize();
    
    return 0;
}