#include <stdio.h>
#include <omp.h>
int main()
{
int k=20;
int j[10];
j[0]=20;
#pragma omp parallel for private(k,j)
for(k=0;k<10;k++)
{
printf("k->%d id=%d\t",k,omp_get_thread_num());
j[k]=k*k;
printf("j[%d]->%d id=%d\n",k,j[k],omp_get_thread_num());
}
printf("k=%d\tj[0]=%d\n",k,j[0]);
#include <omp.h>
int main()
{
int k=20;
int j[10];
j[0]=20;
#pragma omp parallel for private(k,j)
for(k=0;k<10;k++)
{
printf("k->%d id=%d\t",k,omp_get_thread_num());
j[k]=k*k;
printf("j[%d]->%d id=%d\n",k,j[k],omp_get_thread_num());
}
printf("k=%d\tj[0]=%d\n",k,j[0]);
}
vi project3.c
gcc -fopenmp -o project3 project3.c
输出为:
k->6 id=6 j[6]->36 id=6
k->5 id=5 j[5]->25 id=5
k->3 id=3 j[3]->9 id=3
k->4 id=4 j[4]->16 id=4
k->8 id=8 j[8]->64 id=8
k->1 id=1 j[1]->1 id=1
k->0 id=0 j[0]->0 id=0
k->9 id=9 j[9]->81 id=9
k->7 id=7 j[7]->49 id=7
k->2 id=2 j[2]->4 id=2
k=20 j[0]=20