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

ArgParse doesn't work when Julia started in parallel #7

Closed
dkoslicki opened this issue Sep 18, 2014 · 2 comments
Closed

ArgParse doesn't work when Julia started in parallel #7

dkoslicki opened this issue Sep 18, 2014 · 2 comments

Comments

@dkoslicki
Copy link

If you create the file "test.jl" containing the example provided in the documentation:

@everywhere using ArgParse

@everywhere function parse_commandline()
    s = ArgParseSettings()

    @add_arg_table s begin
        "--opt1"
            help = "an option with an argument"
        "--opt2", "-o"
            help = "another option with an argument"
            arg_type = Int
            default = 0
        "--flag1"
            help = "an option without argument, i.e. a flag"
            action = :store_true
        "arg1"
            help = "a positional argument"
    end

    return parse_args(s)
end

function main()
    @everywhere parsed_args = parse_commandline()
    println("Parsed args:")
    for pa in parsed_args
        println("  $(pa[1])  =>  $(pa[2])")
    end
    @everywhere test=parsed_args["opt1"]
end

main()

Then running the command julia test.jl --opt1 test runs as intended, but julia -p 2 test.jl --opt1 test returns the following error

-bash-4.1$ julia -p 2 test.jl --opt1 test
unrecognized option --bind-to
usage: <PROGRAM> [--opt1 OPT1] [-o OPT2] [--flag1] [arg1]
Worker 2 terminated.ERROR: ProcessExitedException()
 in remotecall_fetch at multi.jl:696
 in main at /raid2/labs/Koslicki_lab/koslickd/Scripts/test.jl:314
 in include at boot.jl:244
 in include_from_node1 at loading.jl:128
while loading /raid2/labs/Koslicki_lab/koslickd/Scripts/test.jl, in expression starting on line 32


WARNING: Forcibly interrupting busy workers
exception on 3:
@dkoslicki
Copy link
Author

Instead of trying to call ArgParse locally on each worker, just refer back to the master @everywhere parsed_args = remotecall_fetch(1,()->parse_commandline())
For example

using ArgParse

function parse_commandline()
    s = ArgParseSettings()

    @add_arg_table s begin
        "--opt1"
            help = "an option with an argument"
        "--opt2", "-o"
            help = "another option with an argument"
            arg_type = Int
            default = 0
        "--flag1"
            help = "an option without argument, i.e. a flag"
            action = :store_true
        "arg1"
            help = "a positional argument"
    end

    return parse_args(s)
end

function main()
    parsed_args = remotecall_fetch(1,()->parse_commandline())
    println("Parsed args:")
    for pa in parsed_args
        println("  $(pa[1])  =>  $(pa[2])")
    end
    @everywhere test=parsed_args["opt1"]
end

main()

@carlobaldassi
Copy link
Owner

Sorry for not answering earlier. About the error message, I guess it's something to do with the fact that the worker processes are launched by invoking the julia executable with some command line options, which then ArgParse is attempting to parse (failing).

But I'd argue that argument parsing would typically be done on the master process, and then sent to the workers. IIUC, what your solution is doing is make each worker call the master for the parsing. Probably not a big deal, but doesn't seem very efficient. It would be better if the script you're calling would create the workers itself with addprocs, do the parsing on master, then delegating the work to the workers (based on the parsed_args, probably).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants