mercredi 30 août 2023

OpenMP atomic update of map value

Is the follwing increment operation thread safe?

std::map<uint64_t, uint64_t> val_counts{};

#pragma omp parallel for num_threads(32)
for (uint16_t ix = 0; ix < 96; ++ix) {

#pragma omp atomic update
    val_counts[ix%5]++;

}

Based on my experiments, it seems to be thread safe. Howewer, I wanted to be sure, as I am not sure what this translates into. An alternative would be using #pragma omp critical, of course.

Aucun commentaire:

Enregistrer un commentaire