Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can Shared Arrays handle concurrent writes safely in Julia?

So I was trying to optimize an array operation in Julia, but noticed that I was getting a rather large error on my matrix occasionally. I also noticed that there existed the possibility of concurrently writing to the same index of a SharedArray in Julia. I was wondering if Julia can safely handle it. If not, how may I able able to handle it?

Here is a basic example of my issue

for a list of arbitrary x,y indexes in array J
    j[x,y] += some_value
end

Can Julia handle this case or, like C, will there exist the possibility of overwriting the data. Are their atomic operations in Julia to compensate ffor this?

like image 849
Skylion Avatar asked May 11 '16 15:05

Skylion


1 Answers

Shared arrays deliberately have no locking, since locking can be expensive. The easiest approach is to assign non-overlapping work to different processes. However, you might search to see whether someone has written a locking library, or have a go at it yourself: https://en.wikipedia.org/wiki/Mutual_exclusion

like image 55
tholy Avatar answered Oct 07 '22 01:10

tholy