/*----------------------------------------------------------------*/
 Brought To You By CToHTML 
http://www.cs.washington.edu/homes/zahorjan/homepage/Tools/index.htm
 
/*----------------------------------------------------------------*/


#include <stdio.h>
#include <stdlib.h>
#include <time.h>
//#include <mpi.h>
main(int argc, char *argv[]){
int tid, nthreads, i, j, k,itter, chunk=500;
int nrows=1000,ncols=1000;
 time_t rawtime;
 struct tm * timeinfo;
float** a;
float** b;
float** c;
a= malloc(nrows*sizeof(float*));
b=malloc(nrows*sizeof(float*));
c=malloc(nrows*sizeof(float*));
for(i = 0; i < nrows;i++)
        a[i] = malloc(ncols * sizeof(float));
for(i = 0; i < nrows;i++)
        b[i] = malloc(ncols * sizeof(float));
for(i = 0; i < nrows;i++)
        c[i] = malloc(ncols * sizeof(float));


for (i=0; i<nrows; i++)
    for (j=0;j<ncols; j++)
        a[i][j]=(float) (3+i+0.003186*j);
for (i=0; i<nrows; i++)
    for (j=0;j<ncols; j++)
        b[i][j]=(float) (1+0.04517*i);
/**********************************************************/
time ( &rawtime );
  timeinfo = localtime ( &rawtime );
  printf ( "The current date/time is: %s", asctime (timeinfo) );

for(itter=0;itter<5;itter++){
#pragma omp  parallel shared(a,b,c,nthreads,chunk) private(tid,i,j,k)
#pragma omp for schedule (static, chunk)
for (i=0; i<nrows; i++)
    for (k=0; k<ncols; k++)
        for (j=0;j<ncols; j++)
            c[i][j]+=a[i][k]*b[k][j];
}//Just to take up some time
time ( &rawtime );
  timeinfo = localtime ( &rawtime );
  printf ( "The current date/time is: %s", asctime (timeinfo) );

for (i=0; i<5; i++){
    for (j=0;j<5; j++)
        printf("%f ",c[i][j]);
    printf("\n");

}
}