main.cpp 2.33 KB
Newer Older
Markus Tschlatscher's avatar
Markus Tschlatscher committed
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60
#include<iostream>
#include<fstream>
#include<mkl.h>
#include"../utils/timer.h"
#include"../utils/utils.h"

using namespace std;

int main(){
	ofstream filOut;							//file Object time
	ofstream resOut;							//file Object distance
	filOut.open("dgetrfnpi_single.dat");		
																//avg time per n
	resOut.open("resMKL.dat");		//residual over runs
	int N = 1000;									//dimension of matrix a
	int si = 5;										//how many times we add to dimension
	int ru = 5;										//how many runs for avg
	int info;											//return from MKL
	CUtilTimer clock;							//Object for time meassure
	double sec,avgSec,res,avgRes;	//seconds,avg seconds,residual,avg Residual
	double *A = NULL;							//creating pointer for A matrix
	double *AO = NULL;						//creating pointer for AO matrix
	//int *P = NULL;							//creating pointer for Pivot array
	mkl_set_num_threads(1);				//MKL uses always each core by default
	for(int S=0;S<si;S++){				//for each dimensions
		avgSec = 0.0;								//resetting AvgSeconds
		avgRes = 0.0;								//resetting AvgResidual
		A = (double*) _mm_malloc(sizeof(double)*N*N,64);
																//creating space for Matrix A
		AO = (double*) _mm_malloc(sizeof(double)*N*N,64);
																//creating space for Matrix AO
		//P = (int*) _mm_malloc(sizeof(int)*N,64);
		for(int R=0;R<ru;R++){			//multiple runs vor avg
			randMatrix(A,N);					//create random Matrix
			cblas_dcopy(N*N,A,1,AO,1);//Copy A into AO
			clock.start();						//starting timer
			//info = LAPACKE_dgetrf(LAPACK_ROW_MAJOR,N,N,A,N,P);
			//info = LAPACKE_dgetrf2(LAPACK_ROW_MAJOR,N,N,A,N,P);
			info = LAPACKE_mkl_dgetrfnpi(LAPACK_ROW_MAJOR,N,N,N,A,N);
																//function call lu decomposition
			clock.stop();							//stop timer
			sec = clock.get_time();		//get needed seconds
			avgSec += sec;						//add avg seconds
			res = makeNorm(AO,A,N); 	//calculate distance
			avgRes += res;						//add distance
		}														//end of same n
		avgSec /= ru;								//calculating Avg Time
		avgRes /= ru;								//calculating Avg Res
		filOut << N <<"	"<< avgSec << "\n";
																//write to file
		resOut << N <<"	"<< avgRes << "\n";
																//write to file
		N = N + 1000;								//next dimension
		_mm_free(A);								//free space
		_mm_free(AO);				
	} 														//end of different n
	filOut.close();								//close files
	resOut.close();				
	return 0;
}