Closed Inc0n closed 4 years ago
Have a look at atomic-incf https://github.com/Shinmera/atomics but it's a bad solution since you won't be parallelizing anything. preduce sounds like the way to go although it's hard to tell from such a toy example. HTH
Yeah, your incf
should be serialized, or locked because it's not thread-safe.
You can also look at https://stmx.org to 'protect' your col-acc
.
Thanks for pointing me in the right direction. And the following is the lock I use for the current solution for this problem.
bt:make-lock
bt:with-lock-held
I would like to add parallelism to my project, which utilizes some side effects The following snippet is used to demonstrate how this can leads to inaccurate results.
Running the above script, woud sometimes result in something that is not 100.0 (the expected)
I would like to know if this is doable with lparallel.
However, I do see an alternative approach, is to
pmap
times into list of data, thenpreduce
to summarize it, since i am dealing with number of times as oppose to list of data. But i would want to avoid creating a list of range from0
tons
to feed intopmap
, because oncens
become even bigger,1000
for example, the overhead might be big enough to slow this procedure down, especially if it is called for thousands of times.