added matrix[][] declaration and printing loop

git-svn-id: svn://anubis/gvsu@243 45c1a28c-8058-47b2-ae61-ca45b979098e
This commit is contained in:
josh 2008-11-23 00:00:43 +00:00
parent de4d4a9968
commit ff390e079a

View File

@ -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;