I am new to openMP and I was wondering if someone can review my approach.
Problem: I have sequential arrival of data from a device which has data from many sensors. I think I can parallely process analytics on each data packet to increase resolution.
Solution I thought of is as follows - but it ends up in deadlocks
This is pseudocode - so please ignore the syntax
TOTAL_SENSORS = 1000 omp_lock_t sensor_locks[TOTAL_SENSORS] #pragma omp parallel #pragma omp for for(int i=0;i<TOTAL_SENSORS;i++) { omp_init_lock(&sensor_locks[i]); } #pragma omp parallel #pragma omp single while (! end_of_data){ for sensor_data in packed_data.iterator() { if sensor_data.sensor_type = 'A' { #omp task firstprivate(sensor_data) { omp_set_lock(&sensor_locks[sensor_data.sensor_id]); compute_analytics_type_A(sensor_data) omp_unset_lock(&sensor_locks[sensor_data.sensor_id]); } } else { #omp task firstprivate(sensor_data) { omp_set_lock(&sensor_locks[sensor_data.sensor_id]); compute_analytics_type_B(sensor_data) omp_unset_lock(&sensor_locks[sensor_data.sensor_id]); } } } } When I try this - this leads to a deadlock.
Broadly, I am trying to parallize the computation of analytics as long as they are not being computed for the same sensor.
Can someone help with the idiomatic way of doing it ?
sensor_databeing a structure, beware howfirstprivatemakes a copy if it has pointer components.sensor_datadeclared? I think we need to see more code, and ideally a minimal reproducible example