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
7f39ef4e
Commit
7f39ef4e
authored
Oct 07, 2012
by
Davis King
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Yet more code cleanup
parent
11f83eac
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
247 additions
and
77 deletions
+247
-77
bsp.cpp
dlib/bsp/bsp.cpp
+13
-13
bsp.h
dlib/bsp/bsp.h
+14
-64
bsp_abstract.h
dlib/bsp/bsp_abstract.h
+220
-0
No files found.
dlib/bsp/bsp.cpp
View file @
7f39ef4e
...
...
@@ -201,11 +201,11 @@ namespace dlib
// ----------------------------------------------------------------------------------------
// ----------------------------------------------------------------------------------------
// IMPLEMENTATION OF bsp OBJECT MEMBERS
// IMPLEMENTATION OF bsp
_context
OBJECT MEMBERS
// ----------------------------------------------------------------------------------------
// ----------------------------------------------------------------------------------------
void
bsp
::
void
bsp
_context
::
close_all_connections_gracefully
(
)
{
...
...
@@ -230,8 +230,8 @@ namespace dlib
// ----------------------------------------------------------------------------------------
bsp
::
~
bsp
()
bsp
_context
::
~
bsp
_context
()
{
_cons
.
reset
();
while
(
_cons
.
move_next
())
...
...
@@ -246,8 +246,8 @@ namespace dlib
// ----------------------------------------------------------------------------------------
bsp
::
bsp
(
bsp
_context
::
bsp
_context
(
unsigned
long
node_id_
,
impl
::
map_id_to_con
&
cons_
)
:
...
...
@@ -260,7 +260,7 @@ namespace dlib
{
// spawn a bunch of read threads, one for each connection
member_function_pointer
<
impl
::
bsp_con
*
,
unsigned
long
>::
kernel_1a_c
mfp
;
mfp
.
set
(
*
this
,
&
bsp
::
read_thread
);
mfp
.
set
(
*
this
,
&
bsp
_context
::
read_thread
);
_cons
.
reset
();
while
(
_cons
.
move_next
())
{
...
...
@@ -274,7 +274,7 @@ namespace dlib
// ----------------------------------------------------------------------------------------
bool
bsp
::
bool
bsp
_context
::
receive_data
(
shared_ptr
<
std
::
string
>&
item
,
unsigned
long
&
sending_node_id
...
...
@@ -322,7 +322,7 @@ namespace dlib
// ----------------------------------------------------------------------------------------
void
bsp
::
void
bsp
_context
::
send_to_master_node
(
char
msg
)
...
...
@@ -366,7 +366,7 @@ namespace dlib
// ----------------------------------------------------------------------------------------
void
bsp
::
void
bsp
_context
::
notify_everyone_if_all_blocked
(
)
{
...
...
@@ -413,7 +413,7 @@ namespace dlib
// ----------------------------------------------------------------------------------------
void
bsp
::
void
bsp
_context
::
read_thread
(
impl
::
bsp_con
*
con
,
unsigned
long
sender_id
...
...
@@ -502,7 +502,7 @@ namespace dlib
// ----------------------------------------------------------------------------------------
void
bsp
::
void
bsp
_context
::
check_for_errors
()
{
auto_mutex
lock
(
class_mutex
);
...
...
@@ -512,7 +512,7 @@ namespace dlib
// ----------------------------------------------------------------------------------------
void
bsp
::
void
bsp
_context
::
send_data
(
const
std
::
string
&
item
,
unsigned
long
target_node_id
...
...
dlib/bsp/bsp.h
View file @
7f39ef4e
...
...
@@ -12,6 +12,7 @@
#include "../serialize.h"
#include "../map.h"
#include <deque>
#include <vector>
namespace
dlib
{
...
...
@@ -74,7 +75,7 @@ namespace dlib
// ----------------------------------------------------------------------------------------
class
bsp
:
noncopyable
class
bsp
_context
:
noncopyable
{
public
:
...
...
@@ -84,14 +85,6 @@ namespace dlib
const
T
&
item
,
unsigned
long
target_node_id
)
/*!
requires
- item is serializable
- target_node_id < number_of_nodes()
- target_node_id != node_id()
ensures
- sends a copy of item to the node with the given id.
!*/
{
std
::
ostringstream
sout
;
serialize
(
item
,
sout
);
...
...
@@ -102,10 +95,6 @@ namespace dlib
void
broadcast
(
const
T
&
item
)
/*!
ensures
- sends a copy of item to all other processing nodes.
!*/
{
std
::
ostringstream
sout
;
serialize
(
item
,
sout
);
...
...
@@ -121,50 +110,22 @@ namespace dlib
unsigned
long
node_id
(
)
const
{
return
_node_id
;
}
/*!
ensures
- Returns the id of the current processing node. That is,
returns a number N such that:
- N < number_of_nodes()
- N == the node id of the processing node that called
node_id().
!*/
unsigned
long
number_of_nodes
(
)
const
{
return
_cons
.
size
()
+
1
;
}
/*!
ensures
- returns the number of processing nodes participating in the
BSP computation.
!*/
void
receive
(
)
/*!
ensures
- simply waits for all other nodes to become blocked
on calls to receive() or to terminate (i.e. waits for
other nodes to be in a state that can't send messages).
!*/
{
int
junk
;
if
(
receive
(
junk
))
throw
dlib
::
socket_error
(
"
call to receive got an unexpected message
"
);
throw
dlib
::
socket_error
(
"
Call to bsp_context::receive() got an unexpected message.
"
);
}
template
<
typename
T
>
bool
receive
(
T
&
item
)
/*!
ensures
- if (this function returns true) then
- #item == the next message which was sent to the calling processing
node.
- else
- There were no other messages to receive and all other processing
nodes are blocked on calls to receive().
!*/
{
unsigned
long
sending_node_id
;
return
receive
(
item
,
sending_node_id
);
...
...
@@ -175,17 +136,6 @@ namespace dlib
T
&
item
,
unsigned
long
&
sending_node_id
)
/*!
ensures
- if (this function returns true) then
- #item == the next message which was sent to the calling processing
node.
- #sending_node_id == the node id of the node that sent this message.
- #sending_node_id < number_of_nodes()
- else
- There were no other messages to receive and all other processing
nodes are blocked on calls to receive().
!*/
{
shared_ptr
<
std
::
string
>
temp
;
if
(
receive_data
(
temp
,
sending_node_id
))
...
...
@@ -200,13 +150,13 @@ namespace dlib
}
}
~
bsp
();
~
bsp
_context
();
private
:
bsp
();
bsp
_context
();
bsp
(
bsp
_context
(
unsigned
long
node_id_
,
impl
::
map_id_to_con
&
cons_
);
...
...
@@ -385,7 +335,7 @@ namespace dlib
const
unsigned
long
node_id
=
0
;
connect_all
(
cons
,
hosts
,
node_id
);
send_out_connection_orders
(
cons
,
hosts
);
bsp
obj
(
node_id
,
cons
);
bsp
_context
obj
(
node_id
,
cons
);
funct
(
obj
);
obj
.
close_all_connections_gracefully
();
}
...
...
@@ -406,7 +356,7 @@ namespace dlib
const
unsigned
long
node_id
=
0
;
connect_all
(
cons
,
hosts
,
node_id
);
send_out_connection_orders
(
cons
,
hosts
);
bsp
obj
(
node_id
,
cons
);
bsp
_context
obj
(
node_id
,
cons
);
funct
(
obj
,
arg1
);
obj
.
close_all_connections_gracefully
();
}
...
...
@@ -429,7 +379,7 @@ namespace dlib
const
unsigned
long
node_id
=
0
;
connect_all
(
cons
,
hosts
,
node_id
);
send_out_connection_orders
(
cons
,
hosts
);
bsp
obj
(
node_id
,
cons
);
bsp
_context
obj
(
node_id
,
cons
);
funct
(
obj
,
arg1
,
arg2
);
obj
.
close_all_connections_gracefully
();
}
...
...
@@ -454,7 +404,7 @@ namespace dlib
const
unsigned
long
node_id
=
0
;
connect_all
(
cons
,
hosts
,
node_id
);
send_out_connection_orders
(
cons
,
hosts
);
bsp
obj
(
node_id
,
cons
);
bsp
_context
obj
(
node_id
,
cons
);
funct
(
obj
,
arg1
,
arg2
,
arg3
);
obj
.
close_all_connections_gracefully
();
}
...
...
@@ -474,7 +424,7 @@ namespace dlib
impl
::
map_id_to_con
cons
;
unsigned
long
node_id
;
listen_and_connect_all
(
node_id
,
cons
,
listening_port
);
bsp
obj
(
node_id
,
cons
);
bsp
_context
obj
(
node_id
,
cons
);
funct
(
obj
);
obj
.
close_all_connections_gracefully
();
}
...
...
@@ -494,7 +444,7 @@ namespace dlib
impl
::
map_id_to_con
cons
;
unsigned
long
node_id
;
listen_and_connect_all
(
node_id
,
cons
,
listening_port
);
bsp
obj
(
node_id
,
cons
);
bsp
_context
obj
(
node_id
,
cons
);
funct
(
obj
,
arg1
);
obj
.
close_all_connections_gracefully
();
}
...
...
@@ -516,7 +466,7 @@ namespace dlib
impl
::
map_id_to_con
cons
;
unsigned
long
node_id
;
listen_and_connect_all
(
node_id
,
cons
,
listening_port
);
bsp
obj
(
node_id
,
cons
);
bsp
_context
obj
(
node_id
,
cons
);
funct
(
obj
,
arg1
,
arg2
);
obj
.
close_all_connections_gracefully
();
}
...
...
@@ -540,7 +490,7 @@ namespace dlib
impl
::
map_id_to_con
cons
;
unsigned
long
node_id
;
listen_and_connect_all
(
node_id
,
cons
,
listening_port
);
bsp
obj
(
node_id
,
cons
);
bsp
_context
obj
(
node_id
,
cons
);
funct
(
obj
,
arg1
,
arg2
,
arg3
);
obj
.
close_all_connections_gracefully
();
}
...
...
dlib/bsp/bsp_abstract.h
View file @
7f39ef4e
// Copyright (C) 2012 Davis E. King (davis@dlib.net)
// License: Boost Software License See LICENSE.txt for the full license.
#undef DLIB_BsP_ABSTRACT_H__
#ifdef DLIB_BsP_ABSTRACT_H__
#include "../noncopyable.h"
#include <vector>
namespace
dlib
{
// ----------------------------------------------------------------------------------------
class
bsp_context
:
noncopyable
{
/*!
WHAT THIS OBJECT REPRESENTS
!*/
public
:
template
<
typename
T
>
void
send
(
const
T
&
item
,
unsigned
long
target_node_id
);
/*!
requires
- item is serializable
- target_node_id < number_of_nodes()
- target_node_id != node_id()
ensures
- sends a copy of item to the node with the given id.
!*/
template
<
typename
T
>
void
broadcast
(
const
T
&
item
);
/*!
ensures
- sends a copy of item to all other processing nodes.
!*/
unsigned
long
node_id
(
)
const
;
/*!
ensures
- Returns the id of the current processing node. That is,
returns a number N such that:
- N < number_of_nodes()
- N == the node id of the processing node that called
node_id().
!*/
unsigned
long
number_of_nodes
(
)
const
;
/*!
ensures
- returns the number of processing nodes participating in the
BSP computation.
!*/
template
<
typename
T
>
bool
receive
(
T
&
item
);
/*!
ensures
- if (this function returns true) then
- #item == the next message which was sent to the calling processing
node.
- else
- There were no other messages to receive and all other processing
nodes are blocked on calls to receive().
!*/
template
<
typename
T
>
bool
receive
(
T
&
item
,
unsigned
long
&
sending_node_id
);
/*!
ensures
- if (this function returns true) then
- #item == the next message which was sent to the calling processing
node.
- #sending_node_id == the node id of the node that sent this message.
- #sending_node_id < number_of_nodes()
- else
- There were no other messages to receive and all other processing
nodes are blocked on calls to receive().
!*/
void
receive
(
);
/*!
ensures
- simply waits for all other nodes to become blocked
on calls to receive() or to terminate (i.e. waits for
other nodes to be in a state that can't send messages).
throws
- socket_error:
This exception is thrown if a message is received before this function
would otherwise return.
!*/
};
// ----------------------------------------------------------------------------------------
// ----------------------------------------------------------------------------------------
template
<
typename
funct_type
>
void
bsp_connect
(
const
std
::
vector
<
std
::
pair
<
std
::
string
,
unsigned
short
>
>&
hosts
,
funct_type
&
funct
);
// ----------------------------------------------------------------------------------------
template
<
typename
funct_type
,
typename
ARG1
>
void
bsp_connect
(
const
std
::
vector
<
std
::
pair
<
std
::
string
,
unsigned
short
>
>&
hosts
,
funct_type
&
funct
,
ARG1
arg1
);
// ----------------------------------------------------------------------------------------
template
<
typename
funct_type
,
typename
ARG1
,
typename
ARG2
>
void
bsp_connect
(
const
std
::
vector
<
std
::
pair
<
std
::
string
,
unsigned
short
>
>&
hosts
,
funct_type
&
funct
,
ARG1
arg1
,
ARG2
arg2
);
// ----------------------------------------------------------------------------------------
template
<
typename
funct_type
,
typename
ARG1
,
typename
ARG2
,
typename
ARG3
>
void
bsp_connect
(
const
std
::
vector
<
std
::
pair
<
std
::
string
,
unsigned
short
>
>&
hosts
,
funct_type
&
funct
,
ARG1
arg1
,
ARG2
arg2
,
ARG3
arg3
);
// ----------------------------------------------------------------------------------------
// ----------------------------------------------------------------------------------------
template
<
typename
funct_type
>
void
bsp_listen
(
unsigned
short
listening_port
,
funct_type
&
funct
);
// ----------------------------------------------------------------------------------------
template
<
typename
funct_type
,
typename
ARG1
>
void
bsp_listen
(
unsigned
short
listening_port
,
funct_type
&
funct
,
ARG1
arg1
);
// ----------------------------------------------------------------------------------------
template
<
typename
funct_type
,
typename
ARG1
,
typename
ARG2
>
void
bsp_listen
(
unsigned
short
listening_port
,
funct_type
&
funct
,
ARG1
arg1
,
ARG2
arg2
);
// ----------------------------------------------------------------------------------------
template
<
typename
funct_type
,
typename
ARG1
,
typename
ARG2
,
typename
ARG3
>
void
bsp_listen
(
unsigned
short
listening_port
,
funct_type
&
funct
,
ARG1
arg1
,
ARG2
arg2
,
ARG3
arg3
);
// ----------------------------------------------------------------------------------------
// ----------------------------------------------------------------------------------------
}
#endif // DLIB_BsP_ABSTRACT_H__
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