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
Commits
01dc1f06
Commit
01dc1f06
authored
4 months ago
by
Rasmus Ringdahl
Browse files
Options
Downloads
Patches
Plain Diff
refactor: remove unwanted code
parent
7f9d2de8
No related branches found
No related tags found
1 merge request
!5
refactor: remove unwanted code
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
3_job_array/job_array_task copy.py
+0
-55
0 additions, 55 deletions
3_job_array/job_array_task copy.py
with
0 additions
and
55 deletions
3_job_array/job_array_task copy.py
deleted
100644 → 0
+
0
−
55
View file @
7f9d2de8
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
)
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