#include<iostream>
#include"omp.h"
#define numbs 10000
using namespace std;
int main()
{
int i,j,a[numbs]={0},k=1,b[numbs];
double start, finish;
omp_set_num_threads(16);
omp_set_dynamic(0);
#pragma omp parallel for private(i) shared(a,b)
for (i = 0; i < numbs; i++)
{
b[i] = i;
}
start = omp_get_wtime();
#pragma omp parallel for shared(a) private(i,j) collapse(2)
for (j = 1; j < numbs; j++)
{
for (i = j; i >= 0; i--)
{
a[j] += k * b[i];
k = -k;
}
k = 1;
}
finish = omp_get_wtime();
for (i = 0; i < 10; i++)
{
cout << a[i] << endl;
}
cout << finish-start<<endl ;
}
表示不明白原因