Código
#include <pthread.h> #include <stdlib.h> #include <stdio.h> #include "../include/matrix.h" #include "../include/parser.h" #define FILEIN_1 "in1.txt" #define FILEIN_2 "in2.txt" #define FILEOUT "out.txt" #define NOF_ARGS 2 MATRIX *MAT_ONE, *MAT_TWO, *MAT_OUT; // global matrixes to operate upon int NOF_PROC; // number of processes passed as argument via terminal void *multiplica(void *id) { unsigned long threadId = (unsigned long) id; int i,j,k; for (i = (threadId*(MAT_ONE->r/NOF_PROC)); i < ((threadId+1)*(MAT_ONE->r/NOF_PROC)); i++) for (j = 0; j < MAT_TWO->c; j++){ MAT_OUT->matrix[i][j] = 0; for (k = 0; k < MAT_ONE->c; k++) MAT_OUT->matrix[i][j] += MAT_ONE->matrix[i][k] * MAT_TWO->matrix[k][j]; } pthread_exit(NULL); } int main(int argc, char *argv[]) { int i,j,k,flag; if(argc == NOF_ARGS) { if(NOF_PROC < 0) { } } else { "ERROR: invalid number of arguments. EXPECTS n : integer.\n"); } MAT_ONE = MATRIX_new(parser_rows(FILEIN_1), parser_cols(FILEIN_1)); parser_matrix(FILEIN_1, MAT_ONE); MAT_TWO = MATRIX_new(parser_rows(FILEIN_2), parser_cols(FILEIN_2)); parser_matrix(FILEIN_2, MAT_TWO); if(!(MATRIX_is_multipliable(MAT_ONE, MAT_TWO))) { } MAT_OUT = MATRIX_new(MAT_ONE->r, MAT_TWO->c); pthread_t threads[NOF_PROC]; pthread_attr_t atributos; pthread_attr_init(&atributos); pthread_attr_setdetachstate(&atributos, PTHREAD_CREATE_JOINABLE); pthread_attr_setscope(&atributos,PTHREAD_SCOPE_SYSTEM); for (i = 0; i < NOF_PROC; i++){ flag = pthread_create(&threads[i], NULL, multiplica, (void *) (unsigned long) i); if (flag) } for (i = 0; i < NOF_PROC; i++) pthread_join(threads[i], NULL); for(k = 0; k < (MAT_OUT->r); k++) { for(j = 0; j < MAT_OUT->c; j++) { } } UTILS_write_matrix(FILEOUT, MAT_OUT); MATRIX_free(MAT_ONE); MATRIX_free(MAT_TWO); MATRIX_free(MAT_OUT); return 0; }
Pero ahora no se como modificarlo para poder hacerlo para cualquier tipo de matriz rectangular.
gracias!