Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Multiple instances of CUTEstModel can now coexist #389

Merged
merged 5 commits into from
Aug 26, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 3 additions & 29 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,9 @@ If you use CUTEst.jl in your work, please cite using the format given in [CITATI
## Installing

This package will automatically install the CUTEst binaries for your platform.
The `gfortran` compiler is required to compile decoded SIF problems, except on Windows.
The `gfortran` compiler is required to compile decoded SIF problems.
Users on all platforms except Windows must install it to use CUTEst.jl.
For Windows users, a small artifact containing `gfortran.exe` is installed automatically.
No other Fortran compiler is supported.

The following command installs the CUTEst binaries and the Julia interface:
Expand Down Expand Up @@ -83,34 +85,6 @@ set_mastsif("netlib-lp")

The constructor `CUTEstModel{Float64}(name)` will try to find the SIF file associated with the problem `name` in the current set.

### Run multiple models in parallel

First, decode each of the problems in serial.

```julia
function decodemodel(name)
finalize(CUTEstModel(name))
end

probs = ["AKIVA", "ALLINITU", "ARGLINA", "ARGLINB", "ARGLINC", "ARGTRIGLS", "ARWHEAD"]
broadcast(decodemodel, probs)
```

Then, call functions handling models in parallel. It is important to pass `decode=false` to `CUTEstModel`.

```julia
addprocs(2)
@everywhere using CUTEst
@everywhere function evalmodel(name)
nlp = CUTEstModel(name; decode=false)
retval = obj(nlp, nlp.meta.x0)
finalize(nlp)
retval
end

fvals = pmap(evalmodel, probs)
```

## Related Packages

- [NLPModels.jl](https://github.com/JuliaSmoothOptimizers/NLPModels.jl) provides an
Expand Down
12 changes: 4 additions & 8 deletions gen/wrapper.jl
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@ function main()
options = load_options(joinpath(@__DIR__, "cutest.toml"))
options["general"]["output_file_path"] = joinpath("..", "src", "libcutest.jl")
options["general"]["output_ignorelist"] =
["integer", "real", "doublereal", "logical", "rp_", "rpc_", "ip_", "ipc_"]
["integer", "real", "doublereal", "logical", "rp_", "rpc_", "ip_", "ipc_",
"CUTEst_malloc", "CUTEst_calloc", "CUTEst_realloc", "CUTEst_free", "VarTypes"]

args = get_default_args()
push!(args, "-I$include_dir")
Expand All @@ -39,13 +40,8 @@ function main()
for (index, block) in enumerate(blocks)
if contains(block, "function")
fname = split(split(block, "function ")[2], "(")[1]
if contains(block, "_s(") || contains(block, "_s_(")
ptr = "ptr_$(fname) = Libdl.dlsym(cutest_lib_single, :$(fname))"
elseif contains(block, "_q(") || contains(block, "_q_(")
ptr = "ptr_$(fname) = Libdl.dlsym(cutest_lib_quadruple, :$(fname))"
else
ptr = "ptr_$(fname) = Libdl.dlsym(cutest_lib_double, :$(fname))"
end
block = replace(block, "function $fname(" => "function $fname(libsif, ")
ptr = "ptr_$(fname) = Libdl.dlsym(libsif, :$(fname))"
block = replace(block, " @ccall libcutest.$fname" => " $ptr\n @ccall \$ptr_$(fname)")
end
code = code * block
Expand Down
8 changes: 0 additions & 8 deletions src/CUTEst.jl
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,6 @@ using Quadmath
using NLPModels
import Libdl.dlsym

# Only one problem can be interfaced at any given time.
global cutest_instances_single = 0
global cutest_instances_double = 0
global cutest_instances_quadruple = 0
global cutest_lib_single = C_NULL
global cutest_lib_double = C_NULL
global cutest_lib_quadruple = C_NULL

export CUTEstModel, sifdecoder, build_libsif, set_mastsif

const cutest_problems_path = joinpath(dirname(@__FILE__), "..", "deps", "files")
Expand Down
Loading
Loading