Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
RODIONOV Sergey
parallel-computing-practice
Commits
f29f13b0
Commit
f29f13b0
authored
Nov 30, 2016
by
PARWORK Lambert
Browse files
Merge branch 'master' of
https://gitlab.lam.fr/srodionov/parallel-computing-practice
parents
4001b0ee
bbe79613
Changes
8
Hide whitespace changes
Inline
Side-by-side
01_gnu_parallel/examples.txt
View file @
f29f13b0
...
...
@@ -13,7 +13,7 @@ cat 2.txt | parallel -k
code.py 1
./
code.py 1
seq 1 8 |parallel ./code.py {}
time seq 1 8 |parallel -j1 ./code.py {}
time seq 1 8 |parallel ./code.py {}
...
...
03_matrix_mult/advance_task.txt
View file @
f29f13b0
Study speed-up for "example2" with different N ( -size
parameters
).
Study speed-up for "example2" with different N ( -size
=10000 for example
).
Make sure that for big N speed-up is bigger.
03_matrix_mult/example3/batch_code3.sh
View file @
f29f13b0
...
...
@@ -33,12 +33,3 @@ do
done
rm
-f
times_5000.txt
for
N
in
`
seq
1 12
`
do
export
OMP_NUM_THREADS
=
$N
python ../code3.py 5000
>>
times_5000.txt
done
04_python_map/advance_task1.txt
0 → 100644
View file @
f29f13b0
Parallelize code3.py with Pool+map.
1. rewrite code3.py with build in map function.
2. Parallelize it with Pool+map (see code2.py as an example).
3. Make sure that matrix multipication use only one thread per
process (use "mkl.set_num_threads(1)" in the code and "export
OMP_NUM_THREADS=1" in the batch file).
4. Compare perforamance of code3.py with your new code.
5. We've made sure that we use only one thread per process. Now, try to
set 12 threads per process (set "mkl.set_num_threads(12)" in the code
and OMP_NUM_THREADS=12 in the batch file) and see how performance will
degrade.
04_python_map/advance_task.txt
→
04_python_map/advance_task
2
.txt
View file @
f29f13b0
File moved
04_python_map/advance_task3.txt
0 → 100644
View file @
f29f13b0
1. Read documentation about apply_async method of multiprocessing.Pool
https://docs.python.org/3/library/multiprocessing.html#multiprocessing.pool.Pool.apply_async
This might be useful for server application where you are
continuously receiving data and want to treat them in parallel.
2. See code5.py which is a parallel version code1.py with apply_async
3. Compare performance of code2.py (version with Pool+map) and
code5.py. code5.py is slower because it is equivalent to code2.py
with chunksize=1.
04_python_map/code3.py
View file @
f29f13b0
#!/usr/bin/env python
import
numpy
as
np
import
argparse
from
multiprocessing
import
Pool
import
mkl
# To be sure that we use 1 thread in MKL
mkl
.
set_num_threads
(
1
)
# Parse command line arguments
parser
=
argparse
.
ArgumentParser
()
parser
.
add_argument
(
"Nm"
,
help
=
"Number of matrices"
,
type
=
int
);
parser
.
add_argument
(
"-ncores"
,
help
=
"Number of cores to use"
,
type
=
int
);
args
=
parser
.
parse_args
()
Nm
=
args
.
Nm
...
...
@@ -19,19 +13,10 @@ def fun(i):
np
.
random
.
seed
(
i
)
A
=
np
.
random
.
rand
(
100
,
100
)
B
=
np
.
random
.
rand
(
100
,
100
)
return
np
.
sum
(
np
.
dot
(
A
,
B
))
p
=
Pool
(
args
.
ncores
);
return
np
.
min
(
np
.
dot
(
A
,
B
))
async_
rez
=
[]
rez
=
0
for
i
in
range
(
Nm
):
async_rez
.
append
(
p
.
apply_async
(
fun
,
(
i
,)
)
)
rez
=
0
;
for
i
in
range
(
Nm
):
rez
+=
async_rez
[
i
].
get
()
rez
+=
fun
(
i
)
*
np
.
sqrt
(
i
)
print
(
rez
)
p
.
close
()
p
.
join
()
04_python_map/code5.py
0 → 100755
View file @
f29f13b0
#!/usr/bin/env python
import
numpy
as
np
import
argparse
from
multiprocessing
import
Pool
import
mkl
# To be sure that we use 1 thread in MKL
mkl
.
set_num_threads
(
1
)
# Parse command line arguments
parser
=
argparse
.
ArgumentParser
()
parser
.
add_argument
(
"Nm"
,
help
=
"Number of matrices"
,
type
=
int
);
parser
.
add_argument
(
"-ncores"
,
help
=
"Number of cores to use"
,
type
=
int
);
args
=
parser
.
parse_args
()
Nm
=
args
.
Nm
def
fun
(
i
):
np
.
random
.
seed
(
i
)
A
=
np
.
random
.
rand
(
100
,
100
)
B
=
np
.
random
.
rand
(
100
,
100
)
return
np
.
sum
(
np
.
dot
(
A
,
B
))
p
=
Pool
(
args
.
ncores
);
async_rez
=
[]
for
i
in
range
(
Nm
):
async_rez
.
append
(
p
.
apply_async
(
fun
,
(
i
,)
)
)
rez
=
0
;
for
i
in
range
(
Nm
):
rez
+=
async_rez
[
i
].
get
()
print
(
rez
)
p
.
close
()
p
.
join
()
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