# PATHSolver.jl error using map

**URL:** <https://discourse.julialang.org/t/pathsolver-jl-error-using-map/40724>\
**Category:** Optimization (Mathematical)\
**Created:** [June 4, 2020, 12:32pm UTC](https://discourse.julialang.org/t/pathsolver-jl-error-using-map/40724 "2020-06-04T12:32:34Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![juliauser](https://avatars.discourse-cdn.com/v4/letter/j/46a35a/32.png) [@juliauser](https://discourse.julialang.org/u/juliauser)\
**Post date:** [June 4, 2020, 12:32pm UTC](https://discourse.julialang.org/t/pathsolver-jl-error-using-map/40724/1 "2020-06-04T12:32:34Z")

</div>

I am using PATHSolver to solve linear complementarity problems. I have no problem when using it “normally”, but I get this error when I use parallel computing, as below.  
What seems to be problematic is the presence of the while loop in the function (same if I use a for loop). Any ideas?

````nohighlight
addprocs(3)
@everywhere using PATHSolver
M = [0 0 -1 -1 ;
     0 0 1 -2 ;
     1 -1 2 -2 ;
     1 2 -2 4 ]
q1 = [2; 2; -2; -6]
q2 = [1; 2; 3; -6]
q3 = [5; 2; 3; -6]
q4 = [6; 1; 8; -6]
q = [q1,q2,q3,q4]

@everywhere function examplefun(M,q)
    i = 1
    f = 0
    while i < 10
        myfunc(x) = M*x + q
        n = 4
        lb = zeros(n)
        ub = 100*ones(n)
        options(convergence_tolerance=1e-6, output=:no, cumulative_iteration_limit=100000, crash_iteration_limit=200, time_limit=3600)
        z, f = solveLCP(myfunc,M, lb, ub)
        i = i+1
    end
    return f
end
@everywhere mutable struct state_solve
    M::Array{Int64,2}
    q::Array{Int64,1}
end
@everywhere function solve(state::state_solve)
    M = state.M
    q = state.q
    sol = examplefun(M,q)
end
parSim = [state_solve(M,qi) for qi in q]
@time solve_result = pmap(solve,parSim)

ERROR: On worker 3:
IOError: unlink: no such file or directory (ENOENT)
uv_error at ./libuv.jl:97 [inlined]
unlink at ./file.jl:888
#rm#9 at ./file.jl:268
rm at ./file.jl:260 [inlined]```
````

---

<div class="post-metadata">

**Author:** ![odow](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/odow/32/28685_2.png) [@odow](https://discourse.julialang.org/u/odow)\
**Post date:** [June 4, 2020, 1:14pm UTC](https://discourse.julialang.org/t/pathsolver-jl-error-using-map/40724/2 "2020-06-04T13:14:56Z")

</div>

It looks like PATHSolver uses a single option file: [PATHSolver.jl/PATHSolver.jl at be35790221cb73f324fcc793452547b1525986cb · chkwon/PATHSolver.jl · GitHub](https://github.com/chkwon/PATHSolver.jl/blob/be35790221cb73f324fcc793452547b1525986cb/src/PATHSolver.jl#L319-L324)  
This will cause issues if multiple processes try to write and/or delete it at the same time.

Instead, you can use `PATH.jl` ([https://github.com/odow/PATH.jl](https://github.com/odow/PATH.jl), which you can install with `] add https://github.com/odow/PATH.jl`).

You can either use the documented JuMP interface (see the README), or the low-level `solve_mcp`:

```nohighlight
using Distributed
@everywhere begin
    import Pkg
    Pkg.activate(".")
    using PATH
    mutable struct state_solve
        M::Array{Float64, 2}
        q::Array{Float64, 1}
    end
    function examplefun(M,q)
        i = 1
        f = 0
        n = 4
        lb = zeros(n)
        ub = 100 * ones(n)
        while i < 10
            z, f = PATH.solve_mcp(
                PATH.SparseArrays.SparseMatrixCSC{Float64, Int32}(M),
                q,
                lb,
                ub,
                zeros(n);
                convergence_tolerance=1e-6,
                output="no",
                cumulative_iteration_limit=100000,
                crash_iteration_limit=200,
                time_limit=3600,
            )
            i = i+1
        end
        return f
    end

    function solve(state::state_solve)
        M = state.M
        q = state.q
        sol = examplefun(M,q)
    end
end
M = [0 0 -1 -1 ;
     0 0 1 -2 ;
     1 -1 2 -2 ;
     1 2 -2 4 ]
q1 = [2; 2; -2; -6]
q2 = [1; 2; 3; -6]
q3 = [5; 2; 3; -6]
q4 = [6; 1; 8; -6]
q = [q1,q2,q3,q4]

parSim = [state_solve(M,qi) for qi in q]
using Suppressor
@time @suppress begin
    solve_result = pmap(solve,parSim)
end

```

Which yields:

```julia
  0.059366 seconds (34.85 k allocations: 2.016 MiB)
4-element Array{Array{Float64,1},1}:
 [2.8, 0.0, 0.8, 1.2]                                              
 [0.40000000356019444, 0.7999999982198975, 0.0, 1.0000000000000062]
 [0.0, 1.0, 0.0, 1.0]                                              
 [0.0, 2.0, 0.0, 0.5]    

```

---

<div class="post-metadata">

**Author:** ![juliauser](https://avatars.discourse-cdn.com/v4/letter/j/46a35a/32.png) [@juliauser](https://discourse.julialang.org/u/juliauser)\
**Post date:** [June 4, 2020, 1:21pm UTC](https://discourse.julialang.org/t/pathsolver-jl-error-using-map/40724/3 "2020-06-04T13:21:55Z")

</div>

> [@odow](#):
>
> ] add [GitHub - odow/PATH.jl: A Julia interface to the PATH solver](https://github.com/odow/PATH.jl)

Thanks. I want to try that, but when I add PATH I get this error  
`Error: Error building `PATH`: │ ERROR: LoadError: Unable to download PATH. Set the environment variable `SECRET_URL_PATH_BINARIES`, or install a copy of `libpath50.xx` manually and set the environment variable `PATH_JL_LOCATION` to point to the libpath location.`. Am I missing something in the installation?

---

<div class="post-metadata">

**Author:** ![odow](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/odow/32/28685_2.png) [@odow](https://discourse.julialang.org/u/odow)\
**Post date:** [June 4, 2020, 1:36pm UTC](https://discourse.julialang.org/t/pathsolver-jl-error-using-map/40724/4 "2020-06-04T13:36:08Z")

</div>

I’ve updated the installation instructions: [PATH.jl/README.md at master · odow/PATH.jl · GitHub](https://github.com/odow/PATH.jl/blob/master/README.md#installation)

For now, you need to manually install PATH (the solver).
