示例#1
0
文件: pmms.c 项目: quaz4/PMMS-T
/*execution eg: pmms matrix_A matrix_B M N K*/
int main(int argc, char** argv)
{
    /*Convert paramaters from strings to ints*/
    m = atoi(argv[3]);
    n = atoi(argv[4]);
    k = atoi(argv[5]);

    /*Allocate memory for matrix arrays*/
    /*Uses logical 2D array so can be used in shared memory*/
    a = (int*)malloc(sizeof(int)*m*n);
    b = (int*)malloc(sizeof(int)*n*k);
    c = (int*)malloc(sizeof(int)*m*k);
    
    /*Read files and assign to arrays*/
    readFile(argv[1], m, n, a);
    readFile(argv[2], n, k, b);

    calcTotal(m, n, k, a, b);

    /*Free shared arrays*/
    free(a);
    free(b);
    free(c);

    /*Destroy mutex and conditional variables*/
    pthread_mutex_destroy(&mutex);
    pthread_cond_destroy(&non_empty);
    pthread_cond_destroy(&non_full);

    return 0;
}
示例#2
0
int main(){
    char name[1000];
    printf("Insira o nome do arquivo\n");
    scanf("%s", name);

    FILE* pFile = fopen(name, "r");
    if (pFile){
        char* contents = readFile(pFile);
        printf("Total: %d\n", calcTotal(contents));
        fclose(pFile);
        free(contents);
    }

    return 1;
}