Parallelize write_transformation funcs
This commit is contained in:
parent
b80220f3e7
commit
53b1bfcda7
13
src/main.cpp
13
src/main.cpp
@ -4,7 +4,7 @@
|
|||||||
* The program performs the Jacobi rotation method.
|
* The program performs the Jacobi rotation method.
|
||||||
* The size of the matrix, and number of transformations
|
* The size of the matrix, and number of transformations
|
||||||
* performed are written to file.
|
* performed are written to file.
|
||||||
* Eigenvector correstonding to the 3 smallest eigenvalues
|
* Eigenvector corresponding to the 3 smallest eigenvalues
|
||||||
* for matrices of size 6x6 and 100x100 are written to file.
|
* for matrices of size 6x6 and 100x100 are written to file.
|
||||||
*
|
*
|
||||||
* @author Cory Alexander Balaton (coryab)
|
* @author Cory Alexander Balaton (coryab)
|
||||||
@ -13,7 +13,10 @@
|
|||||||
*/
|
*/
|
||||||
#include <cassert>
|
#include <cassert>
|
||||||
#include <cmath>
|
#include <cmath>
|
||||||
|
#include <ctime>
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
|
#include <omp.h>
|
||||||
|
#include <ostream>
|
||||||
|
|
||||||
#include "utils.hpp"
|
#include "utils.hpp"
|
||||||
#include "matrix.hpp"
|
#include "matrix.hpp"
|
||||||
@ -28,6 +31,7 @@ void write_transformation_dense(int N)
|
|||||||
ofile << "N,T" << std::endl;
|
ofile << "N,T" << std::endl;
|
||||||
|
|
||||||
// Increase size of matrix, start at 5 to avoid logic_error of N=4
|
// Increase size of matrix, start at 5 to avoid logic_error of N=4
|
||||||
|
#pragma omp parallel for ordered schedule(static, 1)
|
||||||
for (int i = 5; i <= N; i++) {
|
for (int i = 5; i <= N; i++) {
|
||||||
arma::mat A = arma::mat(i, i).randn();
|
arma::mat A = arma::mat(i, i).randn();
|
||||||
A = arma::symmatu(A);
|
A = arma::symmatu(A);
|
||||||
@ -40,8 +44,11 @@ void write_transformation_dense(int N)
|
|||||||
jacobi_eigensolver(A, 10e-14, eigval, eigvec, 100000, iters, converged);
|
jacobi_eigensolver(A, 10e-14, eigval, eigvec, 100000, iters, converged);
|
||||||
|
|
||||||
// Write size, and number of iterations to file
|
// Write size, and number of iterations to file
|
||||||
|
#pragma omp ordered
|
||||||
|
{
|
||||||
ofile << i << "," << iters << std::endl;
|
ofile << i << "," << iters << std::endl;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
ofile.close();
|
ofile.close();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -58,6 +65,7 @@ void write_transformation_tridiag(int N)
|
|||||||
ofile << "N,T" << std::endl;
|
ofile << "N,T" << std::endl;
|
||||||
|
|
||||||
// Increase size of matrix, start at 5 to avoid logic_error of N=4
|
// Increase size of matrix, start at 5 to avoid logic_error of N=4
|
||||||
|
#pragma omp parallel for ordered schedule(static, 1)
|
||||||
for (int i = 5; i <= N; i++) {
|
for (int i = 5; i <= N; i++) {
|
||||||
h = 1. / (double) (i+1);
|
h = 1. / (double) (i+1);
|
||||||
a = -1. / (h*h), d = 2. / (h*h);
|
a = -1. / (h*h), d = 2. / (h*h);
|
||||||
@ -72,8 +80,11 @@ void write_transformation_tridiag(int N)
|
|||||||
jacobi_eigensolver(A, 10e-14, eigval, eigvec, 100000, iters, converged);
|
jacobi_eigensolver(A, 10e-14, eigval, eigvec, 100000, iters, converged);
|
||||||
|
|
||||||
// Write size, and number of iterations to file
|
// Write size, and number of iterations to file
|
||||||
|
#pragma omp ordered
|
||||||
|
{
|
||||||
ofile << i << "," << iters << std::endl;
|
ofile << i << "," << iters << std::endl;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
ofile.close();
|
ofile.close();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user