You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
While investigating multi-threaded issues in reproject, I came across an issue which is that if the input array to e.g. wcs_pix2world is a (N, 2) array and if the origin is set to 0, the input array is modified in-place temporarily to make the pixel values be 1-based since this is what WCSLIB expects. This causes multi-threading to fail spectacularly in this case if multiple threads use the same input array, as demonstrated in the following example:
An easy fix is to copy the array before passing it to the C extension, though obviously this will increase memory usage, which isn't ideal. But in any case we shouldn't be modifying the input array in-place. We should probably check if WCSLIB now has a mechanism for dealing with different origins on-the-fly during the conversions and whether our code is still needed.
The text was updated successfully, but these errors were encountered:
Noting here that my proposed pthreads solution for #16245 to ensure a single-threaded execution likely will fix this issue. But that solution does require adding a compile and runtime dependency for pthreads.
Essentially consists of using pthread_mutex_trylock to only execute the single-threaded region on the thread that gets the lock, and then pthread_cond_wait for the other threads to wait while the single thread finishes executing (i.e., the calls to pre-offset and un-offset)
While investigating multi-threaded issues in reproject, I came across an issue which is that if the input array to e.g.
wcs_pix2world
is a (N, 2) array and if the origin is set to0
, the input array is modified in-place temporarily to make the pixel values be 1-based since this is what WCSLIB expects. This causes multi-threading to fail spectacularly in this case if multiple threads use the same input array, as demonstrated in the following example:The output in this case is:
What's happening here is that several threads are applying an offset in-place in the input array at the same time:
astropy/astropy/wcs/src/wcslib_wrap.c
Line 1413 in 01e8729
Note that if the origin is changed to 1, there is no issue since no offset is applied:
gives:
An easy fix is to copy the array before passing it to the C extension, though obviously this will increase memory usage, which isn't ideal. But in any case we shouldn't be modifying the input array in-place. We should probably check if WCSLIB now has a mechanism for dealing with different origins on-the-fly during the conversions and whether our code is still needed.
The text was updated successfully, but these errors were encountered: