# SharedArray using DataFrames()

**URL:** https://discourse.julialang.org/t/sharedarray-using-dataframes/116908
**Category:** General Usage
**Tags:** question, parallel, dataframes, sharedarrays
**Created:** [July 11, 2024, 12:54pm UTC](https://discourse.julialang.org/t/sharedarray-using-dataframes/116908 "2024-07-11T12:54:07Z")
**Posts on this page:** 1
**Page:** 1

<div class="post-metadata">

### Author: ![Gast](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/gast/32/206425_2.png) [@Gast](https://discourse.julialang.org/u/Gast)
#### Post date: [July 11, 2024, 12:54pm UTC](https://discourse.julialang.org/t/sharedarray-using-dataframes/116908/1 "2024-07-11T12:54:07Z")

</div>

Hi all

I use the [DataFrame.jl](https://dataframes.juliadata.org/stable/) package to define and manipulate arrays across several nested functions.

I plan to parallelize some of the tasks (e.g., `for` loops with data allocations) by using the [Distributed.jl](https://github.com/JuliaLang/Distributed.jl?tab=readme-ov-file) package. To allow for a simultaneous modification across workers of these `DataFrame` objects in each iteration, I am planning to use the library [SharedArrays](https://gensoft.pasteur.fr/docs/julia/1.4.1/stdlib/SharedArrays.html#SharedArrays.SharedArray)

Toy example:

```julia
using DataFrames
using Distributed
@everywhere using SharedArrays
addprocs(4)

ixt = 100
ixr = 10

#Empty df()
A = DataFrame(Matrix{Any}(Nothing(), ne, nx), :auto) 

#Non-parallelized loop:
for ie = 1:ne
    for ix = 1:nx
        A[ie, ix] = 10 + ie #random calculation
    end
end

# Parallelized version:
for ie = 1:ne
    @sync @distributed for ix = 1:nx
        A[ie, ix] = 10 + ie #random calculation
    end
end

```

For the parallelized version, we will first need to declare the matrix `A` to be modified inside the `for` loop in each parallel iterations by typing something like:

```julia
A = SharedArray(DataFrame(Matrix{Any}(Nothing(), ne, nx), :auto))

```

However, that produces the following error message:

```julia
julia> A = SharedArray(DataFrame(Matrix{Any}(Nothing(), ne, nx), :auto))
ERROR: MethodError: no method matching SharedArray(::DataFrame)

```

Any idea is much appreciated!
