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:
Josh Holtrop 2009-04-05 18:12:44 +00:00
parent 1dbe7040e4
commit 6fdaf01214
5 changed files with 83 additions and 37 deletions

View File

@ -22,6 +22,8 @@ int distrib::readHostFile(const char * filename)
while ( ! ifs.eof() )
{
ifs >> host;
if ( ifs.eof() )
break;
m_hosts.push_back(host);
}
@ -29,17 +31,18 @@ int distrib::readHostFile(const char * filename)
return 0;
}
int distrib::connect()
int distrib::connect(const std::vector<std::string> & client_options)
{
int err = 0;
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;
}
int distrib::connect(const string & host)
int distrib::connect(const string & host,
const std::vector<std::string> & client_options)
{
int id = fork();
if (id < 0) /* check for fork() error */
@ -55,10 +58,30 @@ int distrib::connect(const string & host)
{
char server_port_str[15];
sprintf(server_port_str, "%d", m_serverport);
execlp("ssh", "ssh", host.c_str(),
"fart", "--host", m_servername.c_str(),
"--port", server_port_str,
(char *) NULL);
vector<string> args;
args.push_back("ssh");
args.push_back(host);
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 */
cerr << "Error " << errno << " with execlp()!" << endl;
@ -68,10 +91,8 @@ int distrib::connect(const string & host)
return 0;
}
int distrib::startServer()
int distrib::startServer(const std::vector<std::string> & client_options)
{
connect();
char hostname[1000];
gethostname(&hostname[0], 1000);
m_servername = hostname;
@ -109,6 +130,8 @@ int distrib::startServer()
<< m_serverport
<< endl;
connect(client_options);
return 0;
}

View File

@ -9,12 +9,13 @@ class distrib
{
public:
int readHostFile(const char * filename);
int startServer();
int startServer(const std::vector<std::string> & client_options);
int startClient(const char * server, int port);
protected:
int connect();
int connect(const std::string & host);
int connect(const std::vector<std::string> & client_options);
int connect(const std::string & host,
const std::vector<std::string> & client_options);
std::vector<std::string> m_hosts;
std::vector<int> m_children;

View File

@ -41,52 +41,68 @@ Scene::Scene(const map<string, const char *> & options,
if (it->first == "width")
{
m_width = atoi(it->second);
m_client_options.push_back("--width");
m_client_options.push_back(it->second);
}
else if (it->first == "height")
{
m_height = atoi(it->second);
m_client_options.push_back("--height");
m_client_options.push_back(it->second);
}
else if (it->first == "multisample")
{
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")
{
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")
{
m_output_file_name = it->second;
/* no client option necessary */
}
else if (it->first == "max-depth")
{
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")
{
m_verbose = true;
/* no client option necessary */
}
else if (it->first == "host")
{
m_server_name = it->second;
m_server = false;
/* no client option necessary */
}
else if (it->first == "port")
{
m_server_port = atoi(it->second);
/* no client option necessary */
}
else if (it->first == "hosts")
{
m_hosts_file = it->second;
/* no client option necessary */
}
}
m_client_options.push_back(filename);
/* start the distribution infrastructure */
if (m_server)
{
if (m_hosts_file != "")
m_distrib.readHostFile(m_hosts_file.c_str());
m_distrib.startServer();
m_distrib.startServer(m_client_options);
}
else
{
@ -108,7 +124,7 @@ Scene::~Scene()
void Scene::render()
{
if (m_verbose)
if (m_verbose && m_server)
{
cout << " *** Beginning scene render ***" << 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 << "Writing output file '" << m_output_file_name << '\'' << endl;

View File

@ -95,6 +95,7 @@ class Scene
std::string m_hosts_file;
int m_server_port;
distrib m_distrib;
std::vector<std::string> m_client_options;
/* framebuffer */
unsigned char * m_data;

View File

@ -30,6 +30,7 @@ int main(int argc, char * argv[])
int opt;
int option_index;
map<string, const char *> scene_options;
bool server = true;
static const struct option long_options[] = {
{ "output-file", required_argument, NULL, 'o' },
@ -77,6 +78,7 @@ int main(int argc, char * argv[])
break;
case 257:
scene_options["host"] = optarg;
server = false;
break;
case 258:
scene_options["port"] = optarg;
@ -104,6 +106,8 @@ int main(int argc, char * argv[])
gettimeofday(&after, NULL); /* stop timing */
if (server)
{
double time_before = before.tv_sec + before.tv_usec / 1000000.0;
double time_after = after.tv_sec + after.tv_usec / 1000000.0;
double total_seconds = time_after - time_before;
@ -127,6 +131,7 @@ int main(int argc, char * argv[])
cout << seconds << " seconds)";
}
cout << endl;
}
return 0;
}