Commit ef95c1a
committed
[numpy_vs_numba_vs_jax] Fix issue in parallel Numba implementation
The previous implementation had a race condition where multiple threads
simultaneously updated the shared variable 'm', causing incorrect results
(returning -inf instead of the actual maximum).
The fix computes per-row maximums in parallel (each thread writes to a
unique index), then reduces to find the global maximum.
Changes:
- Replace shared variable 'm' with thread-safe 'row_maxes' array
- Each parallel iteration computes a thread-local 'row_max'
- Final np.max(row_maxes) combines partial results
- Remove broken nested prange version (same race condition)
- Add explanatory text about avoiding race conditions in reductions1 parent 4f25b05 commit ef95c1a
1 file changed
+11
-32
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
200 | 200 | | |
201 | 201 | | |
202 | 202 | | |
203 | | - | |
| 203 | + | |
204 | 204 | | |
205 | | - | |
| 205 | + | |
| 206 | + | |
| 207 | + | |
| 208 | + | |
206 | 209 | | |
207 | 210 | | |
208 | 211 | | |
209 | 212 | | |
210 | 213 | | |
211 | | - | |
| 214 | + | |
212 | 215 | | |
| 216 | + | |
213 | 217 | | |
214 | 218 | | |
215 | 219 | | |
216 | 220 | | |
217 | | - | |
218 | | - | |
219 | | - | |
| 221 | + | |
| 222 | + | |
| 223 | + | |
| 224 | + | |
220 | 225 | | |
221 | 226 | | |
222 | 227 | | |
| |||
228 | 233 | | |
229 | 234 | | |
230 | 235 | | |
231 | | - | |
232 | | - | |
233 | | - | |
234 | | - | |
235 | | - | |
236 | | - | |
237 | | - | |
238 | | - | |
239 | | - | |
240 | | - | |
241 | | - | |
242 | | - | |
243 | | - | |
244 | | - | |
245 | | - | |
246 | | - | |
247 | | - | |
248 | | - | |
249 | | - | |
250 | | - | |
251 | | - | |
252 | | - | |
253 | | - | |
254 | | - | |
255 | | - | |
256 | | - | |
257 | 236 | | |
258 | 237 | | |
259 | 238 | | |
| |||
0 commit comments