c语言 openmp 程序编译不了 求大牛解答

#include<stdio.h>#include<stdlib.h>#include<time.h>#include<omp.h>#defineDIM12000#def... #include <stdio.h>
#include <stdlib.h>
#include <time.h>
#include <omp.h>
#define DIM1 2000
#define DIM2 2000
#define DIM3 2000
int main()
{
int ii, jj, kk,mm;
int nthreads;
double *A;
double *B;
double *C;
long dim1 = DIM1;
long dim2 = DIM2;
long dim3 = DIM3;
clock_t tic, toc;
float elapsed_time;
double maxr;
A = (double*)malloc(sizeof(double)*(dim1*dim2));
B = (double*)malloc(sizeof(double)*(dim2*dim3));
C = (double*)malloc(sizeof(double)*(dim1*dim3));
// srand(86456);
maxr = 1000;
/* filling out in column-major order */
for (ii = 0; ii < dim1; ii++)
for (jj = 0; jj < dim2; jj++)
A[ii + jj*dim1] = ii + jj*dim1/maxr;
for (ii = 0; ii < dim2; ii++)
for (jj = 0; jj < dim3; jj++)
B[ii + jj*dim2] = ii + jj*dim1/maxr;
tic = clock();
#pragma omp parallel shared(A,B,C) private(ii)
{
#pragma omp for schedule (dynamic) nowait
{
for(mm = 0; mm <dim3; mm+=16384){
for (jj = 0; jj < min(16384,dim3); jj++)
{
for (ii = 0; ii < dim3; ii++)
C[ii + jj*dim1] = 0.;
for (kk = 0; kk < dim2; kk++)
for (ii = 0; ii < dim1; ii++)
C[ii + jj*dim1] += A[ii + kk*dim1]*B[kk + jj*dim2];
}
}

}}
printf("c 2000 = %f \n", C[2000]);
toc = clock();
elapsed_time = (float)(toc - tic)/(float)CLOCKS_PER_SEC;
elapsed_time /= (float)nthreads;
printf("time for C(%d,%d) = A(%d,%d) B(%d,%d) is %fs (%d threads)\n",
dim1, dim3, dim1, dim2, dim2, dim3, elapsed_time, nthreads);
free(A);
free(B);
free(C);
return EXIT_SUCCESS;
}
展开
 我来答
Laplas
2013-02-21 · TA获得超过1万个赞
知道大有可为答主
回答量:2680
采纳率:50%
帮助的人:2444万
展开全部
#include "stdafx.h"
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
#include <omp.h>

#define DIM1 2000
#define DIM2 2000
#define DIM3 2000
int main()
{
int ii, jj, kk,mm;
int nthreads = 1000;
double *A;
double *B;
double *C;
long dim1 = DIM1;
long dim2 = DIM2;
long dim3 = DIM3;
clock_t tic, toc;
float elapsed_time;
double maxr;
A = (double*)malloc(sizeof(double)*(dim1*dim2));
B = (double*)malloc(sizeof(double)*(dim2*dim3));
C = (double*)malloc(sizeof(double)*(dim1*dim3));
srand(86456); maxr = 1000;
/* filling out in column-major order */
for (ii = 0; ii < dim1; ii++)
for (jj = 0; jj < dim2; jj++)
A[ii + jj*dim1] = ii + jj*dim1/maxr;
for (ii = 0; ii < dim2; ii++)
for (jj = 0; jj < dim3; jj++)
B[ii + jj*dim2] = ii + jj*dim1/maxr;
tic = clock();

#pragma omp parallel shared(A,B,C) private(ii)
{
#pragma omp for schedule (dynamic) nowait
{
for(mm = 0; mm <dim3; mm+=16384){
for (jj = 0; jj < __min(16384,dim3); jj++) {
for (ii = 0; ii < dim3; ii++)
C[ii + jj*dim1] = 0.;
for (kk = 0; kk < dim2; kk++)
for (ii = 0; ii < dim1; ii++)
C[ii + jj*dim1] += A[ii + kk*dim1]*B[kk + jj*dim2];
}
}
}
}
printf("c 2000 = %f \n", C[2000]);
toc = clock();
elapsed_time = (float)(toc - tic)/(float)CLOCKS_PER_SEC;
elapsed_time /= (float)nthreads;
printf("time for C(%d,%d) = A(%d,%d) B(%d,%d) is %fs (%d threads)\n", dim1, dim3, dim1, dim2, dim2, dim3, elapsed_time, nthreads);
free(A);
free(B);
free(C);
return EXIT_SUCCESS;
}

我用VS2008新建一个Console工程,然后用这样的代码,
编译成功。

min改为了__min
maxr 和 nthreads 没有设置值就使用,出Warning。 我设为1000了。

执行结果:
c 2000 = 5337330000.000000
time for C(2000,2000) = A(2000,2000) B(2000,2000) is 0.036126s (1000 threads)

另外,你提问时必须把出错信息贴出来。别人才好帮你分析。
本回答被提问者和网友采纳
已赞过 已踩过<
你对这个回答的评价是?
评论 收起
尹先国CO418
2013-02-16 · TA获得超过509个赞
知道小有建树答主
回答量:716
采纳率:0%
帮助的人:321万
展开全部
真厉害。一个中文都没
已赞过 已踩过<
你对这个回答的评价是?
评论 收起
wohaoaijiayu
2013-02-16
知道答主
回答量:5
采纳率:0%
帮助的人:3.3万
展开全部
我去=。=你大学的?
已赞过 已踩过<
你对这个回答的评价是?
评论 收起
收起 更多回答(1)
推荐律师服务: 若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询

为你推荐:

下载百度知道APP,抢鲜体验
使用百度知道APP,立即抢鲜体验。你的手机镜头里或许有别人想知道的答案。
扫描二维码下载
×

类别

我们会通过消息、邮箱等方式尽快将举报结果通知您。

说明

0/200

提交
取消

辅 助

模 式