Array not being modified by function call

Hello, I can't find anything explaining why this would be happening, so I implore this community. I've written a simple enough function to modify an array, normalizing a series of 3-vectors. Checking the status of the vector within the function shows the values I would expect, but checking their values from the caller shows a completely different picture.

Caller:
1
2
3
4
5
6
7
8
9
10
11
12
13
FLOAT rel[3*(length-1)];
		parent->relVecs(backbone,length,rel,i+1);
		for (int j=0; j<length-1; j++) {
			for (int k=0; k<3; k++) 
				cout << rel[(length-1)*3+k] << ' ';
			cout << endl;	
		}
		normalizeVecs(rel,length-1);
		for (int j=0; j<length-1; j++) {
			for (int k=0; k<3; k++) 
				cout << rel[(length-1)*3+k] << ' ';
			cout << endl;	
		}


Function:
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
void normalizeVecs(FLOAT vecs[], int n) {
	FLOAT N[n];
	#ifdef ipp
		int stride2=sizeof(Ipp32f);
		int stride0=3*stride2;
		ippmL2Norm_va_32f(vecs,stride0,stride2,N,3,n);
		Ipp32f iN[n];
		ippsInv_32f_A24(N,iN,n);
		Ipp32f vOut[n*3];
		ippmMul_vaca_32f(vecs,stride0,stride2,iN,stride2,vOut,stride0,stride2,3,n);
		cout << "vout" << endl;
		for (int i=0; i<n; i++) {
			for (int k=0; k<3; k++) 
				cout << vOut[3*i+k] << ' ';
			cout << endl;
		}
		ippsCopy_32f(vOut,vecs,3*n);
		cout << "vecs" << endl;
		for (int i=0; i<n; i++) {
			for (int k=0; k<3; k++) 
				cout << vecs[3*i+k] << ' ';
			cout << endl;
		}
	#else
		#pragma omp parallel
		{
			#pragma omp for
			for (int i=0; i<n; i++)
				N[i]=sqrt(pow(vecs[3*i],2)+pow(vecs[3*i+1],2)+pow(vecs[3*i+2],2));
			#pragma omp for
			for (int i=0; i<n; i++) {
				vecs[3*i]/=N[i];	
				vecs[3*i+1]/=N[i];
				vecs[3*i+2]/=N[i];	
			}
		}
	#endif	
}


The output is as such:

vout
-0.335733 0.740911 -0.581665 
0.267215 0.948367 0.170868 
-0.467162 0.592045 -0.65669 
0.14943 0.98769 0.0462496 
-0.48113 0.552248 -0.680835 
0.252072 0.967383 0.0251195 
-0.690015 0.590117 -0.419095 
0.0657966 0.961727 0.265992 
vecs
-0.335733 0.740911 -0.581665 
0.267215 0.948367 0.170868 
-0.467162 0.592045 -0.65669 
0.14943 0.98769 0.0462496 
-0.48113 0.552248 -0.680835 
0.252072 0.967383 0.0251195 
-0.690015 0.590117 -0.419095 
0.0657966 0.961727 0.265992 
from the caller
-5.9459e+21 8.12753e-44 7.7871e-13 
-5.9459e+21 8.12753e-44 7.7871e-13 
-5.9459e+21 8.12753e-44 7.7871e-13 
-5.9459e+21 8.12753e-44 7.7871e-13 
-5.9459e+21 8.12753e-44 7.7871e-13 
-5.9459e+21 8.12753e-44 7.7871e-13 
-5.9459e+21 8.12753e-44 7.7871e-13 
-5.9459e+21 8.12753e-44 7.7871e-13 

FLOAT is defined as float or Ipp32f depending on how the program is built (with or without Intel Performance Primitives). Built either way gives the same problem.

Thoughts? and thanks in advance.
Last edited on
Do you not need to pass the address of rel rather than the value? I may be wrong but it looks as though vecs is a local variable therefore it won't have changed outside of the normalizeVecs function and won't change the value of rel.
Last edited on
I don't believe so, when passing arrays a pointer to the beginning of the array is what is ultimately passed.
Check line 11 of the caller. I believe you want rel[j*3+k]. The same goes for line 5.
Nailed it, stupid mistake, thanks.
Topic archived. No new replies allowed.