# Error with parallel sparse array building

**URL:** <https://discourse.julialang.org/t/error-with-parallel-sparse-array-building/65833>\
**Category:** Performance\
**Tags:** multithreading, threads\
**Created:** [August 4, 2021, 5:46pm UTC](https://discourse.julialang.org/t/error-with-parallel-sparse-array-building/65833 "2021-08-04T17:46:54Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![Thomas](https://avatars.discourse-cdn.com/v4/letter/t/e36b37/32.png) [@Thomas](https://discourse.julialang.org/u/Thomas)\
**Post date:** [August 4, 2021, 5:46pm UTC](https://discourse.julialang.org/t/error-with-parallel-sparse-array-building/65833/1 "2021-08-04T17:46:54Z")

</div>

~~I know that the recommended way to @thread build array is to split the work based on `nthreads()` and then join the array later.~~ (What I said is the same as the macro @threads.) Nevertheless, in the below each thread should never write to the same column. Could someone explain why building array like this is not safe?

```julia
A = spzeros(Float64, n, m)
@threads for j in 1:m
     A[:, j] = load("a$j") # pseudocode to load array from file
end

```

Edit: I might have found the problem: writing to SparseMatrixCSC like above is wrong (not thread-safe).
