Commit 6aacbc03 authored by RODIONOV Sergey's avatar RODIONOV Sergey

new version

parent 2c07c56e
#!/usr/bin/python
import numpy as np
import sys
import argparse
import matplotlib
matplotlib.use('Agg')
import matplotlib.pyplot as plt
# Slow matrix multiplication
def mult(A,B):
n = len(A);
C = np.zeros((n,n))
for i in range(n):
for j in range(n):
for k in range(n):
C[i,j] += A[i,k] * B[k,j]
return C
# Parse command line arguments
parser = argparse.ArgumentParser()
parser.add_argument("seed", help="Random seed", type=int);
parser.add_argument("-size", help="Size of matrix", type=int, default=100);
args = parser.parse_args()
np.random.seed(args.seed)
A = np.random.rand (args.size, args.size)
B = np.random.rand (args.size, args.size)
C = mult(A,B)
plt.matshow(C)
fname = "out_" + str(args.seed) + ".png"
plt.savefig(fname)
print (fname)
#!/bin/bash
#jobs's name
#PBS -N test
#we request 1 core
#PBS -l nodes=1:ppn=1
#We ask for 600 sec
#PBS -l walltime=600
# output log file name
#PBS -o "run-log.txt"
#output error file name
#PBS -e "run-err.txt"
# change to submission jobs directory
cd $PBS_O_WORKDIR
python ../code.py 1
#!/bin/bash
### run it with "qsub -t 1-20 batch_example2.sh" #########
# it will add in the queue 20 tasks with different PBS_ARRAYID (from 1 to 20 including)
#jobs's name
#PBS -N test
#we request 1 core
#PBS -l nodes=1:ppn=1
#The maximum wall-clock time during which this job can run (hh:mm:ss)
#PBS -l walltime=00:01:00
# output log file name
#PBS -o "run-log.txt"
#output error file name
#PBS -e "run-err.txt"
# change to submission jobs directory
cd $PBS_O_WORKDIR
#$PBS_ARRAYID - id of this task
python ../code.py ${PBS_ARRAYID}
#!/bin/bash
#jobs's name
#PBS -N test
#we request 1 nodes with 8 cores per nodes
#PBS -l nodes=1:ppn=8
#We ask 600 sec
#PBS -l walltime=600
# output log file name
#PBS -o "run-log.txt"
#output error file name
#PBS -e "run-err.txt"
# change to submission jobs directory
cd $PBS_O_WORKDIR
seq 1 20 | parallel python ../code.py {}
#!/usr/bin/env python
import numpy as np
import sys
import argparse
import matplotlib
matplotlib.use('Agg')
import matplotlib.pyplot as plt
#matrix multiplication
def mult(A,B):
n = len(A);
C = np.zeros((n,n))
for i in range(n):
for j in range(n):
for k in range(n):
C[i,j] += A[i,k] * B[k,j]
return C
# Parse command line arguments
parser = argparse.ArgumentParser()
parser.add_argument("seed", help="Random seed", type=int);
parser.add_argument("-size", help="Size of matrix", type=int, default=1000);
args = parser.parse_args()
np.random.seed(args.seed)
A = np.random.rand (args.size, args.size)
B = np.random.rand (args.size, args.size)
C = mult(A,B)
plt.matshow(C)
fname = "out_" + str(args.seed) + ".png"
plt.savefig(fname)
print (fname)
#!/usr/bin/env python
import numpy as np
import sys
import argparse
import matplotlib
matplotlib.use('Agg')
import matplotlib.pyplot as plt
# Parse command line arguments
parser = argparse.ArgumentParser()
parser.add_argument("seed", help="Random seed", type=int);
parser.add_argument("-size", help="Size of matrix", type=int, default=1000);
args = parser.parse_args()
np.random.seed(args.seed)
A = np.random.rand (args.size, args.size)
B = np.random.rand (args.size, args.size)
C = np.dot(A,B)
plt.matshow(C)
fname = "out_" + str(args.seed) + ".png"
plt.savefig(fname)
print (fname)
#!/usr/bin/env python
import numpy as np
import mkl
import time
import argparse
# Parse command line arguments
parser = argparse.ArgumentParser()
parser.add_argument("size", help="Size of matrix", type=int);
args = parser.parse_args()
N = args.size
for i in range(5):
A = np.random.rand (N, N)
B = np.random.rand (N, N)
start = time.time()
C = np.dot(A,B)
end = time.time()
print (mkl.get_max_threads(), end - start)
#!/bin/bash
#jobs's name
#PBS -N test
#we request 1 nodes with 1 cores per nodes = 1 x 12 = 12 cores in total
#PBS -l nodes=1:ppn=12
# We ask for 600 sec
#PBS -l walltime=600
# output log file name
#PBS -o "run-log.txt"
#output error file name
#PBS -e "run-err.txt"
# change to submission jobs directory
cd $PBS_O_WORKDIR
rm -f times.txt
for N in `seq 1 12`
do
export OMP_NUM_THREADS=$N
echo -n "$N " >> times.txt
/usr/bin/time -f %e python ../code2.py -size=5000 ${N} 2>> times.txt
done
#!/bin/bash
#jobs's name
#PBS -N test
#we request 1 nodes with 1 cores per nodes = 1 x 12 = 12 cores in total
#PBS -l nodes=1:ppn=12
# we ask for 600 sec
#PBS -l walltime=600
# output log file name
#PBS -o "run-log.txt"
#output error file name
#PBS -e "run-err.txt"
# change to submission jobs directory
cd $PBS_O_WORKDIR
rm -f times_100.txt
for N in `seq 1 12`
do
export OMP_NUM_THREADS=$N
python ../code3.py 100 >> times_100.txt
done
rm -f times_2000.txt
for N in `seq 1 12`
do
export OMP_NUM_THREADS=$N
python ../code3.py 2000 >> times_2000.txt
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
#!/usr/bin/env python
import numpy as np
import argparse
# Parse command line arguments
parser = argparse.ArgumentParser()
parser.add_argument("input", help="Input two column file: ncore time");
args = parser.parse_args()
tdict = {}
with open(args.input) as f:
for line in f:
sline = line.split()
if (len(sline) != 2):
raise Exception('Input is not a two column file');
tdict[int(sline[0])] = float(sline[1])
for n in sorted(tdict):
t = tdict[n];
s = tdict[1]/t;
print ("%2d %10.5g %10.3g" % (n, t, s))
#!/usr/bin/env python
import numpy as np
import argparse
# Parse command line arguments
parser = argparse.ArgumentParser()
parser.add_argument("Nm", help="Number of matrices", type=int);
args = parser.parse_args()
Nm = args.Nm
rez = 0
for i in range(Nm):
np.random.seed(i)
A = np.random.rand (100, 100)
B = np.random.rand (100, 100)
rez += np.sum(np.dot(A, B))
print (rez)
#!/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);
rez = np.sum( p.map(fun, range(Nm)) )
print (rez)
#!/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)
#!/bin/bash
#jobs's name
#PBS -N test
#we request 1 nodes with 1 cores per nodes = 1 x 12 = 12 cores in total
#PBS -l nodes=1:ppn=12
#The maximum wall-clock time during which this job can run (hh:mm:ss)
#PBS -l walltime=00:60:00
# output log file name
#PBS -o "run-log.txt"
#output error file name
#PBS -e "run-err.txt"
# change to submission jobs directory
cd $PBS_O_WORKDIR
rm -f times_threads.txt times_pmap.txt
for N in `seq 1 12`
do
export OMP_NUM_THREADS=$N
echo -n "$N " >> times_threads.txt
/usr/bin/time -f %e python ../code1.py 5000 2>> times_threads.txt
done
export OMP_NUM_THREADS=1
for N in `seq 1 12`
do
echo -n "$N " >> times_pmap.txt
/usr/bin/time -f %e python ../code2.py 5000 -ncores=$N 2>> times_pmap.txt
done
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment