Reputation: 499
For each run, I wanted to sum grad to overall_grad. to prevent racing condition, I used atomic. But the compiler says:
error: invalid expression type for ‘#pragma omp atomic’
code
#pragma omp atomic
overall_grad.h += grad.h;
overall_grad.w += grad.w;
data type
struct Grad {
Eigen::MatrixXd h;
Eigen::MatrixXd w;
};
Does omp support += only for primitive type? How can Eigen matrix be summed here? Thanks!
Note, I'm not using parallel functionality provided by Eigen library, just run a parallel for over all samples, and update overall_grad.
Upvotes: 0
Views: 642
Reputation: 29245
Yes atomic operations are only for a few native types. In your case you need to use a critical section:
#pragma omp critical
{
...
}
Upvotes: 1