10
1
mirror of https://gitlab.com/scemama/qmcchem.git synced 2024-11-19 12:32:20 +01:00
qmcchem/ocaml/Qmcchem_config.ml

118 lines
2.5 KiB
OCaml
Raw Normal View History

2015-12-19 02:35:13 +01:00
(** QMC=Chem installation directory *)
let root = lazy (
2019-07-14 18:50:44 +02:00
try Sys.getenv "QMCCHEM_PATH" with
| Not_found -> failwith "QMCCHEM_PATH environment variable not set"
2015-12-19 02:35:13 +01:00
)
(* PATH environment variable as a list of strings *)
let path = lazy (
let p =
2019-07-14 18:50:44 +02:00
try Sys.getenv "PATH" with
| Not_found -> failwith "PATH environment variable is not set"
2015-12-19 02:35:13 +01:00
in
2019-07-14 18:50:44 +02:00
String.split_on_char ':' p
2015-12-19 02:35:13 +01:00
)
(* Full path of a binary taken from the PATH *)
let full_path exe =
let rec in_path_rec = function
| [] -> None
| head :: tail ->
begin
let fp =
Filename.concat head exe
in
2019-07-14 18:50:44 +02:00
if Sys.file_exists fp then
Some fp
else
in_path_rec tail
2015-12-19 02:35:13 +01:00
end
in
Lazy.force path
|> in_path_rec
(* True if an executable is in the PATH *)
let in_path x =
2019-07-14 18:50:44 +02:00
match full_path x with
2015-12-19 02:35:13 +01:00
| Some _ -> true
| None -> false
let has_parallel = lazy( in_path "parallel" )
let has_mpirun = lazy( in_path "mpirun" )
let has_srun = lazy( in_path "parallel" )
let has_qmc = lazy( in_path "qmc" )
let mpirun = lazy (
2019-07-14 18:50:44 +02:00
try
Sys.getenv "QMCCHEM_MPIRUN"
with
| Not_found -> "mpirun"
2015-12-19 02:35:13 +01:00
)
let qmcchem = lazy(
Filename.concat (Lazy.force root) "bin/qmcchem"
)
and qmc = lazy(
Filename.concat (Lazy.force root) "bin/qmc"
)
2015-12-29 01:16:19 +01:00
and qmcchem_info = lazy(
Filename.concat (Lazy.force root) "bin/qmcchem_info"
)
2019-07-14 18:50:44 +02:00
2015-12-19 02:35:13 +01:00
and qmc_create_walkers = lazy(
Filename.concat (Lazy.force root) "bin/qmc_create_walkers"
)
let dev_shm = "/dev/shm/"
(** Name of the host on which the data server runs *)
let hostname = lazy (
try
Unix.gethostname ()
with
2019-07-01 11:32:01 +02:00
| _ -> "127.0.0.1"
2015-12-19 02:35:13 +01:00
)
2019-07-14 18:50:44 +02:00
external get_ipv4_address_for_interface : string -> string =
"get_ipv4_address_for_interface"
2015-12-19 02:35:13 +01:00
let ip_address = lazy (
2019-07-14 18:50:44 +02:00
let interface =
try Some (Sys.getenv "QMCCHEM_NIC")
with Not_found -> None
in
match interface with
| None ->
2015-12-19 02:35:13 +01:00
begin
try
2019-07-14 18:50:44 +02:00
let host =
Lazy.force hostname
|> Unix.gethostbyname
in
Unix.string_of_inet_addr host.h_addr_list.(0);
2015-12-19 02:35:13 +01:00
with
| Unix.Unix_error _ ->
failwith "Unable to find IP address from host name."
end
| Some interface ->
2019-07-14 18:50:44 +02:00
let result = get_ipv4_address_for_interface interface in
if String.sub result 0 5 = "error" then
Printf.sprintf "Unable to use network interface %s" interface
|> failwith
else
result
2015-12-19 02:35:13 +01:00
)