hw1: added sources from GH
This commit is contained in:
parent
26a8e93698
commit
0fe1838862
4 changed files with 249 additions and 0 deletions
30
Project1/project_1_maggioni_claudio/membench/Makefile
Normal file
30
Project1/project_1_maggioni_claudio/membench/Makefile
Normal file
|
@ -0,0 +1,30 @@
|
|||
#
|
||||
# Usage:
|
||||
# make # run benchmark on the local machine or on cluster compute node
|
||||
# # operated by SLURM
|
||||
#
|
||||
.PRECIOUS: %.gp %.xxx %.out
|
||||
|
||||
#generic: generic.ps
|
||||
generic: membench
|
||||
|
||||
membench: membench.c
|
||||
gcc -O3 -o membench membench.c
|
||||
|
||||
clean:
|
||||
make generic.clean
|
||||
|
||||
%.ps: membench %.gp
|
||||
sbatch ./run_membench.sh $*
|
||||
module load gnuplot
|
||||
gnuplot %.gp
|
||||
|
||||
%.gp: gnuplot.template
|
||||
sed -e '/sarlacc/ s//$*/' gnuplot.template > $*.gp
|
||||
|
||||
%.clean:
|
||||
rm -f $*.ps $*.gp $*.xxx *.out membench
|
||||
|
||||
tar:
|
||||
cd ../; tar cf membench.tar membench/*
|
||||
|
|
@ -0,0 +1,35 @@
|
|||
set terminal postscript color
|
||||
set output "sarlacc.ps"
|
||||
set style data linespoints
|
||||
set style line 1 linetype 2
|
||||
set style line 2 linetype 3
|
||||
set style line 3 linetype 1
|
||||
|
||||
set logscale x 2
|
||||
set nokey
|
||||
set xtics (4,16,64,256,"1K" 1024,"4K" 4096,"16K" 16384,"64K" 65536,"256K" 262144,"1M" 1048576)
|
||||
|
||||
|
||||
set title "10-Core Intel(R) Xeon(R) CPU E3-1585L v5 @ 3.00GHz Read+Write (ns) Versus Stride"
|
||||
set xlabel "Stride (bytes)"
|
||||
set ylabel "Time Read+Write (nanoseconds)"
|
||||
|
||||
set key on
|
||||
plot 'sarlacc.xxx' index 0 using 2:3 title "0.5 KB" with linespoints, \
|
||||
'sarlacc.xxx' index 1 using 2:3 title "1 KB" with linespoints, \
|
||||
'sarlacc.xxx' index 2 using 2:3 title "2 KB" with linespoints, \
|
||||
'sarlacc.xxx' index 3 using 2:3 title "4 KB" with linespoints, \
|
||||
'sarlacc.xxx' index 4 using 2:3 title "8 KB" with linespoints, \
|
||||
'sarlacc.xxx' index 5 using 2:3 title "16 KB" with linespoints, \
|
||||
'sarlacc.xxx' index 6 using 2:3 title "32 KB" with linespoints, \
|
||||
'sarlacc.xxx' index 7 using 2:3 title "64 KB" with linespoints, \
|
||||
'sarlacc.xxx' index 8 using 2:3 title "128 KB" with linespoints, \
|
||||
'sarlacc.xxx' index 9 using 2:3 title "256 KB" with linespoints, \
|
||||
'sarlacc.xxx' index 10 using 2:3 title "512 KB" with linespoints, \
|
||||
'sarlacc.xxx' index 11 using 2:3 title "1 MB" with linespoints, \
|
||||
'sarlacc.xxx' index 12 using 2:3 title "2 MB" with linespoints, \
|
||||
'sarlacc.xxx' index 13 using 2:3 title "4 MB" with linespoints, \
|
||||
'sarlacc.xxx' index 14 using 2:3 title "8 MB" with linespoints, \
|
||||
'sarlacc.xxx' index 15 using 2:3 title "16 MB" with linespoints, \
|
||||
'sarlacc.xxx' index 16 using 2:3 title "32 MB" with linespoints, \
|
||||
'sarlacc.xxx' index 17 using 2:3 title "64 MB" with linespoints
|
168
Project1/project_1_maggioni_claudio/membench/membench.c
Normal file
168
Project1/project_1_maggioni_claudio/membench/membench.c
Normal file
|
@ -0,0 +1,168 @@
|
|||
/* ==================================================================== *
|
||||
* *
|
||||
* membench.c -- Measurement of the performance of the memory *
|
||||
* hierarchy. *
|
||||
* *
|
||||
* ==================================================================== */
|
||||
|
||||
#include <unistd.h>
|
||||
#include <stdio.h>
|
||||
#include <sys/resource.h>
|
||||
#include <sys/times.h>
|
||||
#include <sys/time.h>
|
||||
#include <sys/types.h>
|
||||
#include <time.h>
|
||||
#include <limits.h>
|
||||
|
||||
#define CACHE_MIN (128) /* smallest cache */
|
||||
#define CACHE_MAX (16 * 1024 * 1024) /* largest cache */
|
||||
#define SAMPLE 10 /* to get larger time sample */
|
||||
|
||||
int x[CACHE_MAX]; /* stride thru this array */
|
||||
|
||||
/**
|
||||
* Get the number of CPU ticks since last booting the computer
|
||||
*/
|
||||
inline unsigned long long getCPUTick (void)
|
||||
{
|
||||
unsigned lo, hi;
|
||||
asm volatile ("rdtsc" : "=a" (lo), "=d" (hi));
|
||||
return (unsigned long long) hi << 32 | lo;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the current system time in milliseconds
|
||||
*/
|
||||
unsigned long timeGetTime (void)
|
||||
{
|
||||
/* Using Linux Time Functions To Determine Time */
|
||||
struct timeval tv;
|
||||
gettimeofday (&tv, 0);
|
||||
return tv.tv_sec * 1000 + tv.tv_usec / 1000;
|
||||
}
|
||||
|
||||
/**
|
||||
* Determine the CPU clock speed.
|
||||
* @param nTime The time in milliseconds used to perform the measurement
|
||||
*/
|
||||
unsigned long getCPUSpeed (long nTime)
|
||||
{
|
||||
long long timeStart, timeStop;
|
||||
long long startTick, endTick;
|
||||
|
||||
long long overhead = getCPUTick () - getCPUTick ();
|
||||
|
||||
/* Calculate Starting Time And Start Tick */
|
||||
timeStart = timeGetTime ();
|
||||
while (timeGetTime () == timeStart)
|
||||
timeStart = timeGetTime();
|
||||
|
||||
while (1)
|
||||
{
|
||||
timeStop = timeGetTime ();
|
||||
if ((timeStop - timeStart) > 1)
|
||||
{
|
||||
startTick = getCPUTick ();
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
/* Calculate Stop Time And End Tick */
|
||||
timeStart = timeStop;
|
||||
while (1)
|
||||
{
|
||||
timeStop = timeGetTime();
|
||||
if ((timeStop - timeStart) > nTime)
|
||||
{
|
||||
endTick = getCPUTick();
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
/* Return The Processors Speed In Hertz */
|
||||
return (unsigned long) ((endTick - startTick) + (overhead));
|
||||
}
|
||||
|
||||
|
||||
int main ()
|
||||
{
|
||||
int register i, index, stride, limit, temp;
|
||||
long steps, tsteps;
|
||||
int csize;
|
||||
|
||||
/* timing variables */
|
||||
double sec;
|
||||
|
||||
/* number of processor cycles used */
|
||||
unsigned long long cycles0, cycles;
|
||||
|
||||
/* The CPU speed in Hz */
|
||||
unsigned long nHz = getCPUSpeed (1000);
|
||||
|
||||
for (csize = CACHE_MIN; csize <= CACHE_MAX; csize <<= 1)
|
||||
{
|
||||
for (stride = 1; stride <= csize / 2; stride <<= 1)
|
||||
{
|
||||
/* init cycles counter */
|
||||
cycles = 0;
|
||||
|
||||
/* cache size this loop */
|
||||
limit = csize - stride + 1;
|
||||
steps = 0;
|
||||
|
||||
do
|
||||
{
|
||||
cycles0 = getCPUTick ();
|
||||
for (i = SAMPLE * stride; i != 0; i--)
|
||||
{
|
||||
/* larger sample */
|
||||
for (index = 0; index < limit; index += stride)
|
||||
{
|
||||
/* cache access */
|
||||
x[index] = x[index] + 1;
|
||||
}
|
||||
}
|
||||
|
||||
/* count while loop iterations */
|
||||
steps++;
|
||||
cycles += getCPUTick () - cycles0;
|
||||
} while (cycles < nHz); /* repeat until collected 1 sec */
|
||||
sec = cycles / (double) nHz;
|
||||
|
||||
/* repeat empty loop to subtract loop overhead */
|
||||
|
||||
/* used to match # while iterations */
|
||||
tsteps = 0;
|
||||
|
||||
/* repeat until same # iterations as above */
|
||||
do
|
||||
{
|
||||
cycles0 = getCPUTick ();
|
||||
for (i = SAMPLE * stride; i != 0; i--)
|
||||
{
|
||||
/* larger sample */
|
||||
|
||||
for (index = 0; index < limit; index += stride)
|
||||
{
|
||||
/* dummy code */
|
||||
temp = temp + index;
|
||||
}
|
||||
}
|
||||
|
||||
/* count while loop iterations */
|
||||
tsteps++;
|
||||
cycles -= getCPUTick () - cycles0;
|
||||
} while (tsteps < steps);
|
||||
|
||||
printf ("Size:%7lu Stride:%7lu read+write:%10.3f ns, sec = %6.3f, cycles = %lld steps = %6.0f\n",
|
||||
csize * sizeof (int), stride * sizeof (int),
|
||||
(double) sec * 1e9 / (steps * SAMPLE * stride * ((limit - 1) / stride + 1)),
|
||||
sec, cycles, (double) steps);
|
||||
fflush(stdout);
|
||||
}
|
||||
|
||||
printf ("\n\n");
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
16
Project1/project_1_maggioni_claudio/membench/run_membench.sh
Normal file
16
Project1/project_1_maggioni_claudio/membench/run_membench.sh
Normal file
|
@ -0,0 +1,16 @@
|
|||
#!/bin/bash -l
|
||||
|
||||
#SBATCH --job-name=membench
|
||||
#SBATCH --time=00:30:00
|
||||
#SBATCH --nodes=1
|
||||
#SBATCH --output=membench-%j.out
|
||||
#SBATCH --error=membench-%j.err
|
||||
|
||||
# load modules
|
||||
if command -v module 1>/dev/null 2>&1; then
|
||||
module load gcc/10.1.0 gnuplot
|
||||
fi
|
||||
|
||||
./membench | sed -e '/:/ s//: /g' -e '/ */ s// /g' | cut -f2,4,6 > generic.xxx && sed -e '/sarlacc/ s//generic/' gnuplot.template > generic.gp
|
||||
|
||||
gnuplot generic.gp
|
Reference in a new issue