I have written the following program for matrix multiplication:
#include <stdio.h>
#include <omp.h>
#include <time.h>
#define NRA 500
#define NCA 500
#define NCB 500
int mat_mul() ;
int i , j , k ;
int main(){
double start , end ;
start = omp_get_wtime() ;
mat_mul() ;
end = omp_get_wtime() ;
printf("Time taken : \n %lf " , (end - start) );
return 0;
}
int mat_mul(){
int mat1[NRA][NCA] , mat2[NCA][NCB] , mat3[NRA][NCB] ;
//double start , end ;
//start = omp_get_wtime() ;
#pragma omp parallel private( i , j , k ) shared(mat1 , mat2 , mat3)
#pragma omp for
for( i = 0 ; i < NRA ; i++){
for( j = 0 ; j < NCB ; j++){
mat1[i][j] = mat2[i][j] = rand() ;
for ( k = 0 ; k < NCB ; k++){
mat3[i][k] += mat1[i][k] * mat2[k][j] ;
}
}
}
//end = omp_get_wtime() ;
printf("REsult : \n");
for( i = 0 ; i < NRA ; i ++ ) {
for( j =0 ; j < k ; j ++)
printf("%lf" , (double)mat3[i][j]);
printf("\n") ;
//printf("Time taken : \n %lf " , (end - start) );
}
return 0 ;
}
Everything's fine(almost): It compiles, it executes, even terminates :-D (and it ACTUALLY provides a speed-up(Compare.
But unfortunately, the output appears somethinf like this:
[tejas@localhost Documents]$ gcc -pedantic -Wall -std=c99 -fopenmp par.c
par.c: In function ‘mat_mul’:
par.c:28:30: warning: implicit declaration of function ‘rand’ [-Wimplicit-function-declaration]
mat1[i][j] = mat2[i][j] = rand() ;
^~~~
[tejas@localhost Documents]$ ./a.out
REsult :
...
(LOTS of blank spaces later)
...
Time taken :
0.177506 [tejas@localhost Documents]$
What am I doing wrong? I'm using Fedora 27 , GCC
Thank you in advance.