2015-12-19 02:35:13 +01:00
|
|
|
|
|
|
|
let full_run ?(start_dataserver=true) ezfio_filename =
|
|
|
|
(* Identify the job scheduler *)
|
|
|
|
let launcher =
|
|
|
|
Launcher.find ()
|
|
|
|
and scheduler =
|
|
|
|
Scheduler.find ()
|
|
|
|
in
|
2016-03-03 13:57:33 +01:00
|
|
|
Printf.printf "Scheduler : %s\n%!" (Scheduler.to_string scheduler);
|
|
|
|
Printf.printf "Launcher : %s\n%!" (Launcher.to_string launcher );
|
2015-12-19 02:35:13 +01:00
|
|
|
|
|
|
|
|
|
|
|
(* Create the node file *)
|
2017-11-29 19:48:28 +01:00
|
|
|
(*
|
|
|
|
let () =
|
|
|
|
let server_file =
|
|
|
|
Filename.concat ezfio_filename "nodefile"
|
|
|
|
in
|
|
|
|
Out_channel.with_file server_file ~f:(fun out_channel ->
|
|
|
|
Launcher.create_nodefile ()
|
|
|
|
|> Out_channel.output_string out_channel
|
|
|
|
)
|
|
|
|
*)
|
2015-12-19 02:35:13 +01:00
|
|
|
|
|
|
|
|
|
|
|
(* Get the configuration of executables *)
|
|
|
|
let qmcchem =
|
|
|
|
Lazy.force Qmcchem_config.qmcchem
|
|
|
|
and qmc =
|
|
|
|
[ Lazy.force Qmcchem_config.qmcchem ; "run" ; "-q" ]
|
|
|
|
in
|
|
|
|
|
|
|
|
|
|
|
|
if (start_dataserver) then
|
|
|
|
begin
|
|
|
|
(* Reset socket address in EZFIO *)
|
2019-07-01 11:32:01 +02:00
|
|
|
Ezfio.set_simulation_http_server "tcp://127.0.0.1:65534";
|
2015-12-19 02:35:13 +01:00
|
|
|
|
|
|
|
|
|
|
|
(* Start the data server *)
|
2019-07-22 11:31:16 +02:00
|
|
|
let prog, args =
|
|
|
|
qmcchem, [| qmcchem; "run" ; "-d" ; ezfio_filename |]
|
2015-12-19 02:35:13 +01:00
|
|
|
in
|
|
|
|
let pid_dataserver =
|
2019-07-22 11:31:16 +02:00
|
|
|
Watchdog.fork_exec ~prog ~args ()
|
2015-12-19 02:35:13 +01:00
|
|
|
in
|
2019-07-22 11:31:16 +02:00
|
|
|
Printf.printf "%7d : %s\n%!" pid_dataserver (String.concat " " (Array.to_list args))
|
2015-12-19 02:35:13 +01:00
|
|
|
end;
|
|
|
|
|
|
|
|
|
2018-06-04 10:26:49 +02:00
|
|
|
(* Check if the Zmq Rep socket is open *)
|
2015-12-19 02:35:13 +01:00
|
|
|
let test_open_rep_socket () =
|
|
|
|
let zmq_context =
|
2018-06-04 10:26:49 +02:00
|
|
|
Zmq.Context.create ()
|
2015-12-19 02:35:13 +01:00
|
|
|
in
|
|
|
|
let socket =
|
2018-06-04 10:26:49 +02:00
|
|
|
Zmq.Socket.create zmq_context Zmq.Socket.req
|
2015-12-19 02:35:13 +01:00
|
|
|
and address =
|
|
|
|
Ezfio.get_simulation_http_server ()
|
|
|
|
in
|
2018-07-09 19:21:59 +02:00
|
|
|
Zmq.Socket.set_receive_timeout socket 100;
|
2015-12-19 02:35:13 +01:00
|
|
|
let reply =
|
|
|
|
try
|
|
|
|
(
|
2018-06-04 10:26:49 +02:00
|
|
|
Zmq.Socket.connect socket address;
|
|
|
|
Zmq.Socket.send socket (Message.(to_string Test));
|
|
|
|
Zmq.Socket.recv socket
|
2015-12-19 02:35:13 +01:00
|
|
|
) with
|
2018-07-09 19:57:05 +02:00
|
|
|
| Unix.Unix_error _ ->
|
2015-12-19 02:35:13 +01:00
|
|
|
begin
|
|
|
|
"Failed"
|
|
|
|
end
|
|
|
|
in
|
2018-07-09 19:21:59 +02:00
|
|
|
Zmq.Socket.set_linger_period socket 1 ;
|
|
|
|
Zmq.Socket.close socket;
|
|
|
|
Zmq.Context.terminate zmq_context;
|
2015-12-19 02:35:13 +01:00
|
|
|
reply = "OK"
|
|
|
|
in
|
|
|
|
|
|
|
|
|
|
|
|
(* Wait until the rep socket is open *)
|
|
|
|
let rec count = function
|
|
|
|
| 0 -> false
|
|
|
|
| -1 -> true
|
|
|
|
| n ->
|
|
|
|
if (not (test_open_rep_socket ())) then
|
|
|
|
begin
|
2019-07-23 17:27:02 +02:00
|
|
|
Unix.sleep 2;
|
2015-12-19 02:35:13 +01:00
|
|
|
count (n-1);
|
|
|
|
end
|
|
|
|
else
|
|
|
|
count (-1);
|
|
|
|
in
|
|
|
|
if (not (count 300)) then
|
|
|
|
Watchdog.kill ();
|
2019-07-22 11:31:16 +02:00
|
|
|
Unix.sleep 3;
|
2015-12-19 02:35:13 +01:00
|
|
|
|
|
|
|
|
|
|
|
(* Start the qmc processes *)
|
2019-07-22 11:31:16 +02:00
|
|
|
let prog, args_list =
|
2015-12-19 02:35:13 +01:00
|
|
|
let launcher =
|
|
|
|
Launcher.(find () |> to_string)
|
|
|
|
in
|
|
|
|
match launcher
|
2019-07-22 11:31:16 +02:00
|
|
|
|> String.split_on_char ' '
|
2020-04-15 14:40:33 +02:00
|
|
|
|> List.rev_map String.trim
|
|
|
|
|> List.rev
|
2019-07-22 11:31:16 +02:00
|
|
|
|> List.filter (fun x -> x <> "")
|
2015-12-19 02:35:13 +01:00
|
|
|
with
|
|
|
|
| launcher_exe::launcher_flags ->
|
|
|
|
launcher_exe, launcher_exe :: launcher_flags @ qmc @ [
|
|
|
|
Ezfio.get_simulation_http_server () ; ezfio_filename ]
|
|
|
|
| _ -> failwith "Error in launcher"
|
|
|
|
in
|
2019-07-22 11:31:16 +02:00
|
|
|
let args = Array.of_list args_list in
|
2015-12-19 02:35:13 +01:00
|
|
|
let pid_qmc =
|
|
|
|
try
|
2019-07-22 11:31:16 +02:00
|
|
|
Watchdog.fork_exec ~prog ~args ()
|
2015-12-19 02:35:13 +01:00
|
|
|
with
|
|
|
|
| Unix.Unix_error _ ->
|
|
|
|
begin
|
|
|
|
let command =
|
2019-07-22 11:31:16 +02:00
|
|
|
String.concat " " args_list
|
2015-12-19 02:35:13 +01:00
|
|
|
in
|
|
|
|
Printf.printf "
|
|
|
|
============================================================
|
|
|
|
Error: Unable to run the following command
|
|
|
|
%s
|
|
|
|
============================================================
|
|
|
|
\n%!" command ;
|
|
|
|
Watchdog.kill ()
|
|
|
|
end
|
|
|
|
in
|
2019-07-22 11:31:16 +02:00
|
|
|
Printf.printf "%7d : %s\n%!" pid_qmc (String.concat " " args_list);
|
2015-12-19 02:35:13 +01:00
|
|
|
|
|
|
|
(* Wait for processes to finish *)
|
|
|
|
Watchdog.join ()
|
|
|
|
|
|
|
|
|
|
|
|
let data_run ezfio_filename =
|
|
|
|
Qmcchem_dataserver.run ezfio_filename ~daemon:false
|
|
|
|
|
|
|
|
let qmc_run dataserver ezfio_filename =
|
|
|
|
Qmcchem_forwarder.run ezfio_filename dataserver
|
|
|
|
|
|
|
|
let ssh_run host dataserver ezfio_filename =
|
|
|
|
print_endline ("ssh "^host^" "^ezfio_filename^" "^dataserver)
|
|
|
|
|
|
|
|
let run a d ?q ?s ezfio_filename =
|
|
|
|
|
2016-01-18 20:17:37 +01:00
|
|
|
Qputils.set_ezfio_filename ezfio_filename;
|
2015-12-19 02:35:13 +01:00
|
|
|
|
|
|
|
(* Signal handler to Kill properly all the processes *)
|
2019-07-22 11:31:16 +02:00
|
|
|
let handler s =
|
|
|
|
Printf.printf "QMC=Chem received signal %d... killing\n%!" s;
|
2015-12-19 02:35:13 +01:00
|
|
|
Watchdog.kill ();
|
|
|
|
in
|
2019-07-22 11:31:16 +02:00
|
|
|
List.iter (fun s -> ignore @@ Sys.signal s (Sys.Signal_handle handler))
|
|
|
|
[
|
|
|
|
Sys.sigint ;
|
|
|
|
Sys.sigterm ;
|
|
|
|
Sys.sigquit ;
|
2015-12-19 02:35:13 +01:00
|
|
|
]
|
|
|
|
;
|
|
|
|
|
2019-07-22 11:31:16 +02:00
|
|
|
|
2015-12-19 02:35:13 +01:00
|
|
|
(* Validate input *)
|
|
|
|
Input.validate ();
|
|
|
|
(* Printf.printf "MD5 : %s\n" (Lazy.force Md5.hash) ; *)
|
|
|
|
|
|
|
|
let runtype =
|
|
|
|
match (a,d,q,s) with
|
|
|
|
| (false,false, None, None) -> `Run
|
|
|
|
| (false,true, None, None) -> `Data
|
|
|
|
| (true,false, None, None) -> `Add
|
|
|
|
| (false,false, Some dataserver, None) -> `Qmc dataserver
|
|
|
|
| (false,false, Some dataserver, Some host) -> `Ssh (host, dataserver)
|
|
|
|
| _ -> failwith "Options (-a|-d|-q [-s]) are mutually exclusive"
|
|
|
|
in
|
|
|
|
|
|
|
|
let run =
|
|
|
|
match runtype with
|
|
|
|
| `Run -> full_run ~start_dataserver:true
|
|
|
|
| `Data -> data_run
|
|
|
|
| `Add -> full_run ~start_dataserver:false
|
|
|
|
| `Qmc dataserver -> qmc_run dataserver
|
|
|
|
| `Ssh (host,dataserver) -> ssh_run host dataserver
|
|
|
|
in
|
|
|
|
run ezfio_filename
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2019-07-22 12:19:12 +02:00
|
|
|
let command () =
|
2019-07-22 11:31:16 +02:00
|
|
|
let open Command_line in
|
|
|
|
begin
|
|
|
|
set_header_doc (Sys.argv.(0) ^ " - QMC=Chem command");
|
|
|
|
set_description_doc "Run a calculation";
|
|
|
|
|
|
|
|
[ { short='a' ; long="add" ; opt=Optional ;
|
|
|
|
doc="Add more resources to a running calculation" ;
|
|
|
|
arg=Without_arg ; };
|
|
|
|
|
|
|
|
{ short='d' ; long="data-server" ; opt=Optional ;
|
|
|
|
doc="Start a dataserver process on the local host" ;
|
|
|
|
arg=Without_arg ; };
|
2015-12-19 02:35:13 +01:00
|
|
|
|
2019-07-22 11:31:16 +02:00
|
|
|
{ short='q' ; long="local-qmc" ; opt=Optional ;
|
|
|
|
doc="Start a qmc process on the local host attached to the addres given as an argument" ;
|
|
|
|
arg=With_arg "<string>" ; };
|
2015-12-19 02:35:13 +01:00
|
|
|
|
2019-07-22 11:31:16 +02:00
|
|
|
{ short='s' ; long="remote-qmc" ; opt=Optional ;
|
|
|
|
doc="Start a qmc process on the remote host as an argument" ;
|
|
|
|
arg=With_arg "<string>" ; };
|
|
|
|
|
|
|
|
anonymous "EZFIO_DIR" Mandatory "EZFIO directory";
|
|
|
|
]
|
|
|
|
|> set_specs
|
|
|
|
end;
|
|
|
|
|
|
|
|
let a = Command_line.get_bool "add" in
|
|
|
|
let d = Command_line.get_bool "data-server" in
|
|
|
|
let q = Command_line.get "local-qmc" in
|
|
|
|
let s = Command_line.get "remote-qmc" in
|
|
|
|
|
|
|
|
let ezfio_file =
|
|
|
|
match Command_line.anon_args () with
|
|
|
|
| ezfio_file :: [] -> ezfio_file
|
|
|
|
| _ -> (Command_line.help () ; failwith "Inconsistent command line")
|
|
|
|
in
|
2015-12-19 02:35:13 +01:00
|
|
|
|
2019-07-22 11:31:16 +02:00
|
|
|
run a d ?q ?s ezfio_file
|
2015-12-19 02:35:13 +01:00
|
|
|
|
|
|
|
|
|
|
|
|