diff --git a/cs677/hw4/src/transpose.cc b/cs677/hw4/src/transpose.cc index a0d0093..3c9385e 100644 --- a/cs677/hw4/src/transpose.cc +++ b/cs677/hw4/src/transpose.cc @@ -37,23 +37,48 @@ inline void taskAllocate(int total_tasks, int total_workers, int this_id, int main(int argc, char * argv[]) { int my_rank; - int comm_size; - int matrix_size = 100; + int p; /* the number of processes */ + int n = 10; /* the size of the matrix */ MPI_Init(&argc, &argv); MPI_Comm_rank(MPI_COMM_WORLD, &my_rank); - MPI_Comm_size(MPI_COMM_WORLD, &comm_size); + MPI_Comm_size(MPI_COMM_WORLD, &p); for (int i = 0; i < argc; i++) { if (!strncmp(argv[i], "-s", 2)) { - matrix_size = atoi(strlen(argv[i]) > 2 + n = atoi(strlen(argv[i]) > 2 ? argv[i] + 2 : argv[++i]); } } + int matrix[n][n]; + int my_first_row; + int my_num_rows; + taskAllocate(n, p, my_rank, &my_first_row, &my_num_rows); + for (int row = my_first_row; row < my_first_row + my_num_rows; row++) + { + for (int j = 0; j < n; j++) + { + matrix[row][j] = 100 * row + j; + } + } + + if (my_rank == 0) + { + cout << "Final matrix:" << endl; + for (int i = 0; i < n; i++) + { + for (int j = 0; j < n; j++) + { + cout << matrix[i][j] << " "; + } + cout << endl; + } + } + MPI_Finalize(); return 0;