[erlang-questions] Erlang and Slurm sbatch scripts

zxq9 <>
Thu Sep 28 17:24:05 CEST 2017

On 2017年09月28日 木曜日 10:25:09 Miloud Eloumri wrote:
> Hello,
> Is there an easy or automated way perhaps a tool or a package to write
> Slurm sbatch scripts to schedule and run Erlang module file or application
> on a server?
> https://slurm.schedmd.com/sbatch.html
> Can somebody please help me and provide an sbatch script (.sh) shows a way
> to schedule and run an Erlang module (.erl file) espically  a way to
> execute the file ?

Are you trying to execute a single file or a project residing in a directory
laid out the traditional way?

The simplest way of all would be to use an escript instead of an .erl file.
Escripts can start with a shebang (just like a shell script), have a main/1
function, and just execute right there.

  :~$ cat foo.escript 
  #! /usr/bin/env escript
  main(_) ->
      io:format("Reporting from within foo.escript.~n").
  :~$ chmod +x foo.escript 
  :~$ ./foo.escript 
  Reporting from within foo.escript.

An .erl file would need to be compiled, loaded, and then called. The `make`
module has just the thing (assuming the file is in the current directory).
>From within Erlang:

  up_to_date = make:files(["foo.erl"]),

>From the shell it would be:

  :~$ cat foo.erl
  bar() ->
      io:format("I am module ~tp~n", [?MODULE]),
  :~$ erlc foo.erl
  :~$ erl -pa ./ -noshell -s foo bar
  I am module foo

Note the explicit system halt called at the end of bar/0.
The invocation of the specific module and function name
are the arguments following `-s`.

Escripts are really the way to go for this, though.
If you DO have an .erl file that can't have a shebang at the
top, but you CAN force that it has a function called main/1,
then you can still run it as an escript:

  :~$ cat foo.erl
  bar() ->
      io:format("I am module ~tp~n", [?MODULE]),
  main(_) ->
      io:format("I didn't need to be exported!~n"),
      io:format("I also don't need to be explicitly terminated~n").
  :~$ escript foo.erl
  I didn't need to be exported!
  I also don't need to be explicitly terminated

I don't know anything about sbatch, but hopefully this sort of points
you in the right direction. There are plenty of ways to skin this cat.


More information about the erlang-questions mailing list