全部博文(77)
分类: LINUX
2009-06-10 18:09:06
#include
#include
#include
#include
#include
#define N 800 //250
int main()
{
int size,rank;
struct timeval starttime,endtime;
double timepast;
int i,j,k,m;
int a[N][N],b[N][N],c[N][N];
for(i=0;i
{
for(j=0;j
{
srand((unsigned int)time(NULL)); //产生随机数种子
m=( rand() % 100); //产生0-100的随机数,给矩阵A,B赋初始值
a[i][j]=b[i][j]=m;
}
}
omp_set_num_threads(4);
gettimeofday(&starttime,NULL);
//#pragma omp parallel for shared(a,b,c) private(i,j,k) num_threads(4) //利用OpenMP静态调度static的方法实现并行
#pragma omp parallel for shared(a,b,c) private(i,j,k) schedule(static,4)
//利用OpenMP静态调度static的方法实现并行
//#pragma omp for schedule(static)
for(i=0;i
{ for(j=0;j
{ c[i][j]=0;
for(k=0;k
{
c[i][j]+=a[i][k]*b[k][j];
//rank= omp_get_thread_num();
//size= omp_get_num_threads();
//printf( "[i=%d][k=%d][j=%d] from %d of %d\n", i,k,j,rank, size );
}
}
}
gettimeofday(&endtime,NULL);
timepast=((double)(endtime.tv_sec-starttime.tv_sec)*1000000+(double)(endtime.tv_usec-starttime.tv_usec))/1000000;
printf("the whole processing time of the program is %lf seconds\n",timepast);
}