Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
G
group-connectivity-pub
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Deploy
Releases
Model registry
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
GitLab community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Radek Hušek
group-connectivity-pub
Commits
b2fd8ff3
Commit
b2fd8ff3
authored
9 years ago
by
Radek Hušek
Committed by
Radek Hušek
7 years ago
Browse files
Options
Downloads
Patches
Plain Diff
Parallelize generateSubdivisions()
parent
aa5ccf59
No related branches found
No related tags found
No related merge requests found
Changes
4
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
.gitignore
+2
-0
2 additions, 0 deletions
.gitignore
Makefile
+1
-1
1 addition, 1 deletion
Makefile
groupConnectivity.pyx
+13
-3
13 additions, 3 deletions
groupConnectivity.pyx
parmap.py
+36
-0
36 additions, 0 deletions
parmap.py
with
52 additions
and
4 deletions
.gitignore
+
2
−
0
View file @
b2fd8ff3
.*.swp
groupConnectivity.so
parmap.pyc
This diff is collapsed.
Click to expand it.
Makefile
+
1
−
1
View file @
b2fd8ff3
default
:
groupConnectivity.so clean_obj
groupConnectivity.so
:
groupConnectivity.pyx group-connectivity.h setup.py compileTimeOptions.h
groupConnectivity.so
:
groupConnectivity.pyx group-connectivity.h setup.py compileTimeOptions.h
parmap.py
python setup.py build_ext
cp
build/lib
*
/groupConnectivity.so .
...
...
This diff is collapsed.
Click to expand it.
groupConnectivity.pyx
+
13
−
3
View file @
b2fd8ff3
...
...
@@ -2,6 +2,7 @@ from libcpp.vector cimport vector
from
libcpp
cimport
bool
from
libcpp.utility
cimport
pair
from
sage.graphs.graph
import
Graph
from
parmap
import
parmap
cdef
extern
from
"
group-connectivity.h
"
namespace
"
Ring
"
:
cdef
cppclass
Z4
[
T
]:
...
...
@@ -87,12 +88,21 @@ def subdivisionIterator(G, edges = None):
for
L
in
subdivisionIterator
(
H
,
edges
[
1
:]):
yield
L
def
generateSubdivisions
(
file
,
G
,
edges
=
None
,
function
=
lambda
H
:
H
.
graph6_string
()):
def
generateSubdivisions
(
file
,
G
,
edges
=
None
,
function
=
lambda
H
:
H
.
graph6_string
(),
parallel
=
1
):
f
=
open
(
file
,
'
w+
'
)
f
.
write
(
"
# Subdivisions of edges
'
%s
'
of graph
'
%s
'
(%s)
\n
"
%
(
edges
,
G
.
graph6_string
(),
G
))
for
H
in
subdivisionIterator
(
G
,
edges
):
f
.
write
(
function
(
H
))
if
parallel
==
1
:
iterator
=
map
(
function
,
subdivisionIterator
(
G
,
edges
))
else
:
iterator
=
parmap
(
function
,
subdivisionIterator
(
G
,
edges
),
parallel
)
for
line
in
iterator
:
f
.
write
(
line
)
f
.
write
(
"
\n
"
)
f
.
close
()
...
...
This diff is collapsed.
Click to expand it.
parmap.py
0 → 100644
+
36
−
0
View file @
b2fd8ff3
# modified version of code written by klaus se from
# http://stackoverflow.com/a/16071616
import
multiprocessing
def
fun
(
f
,
q_in
,
q_out
):
while
True
:
i
,
x
=
q_in
.
get
()
if
i
is
None
:
break
q_out
.
put
((
i
,
f
(
x
)))
def
parmap
(
f
,
X
,
nprocs
=
None
):
if
nprocs
is
None
:
nprocs
=
multiprocessing
.
cpu_count
()
q_in
=
multiprocessing
.
Queue
(
100
)
q_out
=
multiprocessing
.
Queue
()
proc
=
[
multiprocessing
.
Process
(
target
=
fun
,
args
=
(
f
,
q_in
,
q_out
))
for
_
in
range
(
nprocs
)]
for
p
in
proc
:
p
.
daemon
=
True
p
.
start
()
sent
=
[
q_in
.
put
((
i
,
x
))
for
i
,
x
in
enumerate
(
X
)]
[
q_in
.
put
((
None
,
None
))
for
_
in
range
(
nprocs
)]
ret
=
{}
for
_
in
range
(
len
(
sent
)):
i
,
val
=
q_out
.
get
()
ret
[
i
]
=
val
[
p
.
join
()
for
p
in
proc
]
return
[
ret
[
i
]
for
i
in
range
(
len
(
sent
))
]
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment