magistraleinformaticanetworking:spm:samplevvcode
Differenze
Queste sono le differenze tra la revisione selezionata e la versione attuale della pagina.
Entrambe le parti precedenti la revisioneRevisione precedente | |||
magistraleinformaticanetworking:spm:samplevvcode [11/11/2013 alle 15:40 (12 anni fa)] – Marco Danelutto | magistraleinformaticanetworking:spm:samplevvcode [11/11/2013 alle 15:41 (12 anni fa)] (versione attuale) – Marco Danelutto | ||
---|---|---|---|
Linea 64: | Linea 64: | ||
} | } | ||
</ | </ | ||
+ | |||
+ | <code g++ mmkj.c> | ||
+ | #include < | ||
+ | #include < | ||
+ | #include < | ||
+ | #include < | ||
+ | |||
+ | float a[N][N]; | ||
+ | float b[N][N]; | ||
+ | float c[N][N]; | ||
+ | |||
+ | struct timespec diff(struct timespec t0, struct timespec t1); | ||
+ | |||
+ | int main(int argc, char * argv[]) { | ||
+ | |||
+ | // timer resolution | ||
+ | struct timespec res; | ||
+ | struct timespec t0, t1; | ||
+ | |||
+ | clock_getres(CLOCCHE, | ||
+ | printf(" | ||
+ | |||
+ | // init matrixes | ||
+ | srand(getpid()); | ||
+ | for(int i=0; i<N; i++) | ||
+ | for(int j=0; j<N; j++) { | ||
+ | a[i][j]=rand(); | ||
+ | b[i][j]=rand(); | ||
+ | c[i][j]=0.0; | ||
+ | } | ||
+ | |||
+ | clock_gettime(CLOCCHE,& | ||
+ | for(int i=0; i<N; i++) | ||
+ | for(int k=0; k<N; k++) { | ||
+ | float aik = a[i][k]; | ||
+ | for(int j=0; j<N; j++) | ||
+ | c[i][j] += aik*b[k][j]; | ||
+ | } | ||
+ | clock_gettime(CLOCCHE,& | ||
+ | diff(t0, | ||
+ | |||
+ | float sum = 0.0; | ||
+ | for(int i=0; i<N; i++) | ||
+ | for(int j=0; j<N; j++) | ||
+ | sum+=c[i][j]; | ||
+ | |||
+ | printf(" | ||
+ | return(0); | ||
+ | } | ||
+ | |||
+ | timespec diff(timespec start, timespec end) | ||
+ | { | ||
+ | timespec temp; | ||
+ | if ((end.tv_nsec-start.tv_nsec)< | ||
+ | temp.tv_sec = end.tv_sec-start.tv_sec-1; | ||
+ | temp.tv_nsec = 1000000000+end.tv_nsec-start.tv_nsec; | ||
+ | } else { | ||
+ | temp.tv_sec = end.tv_sec-start.tv_sec; | ||
+ | temp.tv_nsec = end.tv_nsec-start.tv_nsec; | ||
+ | } | ||
+ | printf(" | ||
+ | return temp; | ||
+ | } | ||
+ | </ | ||
+ | |||
<code makefile> | <code makefile> | ||
Linea 77: | Linea 142: | ||
mmo3: mm.c | mmo3: mm.c | ||
$(CC) $(CFLAGS) mm.c -o mmo3 $(LDFLAGS) -ftree-vectorizer-verbose=2 -O3 | $(CC) $(CFLAGS) mm.c -o mmo3 $(LDFLAGS) -ftree-vectorizer-verbose=2 -O3 | ||
+ | mmkj: mm.c | ||
+ | $(CC) $(CFLAGS) mmkj.c -o mmkj $(LDFLAGS) -ftree-vectorizer-verbose=2 | ||
+ | mmkjo3: | ||
+ | $(CC) $(CFLAGS) mmkj.c -o mmkjo3 $(LDFLAGS) -ftree-vectorizer-verbose=2 -O3 | ||
</ | </ | ||
magistraleinformaticanetworking/spm/samplevvcode.1384184410.txt.gz · Ultima modifica: 11/11/2013 alle 15:40 (12 anni fa) da Marco Danelutto