/* Written by Holguer A Becerra UBC Student Master of Biomedical Engineering Course: ECE 328 Prof. Guy Lemiuex. Year 2015-Winter Term 1 */ #include #include #include #include #include #define INT 0 #define FLOAT 1 #define DOUBLE 1 #define MIN(a,b) (((a)<(b))?(a):(b)) #define TYPE_VAR FLOAT #if TYPE_VAR == INT int * matrix1; int * matrix2; int * matrix3; int sum; #elif TYPE_VAR == FLOAT float * matrix1; float * matrix2; float * matrix3; float sum; #elif TYPE_VAR == DOUBLE double * matrix1; double * matrix2; double * matrix3; double sum; #endif typedef unsigned long long int64; unsigned measurement=0,ut,mt; void init_timer(); static __inline__ int64 getticks(void); int main(int argc, char *argv[]) { int64 tick,tick1; int N,rows,columns; int c,d,k; int print=0; int B=64; //initializing timer variables and timer init_timer(); if(argc<=1){ printf("too few arguments"); return 0; } // the first argument has the number of rows, in this case the number of columns are the same as the number of rows. sscanf(argv[1],"%d",&N); sscanf(argv[2],"%d",&print); sscanf(argv[3],"%d",&B); /* initialize random seed: */ srand (100); /*Get Timer*/ tick = getticks(); // Initialize Matrices #if TYPE_VAR == INT matrix1=(int *)malloc((N+1)*N*sizeof(int)); #elif TYPE_VAR == FLOAT matrix1=(float *)malloc((N+1)*N*sizeof(float)); #elif TYPE_VAR == DOUBLE matrix1=(double *)malloc((N+1)*N*sizeof(double)); #endif printf("Initializing matrices\n"); for (rows= 0; rows < (N+1)*N; rows++){ #if TYPE_VAR == INT *(matrix1+rows)=rand() % 1000 + 1; //printf("1[%d,%d]=%d\n",rows/N,rows,*(matrix1+rows)); //printf("2[%d,%d]=%d\n",rows/N,rows,*(matrix2+rows)); #elif TYPE_VAR == FLOAT *(matrix1+rows)=rand() % 10 + 1.5; //printf("1[%d,%d]=%f\n",rows/N,rows,*(matrix1+rows)); //printf("2[%d,%d]=%f\n",rows/N,rows,*(matrix2+rows)); #elif TYPE_VAR == DOUBLE *(matrix1+rows)=rand() % 1000 + 1.5; //printf("1[%d,%d]=%f\n",rows/N,rows,*(matrix1+rows)); //printf("2[%d,%d]=%f\n",rows/N,rows,*(matrix2+rows)); #endif } // Performance Finish and Measure /*Get Timer*/ tick1 = getticks(); measurement = (unsigned)((tick1-tick)/ut); printf("\n Initialization time: %d us\n",measurement); printf("Initialization Done, moving over Forward Elminination\n"); if(print){ for (rows= 0; rows < N; rows++){ for (d= 0; d < N+1; d++){ printf("%0.2f ",*(matrix1+rows*(N+1)+d)); } printf("\n"); } } /*Get Timer*/ tick = getticks(); // Gauss Forward Elminination float pivot=0.0; float pivot_n=0.0; int section=0; int section2=0; int count=0; for(c=0;c=0; c--){ for(k=c+1; k