passing client options to distributed clients, ready to actually distribute work
git-svn-id: svn://anubis/fart/trunk@223 7f9b0f55-74a9-4bce-be96-3c2cd072584d
This commit is contained in:
parent
1dbe7040e4
commit
6fdaf01214
@ -22,6 +22,8 @@ int distrib::readHostFile(const char * filename)
|
|||||||
while ( ! ifs.eof() )
|
while ( ! ifs.eof() )
|
||||||
{
|
{
|
||||||
ifs >> host;
|
ifs >> host;
|
||||||
|
if ( ifs.eof() )
|
||||||
|
break;
|
||||||
m_hosts.push_back(host);
|
m_hosts.push_back(host);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -29,17 +31,18 @@ int distrib::readHostFile(const char * filename)
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
int distrib::connect()
|
int distrib::connect(const std::vector<std::string> & client_options)
|
||||||
{
|
{
|
||||||
int err = 0;
|
int err = 0;
|
||||||
for (int i = 0, sz = m_hosts.size(); i < sz; i++)
|
for (int i = 0, sz = m_hosts.size(); i < sz; i++)
|
||||||
{
|
{
|
||||||
err += connect(m_hosts[i]);
|
err += connect(m_hosts[i], client_options);
|
||||||
}
|
}
|
||||||
return err;
|
return err;
|
||||||
}
|
}
|
||||||
|
|
||||||
int distrib::connect(const string & host)
|
int distrib::connect(const string & host,
|
||||||
|
const std::vector<std::string> & client_options)
|
||||||
{
|
{
|
||||||
int id = fork();
|
int id = fork();
|
||||||
if (id < 0) /* check for fork() error */
|
if (id < 0) /* check for fork() error */
|
||||||
@ -55,10 +58,30 @@ int distrib::connect(const string & host)
|
|||||||
{
|
{
|
||||||
char server_port_str[15];
|
char server_port_str[15];
|
||||||
sprintf(server_port_str, "%d", m_serverport);
|
sprintf(server_port_str, "%d", m_serverport);
|
||||||
execlp("ssh", "ssh", host.c_str(),
|
vector<string> args;
|
||||||
"fart", "--host", m_servername.c_str(),
|
args.push_back("ssh");
|
||||||
"--port", server_port_str,
|
args.push_back(host);
|
||||||
(char *) NULL);
|
args.push_back("fart");
|
||||||
|
args.push_back("--host");
|
||||||
|
args.push_back(m_servername);
|
||||||
|
args.push_back("--port");
|
||||||
|
args.push_back(server_port_str);
|
||||||
|
for (int i = 0, sz = client_options.size(); i < sz; i++)
|
||||||
|
args.push_back(client_options[i]);
|
||||||
|
const char * char_star_args[args.size() + 1];
|
||||||
|
for (int i = 0, sz = args.size(); i < sz; i++)
|
||||||
|
char_star_args[i] = args[i].c_str();
|
||||||
|
char_star_args[args.size()] = (char *) NULL;
|
||||||
|
|
||||||
|
#if 0
|
||||||
|
/* debug */
|
||||||
|
cout << "executing: 'ssh', ";
|
||||||
|
for (int i = 0, sz = args.size(); i < sz; i++)
|
||||||
|
cout << "'" << char_star_args[i] << "', ";
|
||||||
|
cout << endl;
|
||||||
|
#endif
|
||||||
|
|
||||||
|
execvp("ssh", (char * const *) char_star_args);
|
||||||
|
|
||||||
/* we should not get here */
|
/* we should not get here */
|
||||||
cerr << "Error " << errno << " with execlp()!" << endl;
|
cerr << "Error " << errno << " with execlp()!" << endl;
|
||||||
@ -68,10 +91,8 @@ int distrib::connect(const string & host)
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
int distrib::startServer()
|
int distrib::startServer(const std::vector<std::string> & client_options)
|
||||||
{
|
{
|
||||||
connect();
|
|
||||||
|
|
||||||
char hostname[1000];
|
char hostname[1000];
|
||||||
gethostname(&hostname[0], 1000);
|
gethostname(&hostname[0], 1000);
|
||||||
m_servername = hostname;
|
m_servername = hostname;
|
||||||
@ -109,6 +130,8 @@ int distrib::startServer()
|
|||||||
<< m_serverport
|
<< m_serverport
|
||||||
<< endl;
|
<< endl;
|
||||||
|
|
||||||
|
connect(client_options);
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -9,12 +9,13 @@ class distrib
|
|||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
int readHostFile(const char * filename);
|
int readHostFile(const char * filename);
|
||||||
int startServer();
|
int startServer(const std::vector<std::string> & client_options);
|
||||||
int startClient(const char * server, int port);
|
int startClient(const char * server, int port);
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
int connect();
|
int connect(const std::vector<std::string> & client_options);
|
||||||
int connect(const std::string & host);
|
int connect(const std::string & host,
|
||||||
|
const std::vector<std::string> & client_options);
|
||||||
|
|
||||||
std::vector<std::string> m_hosts;
|
std::vector<std::string> m_hosts;
|
||||||
std::vector<int> m_children;
|
std::vector<int> m_children;
|
||||||
|
@ -41,52 +41,68 @@ Scene::Scene(const map<string, const char *> & options,
|
|||||||
if (it->first == "width")
|
if (it->first == "width")
|
||||||
{
|
{
|
||||||
m_width = atoi(it->second);
|
m_width = atoi(it->second);
|
||||||
|
m_client_options.push_back("--width");
|
||||||
|
m_client_options.push_back(it->second);
|
||||||
}
|
}
|
||||||
else if (it->first == "height")
|
else if (it->first == "height")
|
||||||
{
|
{
|
||||||
m_height = atoi(it->second);
|
m_height = atoi(it->second);
|
||||||
|
m_client_options.push_back("--height");
|
||||||
|
m_client_options.push_back(it->second);
|
||||||
}
|
}
|
||||||
else if (it->first == "multisample")
|
else if (it->first == "multisample")
|
||||||
{
|
{
|
||||||
m_multisample_level = atoi(it->second);
|
m_multisample_level = atoi(it->second);
|
||||||
|
m_client_options.push_back("--multisample");
|
||||||
|
m_client_options.push_back(it->second);
|
||||||
}
|
}
|
||||||
else if (it->first == "field-of-view")
|
else if (it->first == "field-of-view")
|
||||||
{
|
{
|
||||||
m_vfov = atof(it->second);
|
m_vfov = atof(it->second);
|
||||||
|
m_client_options.push_back("--field-of-view");
|
||||||
|
m_client_options.push_back(it->second);
|
||||||
}
|
}
|
||||||
else if (it->first == "output-file")
|
else if (it->first == "output-file")
|
||||||
{
|
{
|
||||||
m_output_file_name = it->second;
|
m_output_file_name = it->second;
|
||||||
|
/* no client option necessary */
|
||||||
}
|
}
|
||||||
else if (it->first == "max-depth")
|
else if (it->first == "max-depth")
|
||||||
{
|
{
|
||||||
m_max_depth = atoi(it->second);
|
m_max_depth = atoi(it->second);
|
||||||
|
m_client_options.push_back("--max-depth");
|
||||||
|
m_client_options.push_back(it->second);
|
||||||
}
|
}
|
||||||
else if (it->first == "verbose")
|
else if (it->first == "verbose")
|
||||||
{
|
{
|
||||||
m_verbose = true;
|
m_verbose = true;
|
||||||
|
/* no client option necessary */
|
||||||
}
|
}
|
||||||
else if (it->first == "host")
|
else if (it->first == "host")
|
||||||
{
|
{
|
||||||
m_server_name = it->second;
|
m_server_name = it->second;
|
||||||
m_server = false;
|
m_server = false;
|
||||||
|
/* no client option necessary */
|
||||||
}
|
}
|
||||||
else if (it->first == "port")
|
else if (it->first == "port")
|
||||||
{
|
{
|
||||||
m_server_port = atoi(it->second);
|
m_server_port = atoi(it->second);
|
||||||
|
/* no client option necessary */
|
||||||
}
|
}
|
||||||
else if (it->first == "hosts")
|
else if (it->first == "hosts")
|
||||||
{
|
{
|
||||||
m_hosts_file = it->second;
|
m_hosts_file = it->second;
|
||||||
|
/* no client option necessary */
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
m_client_options.push_back(filename);
|
||||||
|
|
||||||
/* start the distribution infrastructure */
|
/* start the distribution infrastructure */
|
||||||
if (m_server)
|
if (m_server)
|
||||||
{
|
{
|
||||||
if (m_hosts_file != "")
|
if (m_hosts_file != "")
|
||||||
m_distrib.readHostFile(m_hosts_file.c_str());
|
m_distrib.readHostFile(m_hosts_file.c_str());
|
||||||
m_distrib.startServer();
|
m_distrib.startServer(m_client_options);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
@ -108,7 +124,7 @@ Scene::~Scene()
|
|||||||
|
|
||||||
void Scene::render()
|
void Scene::render()
|
||||||
{
|
{
|
||||||
if (m_verbose)
|
if (m_verbose && m_server)
|
||||||
{
|
{
|
||||||
cout << " *** Beginning scene render ***" << endl;
|
cout << " *** Beginning scene render ***" << endl;
|
||||||
cout << "Parameters:" << endl;
|
cout << "Parameters:" << endl;
|
||||||
@ -130,7 +146,7 @@ void Scene::render()
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (m_verbose)
|
if (m_verbose && m_server)
|
||||||
{
|
{
|
||||||
cout << " *** Ending scene render ***" << endl;
|
cout << " *** Ending scene render ***" << endl;
|
||||||
cout << "Writing output file '" << m_output_file_name << '\'' << endl;
|
cout << "Writing output file '" << m_output_file_name << '\'' << endl;
|
||||||
|
@ -95,6 +95,7 @@ class Scene
|
|||||||
std::string m_hosts_file;
|
std::string m_hosts_file;
|
||||||
int m_server_port;
|
int m_server_port;
|
||||||
distrib m_distrib;
|
distrib m_distrib;
|
||||||
|
std::vector<std::string> m_client_options;
|
||||||
|
|
||||||
/* framebuffer */
|
/* framebuffer */
|
||||||
unsigned char * m_data;
|
unsigned char * m_data;
|
||||||
|
47
main/fart.cc
47
main/fart.cc
@ -30,6 +30,7 @@ int main(int argc, char * argv[])
|
|||||||
int opt;
|
int opt;
|
||||||
int option_index;
|
int option_index;
|
||||||
map<string, const char *> scene_options;
|
map<string, const char *> scene_options;
|
||||||
|
bool server = true;
|
||||||
|
|
||||||
static const struct option long_options[] = {
|
static const struct option long_options[] = {
|
||||||
{ "output-file", required_argument, NULL, 'o' },
|
{ "output-file", required_argument, NULL, 'o' },
|
||||||
@ -77,6 +78,7 @@ int main(int argc, char * argv[])
|
|||||||
break;
|
break;
|
||||||
case 257:
|
case 257:
|
||||||
scene_options["host"] = optarg;
|
scene_options["host"] = optarg;
|
||||||
|
server = false;
|
||||||
break;
|
break;
|
||||||
case 258:
|
case 258:
|
||||||
scene_options["port"] = optarg;
|
scene_options["port"] = optarg;
|
||||||
@ -104,29 +106,32 @@ int main(int argc, char * argv[])
|
|||||||
|
|
||||||
gettimeofday(&after, NULL); /* stop timing */
|
gettimeofday(&after, NULL); /* stop timing */
|
||||||
|
|
||||||
double time_before = before.tv_sec + before.tv_usec / 1000000.0;
|
if (server)
|
||||||
double time_after = after.tv_sec + after.tv_usec / 1000000.0;
|
|
||||||
double total_seconds = time_after - time_before;
|
|
||||||
cout << "Elapsed time: " << total_seconds << " seconds";
|
|
||||||
|
|
||||||
double seconds = total_seconds;
|
|
||||||
int days = (int) (seconds / (60.0 * 60.0 * 24.0));
|
|
||||||
seconds -= days * 60.0 * 60.0 * 24.0;
|
|
||||||
int hours = (int) (seconds / (60.0 * 60.0));
|
|
||||||
seconds -= hours * 60.0 * 60.0;
|
|
||||||
int minutes = (int) (seconds / 60.0);
|
|
||||||
seconds -= minutes * 60.0;
|
|
||||||
if (days || hours || minutes)
|
|
||||||
{
|
{
|
||||||
cout << " (";
|
double time_before = before.tv_sec + before.tv_usec / 1000000.0;
|
||||||
if (days)
|
double time_after = after.tv_sec + after.tv_usec / 1000000.0;
|
||||||
cout << days << " days, ";
|
double total_seconds = time_after - time_before;
|
||||||
if (days || hours)
|
cout << "Elapsed time: " << total_seconds << " seconds";
|
||||||
cout << hours << " hours, ";
|
|
||||||
cout << minutes << " minutes, ";
|
double seconds = total_seconds;
|
||||||
cout << seconds << " seconds)";
|
int days = (int) (seconds / (60.0 * 60.0 * 24.0));
|
||||||
|
seconds -= days * 60.0 * 60.0 * 24.0;
|
||||||
|
int hours = (int) (seconds / (60.0 * 60.0));
|
||||||
|
seconds -= hours * 60.0 * 60.0;
|
||||||
|
int minutes = (int) (seconds / 60.0);
|
||||||
|
seconds -= minutes * 60.0;
|
||||||
|
if (days || hours || minutes)
|
||||||
|
{
|
||||||
|
cout << " (";
|
||||||
|
if (days)
|
||||||
|
cout << days << " days, ";
|
||||||
|
if (days || hours)
|
||||||
|
cout << hours << " hours, ";
|
||||||
|
cout << minutes << " minutes, ";
|
||||||
|
cout << seconds << " seconds)";
|
||||||
|
}
|
||||||
|
cout << endl;
|
||||||
}
|
}
|
||||||
cout << endl;
|
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user