Is your goal here to learn OpenMP, or make your program faster? If the latter, it would be more advisable to write code that was repeatedly added, reduce the number of passes and enable SIMD.
Step 1: Combine the loops and use multiply-add:
// remove the variable 'temp' completely for(int i=0;i<LAYERS;i++) { for(int j=0;j<NEURONS;j++) { outputs[j] = 0; for(int k=0,l=0;l<INPUTS;l++,k++) { outputs[j] += inputs[l] * weights[i][k]; } outputs[j] = sigmoid(outputs[j]); } std::swap(inputs, outputs); }
source share