Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Write an OpenMP program to transpose a given matrix. The input for this program

ID: 3651707 • Letter: W

Question

Write an OpenMP program to transpose a given matrix. The
input for this program will be from a text file. The name of the file
will be matrix.txt and will be in your pgm directory. In the above
example the matrix.txt file would be:
3 3
1 2 8
3 4 3
5 6 1
Example Output:
1 3 5
2 4 6





So this is what I have:

#include <iostream>
#include <fstream>

using namespace std;

int main()
{
int a[3][3], b[3][3], i, j, rows, cols;
ofstream myfile;
myfile.open("matrix.txt");
if(myfile.is_open()){
#pragma omp parallel for
for(i = 0; i < rows; i++)
for (j = 0; j < cols; j++)
b[j][i] = a[i][j];
cout << " sample transpose of a matrix is: ";

for (i = 0; i < cols; i++){
for(j = 0; j < rows; j++)
cout << b[i][j] << " ";

}

}

}

Unfortunately it is not working. What am I doing wrong?

Explanation / Answer

typo error in line 8

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote