OpenMP中的firstprivate子句不起作用

时间:2018-11-28 12:20:21

标签: c++ parallel-processing synchronization openmp

我有一个使用类对象和函数进行操作的循环。它还计算几个和值。我尝试将其与OpenMP并行:

    Network  net = *m_pNetwork;
    TrainingSet tran = trainingSet;
    omp_set_num_threads(4);

    #pragma omp parallel for reduction(+:MSE, incorrectEntries) firstprivate(tran, net) lastprivate(net) private(outputIdx)  
    for (int i = 0; i < tran.size(); i++)
    {    
        net->Evaluate(tran[i].m_inputs);
        Backpropagate(tran[i].m_expectedOutputs);

        // Check all outputs from neural network against desired values
        bool resultCorrect = true;
        for (outputIdx = 0; outputIdx < net->m_numOutputs; outputIdx++)
        {
            if (net->m_clampedOutputs[outputIdx] != tran[i].m_expectedOutputs[outputIdx])
            {
                resultCorrect = false;
            }
            MSE += pow((net->m_outputNeurons[outputIdx] - tran[i].m_expectedOutputs[outputIdx]), 2);
        }       
        if (!resultCorrect)
        {
            //#pragma omp atomic
            incorrectEntries++;
        }
    }

    *m_pNetwork = net;

我的问题是每次迭代的和值都相同。那我没有做正确的事吗?

0 个答案:

没有答案