all processes print their matrices
git-svn-id: svn://anubis/gvsu@252 45c1a28c-8058-47b2-ae61-ca45b979098e
This commit is contained in:
parent
94c42ca5e0
commit
c44c1f028e
@ -14,7 +14,7 @@ using namespace std;
|
||||
* 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
|
||||
*/
|
||||
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 l_num;
|
||||
@ -32,6 +32,18 @@ inline void taskAllocate(int total_tasks, int total_workers, int this_id,
|
||||
*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 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_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 */
|
||||
int displs[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)
|
||||
cout << " *** Final Transposed Matrices ***" << endl;
|
||||
for (int i = 0; i < comm_size; i++)
|
||||
{
|
||||
cout << "Final matrix:" << endl;
|
||||
for (int i = 0; i < n; i++)
|
||||
{
|
||||
for (int j = 0; j < n; j++)
|
||||
{
|
||||
cout << recvmatrix[i][j] << " ";
|
||||
}
|
||||
cout << endl;
|
||||
}
|
||||
if (my_rank == i)
|
||||
printMatrix(&matrix[0][0], n, n);
|
||||
MPI_Barrier(); /* for printint coherently */
|
||||
}
|
||||
|
||||
MPI_Finalize();
|
||||
|
Loading…
x
Reference in New Issue
Block a user