I'm an amateur programmer who started using OpenMP recently. I was wondering if what I'm doing is fine. I attached a code. The problem is that I have a static array of length 8 (called val and weight) which I would like to use as a private variable in the loop I'm parallelizing. Is that legitimate?

Also I accumulate on variables sum and weight at the very end, would this work correctly? (Parallelization is for the outermost loop, that's why I do not use reduction.)

I keep getting wrong mathematical results and I was wondering if my code contains a bug.

Thank you very much for your input.