Commit 2d925f1e authored by Davis King's avatar Davis King

Made BSP interfaces more explicit by using network_address rather

than std::pair to represent hostname/port combos.
parent 6eac0539
...@@ -15,7 +15,7 @@ namespace dlib ...@@ -15,7 +15,7 @@ namespace dlib
void connect_all ( void connect_all (
map_id_to_con& cons, map_id_to_con& cons,
const std::vector<std::pair<std::string,unsigned short> >& hosts, const std::vector<network_address>& hosts,
unsigned long node_id unsigned long node_id
) )
{ {
...@@ -41,7 +41,7 @@ namespace dlib ...@@ -41,7 +41,7 @@ namespace dlib
{ {
try try
{ {
scoped_ptr<bsp_con> con(new bsp_con(make_pair(hosts[i].ip,hosts[i].port))); scoped_ptr<bsp_con> con(new bsp_con(hosts[i].addr));
dlib::serialize(node_id, con->stream); // tell the other end our node_id dlib::serialize(node_id, con->stream); // tell the other end our node_id
con->stream.flush(); con->stream.flush();
unsigned long id = hosts[i].node_id; unsigned long id = hosts[i].node_id;
...@@ -50,7 +50,7 @@ namespace dlib ...@@ -50,7 +50,7 @@ namespace dlib
catch (std::exception&) catch (std::exception&)
{ {
std::ostringstream sout; std::ostringstream sout;
sout << "Could not connect to " << hosts[i].ip << ":" << hosts[i].port; sout << "Could not connect to " << hosts[i].addr;
error_string = sout.str(); error_string = sout.str();
break; break;
} }
...@@ -60,7 +60,7 @@ namespace dlib ...@@ -60,7 +60,7 @@ namespace dlib
void send_out_connection_orders ( void send_out_connection_orders (
map_id_to_con& cons, map_id_to_con& cons,
const std::vector<std::pair<std::string,unsigned short> >& hosts const std::vector<network_address>& hosts
) )
{ {
// tell everyone their node ids // tell everyone their node ids
...@@ -74,7 +74,7 @@ namespace dlib ...@@ -74,7 +74,7 @@ namespace dlib
std::vector<hostinfo> targets; std::vector<hostinfo> targets;
for (unsigned long i = 0; i < hosts.size(); ++i) for (unsigned long i = 0; i < hosts.size(); ++i)
{ {
hostinfo info(hosts[i].first, hosts[i].second, i+1); hostinfo info(hosts[i], i+1);
dlib::serialize(targets, cons[info.node_id]->stream); dlib::serialize(targets, cons[info.node_id]->stream);
targets.push_back(info); targets.push_back(info);
......
...@@ -29,9 +29,9 @@ namespace dlib ...@@ -29,9 +29,9 @@ namespace dlib
struct bsp_con struct bsp_con
{ {
bsp_con( bsp_con(
const std::pair<std::string,unsigned short>& dest const network_address& dest
) : ) :
con(connect(dest.first,dest.second)), con(connect(dest)),
buf(con), buf(con),
stream(&buf), stream(&buf),
terminated(false) terminated(false)
...@@ -62,7 +62,7 @@ namespace dlib ...@@ -62,7 +62,7 @@ namespace dlib
void connect_all ( void connect_all (
map_id_to_con& cons, map_id_to_con& cons,
const std::vector<std::pair<std::string,unsigned short> >& hosts, const std::vector<network_address>& hosts,
unsigned long node_id unsigned long node_id
); );
/*! /*!
...@@ -72,7 +72,7 @@ namespace dlib ...@@ -72,7 +72,7 @@ namespace dlib
void send_out_connection_orders ( void send_out_connection_orders (
map_id_to_con& cons, map_id_to_con& cons,
const std::vector<std::pair<std::string,unsigned short> >& hosts const std::vector<network_address>& hosts
); );
// ------------------------------------------------------------------------------------ // ------------------------------------------------------------------------------------
...@@ -81,18 +81,15 @@ namespace dlib ...@@ -81,18 +81,15 @@ namespace dlib
{ {
hostinfo() {} hostinfo() {}
hostinfo ( hostinfo (
const std::string& ip_, const network_address& addr_,
unsigned short port_,
unsigned long node_id_ unsigned long node_id_
) : ) :
ip(ip_), addr(addr_),
port(port_),
node_id(node_id_) node_id(node_id_)
{ {
} }
std::string ip; network_address addr;
unsigned short port;
unsigned long node_id; unsigned long node_id;
}; };
...@@ -101,8 +98,7 @@ namespace dlib ...@@ -101,8 +98,7 @@ namespace dlib
std::ostream& out std::ostream& out
) )
{ {
dlib::serialize(item.ip, out); dlib::serialize(item.addr, out);
dlib::serialize(item.port, out);
dlib::serialize(item.node_id, out); dlib::serialize(item.node_id, out);
} }
...@@ -111,8 +107,7 @@ namespace dlib ...@@ -111,8 +107,7 @@ namespace dlib
std::istream& in std::istream& in
) )
{ {
dlib::deserialize(item.ip, in); dlib::deserialize(item.addr, in);
dlib::deserialize(item.port, in);
dlib::deserialize(item.node_id, in); dlib::deserialize(item.node_id, in);
} }
...@@ -531,7 +526,7 @@ namespace dlib ...@@ -531,7 +526,7 @@ namespace dlib
typename funct_type typename funct_type
> >
friend void bsp_connect ( friend void bsp_connect (
const std::vector<std::pair<std::string,unsigned short> >& hosts, const std::vector<network_address>& hosts,
funct_type funct funct_type funct
); );
...@@ -540,7 +535,7 @@ namespace dlib ...@@ -540,7 +535,7 @@ namespace dlib
typename ARG1 typename ARG1
> >
friend void bsp_connect ( friend void bsp_connect (
const std::vector<std::pair<std::string,unsigned short> >& hosts, const std::vector<network_address>& hosts,
funct_type funct, funct_type funct,
ARG1 arg1 ARG1 arg1
); );
...@@ -551,7 +546,7 @@ namespace dlib ...@@ -551,7 +546,7 @@ namespace dlib
typename ARG2 typename ARG2
> >
friend void bsp_connect ( friend void bsp_connect (
const std::vector<std::pair<std::string,unsigned short> >& hosts, const std::vector<network_address>& hosts,
funct_type funct, funct_type funct,
ARG1 arg1, ARG1 arg1,
ARG2 arg2 ARG2 arg2
...@@ -564,7 +559,7 @@ namespace dlib ...@@ -564,7 +559,7 @@ namespace dlib
typename ARG3 typename ARG3
> >
friend void bsp_connect ( friend void bsp_connect (
const std::vector<std::pair<std::string,unsigned short> >& hosts, const std::vector<network_address>& hosts,
funct_type funct, funct_type funct,
ARG1 arg1, ARG1 arg1,
ARG2 arg2, ARG2 arg2,
...@@ -579,7 +574,7 @@ namespace dlib ...@@ -579,7 +574,7 @@ namespace dlib
typename ARG4 typename ARG4
> >
friend void bsp_connect ( friend void bsp_connect (
const std::vector<std::pair<std::string,unsigned short> >& hosts, const std::vector<network_address>& hosts,
funct_type funct, funct_type funct,
ARG1 arg1, ARG1 arg1,
ARG2 arg2, ARG2 arg2,
...@@ -671,7 +666,7 @@ namespace dlib ...@@ -671,7 +666,7 @@ namespace dlib
typename funct_type typename funct_type
> >
void bsp_connect ( void bsp_connect (
const std::vector<std::pair<std::string,unsigned short> >& hosts, const std::vector<network_address>& hosts,
funct_type funct funct_type funct
) )
{ {
...@@ -691,7 +686,7 @@ namespace dlib ...@@ -691,7 +686,7 @@ namespace dlib
typename ARG1 typename ARG1
> >
void bsp_connect ( void bsp_connect (
const std::vector<std::pair<std::string,unsigned short> >& hosts, const std::vector<network_address>& hosts,
funct_type funct, funct_type funct,
ARG1 arg1 ARG1 arg1
) )
...@@ -713,7 +708,7 @@ namespace dlib ...@@ -713,7 +708,7 @@ namespace dlib
typename ARG2 typename ARG2
> >
void bsp_connect ( void bsp_connect (
const std::vector<std::pair<std::string,unsigned short> >& hosts, const std::vector<network_address>& hosts,
funct_type funct, funct_type funct,
ARG1 arg1, ARG1 arg1,
ARG2 arg2 ARG2 arg2
...@@ -737,7 +732,7 @@ namespace dlib ...@@ -737,7 +732,7 @@ namespace dlib
typename ARG3 typename ARG3
> >
void bsp_connect ( void bsp_connect (
const std::vector<std::pair<std::string,unsigned short> >& hosts, const std::vector<network_address>& hosts,
funct_type funct, funct_type funct,
ARG1 arg1, ARG1 arg1,
ARG2 arg2, ARG2 arg2,
...@@ -763,7 +758,7 @@ namespace dlib ...@@ -763,7 +758,7 @@ namespace dlib
typename ARG4 typename ARG4
> >
void bsp_connect ( void bsp_connect (
const std::vector<std::pair<std::string,unsigned short> >& hosts, const std::vector<network_address>& hosts,
funct_type funct, funct_type funct,
ARG1 arg1, ARG1 arg1,
ARG2 arg2, ARG2 arg2,
......
...@@ -251,7 +251,7 @@ namespace dlib ...@@ -251,7 +251,7 @@ namespace dlib
typename funct_type typename funct_type
> >
void bsp_connect ( void bsp_connect (
const std::vector<std::pair<std::string,unsigned short> >& hosts, const std::vector<network_address>& hosts,
funct_type funct funct_type funct
); );
/*! /*!
...@@ -265,9 +265,9 @@ namespace dlib ...@@ -265,9 +265,9 @@ namespace dlib
calling bsp_connect(). In particular, this node will execute funct(CONTEXT), calling bsp_connect(). In particular, this node will execute funct(CONTEXT),
which is expected to carry out this node's portion of the BSP computation. which is expected to carry out this node's portion of the BSP computation.
- The other processing nodes are executed on the hosts indicated by the input - The other processing nodes are executed on the hosts indicated by the input
argument. In particular, this function interprets hosts as a list of IP argument. In particular, this function interprets hosts as a list addresses
addresses and port numbers identifying machines running the bsp_listen() or identifying machines running the bsp_listen() or bsp_listen_dynamic_port()
bsp_listen_dynamic_port() routines. routines.
- This call to bsp_connect() blocks until the BSP computation has completed on - This call to bsp_connect() blocks until the BSP computation has completed on
all processing nodes. all processing nodes.
throws throws
...@@ -285,7 +285,7 @@ namespace dlib ...@@ -285,7 +285,7 @@ namespace dlib
typename ARG1 typename ARG1
> >
void bsp_connect ( void bsp_connect (
const std::vector<std::pair<std::string,unsigned short> >& hosts, const std::vector<network_address>& hosts,
funct_type funct, funct_type funct,
ARG1 arg1 ARG1 arg1
); );
...@@ -300,9 +300,9 @@ namespace dlib ...@@ -300,9 +300,9 @@ namespace dlib
calling bsp_connect(). In particular, this node will execute funct(CONTEXT,arg1), calling bsp_connect(). In particular, this node will execute funct(CONTEXT,arg1),
which is expected to carry out this node's portion of the BSP computation. which is expected to carry out this node's portion of the BSP computation.
- The other processing nodes are executed on the hosts indicated by the input - The other processing nodes are executed on the hosts indicated by the input
argument. In particular, this function interprets hosts as a list of IP argument. In particular, this function interprets hosts as a list addresses
addresses and port numbers identifying machines running the bsp_listen() or identifying machines running the bsp_listen() or bsp_listen_dynamic_port()
bsp_listen_dynamic_port() routines. routines.
- This call to bsp_connect() blocks until the BSP computation has completed on - This call to bsp_connect() blocks until the BSP computation has completed on
all processing nodes. all processing nodes.
throws throws
...@@ -321,7 +321,7 @@ namespace dlib ...@@ -321,7 +321,7 @@ namespace dlib
typename ARG2 typename ARG2
> >
void bsp_connect ( void bsp_connect (
const std::vector<std::pair<std::string,unsigned short> >& hosts, const std::vector<network_address>& hosts,
funct_type funct, funct_type funct,
ARG1 arg1, ARG1 arg1,
ARG2 arg2 ARG2 arg2
...@@ -337,9 +337,9 @@ namespace dlib ...@@ -337,9 +337,9 @@ namespace dlib
calling bsp_connect(). In particular, this node will execute funct(CONTEXT,arg1,arg2), calling bsp_connect(). In particular, this node will execute funct(CONTEXT,arg1,arg2),
which is expected to carry out this node's portion of the BSP computation. which is expected to carry out this node's portion of the BSP computation.
- The other processing nodes are executed on the hosts indicated by the input - The other processing nodes are executed on the hosts indicated by the input
argument. In particular, this function interprets hosts as a list of IP argument. In particular, this function interprets hosts as a list addresses
addresses and port numbers identifying machines running the bsp_listen() or identifying machines running the bsp_listen() or bsp_listen_dynamic_port()
bsp_listen_dynamic_port() routines. routines.
- This call to bsp_connect() blocks until the BSP computation has completed on - This call to bsp_connect() blocks until the BSP computation has completed on
all processing nodes. all processing nodes.
throws throws
...@@ -359,7 +359,7 @@ namespace dlib ...@@ -359,7 +359,7 @@ namespace dlib
typename ARG3 typename ARG3
> >
void bsp_connect ( void bsp_connect (
const std::vector<std::pair<std::string,unsigned short> >& hosts, const std::vector<network_address>& hosts,
funct_type funct, funct_type funct,
ARG1 arg1, ARG1 arg1,
ARG2 arg2, ARG2 arg2,
...@@ -376,9 +376,9 @@ namespace dlib ...@@ -376,9 +376,9 @@ namespace dlib
calling bsp_connect(). In particular, this node will execute funct(CONTEXT,arg1,arg2,arg3), calling bsp_connect(). In particular, this node will execute funct(CONTEXT,arg1,arg2,arg3),
which is expected to carry out this node's portion of the BSP computation. which is expected to carry out this node's portion of the BSP computation.
- The other processing nodes are executed on the hosts indicated by the input - The other processing nodes are executed on the hosts indicated by the input
argument. In particular, this function interprets hosts as a list of IP argument. In particular, this function interprets hosts as a list addresses
addresses and port numbers identifying machines running the bsp_listen() or identifying machines running the bsp_listen() or bsp_listen_dynamic_port()
bsp_listen_dynamic_port() routines. routines.
- This call to bsp_connect() blocks until the BSP computation has completed on - This call to bsp_connect() blocks until the BSP computation has completed on
all processing nodes. all processing nodes.
throws throws
...@@ -399,7 +399,7 @@ namespace dlib ...@@ -399,7 +399,7 @@ namespace dlib
typename ARG4 typename ARG4
> >
void bsp_connect ( void bsp_connect (
const std::vector<std::pair<std::string,unsigned short> >& hosts, const std::vector<network_address>& hosts,
funct_type funct, funct_type funct,
ARG1 arg1, ARG1 arg1,
ARG2 arg2, ARG2 arg2,
...@@ -417,9 +417,9 @@ namespace dlib ...@@ -417,9 +417,9 @@ namespace dlib
calling bsp_connect(). In particular, this node will execute funct(CONTEXT,arg1,arg2,arg3,arg4), calling bsp_connect(). In particular, this node will execute funct(CONTEXT,arg1,arg2,arg3,arg4),
which is expected to carry out this node's portion of the BSP computation. which is expected to carry out this node's portion of the BSP computation.
- The other processing nodes are executed on the hosts indicated by the input - The other processing nodes are executed on the hosts indicated by the input
argument. In particular, this function interprets hosts as a list of IP argument. In particular, this function interprets hosts as a list addresses
addresses and port numbers identifying machines running the bsp_listen() or identifying machines running the bsp_listen() or bsp_listen_dynamic_port()
bsp_listen_dynamic_port() routines. routines.
- This call to bsp_connect() blocks until the BSP computation has completed on - This call to bsp_connect() blocks until the BSP computation has completed on
all processing nodes. all processing nodes.
throws throws
......
...@@ -158,10 +158,10 @@ namespace ...@@ -158,10 +158,10 @@ namespace
try try
{ {
int result; int result;
std::vector<std::pair<std::string,unsigned short> > hosts; std::vector<network_address> hosts;
hosts.push_back(make_pair("127.0.0.1",12345)); hosts.push_back(network_address("127.0.0.1",12345));
hosts.push_back(make_pair("127.0.0.1",12346)); hosts.push_back(network_address("127.0.0.1",12346));
hosts.push_back(make_pair("127.0.0.1",12347)); hosts.push_back(network_address("127.0.0.1",12347));
bsp_connect(hosts, sum_array_driver, dlib::ref(v), dlib::ref(result)); bsp_connect(hosts, sum_array_driver, dlib::ref(v), dlib::ref(result));
dlog << LINFO << "result: "<< result; dlog << LINFO << "result: "<< result;
...@@ -202,10 +202,10 @@ namespace ...@@ -202,10 +202,10 @@ namespace
try try
{ {
std::vector<std::pair<std::string,unsigned short> > hosts; std::vector<network_address> hosts;
hosts.push_back(make_pair("127.0.0.1",12345)); hosts.push_back(network_address("127.0.0.1",12345));
hosts.push_back(make_pair("127.0.0.1",12346)); hosts.push_back(network_address("127.0.0.1",12346));
hosts.push_back(make_pair("127.0.0.1",12347)); hosts.push_back(network_address("127.0.0.1",12347));
bsp_connect(hosts, test2_job<id>); bsp_connect(hosts, test2_job<id>);
} }
catch (std::exception& e) catch (std::exception& e)
...@@ -285,11 +285,11 @@ namespace ...@@ -285,11 +285,11 @@ namespace
try try
{ {
std::vector<std::pair<std::string,unsigned short> > hosts; std::vector<network_address> hosts;
unsigned short port; unsigned short port;
ports.dequeue(port); hosts.push_back(make_pair("127.0.0.1",port)); dlog << LINFO << "PORT: " << port; ports.dequeue(port); hosts.push_back(network_address("127.0.0.1",port)); dlog << LINFO << "PORT: " << port;
ports.dequeue(port); hosts.push_back(make_pair("127.0.0.1",port)); dlog << LINFO << "PORT: " << port; ports.dequeue(port); hosts.push_back(network_address("127.0.0.1",port)); dlog << LINFO << "PORT: " << port;
ports.dequeue(port); hosts.push_back(make_pair("127.0.0.1",port)); dlog << LINFO << "PORT: " << port; ports.dequeue(port); hosts.push_back(network_address("127.0.0.1",port)); dlog << LINFO << "PORT: " << port;
int result = 0; int result = 0;
const int expected = 1+2+3 + 0+2+3 + 0+1+3 + 0+1+2; const int expected = 1+2+3 + 0+2+3 + 0+1+3 + 0+1+2;
bsp_connect(hosts, test3_job_driver, dlib::ref(result)); bsp_connect(hosts, test3_job_driver, dlib::ref(result));
...@@ -377,11 +377,11 @@ namespace ...@@ -377,11 +377,11 @@ namespace
try try
{ {
std::vector<std::pair<std::string,unsigned short> > hosts; std::vector<network_address> hosts;
unsigned short port; unsigned short port;
ports.dequeue(port); hosts.push_back(make_pair("127.0.0.1",port)); dlog << LINFO << "PORT: " << port; ports.dequeue(port); hosts.push_back(network_address("127.0.0.1",port)); dlog << LINFO << "PORT: " << port;
ports.dequeue(port); hosts.push_back(make_pair("127.0.0.1",port)); dlog << LINFO << "PORT: " << port; ports.dequeue(port); hosts.push_back(network_address("127.0.0.1",port)); dlog << LINFO << "PORT: " << port;
ports.dequeue(port); hosts.push_back(make_pair("127.0.0.1",port)); dlog << LINFO << "PORT: " << port; ports.dequeue(port); hosts.push_back(network_address("127.0.0.1",port)); dlog << LINFO << "PORT: " << port;
int result = 0; int result = 0;
const int expected = 1+2+3 + 0+2+3 + 0+1+3 + 0+1+2; const int expected = 1+2+3 + 0+2+3 + 0+1+3 + 0+1+2;
bsp_connect(hosts, test4_job_driver, dlib::ref(result)); bsp_connect(hosts, test4_job_driver, dlib::ref(result));
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment