Erlang and Slurm sbatch scripts

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|

Erlang and Slurm sbatch scripts

Miloud.Eloumri
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?
 

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 ? 

Thank you, 
Miloud 

_______________________________________________
erlang-questions mailing list
[hidden email]
http://erlang.org/mailman/listinfo/erlang-questions
Reply | Threaded
Open this post in threaded view
|

Re: Erlang and Slurm sbatch scripts

zxq9-2
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.


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


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"]),
  foo:bar().

From the shell it would be:


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


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:


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


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.

-Craig
_______________________________________________
erlang-questions mailing list
[hidden email]
http://erlang.org/mailman/listinfo/erlang-questions