PATHSolver.jl error using map

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?

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]```

It looks like PATHSolver uses a single option file: PATHSolver.jl/PATHSolver.jl at be35790221cb73f324fcc793452547b1525986cb · chkwon/PATHSolver.jl · GitHub
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, 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:

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:

  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]    

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?

I’ve updated the installation instructions: PATH.jl/README.md at master · odow/PATH.jl · GitHub

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