# Parallel computing \`@parallel\`

**URL:** https://discourse.julialang.org/t/parallel-computing-parallel/6082
**Category:** New to Julia
**Created:** [September 26, 2017, 12:03pm UTC](https://discourse.julialang.org/t/parallel-computing-parallel/6082 "2017-09-26T12:03:20Z")
**Posts on this page:** 2
**Page:** 1

<div class="post-metadata">

### Author: ![Federica\_D](https://avatars.discourse-cdn.com/v4/letter/f/6bbea6/32.png) [@Federica\_D](https://discourse.julialang.org/u/Federica_D)
#### Post date: [September 26, 2017, 12:03pm UTC](https://discourse.julialang.org/t/parallel-computing-parallel/6082/1 "2017-09-26T12:03:20Z")

</div>

Hi,  
I am relatvely new to Julia and I am having some weird issue when trying to parallelize.  
I use the `@parallel` with Shared Arrays approach (but I have the same issue when I use `pmap` ).  
So, I have something like this:

```julia
addprocs(7)
A=SharedArray{Float64}(a_size,b_size,c_size)
toler=1e-3
maxit=1000
 while (metric1>toler) && (iter1<maxit)
`@inbounds` `@sync` `@parallel` for i in 1:c_size
 A[:,:,i]=compute_A(fs,A0[:,:,i],i)
end
A_new=sdata(A)
metric1=maximum(abs.((A_new-A0)))
A0=copy(A_new)
iter1=iter1+1
println("$(iter1) $(metric1)")
end

```

where the inputs of the function “compute\_A” are:  
-fs is a “DataType” defined by me  
-A0 is an array  
-i is the index I m looping over (dimension c\_size)

So, it seems to be working fine when I compute it like this.  
The problem is that when I wrap this up in a function  
like:

```julia
addprocs(7)
myfunction(fs::DataType, toler::Float64, maxit::Int)
 A=SharedArray{Float64}(a_size,b_size,c_size)
 
  while (metric1>toler) && (iter1<maxit)
 `@inbounds` `@sync` `@parallel` for i in 1:c_size
  A[:,:,i]=compute_A(fs,A0[:,:,i],i)
 end
 A_new=sdata(A)
 metric1=maximum(abs.((A_new-A0)))
 A0=copy(A_new)
 iter1=iter1+1
 println("$(iter1) $(metric1)")
 end

end 

```

This: wrap(fs, 1e-3, 1000)

runs WAY SLOWER than the other one (like 6 vs 600 seconds). It seems extremely weird and  
I don’t understand what I am doing wrong but there is definitely something I am missing. So I was hoping I could get some help here. Thanks a lot for your time and help.

---

<div class="post-metadata">

### Author: ![mauro3](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/mauro3/32/292_2.png) [@mauro3](https://discourse.julialang.org/u/mauro3)
#### Post date: [September 26, 2017, 12:14pm UTC](https://discourse.julialang.org/t/parallel-computing-parallel/6082/2 "2017-09-26T12:14:59Z")

</div>

Welcome @Federica_D! I can’t help you with your problem but please quote code with backticks: in-line with one ```, like e.g. ``@parallel``, and whole blocks with `````, eg.:

````julia
```
A=SharedArray{Float64}(a_size,b_size,c_size)
toler=1e-3
...
```

````

In particular the `@something` can ping users unfortunate enough to have a username which is also a macro.
