all processes print their matrices

git-svn-id: svn://anubis/gvsu@252 45c1a28c-8058-47b2-ae61-ca45b979098e
This commit is contained in:
josh 2008-11-23 16:04:17 +00:00
parent 94c42ca5e0
commit c44c1f028e

View File

@ -14,7 +14,7 @@ using namespace std;
* first_task_id : OUT : the id (0-based) of the first task for this worker * first_task_id : OUT : the id (0-based) of the first task for this worker
* num : OUT : the number of tasks assigned to this worker * num : OUT : the number of tasks assigned to this worker
*/ */
inline void taskAllocate(int total_tasks, int total_workers, int this_id, void taskAllocate(int total_tasks, int total_workers, int this_id,
int * first_task_id, int * num) int * first_task_id, int * num)
{ {
int l_num; int l_num;
@ -32,6 +32,18 @@ inline void taskAllocate(int total_tasks, int total_workers, int this_id,
*num = l_num; *num = l_num;
} }
void printMatrix(int * matrix, int width, int height)
{
for (int i = 0; i < height; i++)
{
for (int j = 0; j < width; j++)
{
cout << *matrix++ << " ";
}
cout << endl;
}
}
int main(int argc, char * argv[]) int main(int argc, char * argv[])
{ {
int my_rank; int my_rank;
@ -66,7 +78,7 @@ int main(int argc, char * argv[])
} }
} }
/* Determine which rows I am responsible for */ /* Determine which rows I am responsible for and initialize them */
int my_first_row; int my_first_row;
int my_num_rows; int my_num_rows;
taskAllocate(n, p, my_rank, &my_first_row, &my_num_rows); taskAllocate(n, p, my_rank, &my_first_row, &my_num_rows);
@ -78,6 +90,16 @@ int main(int argc, char * argv[])
} }
} }
/* Print the initial matrices */
if (my_rank == 0)
cout << " *** Initial Matrices ***" << endl;
for (int i = 0; i < comm_size; i++)
{
if (my_rank == i)
printMatrix(&matrix[0][0], n, n);
MPI_Barrier(); /* for printint coherently */
}
/* Populate the displacements array */ /* Populate the displacements array */
int displs[p]; int displs[p];
int counts[p]; int counts[p];
@ -108,18 +130,14 @@ int main(int argc, char * argv[])
} }
} }
/* Print out the final matrix */ /* Print the transposed matrices */
if (my_rank == 0) if (my_rank == 0)
cout << " *** Final Transposed Matrices ***" << endl;
for (int i = 0; i < comm_size; i++)
{ {
cout << "Final matrix:" << endl; if (my_rank == i)
for (int i = 0; i < n; i++) printMatrix(&matrix[0][0], n, n);
{ MPI_Barrier(); /* for printint coherently */
for (int j = 0; j < n; j++)
{
cout << recvmatrix[i][j] << " ";
}
cout << endl;
}
} }
MPI_Finalize(); MPI_Finalize();