10
1
mirror of https://gitlab.com/scemama/qmcchem.git synced 2024-11-11 16:43:39 +01:00
qmcchem/ocaml/Launcher.ml

93 lines
1.7 KiB
OCaml
Raw Normal View History

2015-12-19 02:35:13 +01:00
type t =
| Srun
| MPI
| Bash
let to_string = function
| Srun -> "srun"
| Bash -> "env"
2020-05-11 13:49:07 +02:00
| MPI -> String.concat " " [ Lazy.force Qmcchem_config.mpirun ;
try Sys.getenv "QMCCHEM_MPIRUN_FLAGS" with Not_found -> ""
]
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"
2020-05-11 13:49:07 +02:00
*)
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 =
2019-07-14 18:50:44 +02:00
Hashtbl.create 1000
2015-12-19 02:35:13 +01:00
in
let in_channel =
Unix.open_process_in (launcher_command^" hostname -s")
in
2019-07-14 18:50:44 +02:00
String_ext.input_lines in_channel
|> List.map String.trim
|> List.iter ( fun host ->
let n =
match Hashtbl.find_opt h host with
| Some x -> x+1
| None -> 1
in
Hashtbl.replace h host n
2015-12-19 02:35:13 +01:00
);
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
2019-07-14 18:50:44 +02:00
Hashtbl.fold (fun k v a -> (f (k,v)) :: a) h []
|> String.concat "\n"
2015-12-19 02:35:13 +01:00