Skip to content

Commit

Permalink
fixed some bugs and added generic flag parsing
Browse files Browse the repository at this point in the history
  • Loading branch information
Louis Ponet committed May 27, 2021
1 parent c5eaea9 commit f5ba88d
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 13 deletions.
2 changes: 1 addition & 1 deletion deps/asset_init.jl
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ open(joinpath(@__DIR__, "mpirunflags.jl"), "w") do wf
symbols = [Symbol(name)]
end
for symbol in symbols
writefbodyline(wf, 1,"""ExecFlag(Symbol("$symbol"), "$name", $type, "$description", nothing),""")
writefbodyline(wf, 1,"""ExecFlag(Symbol("$symbol"), "$name", $type, "$description", nothing, 1),""")
end
end
end
Expand Down
32 changes: 28 additions & 4 deletions src/fileio.jl
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,8 @@ function writeexec(f, exec::Exec)
direxec = joinpath(exec.dir, exec.exec)
write(f, "$direxec")
for flag in exec.flags
write(f, " -$(flag.symbol)")

write(f, " $(join(fill('-', flag.minus_count)))$(flag.symbol)")
if !isa(flag.value, AbstractString)
for v in flag.value
write(f," $v")
Expand Down Expand Up @@ -249,7 +250,7 @@ Writes all the input files and job file that are linked to a DFJob.
Kwargs will be passed down to various writetojob functions.
"""
function writejobfiles(job::DFJob; kwargs...)
rm.(joinpath.(Ref(job.local_dir), searchdir(job.local_dir, ".in")))
# rm.(joinpath.(Ref(job.local_dir), searchdir(job.local_dir, ".in")))
open(joinpath(job.local_dir, "job.tt"), "w") do f
write(f, "#!/bin/bash\n")
write_job_name(f, job)
Expand Down Expand Up @@ -291,7 +292,8 @@ function read_job_line(line)
#TODO This is not really nice, we don't handle execs that are unparseable...
# Not sure how we can actually do this
for s in spl
if any(occursin.(allexecs(), (s,)))
d, e = splitdir(s)
if e allexecs()
push!(exec_and_flags, s => SubString[])
elseif !isempty(exec_and_flags)
# else
Expand All @@ -316,12 +318,34 @@ function read_job_line(line)
output = "elk.out"
push!(execs, Exec(efile, dir))
else
push!(execs, Exec(efile, dir))
push!(execs, Exec(efile, dir, parse_generic_flags(flags)))
end
end
return execs, input, output, run
end

function parse_generic_flags(flags::Vector{<:SubString})
out = ExecFlag[]
f = :none
c = 1
for s in flags
if s[1] == '-'
c = count(isequal('-'), s)
f = Symbol(strip(s, '-'))
else
v = tryparse(Int, s)
if v === nothing
v = tryparse(Float64, s)
if v === nothing
v = s
end
end
push!(out, ExecFlag(f => v, c))
end
end
return out
end

# TODO: make this work again
# function read_job_filenames(job_file::String)
# input_files = String[]
Expand Down
18 changes: 10 additions & 8 deletions src/types.jl
Original file line number Diff line number Diff line change
Expand Up @@ -56,18 +56,20 @@ mutable struct ExecFlag
typ ::Type
description::String
value
minus_count::Int
end
Base.:(==)(e1::ExecFlag, e2::ExecFlag) =
all(x -> getfield(e1, x) == getfield(e2, x), (:symbol, :value))

ExecFlag(e::ExecFlag, value) = ExecFlag(e.symbol, e.name, e.typ, e.description, value)
ExecFlag(p::Pair{Symbol, T}) where T = ExecFlag(first(p), String(first(p)), T, "", last(p))
ExecFlag(e::ExecFlag, value) = ExecFlag(e.symbol, e.name, e.typ, e.description, value, 1)
ExecFlag(p::Pair{Symbol, T}) where T = ExecFlag(first(p), String(first(p)), T, "", last(p), 1)
ExecFlag(p::Pair{Symbol, T}, count::Int) where T = ExecFlag(first(p), String(first(p)), T, "", last(p), count)

const QE_EXECFLAGS = ExecFlag[
ExecFlag(:nk, "kpoint-pools", Int, "groups k-point parallelization into nk processor pools", 0),
ExecFlag(:ntg, "task-groups", Int, "FFT task groups", 0),
ExecFlag(:ndiag, "diag", Int, "Number of processes for linear algebra", 0),
ExecFlag(:ni, "images", Int, "Number of processes used for the images", 0)
ExecFlag(:nk, "kpoint-pools", Int, "groups k-point parallelization into nk processor pools", 0, 1),
ExecFlag(:ntg, "task-groups", Int, "FFT task groups", 0, 1),
ExecFlag(:ndiag, "diag", Int, "Number of processes for linear algebra", 0, 1),
ExecFlag(:ni, "images", Int, "Number of processes used for the images", 0, 1)
]

qeexecflag(flag::AbstractString) = getfirst(x -> x.name==flag, QE_EXECFLAGS)
Expand All @@ -85,7 +87,7 @@ function parse_qeexecflags(line::Vector{<:AbstractString})
end

const WAN_EXECFLAGS = ExecFlag[
ExecFlag(:pp, "preprocess", Nothing, "Whether or not to preprocess the wannier input", nothing),
ExecFlag(:pp, "preprocess", Nothing, "Whether or not to preprocess the wannier input", nothing, 1),
]

wan_execflag(flag::AbstractString) = getfirst(x -> x.name==flag, WAN_EXECFLAGS)
Expand Down Expand Up @@ -181,7 +183,7 @@ function parse_mpi_flags(line::Vector{<:SubString})
eflags
end

const RUN_EXECS = ["mpirun", "mpi", "mpiexec", "srun"]
const RUN_EXECS = ["mpirun", "mpiexec", "srun"]
allexecs() = vcat(RUN_EXECS, QE_EXECS, WAN_EXECS, ELK_EXECS)
parseable_execs() = vcat(QE_EXECS, WAN_EXECS, ELK_EXECS)
has_parseable_exec(l::String) = occursin(">", l) && any(occursin.(parseable_execs(), (l,)))
Expand Down

0 comments on commit f5ba88d

Please sign in to comment.