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

Fix flush of stdout after solve #275

Merged
merged 2 commits into from
Jun 6, 2023
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
4 changes: 4 additions & 0 deletions src/c_wrapper.jl
Original file line number Diff line number Diff line change
Expand Up @@ -402,5 +402,9 @@ function _unsafe_scs_solve(model::_ScsDataWrapper{S,T}) where {S,T}
model.options[:warm_start],
)
scs_finish(model.linear_solver, scs_work)
# SCS does not flush stdout on exit, and the C stdout is not the same as
# Julia's stdout, so regular calls to flush(stdout) do not work. A
# work-around is for us to manually flush the output after each solve.
Base.Libc.flush_cstdio()
return Solution(model.primal, model.dual, model.slack, scs_info, status)
end
20 changes: 20 additions & 0 deletions test/MOI_wrapper.jl
Original file line number Diff line number Diff line change
Expand Up @@ -181,6 +181,26 @@ function test_Name_skip()
return
end

function test_redirect_stdout()
filename = tempname()
open(filename, "w") do io
redirect_stdout(io) do
model = MOI.Utilities.Model{Float64}()
x = MOI.add_variables(model, 3)
f = MOI.Utilities.operate(vcat, Float64, 1.0 .* x...)
MOI.add_constraint(model, f, MOI.Nonnegatives(3))
scs = SCS.Optimizer()
MOI.optimize!(scs, model)
odow marked this conversation as resolved.
Show resolved Hide resolved
return
end
odow marked this conversation as resolved.
Show resolved Hide resolved
return
end
output = read(filename, String)
@test occursin("SCS", output)
@test length(output) > 100
return
end

end # module

TestSCS.runtests()
Loading