You create an OpenMP application by using Microsoft Visual C++.
You write the following code segment. (Line numbers are included for reference only.)
01 int addIndices(int a,int b)
02 {
03 return a+b;
04 }
05 int _tmain(int argc, _TCHAR* argv[])
06 {
07 int i, j;
08 int a[10][10];
09 #pragma omp parallel for
10 for (i = 0; i < 10; i++)
11 for (j = 0; j < 10; j++)
12 {
14 a[i][j] = addIndices(i, j);
15 }
16 }
The code segment stores some incorrect data in the array. You need to ensure that the code segment stores only correct data in the array.
What should you do?
A.
Insert the following line of code at line 13:
#pragma critical
B.
Replace the code at line 09 with the following line of code:
#pragma atomic
C.
Replace the code at line 09 with the following line of code:
#pragma omp parallel for private(i)
D.
Replace the code at line 09 with the following line of code:
#pragma omp parallel for private(j)