openMP 小程序改错
写了一个计算3在数组里面出现的次数,现在的问题是不能多线程运算,而且统计出来的3的次数是始终不变的,求高手帮忙看一下
#include<stdio.h>
#include<stdlib.h>
#include<omp.h>
#define N 10000
int main(int argc, char *argv[])
{ int i; int array[N];
int count,nthreads, tid,chunk;
chunk = 100;
count = 0;
double start, end;
start = omp_get_wtime();
#pragma opm parallel shared(nthreads,chunk)
{
tid=omp_get_thread_num();
if(tid==0)
{
nthreads=omp_get_num_threads();
printf("Starting count with %d threads\n",nthreads);
}
}
#pragma omp for schedule (static,chunk)
for( i = 0; i<N; i++)
{
array[i] = rand() % 10;
if(array[i]==3)
count +=1;
}
end =omp_get_wtime();
printf("The count cost %f sec. time.\n", end- start);
#include<stdio.h>
#include<stdlib.h>
#include<omp.h>
#define N 10000
int main(int argc, char *argv[])
{ int i; int array[N];
int count,nthreads, tid,chunk;
chunk = 100;
count = 0;
double start, end;
start = omp_get_wtime();
#pragma opm parallel shared(nthreads,chunk)
{
tid=omp_get_thread_num();
if(tid==0)
{
nthreads=omp_get_num_threads();
printf("Starting count with %d threads\n",nthreads);
}
}
#pragma omp for schedule (static,chunk)
for( i = 0; i<N; i++)
{
array[i] = rand() % 10;
if(array[i]==3)
count +=1;
}
end =omp_get_wtime();
printf("The count cost %f sec. time.\n", end- start);