void MatrixInit(ASTnode* ID,ASTnode* rows){ ASTnode* rowsMain=rows; int colSize,curColSize; int n=0; token bufToken; colSize=computeColSize(rows->array[0]); bufToken.lineNumber=rows->array[0]->array[0]->t.lineNumber; while(rows!=NULL){ n++; curColSize=computeColSize(rows->array[0]); rows=rows->array[1]; if(curColSize!=colSize){ semanticError(4,bufToken); return; } } SymbolTableEntryNode* t=getSymbolTableNode(ID); SymbolTable* h=getSymbolTable(ID); t->type.id.initialized=1; t->type.id.length[0]=n; t->type.id.length[1]=colSize; t->type.id.offset=h->offset; populateMatrix(t, rowsMain); h->offset+=n*colSize; //printf("Matrix t->lexeme %s, size initialized: %d %d",t->lexeme,t->type.id.length[0],t->type.id.length[1]); }
int main(int argc, char *argv[]) { int size, rank; int tag = 1234; MPI_Status status; const int rows = 4; const int columns = 2; int matrix[rows][columns]; const int tRows = columns; const int tColumns = rows; // Init MPI_Init(&argc, &argv); MPI_Comm_size(MPI_COMM_WORLD, &size); MPI_Comm_rank(MPI_COMM_WORLD, &rank); if(size != 3) { printf("Su potrebne prave 3 procesy\n"); return 0; } if(rows % 2 != 0) { printf("Matica musi mat parny pocet riadkov\n"); return 0; } if(rank == 0) { // Generate matrix populateMatrix(rows, columns, matrix); // Print matrix printMatrix(rows, columns, matrix); int firstHalf[rows / 2][columns]; int secondHalf[rows / 2][columns]; divideMatrix(rows, columns, matrix, firstHalf, secondHalf); MPI_Send(firstHalf, (rows / 2) * columns, MPI_INT, 1, tag, MPI_COMM_WORLD); MPI_Send(secondHalf, (rows / 2) * columns, MPI_INT, 2, tag, MPI_COMM_WORLD); int tFirstHalf[tRows][tColumns / 2]; int tSecondHalf[tRows][tColumns / 2]; MPI_Recv(tFirstHalf, tRows * tColumns / 2, MPI_INT, 1, tag, MPI_COMM_WORLD, &status); MPI_Recv(tSecondHalf, tRows * tColumns / 2, MPI_INT, 2, tag, MPI_COMM_WORLD, &status); int tMatrix[tRows][tColumns]; joinMatrices(tRows, tColumns / 2, tMatrix, tFirstHalf, tSecondHalf); printMatrix(tRows, tColumns, tMatrix); } else { int sRows = rows / 2; int sColumns = 2; int subMatrix[sRows][sColumns]; MPI_Recv(subMatrix, sRows * sColumns, MPI_INT, 0, tag, MPI_COMM_WORLD, &status); // Transpose matrix int subTMatrix[sColumns][sRows]; transposeMatrix(sRows, sColumns, subMatrix, subTMatrix); MPI_Send(subTMatrix, sRows * sColumns, MPI_INT, 0, tag, MPI_COMM_WORLD); } // Teardown MPI_Finalize(); // Exit return 0; }