2015-02-26 15:02:31 +00:00
|
|
|
|
|
|
|
#include <sys/stat.h>
|
|
|
|
#include <libgen.h>
|
|
|
|
|
2015-06-01 15:28:29 +00:00
|
|
|
#include "trick/MonteCarlo.hh"
|
|
|
|
#include "trick/command_line_protos.h"
|
|
|
|
#include "trick/message_proto.h"
|
|
|
|
#include "trick/message_type.h"
|
|
|
|
#include "trick/tc_proto.h"
|
2015-02-26 15:02:31 +00:00
|
|
|
|
|
|
|
/** @par Detailed Design: */
|
|
|
|
int Trick::MonteCarlo::slave_init() {
|
|
|
|
/** <ul><li> Construct the run directory. */
|
|
|
|
run_directory = std::string(command_line_args_get_output_dir());
|
|
|
|
|
|
|
|
if (access(run_directory.c_str(), F_OK) != 0) {
|
|
|
|
if (mkdir(run_directory.c_str(), 0775) == -1) {
|
2018-07-25 18:05:10 +00:00
|
|
|
if (verbosity >= MC_ERROR) {
|
2017-03-23 17:22:40 +00:00
|
|
|
message_publish(MSG_ERROR, "Monte [%s:%d] Unable to create directory %s.\nTerminating.\n",
|
2015-02-26 15:02:31 +00:00
|
|
|
run_directory.c_str(), machine_name.c_str(), slave_id) ;
|
|
|
|
}
|
|
|
|
exit(-1);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/** <li> Run the slave initialization jobs. */
|
|
|
|
run_queue(&slave_init_queue, "in slave_init queue") ;
|
|
|
|
|
|
|
|
/** <li> Initialize the sockets. */
|
|
|
|
tc_error(&listen_device, 0);
|
|
|
|
tc_error(&connection_device, 0);
|
2017-06-21 13:59:22 +00:00
|
|
|
tc_init(&listen_device);
|
2015-02-26 15:02:31 +00:00
|
|
|
listen_device.disable_handshaking = TC_COMM_TRUE;
|
|
|
|
|
|
|
|
/** <li> Connect to the master and write the port over which we are listening for new runs. */
|
2017-03-23 17:22:40 +00:00
|
|
|
connection_device.port = master_port;
|
2015-02-26 15:02:31 +00:00
|
|
|
if (tc_connect(&connection_device) != TC_SUCCESS) {
|
2018-07-25 18:05:10 +00:00
|
|
|
if (verbosity >= MC_ERROR) {
|
2017-03-23 17:22:40 +00:00
|
|
|
message_publish(MSG_ERROR, "Monte [%s:%d] Failed to initialize communication sockets.\nTerminating.\n",
|
2015-02-26 15:02:31 +00:00
|
|
|
machine_name.c_str(), slave_id) ;
|
|
|
|
}
|
|
|
|
exit(-1);
|
|
|
|
}
|
|
|
|
|
2018-07-25 18:05:10 +00:00
|
|
|
if (verbosity >= MC_ALL) {
|
2017-03-23 17:22:40 +00:00
|
|
|
message_publish(MSG_INFO, "Monte [%s:%d] Making initial connection with Master.\n",
|
2015-02-26 15:02:31 +00:00
|
|
|
machine_name.c_str(), slave_id) ;
|
|
|
|
}
|
|
|
|
|
|
|
|
int id = htonl(slave_id);
|
|
|
|
tc_write(&connection_device, (char *)&id, (int)sizeof(id));
|
|
|
|
|
2017-03-23 17:22:40 +00:00
|
|
|
char hostname[_POSIX_HOST_NAME_MAX] = {};
|
2015-02-26 15:02:31 +00:00
|
|
|
gethostname(hostname, sizeof(hostname)-1);
|
|
|
|
|
|
|
|
int num_bytes = htonl(strlen(hostname));
|
|
|
|
tc_write(&connection_device, (char *)&num_bytes, (int)sizeof(num_bytes));
|
|
|
|
tc_write(&connection_device, hostname, strlen(hostname));
|
|
|
|
int listen_port = htonl(listen_device.port);
|
|
|
|
tc_write(&connection_device, (char *)&listen_port, (int)sizeof(listen_port));
|
|
|
|
tc_disconnect(&connection_device);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|