10
1
mirror of https://gitlab.com/scemama/qmcchem.git synced 2024-06-02 03:15:19 +02:00
qmcchem/ocaml/Launcher.ml

90 lines
1.6 KiB
OCaml
Raw Normal View History

2017-10-10 09:39:58 +02:00
open Core
2015-12-19 02:35:13 +01:00
type t =
| Srun
| MPI
| Bash
let to_string = function
| Srun -> "srun"
| Bash -> "env"
| MPI -> Lazy.force Qmcchem_config.mpirun
2018-07-13 10:05:51 +02:00
(*
let to_string = function
| MPI
| Srun -> String.concat ~sep:" " [ Lazy.force Qmcchem_config.mpirun ;
match Sys.getenv "QMCCHEM_MPIRUN_FLAGS" with
| None -> ""
| Some p -> p
]
| Bash -> "env"
*)
2015-12-19 02:35:13 +01:00
(** Find the launcher for the current job scheduler *)
let find () =
let result =
match Scheduler.find () with
| Scheduler.SLURM -> Srun
| Scheduler.Batch
| Scheduler.PBS
| Scheduler.SGE ->
if Lazy.force Qmcchem_config.has_mpirun then
MPI
else
Bash
in
result
(** Create a file contaning the list of nodes and the number of available CPUs *)
let create_nodefile () =
let launcher =
find ()
in
let launcher_command =
to_string launcher
in
let h =
2018-03-14 17:02:52 +01:00
String.Table.create ~size:1000 ()
2015-12-19 02:35:13 +01:00
in
let in_channel =
Unix.open_process_in (launcher_command^" hostname -s")
in
In_channel.input_lines in_channel
|> List.map ~f:String.strip
|> List.iter ~f:( fun host ->
Hashtbl.change h host (function
| Some x -> Some (x+1)
| None -> Some 1
)
);
match
Unix.close_process_in in_channel
with
| _ -> ();
let f =
match launcher with
| MPI ->
fun (node, n) ->
Printf.sprintf "%s slots=%d\n" node n
| Srun
| Bash ->
fun (node, n) ->
Printf.sprintf "%s %d\n" node n
in
Hashtbl.to_alist h
|> List.map ~f
|> String.concat