Last active
October 15, 2015 12:07
-
-
Save harkalygergo/af69460a52998636ec06 to your computer and use it in GitHub Desktop.
PEP Feladat 1.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
Function: 1. Készítsen programot, amely rögzített, 1024 × 1024 méretű, egészeket tartalmazó mátrixok sor és oszlopvektorát állítja elő! Hasonlítsa össze a program futási idejét -O3 optimalizálással, auto-vektorizálással és annak kikapcsolása esetén. A -O3 optimalizálás alapértelmezett módon tartalmazza az auto-vektorizálást, amely azonban kikapcsolható a -fno-tree-vectorize kapcsolóval. | |
Version: 2015.10.15. | |
Copyright: Harkály Gergő & Lehoczky Tamás | Miskolci Egyetem | |
Install: | |
- CMakeLists.txt: | |
CMAKE_MINIMUM_REQUIRED(VERSION 2.8) | |
PROJECT(feladat1 C) | |
SET(EXECUTABLE_OUTPUT_PATH ${PROJECT_BINARY_DIR}) | |
SET(TARGET_NAME feladat1) | |
AUX_SOURCE_DIRECTORY(. SRC) | |
ADD_EXECUTABLE(${TARGET_NAME} ${SRC}) | |
SET(CMAKE_VERBOSE_MAKEFILE on) | |
- figure.R: | |
library('Cairo') | |
library('ggplot2') | |
library('reshape') | |
library("grid") | |
plottitle <- "mátrix sor- és oszlopösszeg" | |
plotlabels <- c("kapcsoló: -", "kapcsoló: -03", "kapcsolók: -03 -fno-tree-vectorize") | |
xlabel <- "Tömb méret (32x32, 64x64, 128x128, 256x256, 512x512, 1024x1024)" | |
ylabel <- "Idő" | |
data0 <- read.table('results-none.dat') | |
data1 <- read.table('results-03.dat') | |
data2 <- read.table('results-03fnotreevectorize.dat') | |
d <- data.frame(data0$V2, data0$V1, data1$V1, data2$V1) | |
colnames(d) <- c('alpha', 'runtime1', 'runtime2', 'runtime3') | |
d <- melt(d, id='alpha', variable_name='series') | |
CairoPDF("stat.pdf", width=30, height=12) | |
p<-ggplot(d, | |
aes_string(x=names(d)[1], y=names(d)[3], colour=names(d)[2]), | |
labeller=label_parsed) + | |
geom_point(size=4) + | |
geom_line(size=1.5) + | |
labs(title=plottitle) + | |
xlab(xlabel) + | |
ylab(ylabel) + | |
scale_colour_manual(values=c("red", "green", "blue", "orange", "gray"), name="", labels=plotlabels, guide=guide_legend(keyheight=unit(2, "line"), keywidth=unit(5, "line"))) + | |
theme_gray(24) + | |
scale_x_continuous(breaks=round(seq(1.0, 10.0, by=0.5), 1)) + | |
scale_y_continuous(breaks=sort(c(round(seq(0, max(d$value)+1, by=20), 1)))) + | |
theme(legend.position="bottom") | |
print(p) | |
dev.off() | |
Run: cmake .; make clean; make; ./feladat1; ./feladat1 -03; ./feladat1 -03 -fno-tree-vectorize; Rscript figure.R | |
*/ | |
#include <stdio.h> | |
#include <stdarg.h> | |
#include <time.h> | |
#include <sys/time.h> | |
/* STOPPER */ | |
// stopper.h | |
#ifndef _STOPPER_H_ | |
#define _STOPPER_H_ | |
typedef struct stopper | |
{ | |
clock_t begin; | |
clock_t end; | |
} stopper; | |
void startS(stopper* st); | |
void stopS(stopper* st); | |
int tprintf(stopper* st, const char* fmt, ...); | |
#endif | |
// stooper.c | |
void startS(stopper *st) | |
{ | |
st->begin= clock(); | |
} | |
void stopS(stopper *st) | |
{ | |
st->end= clock(); | |
} | |
int tprintf(stopper *st, const char* fmt, ...) | |
{ | |
float d= st->end - st->begin; | |
long ms, s; | |
d*=1000; | |
d/=CLOCKS_PER_SEC; | |
ms= d; | |
s= ms / 100; | |
ms= ms % 100; | |
va_list arg; | |
va_start(arg, fmt); | |
printf("%02ld ", ms); | |
vprintf(fmt, arg); | |
va_end(arg); | |
fflush(stdout); | |
return ms; | |
} | |
int getstoppertime(stopper *st) | |
{ | |
float d = st->end - st->begin; | |
long ms; | |
d *= 1000; | |
d /= CLOCKS_PER_SEC; | |
ms = d; | |
ms = ms % 100; | |
return ms; | |
} | |
/* MAIN */ | |
int main(int argc, char** argv[]) | |
{ | |
FILE *file; | |
switch(argc) // open results file | |
{ | |
case 1: { file = fopen("results-none.dat", "w"); break; } | |
case 2: { file = fopen("results-03.dat", "w"); break; } | |
case 3: { file = fopen("results-03fnotreevectorize.dat", "w"); break; } | |
} | |
if(file == NULL) | |
{ | |
printf("Error opening file!\n"); | |
} | |
else | |
{ | |
int matrixarray[6] = {32, 64, 128, 256, 512, 1024}; | |
int r, m; | |
for(r=0; r<6; r++) | |
{ | |
int N = matrixarray[r]; | |
int sum = 0; | |
stopper st; | |
for(m=0; m<100; m++) | |
{ | |
startS(&st); // start stopper | |
int i, j, k, matrix[N][N], sorosszeg[N], oszloposszeg[N]; | |
for(i=0; i<N; i++) | |
{ | |
for(j=0; j<N; j++) | |
{ | |
//matrix[i][j] = 5; | |
matrix[i][j] = rand()%10; | |
} | |
} | |
for(j=0; j<N; j++) | |
{ | |
oszloposszeg[j] = 0; | |
for(i=0; i<N; i++) | |
{ | |
oszloposszeg[j] += matrix[i][j]; | |
} | |
} | |
for(i=0; i<N; i++) | |
{ | |
sorosszeg[i] = 0; | |
for(j=0; j<N; j++) | |
{ | |
sorosszeg[i] += matrix[i][j]; | |
} | |
} | |
for(i=0; i<N; i++) | |
{ | |
for(j=0; j<N; j++) | |
{ | |
printf("%d\t", matrix[i][j]); | |
} | |
printf("\n"); | |
} | |
printf("\nOszlopvektor:\t"); | |
for(j=0; j<N; j++) | |
{ | |
printf("%d\t", oszloposszeg[j]); | |
} | |
printf("\nSorvektor:\t"); | |
for(j=0; j<N; j++) | |
{ | |
printf("%d\t", sorosszeg[j]); | |
} | |
*/ | |
stopS(&st); // stop stopper | |
sum += getstoppertime(&st); // add current runtime to sum variable | |
//tprintf(&st, "\n"); // echo current runtime | |
} | |
sum = sum/100; | |
fprintf(file, "%d\t%d\n", sum, r+1); // write summary to results file | |
} | |
fclose(file); // close results file | |
} | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment