qmcchem/ocaml/Qmcchem_config.ml

124 lines
2.5 KiB
OCaml
Raw Permalink 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 (
2022-01-11 14:47:04 +01:00
let p =
2019-07-14 18:50:44 +02:00
try Sys.getenv "PATH" with
| Not_found -> failwith "PATH environment variable is not set"
2022-01-11 14:47:04 +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
2022-01-11 14:47:04 +01:00
let fp =
Filename.concat head exe
2015-12-19 02:35:13 +01:00
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
)
2022-01-11 14:47:04 +01:00
external get_ipv4_address_for_interface : string -> string =
"get_ipv4_address_for_interface"
2019-07-14 18:50:44 +02:00
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
2022-01-11 14:47:04 +01:00
if String.sub result 0 5 = "error" then
2019-07-14 18:50:44 +02:00
Printf.sprintf "Unable to use network interface %s" interface
|> failwith
else
result
2015-12-19 02:35:13 +01:00
)
2022-01-11 22:12:02 +01:00
let binary_io =
try
2022-01-12 19:05:15 +01:00
let qmcchem_io = Sys.getenv "QMCCHEM_IO" in
qmcchem_io = "B" || qmcchem_io = "b"
2022-01-11 22:12:02 +01:00
with Not_found -> false
2022-01-11 14:47:04 +01:00