Skip to content

Instantly share code, notes, and snippets.

@shahrzad
Created March 25, 2021 15:18
Show Gist options
  • Save shahrzad/73fb83dd0c908fdcc4ecc64cdd9fc059 to your computer and use it in GitHub Desktop.
Save shahrzad/73fb83dd0c908fdcc4ecc64cdd9fc059 to your computer and use it in GitHub Desktop.
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
Created on Mon Jan 13 14:19:59 2020
@author: shahrzad
"""
import pandas
import numpy as np
from matplotlib import pyplot as plt
from matplotlib.backends.backend_pdf import PdfPages
import itertools
import glob
import matplotlib.tri as mtri
from mpl_toolkits import mplot3d
import math
from scipy.optimize import curve_fit
from collections import Counter
from scipy.optimize import nnls
import csv
from scipy.optimize import nnls
def create_dict_stencil(directories,to_csv=False):
thr=[]
data_files=[]
for directory in directories:
[data_files.append(i) for i in glob.glob(directory+'/*.dat')]
nps=[]
nxs=[]
nodes=[]
gps=[]
if to_csv:
f_csv=open('/home/shahrzad/repos/Blazemark/data/stencil_data_perf_all.csv','w')
f_writer=csv.writer(f_csv, delimiter=',', quotechar='"', quoting=csv.QUOTE_MINIMAL)
f_writer.writerow(['node','grid_points','num_threads','num_partitions','partition_size','grain_size','work_per_core','num_tasks','execution_time'])
for filename in data_files:
(node, _, th, npo, nx) = filename.replace('_old','').split('/')[-1].replace('.dat','').split('_')
th=int(th)
npo=int(npo)
nx=int(nx)
if node not in nodes:
nodes.append(node)
if npo not in nps:
nps.append(npo)
if nx not in nxs:
nxs.append(nx)
if th not in thr:
thr.append(th)
if nx*npo not in gps:
gps.append(nx*npo)
nodes.sort()
nxs.sort()
nps.sort()
gps.sort()
thr.sort()
data_files.sort()
for filename in data_files:
f=open(filename, 'r')
result=f.readlines()
if len(result)!=0:
print(filename)
(node, _, th, npo, nx) = filename.replace('_old','').split('/')[-1].replace('.dat','').split('_')
th=float(th)
npo=float(npo)
nx=float(nx)
r=result[1].split(',')
r=[rr.strip() for rr in r]
execution_time=float(r[1])*1e6
num_tasks=npo
grain_size=nx
w_c=math.ceil(num_tasks/th)*grain_size
f_writer.writerow([node,npo*nx,th,npo,nx,grain_size,w_c,num_tasks,execution_time])
if to_csv:
f_csv.close()
# return (data, d, thr, iter_lengths, num_iterations)
marvin_dir='/home/shahrzad/repos/Blazemark/data/stencil/marvin_old/100000000'
create_dict_stencil([marvin_dir],1)
titles=['node','grid_points','num_threads','num_partitions','partition_size','grain_size','work_per_core','num_tasks','execution_time']
filename='/home/shahrzad/repos/Blazemark/data/stencil_data_perf_all.csv'
dataframe = pandas.read_csv(filename, header=0,index_col=False,dtype=str,names=titles)
for col in titles[1:]:
dataframe[col] = dataframe[col].astype(float)
nodes=dataframe['node'].drop_duplicates().values
nodes.sort()
grid_points=dataframe['grid_points'].drop_duplicates().values
grid_points.sort()
for node in nodes:
node_selected=dataframe['node']==node
df_n_selected=dataframe[node_selected][titles[1:]]
thr=df_n_selected['num_threads'].drop_duplicates().values
thr.sort()
grid_points=dataframe['grid_points'].drop_duplicates().values
grid_points.sort()
array=df_n_selected[['num_threads','grain_size','execution_time']].values
array=array.astype(float)
j=1
for th in range(1,9):
plt.figure(j)
array_t=array[array[:,0]==th]
plt.scatter(array_t[:,1],array_t[:,2],marker='.',label=str(th))
plt.legend(bbox_to_anchor=(1.05, 1), loc=2, borderaxespad=0.)
plt.xscale('log')
j=j+1
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment