omp barrier improperly nested in a work-sharing construct

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
#include <stdio.h>
#include<array>
#include<vector>
#include <omp.h>
#include <algorithm>

std::vector<int> pNum;
std::array<int, 4> arr;
std::array<int, 4> logT;
int pGen(int);
void outArr()
{
	//
	for (int i = 0; i < arr.size(); i++)
	{
		//
		printf("arr[%d] = %d \n", i, arr[i]);
	}
}
void genP()
{
	//
	std::fill(arr.begin(), arr.end(), 0);
	std::fill(logT.begin(), logT.end(), 0);
	int i, j, id, n, k, tLog = 0; 
	int state = 0;
	j = 0;
#pragma omp parallel num_threads(4)
	{
		//
#pragma omp for schedule(dynamic, 4) private(j, id, k, state, n)
	//
		for (i = 0; i < 100; i++)
		{
			//
			if (tLog > 0) break;
			id = omp_get_thread_num();
			//printf("%d stored by thread %d and store number is: %d \n", n, id, tLog);
			n = pNum.back() + i * 2;
			for (k = 1; k < pNum.size(); k++)
			{
				//
				if (n % pNum[k] == 0) break;
				if (n / pNum[k] <= pNum[k])
				{
					//
#pragma omp critical
					{
						if (logT[id] == 0)
						{
							//
							logT[id] = 1;
							tLog++;
							arr[id] = n;
						}
						else break;
					}	
				}
			}
		}
	}
}
int main()
{
	pNum.push_back(2);
	pNum.push_back(3);
	genP();
	outArr();
	for (int i = 0; i < pNum.size(); i++)
	{
		printf("%d \n", pNum[i]);
	}
	printf("top say: %d", pNum.size());
	getchar();
}


This is my code above. I am trying to find first 50 prime numbers with openMP but this is the strange thing. As you can see I did not use pragma barrier any where in the code but I am getting "#pragma omp barrier improperly nested in a work-sharing construct" error. What is this about?
Last edited on
Topic archived. No new replies allowed.