#include #include #include #include #include #include #include #define PERMS 0666 int parse_args(int argc, char *argv[ ], int* fd, int *np){ if ((argc != 5) || ((fd[0] = open(argv[1], O_RDONLY)) == -1) || ((fd[1] = open(argv[2], O_RDONLY)) == -1) || ((fd[2] = creat(argv[3], PERMS)) == -1) || ((*np = atoi(argv[4])) <= 0)){ fprintf(stderr, "Usage: %s matrixA matrixB matrixC dimension\n", argv[0]); return(-1); }; return 0; } int allocate_space(int** sp, int nproc){ *sp = (int *) calloc(nproc, sizeof(int)); if(*sp == NULL){ perror("Calloc failed"); return -1; } else { return 0; } } int allocate_rows(int** A, int** B, int** C, int nproc){ if(allocate_space(A, nproc) < 0) return -1; if(allocate_space(B, nproc) < 0) return -1; if(allocate_space(C, nproc) < 0) return -1; return 0; }