Parallelizing using OpenMP

Hi, I am trying to parallelize a section of my code. The for loop calls an external function pvnorm which is in a wrapper for some FORTRAN code. Since most of the arguments are pointers/addresses, I declared and initialized all of them within the for loop.

The following example is a simplified version I have been trying to debug. Ideally it must produce the same output since all the arguments are constant but it returns different values over different iterations.

The code works well if I have the function in a critical region. Is there a reason why the code doesn't work. Any help would be greatly appreciated. Thanks!
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
#pragma omp parallel num_threads(2) 
{		
	int future;	
	#pragma omp for private(future) schedule(static)
	for (future=0;future<num_approx_states;future++)
	{
		//Paramters
		double* lower = new double[3];
		double* upper = new double[3];
		double* sigma = new double[3];
		int* infin = new int[3]; 
		double* delta = new double[3]; 
		lower[0] = -1;
		lower[1] = -1;
		lower[2] = -1;
		
		upper[0] = 3;
		upper[1] = 3;
		upper[2] = 3;

		sigma[0] = -0.554779;
		sigma[1] = -0.471816;
		sigma[2] = -0.471816;
		
		infin[0] = 2;
		infin[1] = 2;
		infin[2] = 2;
		
		delta[0] = 0.0;
		delta[1] = 0.0;
		delta[2] = 0.0;
		
		double final_answer=0;
		double error=0;
		int nu_ = 0;
		int maxpts_ = 25000;
		double abseps_ = 1e-6;
		double releps_ = 0;
		double value_ = 0.0;
		int inform_ = 0;
		int n = 3;
			
		//#pragma omp critical
		//{
		final_answer = pmvnorm(&n, &nu_, lower, upper, infin, sigma, delta, &maxpts_, &abseps_, &releps_, &error, &value_, &inform_); 
		//}
				
		cout << final_answer << endl;

		delete[] (lower);
		delete[] (upper);
		delete[] (sigma);
		delete[] (infin);
		delete[] (delta);		
	}
}
Topic archived. No new replies allowed.