Parallelize write_transformation funcs
This commit is contained in:
parent
b80220f3e7
commit
53b1bfcda7
21
src/main.cpp
21
src/main.cpp
@ -4,7 +4,7 @@
|
||||
* The program performs the Jacobi rotation method.
|
||||
* The size of the matrix, and number of transformations
|
||||
* 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.
|
||||
*
|
||||
* @author Cory Alexander Balaton (coryab)
|
||||
@ -13,7 +13,10 @@
|
||||
*/
|
||||
#include <cassert>
|
||||
#include <cmath>
|
||||
#include <ctime>
|
||||
#include <iostream>
|
||||
#include <omp.h>
|
||||
#include <ostream>
|
||||
|
||||
#include "utils.hpp"
|
||||
#include "matrix.hpp"
|
||||
@ -28,6 +31,7 @@ void write_transformation_dense(int N)
|
||||
ofile << "N,T" << std::endl;
|
||||
|
||||
// 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++) {
|
||||
arma::mat A = arma::mat(i, i).randn();
|
||||
A = arma::symmatu(A);
|
||||
@ -40,7 +44,10 @@ void write_transformation_dense(int N)
|
||||
jacobi_eigensolver(A, 10e-14, eigval, eigvec, 100000, iters, converged);
|
||||
|
||||
// Write size, and number of iterations to file
|
||||
ofile << i << "," << iters << std::endl;
|
||||
#pragma omp ordered
|
||||
{
|
||||
ofile << i << "," << iters << std::endl;
|
||||
}
|
||||
}
|
||||
ofile.close();
|
||||
}
|
||||
@ -58,6 +65,7 @@ void write_transformation_tridiag(int N)
|
||||
ofile << "N,T" << std::endl;
|
||||
|
||||
// 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++) {
|
||||
h = 1. / (double) (i+1);
|
||||
a = -1. / (h*h), d = 2. / (h*h);
|
||||
@ -72,7 +80,10 @@ void write_transformation_tridiag(int N)
|
||||
jacobi_eigensolver(A, 10e-14, eigval, eigvec, 100000, iters, converged);
|
||||
|
||||
// Write size, and number of iterations to file
|
||||
ofile << i << "," << iters << std::endl;
|
||||
#pragma omp ordered
|
||||
{
|
||||
ofile << i << "," << iters << std::endl;
|
||||
}
|
||||
}
|
||||
ofile.close();
|
||||
}
|
||||
@ -156,8 +167,8 @@ void write_eigenvec(int N)
|
||||
|
||||
int main()
|
||||
{
|
||||
write_transformation_tridiag(100);
|
||||
write_transformation_dense(100);
|
||||
write_transformation_tridiag(100);
|
||||
write_transformation_dense(100);
|
||||
write_eigenvec(10);
|
||||
write_eigenvec(100);
|
||||
return 0;
|
||||
|
||||
Loading…
Reference in New Issue
Block a user