added a recvmatrix

git-svn-id: svn://anubis/gvsu@251 45c1a28c-8058-47b2-ae61-ca45b979098e
This commit is contained in:
josh 2008-11-23 16:00:39 +00:00
parent 31d4ee0887
commit 94c42ca5e0

View File

@ -56,9 +56,15 @@ int main(int argc, char * argv[])
/* Initialize the matrices */ /* Initialize the matrices */
int matrix[n][n]; int matrix[n][n];
int recvmatrix[n][n];
for (int i = 0; i < n; i++) /* zero the matrices for prettier */ for (int i = 0; i < n; i++) /* zero the matrices for prettier */
{
for (int j = 0; j < n; j++) /* printing */ for (int j = 0; j < n; j++) /* printing */
{
matrix[i][j] = 0; matrix[i][j] = 0;
recvmatrix[i][j] = 0;
}
}
/* Determine which rows I am responsible for */ /* Determine which rows I am responsible for */
int my_first_row; int my_first_row;
@ -92,7 +98,7 @@ int main(int argc, char * argv[])
for (int row_offset = 0; row_offset < my_num_rows; row_offset++) for (int row_offset = 0; row_offset < my_num_rows; row_offset++)
my_col_i_vals[row_offset] = matrix[my_first_row + row_offset][i]; my_col_i_vals[row_offset] = matrix[my_first_row + row_offset][i];
MPI_Gatherv(&my_col_i_vals[0], my_num_rows, MPI_INT, MPI_Gatherv(&my_col_i_vals[0], my_num_rows, MPI_INT,
&matrix[i][0], &counts[0], &displs[0], &recvmatrix[i][0], &counts[0], &displs[0],
MPI_INT, toproc, MPI_COMM_WORLD); MPI_INT, toproc, MPI_COMM_WORLD);
proccount--; proccount--;
if (proccount <= 0) if (proccount <= 0)
@ -110,7 +116,7 @@ int main(int argc, char * argv[])
{ {
for (int j = 0; j < n; j++) for (int j = 0; j < n; j++)
{ {
cout << matrix[i][j] << " "; cout << recvmatrix[i][j] << " ";
} }
cout << endl; cout << endl;
} }