Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
What's new
10
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in / Register
Toggle navigation
Open sidebar
Peter-Bernd Otte
Workload Manager
Commits
13c5900e
Commit
13c5900e
authored
May 01, 2019
by
Peter-Bernd Otte
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Update wkmgr.py
parent
a9c342d7
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
83 additions
and
0 deletions
+83
-0
wkmgr.py
wkmgr.py
+83
-0
No files found.
wkmgr.py
0 → 100644
View file @
13c5900e
#!/usr/bin/env python
# -*- coding: utf-8 -*-
#
# Workload Distributor
# Version 0.1
#
# Minimal python version 3.6
# on Mogon 2: run first
# module load lang/Python/3.6.6-foss-2018b
from
mpi4py
import
MPI
import
platform
import
multiprocessing
#to get number of cores
import
argparse
import
subprocess
from
time
import
sleep
import
os
import
datetime
comm
=
MPI
.
COMM_WORLD
size
=
comm
.
Get_size
()
rank
=
comm
.
Get_rank
()
parser
=
argparse
.
ArgumentParser
(
description
=
'Workload distributor for trivial parallelism.'
)
parser
.
add_argument
(
'execname'
,
help
=
'name of executable to call'
)
parser
.
add_argument
(
"-v"
,
"--verbose"
,
help
=
"increase output verbosity"
,
default
=
False
,
action
=
"store_true"
)
parser
.
add_argument
(
"-V"
,
"--version"
,
help
=
"Returns the actual program version"
,
action
=
"version"
,
version
=
'%(prog)s 0.1'
)
parser
.
add_argument
(
"-d"
,
"--delay"
,
help
=
"time delay in ms between starts of consecutive workers"
,
default
=
50
,
type
=
int
)
if
rank
==
0
:
args
=
parser
.
parse_args
()
print
(
"Delay: "
+
str
(
args
.
delay
)
+
" ms"
)
clients
=
{}
worklist
=
[
'file1.txt'
,
'file2.txt'
,
'file3.txt'
]
now
=
datetime
.
datetime
.
now
()
outputdir
=
os
.
getcwd
()
+
"output_{:04d}{:02d}{:02d}{:02d}{:02d}{:02d}"
.
format
(
now
.
year
,
now
.
month
,
now
.
day
,
now
.
hour
,
now
.
minute
,
now
.
second
)
if
os
.
path
.
isdir
(
"./"
+
outputdir
):
print
(
"Output directory already exists. Exiting."
)
exit
(
1
)
if
rank
==
0
:
if
args
.
verbose
:
print
(
"verbosity turned on"
)
print
(
"Executing: "
,
args
.
execname
)
print
(
"Output dir: "
,
outputdir
)
#prepare output directory
os
.
mkdir
(
outputdir
)
print
(
'Total number of workers '
,
size
-
1
)
for
i
in
range
(
1
,
size
):
clients
[
i
]
=
comm
.
recv
(
source
=
i
)
print
(
clients
)
for
i
in
range
(
1
,
size
):
comm
.
send
(
args
.
execname
,
dest
=
i
)
sleep
(
args
.
delay
/
1000
)
else
:
print
(
"rank "
+
str
(
rank
))
nodeinfo
=
{
'machine'
:
platform
.
machine
(),
'hostname'
:
platform
.
node
(),
'Ncores'
:
multiprocessing
.
cpu_count
(),
'os'
:
platform
.
system
(),
'pythonVersion'
:
platform
.
python_version
()
}
comm
.
send
(
nodeinfo
,
dest
=
0
)
workstr
=
comm
.
recv
(
source
=
0
)
print
(
"Rank "
+
str
(
rank
)
+
" recieved: "
+
workstr
)
bashCommand
=
workstr
+
" > output"
+
str
(
rank
)
+
".txt"
try
:
completed
=
subprocess
.
run
(
bashCommand
,
shell
=
True
)
print
(
'Rank '
+
str
(
rank
)
+
' returncode: '
,
completed
.
returncode
)
except
subprocess
.
CalledProcessError
as
err
:
print
(
'Rank '
+
str
(
rank
)
+
' ERROR:'
,
err
)
if
rank
==
0
:
# print(clients)
print
(
worklist
)
# run commands
#cd into subdirector
# catch exceptions
\ No newline at end of file
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