Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Menu
Open sidebar
Mpp
Mpp
Commits
2fa3ef1f
Commit
2fa3ef1f
authored
Feb 21, 2020
by
niklas.baumgarten
Browse files
worked on mppy
parent
26463fda
Changes
1
Hide whitespace changes
Inline
Side-by-side
python/mppy.py
View file @
2fa3ef1f
import
os
import
re
from
subprocess
import
Popen
,
PIPE
import
shutil
import
socket
from
subprocess
import
Popen
,
PIPE
,
CalledProcessError
import
sys
import
io
import
os
import
re
PROJECT_ROOT_DIR
=
'..'
BUILD_DIR
=
PROJECT_ROOT_DIR
+
'/build'
LOG_DIR
=
BUILD_DIR
+
'/log'
DATA_DIR
=
BUILD_DIR
+
'/data'
VTK_DATA_DIR
=
DATA_DIR
+
'/vtk'
PY_DATA_DIR
=
DATA_DIR
+
'/py'
PY_FILE_DIR
=
os
.
path
.
dirname
(
os
.
path
.
realpath
(
__file__
))
MPP_DIR
=
os
.
path
.
abspath
(
os
.
path
.
join
(
PY_FILE_DIR
,
'..'
))
MPP_BUILD_DIR
=
os
.
path
.
abspath
(
os
.
path
.
join
(
MPP_DIR
,
'build'
))
MPP_LOG_DIR
=
os
.
path
.
abspath
(
os
.
path
.
join
(
MPP_BUILD_DIR
,
'log'
))
MPP_DATA_DIR
=
os
.
path
.
abspath
(
os
.
path
.
join
(
MPP_BUILD_DIR
,
'data'
))
MPP_VTK_DATA_DIR
=
os
.
path
.
abspath
(
os
.
path
.
join
(
MPP_DATA_DIR
,
'vtk'
))
MPP_PY_DATA_DIR
=
os
.
path
.
abspath
(
os
.
path
.
join
(
MPP_DATA_DIR
,
'py'
))
PROJECT_ROOT_DIR
=
os
.
path
.
abspath
(
os
.
path
.
join
(
MPP_DIR
,
'..'
))
PROJECT_BUILD_DIR
=
os
.
path
.
abspath
(
os
.
path
.
join
(
PROJECT_ROOT_DIR
,
'build'
))
PROJECT_LOG_DIR
=
os
.
path
.
abspath
(
os
.
path
.
join
(
PROJECT_BUILD_DIR
,
'log'
))
PROJECT_DATA_DIR
=
os
.
path
.
abspath
(
os
.
path
.
join
(
PROJECT_BUILD_DIR
,
'data'
))
PROJECT_VTK_DATA_DIR
=
os
.
path
.
abspath
(
os
.
path
.
join
(
PROJECT_DATA_DIR
,
'vtk'
))
PROJECT_PY_DATA_DIR
=
os
.
path
.
abspath
(
os
.
path
.
join
(
PROJECT_DATA_DIR
,
'py'
))
class
Mpp
:
...
...
@@ -21,45 +27,44 @@ class Mpp:
@
staticmethod
def
run_subprocess
(
args
,
cwd
):
if
isinstance
(
args
,
list
):
process
=
Popen
(
args
,
cwd
=
cwd
,
stdout
=
sys
.
stdout
,
stderr
=
sys
.
stderr
)
process
.
communicate
()
return_code
=
process
.
wait
()
if
return_code
!=
0
:
sys
.
exit
(
return_code
)
process
=
Popen
(
args
,
cwd
=
cwd
,
stdout
=
PIPE
,
stderr
=
PIPE
)
while
True
:
stdout
=
process
.
stdout
.
readline
()
if
stdout
==
b
''
and
process
.
poll
()
is
not
None
:
break
if
stdout
:
print
(
stdout
.
decode
(
'utf-8'
).
strip
(
'
\n
'
))
return
process
.
poll
()
@
staticmethod
def
create_working_dir
():
if
os
.
path
.
isdir
(
BUILD_DIR
):
os
.
chdir
(
BUILD_DIR
)
else
:
os
.
mkdir
(
BUILD_DIR
)
os
.
chdir
(
BUILD_DIR
)
if
not
os
.
path
.
isdir
(
PROJECT_BUILD_DIR
):
os
.
mkdir
(
PROJECT_BUILD_DIR
)
def
setup_cluster
(
self
):
print
(
'================ setup cluster ================'
)
print
(
'
\n
================ setup cluster ================
\n
'
)
if
socket
.
gethostname
().
find
(
'ma-pde'
)
!=
-
1
:
self
.
run_subprocess
([
'module'
,
'add'
,
'OpenMPI/3.1.3-GCC-8.2.0-2.31.1'
],
cwd
=
PROJECT_ROOT_DIR
)
rc
=
self
.
run_subprocess
([
'module'
,
'add'
,
'foss'
],
cwd
=
PROJECT_ROOT_DIR
)
def
run_cmake
(
self
):
print
(
'================ running cmake ================'
)
self
.
run_subprocess
([
'cmake'
,
'..'
],
cwd
=
BUILD_DIR
)
print
(
'
\n
================ running cmake ================
\n
'
)
rc
=
self
.
run_subprocess
([
'cmake'
,
'..'
],
cwd
=
PROJECT_
BUILD_DIR
)
def
run_make
(
self
):
print
(
'================ running make ================'
)
self
.
run_subprocess
([
'make'
,
'-j'
],
cwd
=
BUILD_DIR
)
print
(
'
\n
================ running make ================
\n
'
)
self
.
run_subprocess
([
'make'
,
'-j'
],
cwd
=
PROJECT_
BUILD_DIR
)
def
kill
(
self
):
print
(
'================ kill
ing
mpp ================'
)
self
.
run_subprocess
([
'killall'
,
self
.
executable
],
cwd
=
BUILD_DIR
)
print
(
'
\n
================ kill
every
mpp ================
\n
'
)
self
.
run_subprocess
([
'killall'
,
self
.
executable
],
cwd
=
PROJECT_
BUILD_DIR
)
def
run_tests
(
self
):
print
(
'================ running tests ================'
)
files
=
os
.
listdir
(
BUILD_DIR
)
print
(
'
\n
================ running tests ================
\n
'
)
files
=
os
.
listdir
(
PROJECT_
BUILD_DIR
)
for
file
in
files
:
if
file
.
find
(
"Test"
)
!=
-
1
:
run_parameters
=
self
.
chain_run_parameters
(
1
,
None
,
executable
=
file
)
self
.
run_subprocess
(
run_parameters
,
cwd
=
BUILD_DIR
)
self
.
run_subprocess
(
run_parameters
,
cwd
=
PROJECT_
BUILD_DIR
)
def
chain_run_parameters
(
self
,
kernels
,
args
,
executable
=
None
):
executable
=
self
.
executable
if
executable
is
None
else
executable
...
...
@@ -88,13 +93,13 @@ class Mpp:
print
(
e
)
def
clean_vtk
(
self
):
self
.
clean_directory
(
VTK_DATA_DIR
,
True
)
self
.
clean_directory
(
PROJECT_
VTK_DATA_DIR
,
True
)
def
clean_log
(
self
):
self
.
clean_directory
(
LOG_DIR
,
False
)
self
.
clean_directory
(
PROJECT_
LOG_DIR
,
False
)
def
clean_python_plots
(
self
):
self
.
clean_directory
(
PY_DATA_DIR
,
False
)
self
.
clean_directory
(
PROJECT_
PY_DATA_DIR
,
False
)
def
clean_data
(
self
):
self
.
clean_vtk
()
...
...
@@ -102,16 +107,16 @@ class Mpp:
self
.
clean_python_plots
()
def
clean_build
(
self
):
if
os
.
path
.
isdir
(
BUILD_DIR
):
self
.
clean_directory
(
BUILD_DIR
,
True
)
if
os
.
path
.
isdir
(
PROJECT_
BUILD_DIR
):
self
.
clean_directory
(
PROJECT_
BUILD_DIR
,
True
)
def
run
(
self
,
kernels
,
args
=
None
):
run_parameters
=
self
.
chain_run_parameters
(
kernels
,
args
)
self
.
run_subprocess
(
run_parameters
,
cwd
=
BUILD_DIR
)
self
.
run_subprocess
(
run_parameters
,
cwd
=
PROJECT_
BUILD_DIR
)
@
staticmethod
def
read_log
(
log_file
=
None
):
log_file
=
LOG_DIR
+
'/log'
if
log_file
is
None
else
LOG_DIR
+
log_file
log_file
=
PROJECT_
LOG_DIR
+
'/log'
if
log_file
is
None
else
PROJECT_
LOG_DIR
+
log_file
if
os
.
path
.
isfile
(
log_file
):
with
open
(
log_file
)
as
file
:
content
=
file
.
readlines
()
...
...
Write
Preview
Supports
Markdown
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