first attempt completed, needs rework to receive multiple columns

git-svn-id: svn://anubis/gvsu@245 45c1a28c-8058-47b2-ae61-ca45b979098e
This commit is contained in:
josh 2008-11-23 03:23:55 +00:00
parent 334598ffca
commit 43a5b30712

View File

@ -44,6 +44,7 @@ int main(int argc, char * argv[])
MPI_Comm_rank(MPI_COMM_WORLD, &my_rank);
MPI_Comm_size(MPI_COMM_WORLD, &p);
#if 0
for (int i = 0; i < argc; i++)
{
if (!strncmp(argv[i], "-s", 2))
@ -53,8 +54,13 @@ int main(int argc, char * argv[])
: argv[++i]);
}
}
#endif
/* Initialize the matrix */
int matrix[n][n];
for (int i = 0; i < n; i++)
for (int j = 0; j < n; j++)
matrix[i][j] = 0;
int my_first_row;
int my_num_rows;
taskAllocate(n, p, my_rank, &my_first_row, &my_num_rows);
@ -66,6 +72,41 @@ int main(int argc, char * argv[])
}
}
/* Populate the displacements array */
int displs[p];
int counts[p];
for (int i = 0, total = 0; i < p; i++)
{
int first;
int count;
taskAllocate(n, p, i, &first, &count);
displs[i] = total;
count[i] = count;
total += count;
}
/* Transpose the matrix with p gather operations */
int recvbuf[p];
for (int i = 0; i < p; i++)
{
int col_i_vals_for_proc_p[my_num_rows];
for (int row_offset = 0; row_offset < my_num_rows; row_offset++)
{
col_i_vals_for_proc_p[row_offset] =
matrix[my_first_row + row_offset][i];
}
MPI_Gatherv(&col_i_vals_for_proc_p[0], my_num_rows, MPI_INT,
&recvbuf[0], &counts[0], &displs[0],
MPI_INT, MPI_COMM_WORLD);
}
/* Put my received entries into my columns of the matrix */
for (int i = 0; i < p; i++)
{
matrix[i][p] = recvbuf[i];
}
/* Print out the final matrix */
if (my_rank == 0)
{
cout << "Final matrix:" << endl;