dimanche 1 avril 2018

Different result than the one expected with pragma omp reduction

the following code works well when I have small instances of the vector (aux1) that I use to retrieve some values and do calculations with but it does not with bigger ones. I have checked with the debugger (doing the sum myself with a breakpoint in the total line) that the expected sum of total should be greater than the one I am getting and I dont know whats wrong with the pragma configuration. Any ideas?

    double total = 0;
    #pragma omp parallel for collapse(2) reduction(+:total)
    for (int w0 = 0; w0 < lastElem; ++w0) {
        for (int w1 = 0; w1 < lastElem; ++w1) {
            bool soFarSoGood = true;
            for (uint8_t i = 0; i < topeK; ++i) {
                if ((aux1[w0].values[indexValues::getIndex(n,k,i)]) != -(aux1[w1].values[indexValues::getIndex(n,k,i)])) {
                    soFarSoGood = false;
                    break;
                }
            }
            switch (soFarSoGood) {
                case true : {
                    total += (aux1[w0].cardinal * aux1[w1].cardinal);
                    break;
                }
                default :
                    break;
            }
        }
    }
    std::cout << "Total: " << total << std::endl;

Aucun commentaire:

Enregistrer un commentaire