Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
L
lundgren examples
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Deploy
Releases
Analyze
Value stream analytics
Contributor analytics
Repository analytics
Code review analytics
Issue analytics
Insights
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Rasmus Ringdahl
lundgren examples
Merge requests
!5
refactor: remove unwanted code
Code
Review changes
Check out branch
Download
Patches
Plain diff
Merged
refactor: remove unwanted code
dev
into
main
Overview
0
Commits
1
Pipelines
0
Changes
1
Merged
Rasmus Ringdahl
requested to merge
dev
into
main
4 months ago
Overview
0
Commits
1
Pipelines
0
Changes
1
Expand
0
0
Merge request reports
Compare
main
main (base)
and
latest version
latest version
01dc1f06
1 commit,
4 months ago
1 file
+
0
−
55
Inline
Compare changes
Side-by-side
Inline
Show whitespace changes
Show one file at a time
3_job_array/job_array_task copy.py deleted
100644 → 0
+
0
−
55
Options
from
datetime
import
datetime
from
multiprocessing
import
Pool
import
json
import
logging
import
os
import
sys
import
time
logger
=
logging
.
getLogger
(
__name__
)
def
sleep
(
input
):
time
.
sleep
(
input
[
1
])
logger
.
info
(
'
Task %d done.
'
,
input
[
0
])
def
main
(
filename
:
str
):
# Read environment variables.
NUMBER_OF_CORES
=
os
.
environ
.
get
(
'
SLURM_CPUS_PER_TASK
'
,
'
Unknown
'
)
if
NUMBER_OF_CORES
in
'
Unknown
'
:
logger
.
error
(
'
Unkown number of cores, exiting.
'
)
return
NUMBER_OF_CORES
=
int
(
NUMBER_OF_CORES
)
logger
.
info
(
'
Running program with %d cores.
'
,
NUMBER_OF_CORES
)
# Reading configuration file and create a list of tasks
# This represents the reading of parameters and calculations
logger
.
info
(
'
Reading configuration from %s.
'
,
filename
)
with
open
(
filename
,
'
r
'
)
as
file
:
data
=
json
.
load
(
file
)
tasks
=
[]
total_time
=
0
for
i
in
range
(
len
(
data
[
'
sleep
'
])):
time
=
data
[
'
sleep
'
][
i
]
tasks
.
append
((
i
,
time
))
total_time
=
total_time
+
time
# Creating a multiprocessing pool to perform the tasks
pool
=
Pool
(
processes
=
NUMBER_OF_CORES
)
# Running submitting the tasks to the worker pool
tic
=
datetime
.
now
()
logger
.
info
(
'
Submitting tasks to pool.
'
)
pool
.
map
(
sleep
,
tasks
)
toc
=
datetime
.
now
()
logger
.
info
(
'
All tasks are done, took %d seconds, compared to %d seconds with single thread.
'
,
(
toc
-
tic
).
seconds
,
total_time
)
if
__name__
==
'
__main__
'
:
logging
.
basicConfig
(
level
=
logging
.
INFO
)
filename
=
sys
.
argv
[
1
]
main
(
filename
)
Loading