How do we exec a julia program for competitive programming?

Hey everyone.

I want your idea to exec a julia program quickly and usefuly for competitive prgramming.

You may not know competitive programming.
It is

A programming competition generally involves the host presenting a set of logical or
mathematical problems to the contestants (who can vary in number from tens to several thousands),
and contestants are required to write computer programs capable of solving each problem.

[Competitive programming - Wikipedia]

I am a user at AtCoder.
AtCoder is a competitive programming site. [AtCoder]
Next week, AtCoder seeks methods of language install, compile and exec from AtCoder users.

Its environment is Ubuntu 18.04.
Here are some its fotmats from 2016 (I translate this Japanese to English).

language version compile command execute command object file file extension library
c GCC 4.9.2 gcc-4.9 -O2 -o {dirname}/a.out {dirname}/{basename} -lm {dirname}/a.out {dirname}/a.out c no
Julia 0.4.2 please, anyone help julia {filename} jl no
install procedure
"$ sudo add-apt-repository ppa:staticfloat/juliareleases
$ sudo add-apt-repository ppa:staticfloat/julia-deps
$ sudo apt-get update
$ sudo apt-get install julia"

[AtCoder 2016幓2꜈č؀čŖžę›“ꖰ - Google Sheets]

I think that it can be imporoved more.

For example

Time limit of exec command is 2 sec on AtCoder.
Now, normal Julia doesnā€™t have any aot way, and JIT compile needs a little milli sec.
I am going to suggest PackageCompiler.jl[GitHub - JuliaLang/PackageCompiler.jl: Compile your Julia Package] that can precomile.
But, I tested it which isnā€™t so fast on my environment.

Please tell me your ideas of install, compile, exec, library, etcā€¦ .

2 Likes

I know this is a very old post, but Iā€™ve been interested in using Julia for competitive programming too recently, and I thought Iā€™d share some thoughts I had regarding how to go about doing this. I tested Julia on AtCoder earlier today and the overhead is between 1 and 2 seconds for even simple code, which is far too high to be usable with a 2s time limit, so precompilation does seem like the only way forward. (A quick disclaimer: Iā€™m fairly new to Julia, and some of the things I say might be incorrect and/or not make sense.)

Having skimmed the PackageCompiler manual, the basic idea we want to use is probably something like the following.

I havenā€™t tested this myself yet, but it will probably make most cases significantly faster, provided that your code is nice enough (e.g. types not dependent on input).

Obviously, unlike the modules that PackageCompiler would usually be used with, we are dealing with standalone programs. Using the program directly would result in it being run, so people would have to write their solution body within a main() function. With regards to global scope, my understanding is that any variables there would be dirtied in the sysimage by already having had computations performed on them in main() once, which could sometimes be annoying to deal with. Putting any computations at global scope would also allow a contestant to do precomputations at ā€œcompile timeā€, effectively doubling the time limit in some cases. You can deal with this by forcing everything to be in a local scope, but that starts to get restrictive.

One potential alternative that doesnā€™t require the contestant to do anything differently is to generate a sysimage using only the precompile statements for functions in Base and the other packages supported by AtCoder, and without the module in it. The problem is that this doesnā€™t deal with things like parsing and type inference for the contestantā€™s code at all, which seem to me like they would probably take up a significant amount of time, so Iā€™m not sure how useful this would be; nevertheless I can test it if youā€™re interested.

An ideal solution would probably involve being able to force the computations at global scope to get re-run in some sense (to both clean up the residual sysimage state and prevent precomputation at compile time from being effective). Let me know if you have any ideas about how it might be possible to achieve this, or if anything here needs further explanation / is insane.

2 Likes

I do not think that there is such a high (1-2-sec) penalty for julia, (i just solved
some problems from the last abc contests in julia, using only standard IO/algo
stuff.)
I agree that the current online judge systems are not fair to julia/python/java(they favor the compiled languages).
Imagine a scenario where each language (that can be used) has its own tester app (written on the lang to be tested) and a contestant is required to write a solution that has function with a fixed name (and signature):

function solve(inputfile, outputfile)
  # work with the provided file handlers
end

The tester app loads the actual solution (warmup/precompile only once) and call it
several times with appropriate parameters. This way only the net running times are measured ā€¦ It is an already worked out approach: codewars, codesignal are using similar methods for evaluating (i suspect)

2 Likes