# #!/usr/bin/env JULIA_NUM_THREADS=50 julia

using PairwiseVsMultipleNA

function main()
    n = length(ARGS)
    if n < 3 || n > 5
        println("pnavsmna.jl <exp_name, pef, mef, or, mef_approach3> <alignment description file (input)> <alignment results file (output)> <number of random samples (optional, default=0)> <number of processes (optional, default=1)>")
    end
    expname = ARGS[1]
    alndescfile = ARGS[2]
    alnresultsfile = ARGS[3]
    numsamples = n < 4 ? 0 : parse(Int, ARGS[4])
    if n < 5 || ARGS[5][1] == 't'
        if Threads.nthreads()==1
            println("WARNING: Set environment variable to JULIA_NUM_THREADS=$(parse(Int,ARGS[5][2:end])) in order to use multiple threads")
        end
        setparrmethod("threads")
        println("expname = $expname alndescfile = $alndescfile alnresultsfile = $alnresultsfile numsamples = $numsamples with $(Threads.nthreads()) threads")
    elseif ARGS[5][1] == 'p'
        setparrmethod("procs")
        numprocs = parse(Int, ARGS[5][2:end])
        if numprocs > 1
            addprocs(numprocs-1)
            @everywhere eval(parse("using PairwiseVsMultipleNA"))
        end
        println("expname = $expname alndescfile = $alndescfile alnresultsfile = $alnresultsfile numsamples = $numsamples with $(numprocs) processes")
    else
        error("bad 5th argument: $(ARGS[5])")
    end
    calc_alnlist_scores(expname, alndescfile, alnresultsfile, numsamples)
end

main()


