Commit 80ea0688 authored by Markus Tschlatscher's avatar Markus Tschlatscher
Browse files

First upload

parents
Loading
Loading
Loading
Loading

MKL/Makefile

0 → 100644
+16 −0
Original line number Diff line number Diff line
all: logic full

logic: clean
	#compile 
	icpc -c logicMain.cpp -Wall -o logicMain.o
	#link
	icpc logicMain.o ../utils/utils.o -mkl -o logicMain

full: clean
	#compile
	icpc -c main.cpp -Wall -O3 -o main.o
	#link
	icpc main.o ../utils/utils.o ../utils/timer.o -mkl -o main

clean: 
	rm -f main logicMain *.o *.dat
 No newline at end of file

MKL/logicMain.cpp

0 → 100644
+18 −0
Original line number Diff line number Diff line
#include<iostream>
#include<mkl.h>
#include"../utils/utils.h"

using namespace std;

int main(){
	int N = 4;
	double res = 0.0;
	double A[16] = {1,2,5,1,3,4,4,2,1,2,3,3,7,6,5,4};
	matrixprint(A,N);
	//double AO[16];
	//cblas_dcopy(N*N,A,1,AO,1);
	int info;
	info = LAPACKE_mkl_dgetrfnpi(LAPACK_ROW_MAJOR,N,N,N,A,N);
	matrixprint(A,N);
	return 0;
}
 No newline at end of file

MKL/main.cpp

0 → 100644
+60 −0
Original line number Diff line number Diff line
#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;
}
 No newline at end of file

OVER/LUOver.cpp

0 → 100644
+144 −0
Original line number Diff line number Diff line
#include"../utils/hilloop.h"
#include<omp.h>
#include<iostream>

void nativeOver(double *a,int n){
  for(int k=0;k<n;k++){
    for(int i=k;i<n;i++){
      double sum = 0.0;
      for(int j=0;j<k;j++){
        sum+=a[k*n+j]*a[j*n+i];
      }
      a[k*n+i]=(a[k*n+i]-sum);
    }
    for(int i=k+1;i<n;i++){
      double sum=0.0;
      for(int j=0;j<k;j++){
        sum+=a[i*n+j]*a[j*n+k];
      }
      a[i*n+k]=(a[i*n+k]-sum)/a[k*n+k];
    }
  }
}
  
void nativeLUOv(double *a,int n){
  int i,j,k;
  double s;
  for(i=0;i<n;i++){
    for(j=0;j<n;j++){
      if(i>j){
        s = 0.0;
        for(k=0;k<j;k++){
          s += a[i*n+k] * a[k*n+j];
        }
        a[i*n+j] = (1/(a[j*n+j]))*(a[i*n+j]-s);
      }
      else{
        for(k=0;k<i;k++){
          a[i*n+j] -= a[i*n+k] * a[k*n+j];
        }
      }
    }
  } 
}

void paraNativeLUOv(double *a, int n, int t){
  int k,i,j;
  for(k=0;k<n;k++){
    #pragma omp parallel for num_threads(t)
    for(i=k+1;i<n;i++){
      a[i*n+k] = a[i*n+k]/a[k*n+k];
    }
    #pragma omp parallel for num_threads(t)
    for(i=k+1;i<n;i++){
      for(j=k+1;j<n;j++){
        a[i*n+j] = a[i*n+j] - a[i*n+k] * a[k*n+j];
      }
    }
  }
}

void zorderLUOv(double *a, int n){
	int i,j,k;
  double s;
  ZORDLOOP_START(i,j,0,n,0,n){
    if(i>j){
      s = 0.0;
      for(k=0;k<j;k++){
        s += a[i*n+k] * a[k*n+j];
      }
      a[i*n+j] = (1/(a[j*n+j]))*(a[i*n+j]-s);
    }
    else{
      for(k=0;k<i;k++){
        a[i*n+j] -= a[i*n+k] * a[k*n+j];
      }
    }
  }
  ZORDLOOP_END(i,j)
}

void zorderLUOvR(double *a, int n){
  int k,i,j;
  for(k=0;k<n;k++){
    for(i=k+1;i<n;i++){
      a[i*n+k] = a[i*n+k]/a[k*n+k];
    }
    ZORDLOOP_START(i,j,k+1,n,k+1,n){
      a[i*n+j] = a[i*n+j] - a[i*n+k] * a[k*n+j];
    }
    ZORDLOOP_END(i,j);
  }
}

void paraZorderLUOv(double *a, int n, int t){
	int i,j,k,istart,istop,jstart,jstop,r,c,pn,f;
  for(k=0;k<n;k++){
    #pragma omp parallel for num_threads(t)
    for(i=k+1;i<n;i++){
      a[i*n+k] = a[i*n+k]/a[k*n+k];
    }
    pn = ((n-(k+1))+t-1)/t;
    #pragma omp parallel for num_threads(t)
    for(r=0;r<t;r++){
      istart = (k+1)+(pn*r);
      istop = (k+1)+(pn*(r+1));
      for(c=0;c<t;c++){
        jstart = (k+1)+(pn*c);
        jstop = (k+1)+(pn*(c+1));
        if(istop > n){istop = n;}
        if(jstop > n){jstop = n;}
        ZORDLOOP_START(i,j,istart,istop,jstart,jstop){
          a[i*n+j] = a[i*n+j] - a[i*n+k] * a[k*n+j];
        }
        ZORDLOOP_END(i,j);
      }
    }
  }
}

void paraHilbertLUOv(double *a, int n, int t){
  int i,j,k,istart,istop,jstart,jstop,r,c,pn,f;
  for(k=0;k<n;k++){
    #pragma omp parallel for num_threads(t)
    for(i=k+1;i<n;i++){
      a[i*n+k] = a[i*n+k]/a[k*n+k];
    }
    pn = ((n-(k+1))+t-1)/t;
    #pragma omp parallel for num_threads(t)
    for(r=0;r<t;r++){
      istart = (k+1)+(pn*r);
      istop = (k+1)+(pn*(r+1));
      for(c=0;c<t;c++){
        jstart = (k+1)+(pn*c);
        jstop = (k+1)+(pn*(c+1));
        if(istop > n){istop = n;}
        if(jstop > n){jstop = n;}
        HILLOOP_START(i,j,istart,istop,jstart,jstop){
          a[i*n+j] = a[i*n+j] - a[i*n+k] * a[k*n+j];
        }
        HILLOOP_END(i,j);
      }
    }
  }
}
 No newline at end of file

OVER/LUOver.h

0 → 100644
+26 −0
Original line number Diff line number Diff line
#ifndef _luOv
#define _luOv
	//gets 1 array and overrides it with l and u
	//The 1 on the l diagonal are not saved
	void nativeLUOv(double *a, int n);

	//gets 1 array and overrides it with l and u
	//The 1 on the l diagonal are not saved
	void nativeOver(double *a, int n);

	//parallel version of nativeLUOv
	void paraNativeLUOv(double *a, int n, int t);

	//gets 1 array and overrides it with l and u in zorder
	//The 1 on the l diagonal are not saved
	void zorderLUOv(double *a, int n);

	//version that gets parallized
	void zorderLUOvR(double *a, int n);

	//parallel version ov zorderLUOv
	void paraZorderLUOv(double *a, int n, int t);

	//parallel version ov hilbertLUOv
	void paraHilbertLUOv(double *a, int n, int t);
#endif
 No newline at end of file
Loading