Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in
Toggle navigation
D
dlib
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
钟尚武
dlib
Commits
2d925f1e
Commit
2d925f1e
authored
Oct 21, 2012
by
Davis King
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Made BSP interfaces more explicit by using network_address rather
than std::pair to represent hostname/port combos.
parent
6eac0539
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
60 additions
and
65 deletions
+60
-65
bsp.cpp
dlib/bsp/bsp.cpp
+5
-5
bsp.h
dlib/bsp/bsp.h
+19
-24
bsp_abstract.h
dlib/bsp/bsp_abstract.h
+20
-20
bsp.cpp
dlib/test/bsp.cpp
+16
-16
No files found.
dlib/bsp/bsp.cpp
View file @
2d925f1e
...
...
@@ -15,7 +15,7 @@ namespace dlib
void
connect_all
(
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
)
{
...
...
@@ -41,7 +41,7 @@ namespace dlib
{
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
con
->
stream
.
flush
();
unsigned
long
id
=
hosts
[
i
].
node_id
;
...
...
@@ -50,7 +50,7 @@ namespace dlib
catch
(
std
::
exception
&
)
{
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
();
break
;
}
...
...
@@ -60,7 +60,7 @@ namespace dlib
void
send_out_connection_orders
(
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
...
...
@@ -74,7 +74,7 @@ namespace dlib
std
::
vector
<
hostinfo
>
targets
;
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
);
targets
.
push_back
(
info
);
...
...
dlib/bsp/bsp.h
View file @
2d925f1e
...
...
@@ -29,9 +29,9 @@ namespace dlib
struct
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
),
stream
(
&
buf
),
terminated
(
false
)
...
...
@@ -62,7 +62,7 @@ namespace dlib
void
connect_all
(
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
);
/*!
...
...
@@ -72,7 +72,7 @@ namespace dlib
void
send_out_connection_orders
(
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
{
hostinfo
()
{}
hostinfo
(
const
std
::
string
&
ip_
,
unsigned
short
port_
,
const
network_address
&
addr_
,
unsigned
long
node_id_
)
:
ip
(
ip_
),
port
(
port_
),
addr
(
addr_
),
node_id
(
node_id_
)
{
}
std
::
string
ip
;
unsigned
short
port
;
network_address
addr
;
unsigned
long
node_id
;
};
...
...
@@ -101,8 +98,7 @@ namespace dlib
std
::
ostream
&
out
)
{
dlib
::
serialize
(
item
.
ip
,
out
);
dlib
::
serialize
(
item
.
port
,
out
);
dlib
::
serialize
(
item
.
addr
,
out
);
dlib
::
serialize
(
item
.
node_id
,
out
);
}
...
...
@@ -111,8 +107,7 @@ namespace dlib
std
::
istream
&
in
)
{
dlib
::
deserialize
(
item
.
ip
,
in
);
dlib
::
deserialize
(
item
.
port
,
in
);
dlib
::
deserialize
(
item
.
addr
,
in
);
dlib
::
deserialize
(
item
.
node_id
,
in
);
}
...
...
@@ -531,7 +526,7 @@ namespace dlib
typename
funct_type
>
friend
void
bsp_connect
(
const
std
::
vector
<
std
::
pair
<
std
::
string
,
unsigned
short
>
>&
hosts
,
const
std
::
vector
<
network_address
>&
hosts
,
funct_type
funct
);
...
...
@@ -540,7 +535,7 @@ namespace dlib
typename
ARG1
>
friend
void
bsp_connect
(
const
std
::
vector
<
std
::
pair
<
std
::
string
,
unsigned
short
>
>&
hosts
,
const
std
::
vector
<
network_address
>&
hosts
,
funct_type
funct
,
ARG1
arg1
);
...
...
@@ -551,7 +546,7 @@ namespace dlib
typename
ARG2
>
friend
void
bsp_connect
(
const
std
::
vector
<
std
::
pair
<
std
::
string
,
unsigned
short
>
>&
hosts
,
const
std
::
vector
<
network_address
>&
hosts
,
funct_type
funct
,
ARG1
arg1
,
ARG2
arg2
...
...
@@ -564,7 +559,7 @@ namespace dlib
typename
ARG3
>
friend
void
bsp_connect
(
const
std
::
vector
<
std
::
pair
<
std
::
string
,
unsigned
short
>
>&
hosts
,
const
std
::
vector
<
network_address
>&
hosts
,
funct_type
funct
,
ARG1
arg1
,
ARG2
arg2
,
...
...
@@ -579,7 +574,7 @@ namespace dlib
typename
ARG4
>
friend
void
bsp_connect
(
const
std
::
vector
<
std
::
pair
<
std
::
string
,
unsigned
short
>
>&
hosts
,
const
std
::
vector
<
network_address
>&
hosts
,
funct_type
funct
,
ARG1
arg1
,
ARG2
arg2
,
...
...
@@ -671,7 +666,7 @@ namespace dlib
typename
funct_type
>
void
bsp_connect
(
const
std
::
vector
<
std
::
pair
<
std
::
string
,
unsigned
short
>
>&
hosts
,
const
std
::
vector
<
network_address
>&
hosts
,
funct_type
funct
)
{
...
...
@@ -691,7 +686,7 @@ namespace dlib
typename
ARG1
>
void
bsp_connect
(
const
std
::
vector
<
std
::
pair
<
std
::
string
,
unsigned
short
>
>&
hosts
,
const
std
::
vector
<
network_address
>&
hosts
,
funct_type
funct
,
ARG1
arg1
)
...
...
@@ -713,7 +708,7 @@ namespace dlib
typename
ARG2
>
void
bsp_connect
(
const
std
::
vector
<
std
::
pair
<
std
::
string
,
unsigned
short
>
>&
hosts
,
const
std
::
vector
<
network_address
>&
hosts
,
funct_type
funct
,
ARG1
arg1
,
ARG2
arg2
...
...
@@ -737,7 +732,7 @@ namespace dlib
typename
ARG3
>
void
bsp_connect
(
const
std
::
vector
<
std
::
pair
<
std
::
string
,
unsigned
short
>
>&
hosts
,
const
std
::
vector
<
network_address
>&
hosts
,
funct_type
funct
,
ARG1
arg1
,
ARG2
arg2
,
...
...
@@ -763,7 +758,7 @@ namespace dlib
typename
ARG4
>
void
bsp_connect
(
const
std
::
vector
<
std
::
pair
<
std
::
string
,
unsigned
short
>
>&
hosts
,
const
std
::
vector
<
network_address
>&
hosts
,
funct_type
funct
,
ARG1
arg1
,
ARG2
arg2
,
...
...
dlib/bsp/bsp_abstract.h
View file @
2d925f1e
...
...
@@ -251,7 +251,7 @@ namespace dlib
typename
funct_type
>
void
bsp_connect
(
const
std
::
vector
<
std
::
pair
<
std
::
string
,
unsigned
short
>
>&
hosts
,
const
std
::
vector
<
network_address
>&
hosts
,
funct_type
funct
);
/*!
...
...
@@ -265,9 +265,9 @@ namespace dlib
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.
- 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
addresses and port numbers identifying machines running the bsp_listen() or
bsp_listen_dynamic_port()
routines.
argument. In particular, this function interprets hosts as a list
addresses
identifying machines running the bsp_listen() or bsp_listen_dynamic_port()
routines.
- This call to bsp_connect() blocks until the BSP computation has completed on
all processing nodes.
throws
...
...
@@ -285,7 +285,7 @@ namespace dlib
typename
ARG1
>
void
bsp_connect
(
const
std
::
vector
<
std
::
pair
<
std
::
string
,
unsigned
short
>
>&
hosts
,
const
std
::
vector
<
network_address
>&
hosts
,
funct_type
funct
,
ARG1
arg1
);
...
...
@@ -300,9 +300,9 @@ namespace dlib
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.
- 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
addresses and port numbers identifying machines running the bsp_listen() or
bsp_listen_dynamic_port()
routines.
argument. In particular, this function interprets hosts as a list
addresses
identifying machines running the bsp_listen() or bsp_listen_dynamic_port()
routines.
- This call to bsp_connect() blocks until the BSP computation has completed on
all processing nodes.
throws
...
...
@@ -321,7 +321,7 @@ namespace dlib
typename
ARG2
>
void
bsp_connect
(
const
std
::
vector
<
std
::
pair
<
std
::
string
,
unsigned
short
>
>&
hosts
,
const
std
::
vector
<
network_address
>&
hosts
,
funct_type
funct
,
ARG1
arg1
,
ARG2
arg2
...
...
@@ -337,9 +337,9 @@ namespace dlib
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.
- 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
addresses and port numbers identifying machines running the bsp_listen() or
bsp_listen_dynamic_port()
routines.
argument. In particular, this function interprets hosts as a list
addresses
identifying machines running the bsp_listen() or bsp_listen_dynamic_port()
routines.
- This call to bsp_connect() blocks until the BSP computation has completed on
all processing nodes.
throws
...
...
@@ -359,7 +359,7 @@ namespace dlib
typename
ARG3
>
void
bsp_connect
(
const
std
::
vector
<
std
::
pair
<
std
::
string
,
unsigned
short
>
>&
hosts
,
const
std
::
vector
<
network_address
>&
hosts
,
funct_type
funct
,
ARG1
arg1
,
ARG2
arg2
,
...
...
@@ -376,9 +376,9 @@ namespace dlib
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.
- 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
addresses and port numbers identifying machines running the bsp_listen() or
bsp_listen_dynamic_port()
routines.
argument. In particular, this function interprets hosts as a list
addresses
identifying machines running the bsp_listen() or bsp_listen_dynamic_port()
routines.
- This call to bsp_connect() blocks until the BSP computation has completed on
all processing nodes.
throws
...
...
@@ -399,7 +399,7 @@ namespace dlib
typename
ARG4
>
void
bsp_connect
(
const
std
::
vector
<
std
::
pair
<
std
::
string
,
unsigned
short
>
>&
hosts
,
const
std
::
vector
<
network_address
>&
hosts
,
funct_type
funct
,
ARG1
arg1
,
ARG2
arg2
,
...
...
@@ -417,9 +417,9 @@ namespace dlib
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.
- 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
addresses and port numbers identifying machines running the bsp_listen() or
bsp_listen_dynamic_port()
routines.
argument. In particular, this function interprets hosts as a list
addresses
identifying machines running the bsp_listen() or bsp_listen_dynamic_port()
routines.
- This call to bsp_connect() blocks until the BSP computation has completed on
all processing nodes.
throws
...
...
dlib/test/bsp.cpp
View file @
2d925f1e
...
...
@@ -158,10 +158,10 @@ namespace
try
{
int
result
;
std
::
vector
<
std
::
pair
<
std
::
string
,
unsigned
short
>
>
hosts
;
hosts
.
push_back
(
make_pair
(
"127.0.0.1"
,
12345
));
hosts
.
push_back
(
make_pair
(
"127.0.0.1"
,
12346
));
hosts
.
push_back
(
make_pair
(
"127.0.0.1"
,
12347
));
std
::
vector
<
network_address
>
hosts
;
hosts
.
push_back
(
network_address
(
"127.0.0.1"
,
12345
));
hosts
.
push_back
(
network_address
(
"127.0.0.1"
,
12346
));
hosts
.
push_back
(
network_address
(
"127.0.0.1"
,
12347
));
bsp_connect
(
hosts
,
sum_array_driver
,
dlib
::
ref
(
v
),
dlib
::
ref
(
result
));
dlog
<<
LINFO
<<
"result: "
<<
result
;
...
...
@@ -202,10 +202,10 @@ namespace
try
{
std
::
vector
<
std
::
pair
<
std
::
string
,
unsigned
short
>
>
hosts
;
hosts
.
push_back
(
make_pair
(
"127.0.0.1"
,
12345
));
hosts
.
push_back
(
make_pair
(
"127.0.0.1"
,
12346
));
hosts
.
push_back
(
make_pair
(
"127.0.0.1"
,
12347
));
std
::
vector
<
network_address
>
hosts
;
hosts
.
push_back
(
network_address
(
"127.0.0.1"
,
12345
));
hosts
.
push_back
(
network_address
(
"127.0.0.1"
,
12346
));
hosts
.
push_back
(
network_address
(
"127.0.0.1"
,
12347
));
bsp_connect
(
hosts
,
test2_job
<
id
>
);
}
catch
(
std
::
exception
&
e
)
...
...
@@ -285,11 +285,11 @@ namespace
try
{
std
::
vector
<
std
::
pair
<
std
::
string
,
unsigned
short
>
>
hosts
;
std
::
vector
<
network_address
>
hosts
;
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
(
make_pair
(
"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
(
network_address
(
"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
;
const
int
expected
=
1
+
2
+
3
+
0
+
2
+
3
+
0
+
1
+
3
+
0
+
1
+
2
;
bsp_connect
(
hosts
,
test3_job_driver
,
dlib
::
ref
(
result
));
...
...
@@ -377,11 +377,11 @@ namespace
try
{
std
::
vector
<
std
::
pair
<
std
::
string
,
unsigned
short
>
>
hosts
;
std
::
vector
<
network_address
>
hosts
;
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
(
make_pair
(
"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
(
network_address
(
"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
;
const
int
expected
=
1
+
2
+
3
+
0
+
2
+
3
+
0
+
1
+
3
+
0
+
1
+
2
;
bsp_connect
(
hosts
,
test4_job_driver
,
dlib
::
ref
(
result
));
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment