main.c
/*******************************************************************************************************
							Matrix Multiplication using IJK algorithm using AVX to improve performance

********************************************************************************************************/
Matrix Multiplication using IJK algorithm using AVX to improve performance
Matrix Multiplication using IJK algorithm using AVX to improve performance
void avx_dgemmIJK(int size) {
	double alpha, beta;
	alpha = beta = 1.0;
	clock_t  start;
	clock_t end;
	double cpu_time_used;
	double sum = 0;
		posix_memalign((void**)&matrixA, 32, size*size*sizeof(double));
		posix_memalign((void**)&matrixB, 32, size*size*sizeof(double));
 	 	posix_memalign((void**)&matrixC, 32, size*size*sizeof(double));
		posix_memalign((void**)&matrixC1, 32, size*size*sizeof(double));
			fillArray(matrixA);
			fillArray(matrixB);
			resetMatrix(matrixC1);
		for (int ctr2 = 0; ctr2 < 2; ctr2++) {
			resetMatrix(matrixA);
			resetMatrix(matrixB);
			fillArray(matrixA);
			fillArray(matrixB);
			resetMatrix(matrixC);
			start = clock();
			for (int i = 0; i < size; i+=4) {
				for (int j = 0; j < size; j++) {
						__m256d c = _mm256_load_pd(matrixC+i*size+j);
					for (int k = 0; k < size; k++) {
							c = _mm256_add_pd(c, _mm256_mul_pd(_mm256_load_pd(matrixA+i*size+k),_mm256_broadcast_sd(matrixB+k*size+j)));
							_mm256_store_pd(matrixC+i*size+j, c);
					}
				}
			}
			end = clock();
			cpu_time_used = ((double)(end - start));
			sum += cpu_time_used;
		}
		cblas_dgemm(CblasRowMajor, CblasNoTrans, CblasNoTrans, size, size, size, alpha, matrixA, size, matrixB, size, beta, matrixC1, size);
		printf("\n**************************************************************************************************************\n\n");
		printf("Avg execution time with Ctimer\n Size (NxN) %d \t\t %lf\n\n", size, (sum / 3.0));
		printf("GFLOPS:\t\t %lf\n\n",calculateGFLOPS(sum,size) );
		sum = 0;
		printf("\n\n______________________________________________________________________________________________________________\n\n");
		free(matrixA);
		free(matrixB);
		free(matrixC);
		free(matrixC1);
}
void avx_dgemmIJK ( int size ) { double alpha , beta ; alpha = beta = 1.0 ; clock_t start ; clock_t end ; double cpu_time_used ; double sum = 0 ; posix_memalign ( ( void * * ) & matrixA , 32 , size * size * sizeof ( double ) ) ; posix_memalign ( ( void * * ) & matrixB , 32 , size * size * sizeof ( double ) ) ; posix_memalign ( ( void * * ) & matrixC , 32 , size * size * sizeof ( double ) ) ; posix_memalign ( ( void * * ) & matrixC1 , 32 , size * size * sizeof ( double ) ) ; fillArray ( matrixA ) ; fillArray ( matrixB ) ; resetMatrix ( matrixC1 ) ; for ( int ctr2 = 0 ; ctr2 < 2 ; ctr2 ++ ) { resetMatrix ( matrixA ) ; resetMatrix ( matrixB ) ; fillArray ( matrixA ) ; fillArray ( matrixB ) ; resetMatrix ( matrixC ) ; start = clock ( ) ; for ( int i = 0 ; i < size ; i += 4 ) { for ( int j = 0 ; j < size ; j ++ ) { __m256d c = _mm256_load_pd ( matrixC + i * size + j ) ; for ( int k = 0 ; k < size ; k ++ ) { c = _mm256_add_pd ( c , _mm256_mul_pd ( _mm256_load_pd ( matrixA + i * size + k ) , _mm256_broadcast_sd ( matrixB + k * size + j ) ) ) ; _mm256_store_pd ( matrixC + i * size + j , c ) ; } } } end = clock ( ) ; cpu_time_used = ( ( double ) ( end - start ) ) ; sum += cpu_time_used ; } cblas_dgemm ( CblasRowMajor , CblasNoTrans , CblasNoTrans , size , size , size , alpha , matrixA , size , matrixB , size , beta , matrixC1 , size ) ; printf ( " \n \n \n " ) ; printf ( " \n \t \t \n \n " , size , ( sum / 3.0 ) ) ; printf ( " \t \t \n \n " , calculateGFLOPS ( sum , size ) ) ; sum = 0 ; printf ( " \n \n \n \n " ) ; free ( matrixA ) ; free ( matrixB ) ; free ( matrixC ) ; free ( matrixC1 ) ; }
Matrix Multiplication using IJK algorithm using AVX to improve performance
Matrix Multiplication using IJK algorithm using AVX to improve performance
//memory allocation for matrices
 //filling the matrix
 //reset matrixC1
 //filling the matrix
 //reset matrixC
 //	matrix multiplication
 //double cij = matrixC[i*N + j];
 //cij = cij + matrixA[i*N + k] * matrixB[k*N + j];
 //matrixC[i*N + j] = cij;
 //Matrix Verification Using CBLAS
 //Computing Matrix Multiplication using CBLAS
 //freeing the dynamic memory
