Page Menu
Home
c4science
Search
Configure Global Search
Log In
Files
F111160129
dgemm_omp.c
No One
Temporary
Actions
Download File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Subscribers
None
File Metadata
Details
File Info
Storage
Attached
Created
Tue, Apr 29, 23:02
Size
1 KB
Mime Type
text/x-c
Expires
Thu, May 1, 23:02 (1 d, 23 h)
Engine
blob
Format
Raw Data
Handle
25862622
Attached To
R7871 phys-743-exercises
dgemm_omp.c
View Options
#include <sys/time.h>
#include <stdio.h>
#include <omp.h>
#define N 1000
double second()
{
struct timeval tp;
int i;
i = gettimeofday(&tp,NULL);
return ( (double) tp.tv_sec + (double) tp.tv_usec * 1.e-6 );
}
int main(){
double ** A;
double ** B;
double ** C;
int mysize, myrank;
int chunk;
int i,j,k;
double t1,t2;
A = (double**)malloc(N*sizeof(double*));
B = (double**)malloc(N*sizeof(double*));
C = (double**)malloc(N*sizeof(double*));
for (i=0;i<N;i++){
A[i]=(double*)malloc(N*sizeof(double));
B[i]=(double*)malloc(N*sizeof(double));
C[i]=(double*)malloc(N*sizeof(double));
}
for (i=0;i<N;i++){
for (j=0;j<N;j++){
A[i][j] = 1.0;
B[i][j] = 2.0;
C[i][j] = 0.0;
}
}
t1 = second();
#pragma omp parallel shared(A,B,C) private(i,j,k,myrank)
{
myrank=omp_get_thread_num();
mysize=omp_get_num_threads();
chunk=(N/mysize);
#pragma omp for schedule(runtime)
for (i=0;i<N;i++){
for (j=0;j<N;j++){
for (k=0;k<N;k++){
C[i][j]=C[i][j] + A[i][k]*B[k][j];
}
}
}
}
t2 = second();
printf("Time = %E [s], GF/s = %E \n",(t2-t1), (pow(N,3)/(t2-t1))/10E9 );
}
Event Timeline
Log In to Comment