Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
P
pytools
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Andreas Klöckner
pytools
Commits
76ef26c9
Commit
76ef26c9
authored
15 years ago
by
Andreas Klöckner
Browse files
Options
Downloads
Patches
Plain Diff
Add pytools.mpiwrap. Migrate from boostmpi to mpi4py.
parent
6275791b
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
.gitignore
+1
-0
1 addition, 0 deletions
.gitignore
pytools/log.py
+8
-12
8 additions, 12 deletions
pytools/log.py
pytools/mpi.py
+2
-2
2 additions, 2 deletions
pytools/mpi.py
pytools/mpiwrap.py
+11
-0
11 additions, 0 deletions
pytools/mpiwrap.py
with
22 additions
and
14 deletions
.gitignore
+
1
−
0
View file @
76ef26c9
...
...
@@ -7,3 +7,4 @@ build
MANIFEST
dist
setuptools*egg
setuptools.pth
This diff is collapsed.
Click to expand it.
pytools/log.py
+
8
−
12
View file @
76ef26c9
...
...
@@ -232,13 +232,13 @@ class LogManager(object):
def
__init__
(
self
,
filename
=
None
,
mode
=
"
r
"
,
mpi_comm
=
None
,
capture_warnings
=
True
):
"""
Initialize this log manager instance.
@arg
filename: If given, the filename to which this log is bound.
:param
filename: If given, the filename to which this log is bound.
If this database exists, the current state is loaded from it.
@arg
mode: One of
"
w
"
,
"
r
"
for write, read.
"
w
"
assumes that the
:param
mode: One of
"
w
"
,
"
r
"
for write, read.
"
w
"
assumes that the
database is initially empty.
@
arg mpi_comm: An C{
boost
mpi} communicator. If given, logs are periodically
:
arg mpi_comm: An C{mpi
4py
} communicator. If given, logs are periodically
synchronized to the head node, which then writes them out to disk.
@arg
capture_warnings: Tap the Python warnings facility and save warnings
:param
capture_warnings: Tap the Python warnings facility and save warnings
to the log file.
"""
...
...
@@ -306,15 +306,13 @@ class LogManager(object):
# set globally unique run_id
if
self
.
is_parallel
:
from
boostmpi
import
broadcast
self
.
set_constant
(
"
unique_run_id
"
,
broadcast
(
self
.
mpi_comm
,
_get_unique_id
(),
root
=
self
.
head_rank
))
self
.
mpi_comm
.
bcast
(
_get_unique_id
(),
root
=
self
.
head_rank
))
else
:
self
.
set_constant
(
"
unique_run_id
"
,
_get_unique_id
())
if
self
.
is_parallel
:
self
.
set_constant
(
"
rank_count
"
,
self
.
mpi_comm
.
size
)
self
.
set_constant
(
"
rank_count
"
,
self
.
mpi_comm
.
Get_
size
()
)
else
:
self
.
set_constant
(
"
rank_count
"
,
1
)
else
:
...
...
@@ -780,9 +778,7 @@ class LogManager(object):
for
qname
in
self
.
quantity_data
.
iterkeys
())
if
self
.
mpi_comm
is
not
None
and
self
.
have_nonlocal_watches
:
from
boostmpi
import
broadcast
,
gather
gathered_data
=
gather
(
self
.
mpi_comm
,
data_block
,
self
.
head_rank
)
gathered_data
=
self
.
mpi_comm
.
gather
(
data_block
,
self
.
head_rank
)
else
:
gathered_data
=
[
data_block
]
...
...
@@ -808,7 +804,7 @@ class LogManager(object):
self
.
next_watch_tick
=
self
.
tick_count
+
int
(
max
(
1
,
ticks_per_sec
))
if
self
.
mpi_comm
is
not
None
and
self
.
have_nonlocal_watches
:
self
.
next_watch_tick
=
broadcast
(
self
.
mpi_comm
,
self
.
next_watch_tick
=
self
.
mpi_comm
.
bcast
(
self
.
next_watch_tick
,
self
.
head_rank
)
...
...
This diff is collapsed.
Click to expand it.
pytools/mpi.py
+
2
−
2
View file @
76ef26c9
def
in_mpi_relaunch
():
import
os
return
"
BOOSTMPI
_RUN_WITHIN_MPI
"
in
os
.
environ
return
"
PYTOOLS
_RUN_WITHIN_MPI
"
in
os
.
environ
def
run_with_mpi_ranks
(
py_script
,
ranks
,
callable
,
*
args
,
**
kwargs
):
if
in_mpi_relaunch
():
...
...
@@ -8,7 +8,7 @@ def run_with_mpi_ranks(py_script, ranks, callable, *args, **kwargs):
else
:
import
sys
,
os
newenv
=
os
.
environ
.
copy
()
newenv
[
"
BOOSTMPI
_RUN_WITHIN_MPI
"
]
=
"
1
"
newenv
[
"
PYTOOLS
_RUN_WITHIN_MPI
"
]
=
"
1
"
from
subprocess
import
check_call
check_call
([
"
mpirun
"
,
"
-np
"
,
str
(
ranks
),
...
...
This diff is collapsed.
Click to expand it.
pytools/mpiwrap.py
0 → 100644
+
11
−
0
View file @
76ef26c9
import
mpi4py.rc
mpi4py
.
rc
.
initialize
=
False
import
pytools.prefork
pytools
.
prefork
.
enable_prefork
()
from
mpi4py.MPI
import
*
if
Is_initialized
():
raise
RuntimeError
(
"
MPI already initialized before MPI wrapper import
"
)
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