Skip to content

Commit

Permalink
Material analisis del rendimiento
Browse files Browse the repository at this point in the history
  • Loading branch information
jesusc committed Oct 20, 2020
1 parent 9ce237c commit c328589
Show file tree
Hide file tree
Showing 6 changed files with 105 additions and 0 deletions.
Binary file added apuntes/analisis.pdf
Binary file not shown.
30 changes: 30 additions & 0 deletions src/omp/false-sharing/cache-miss-col-parallel.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
#include <stdio.h>
#include <omp.h>
#include <stdlib.h>

#define NUM 10000

float array[NUM][NUM];

int main( int argc, char *argv[ ] ){
float sum = 0.;

if (argc < 2) {
printf("Se espera el número de hilos\n");
return -1;
}

omp_set_num_threads(atoi(argv[1]));
double start = omp_get_wtime();

#pragma omp parallel for shared(array) reduction(+:sum)
for( int i = 0; i < NUM; i++ ){
for( int j = 0; j < NUM; j++ ){
sum += array[ j ][ i ]; // acceso por columnas (j, i)
}
}
double finish = omp_get_wtime();
double elapsed = finish - start;

printf("Tiempo = %2.8f seconds\n", elapsed);
}
22 changes: 22 additions & 0 deletions src/omp/false-sharing/cache-miss-col.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
#include <stdio.h>
#include <omp.h>

#define NUM 10000

float array[NUM][NUM];

int main( int argc, char *argv[ ] ){
float sum = 0.;

double start = omp_get_wtime();

for( int i = 0; i < NUM; i++ ){
for( int j = 0; j < NUM; j++ ){
sum += array[ j ][ i ]; // acceso por columnas (j, i)
}
}
double finish = omp_get_wtime();
double elapsed = finish - start;

printf("Tiempo = %2.8f seconds\n", elapsed);
}
31 changes: 31 additions & 0 deletions src/omp/false-sharing/cache-miss-row-parallel.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
#include <stdio.h>
#include <omp.h>
#include <stdlib.h>

#define NUM 10000

float array[NUM][NUM];

int main( int argc, char *argv[ ] ){
float sum = 0.;

if (argc < 2) {
printf("Se espera el número de hilos\n");
return -1;
}

omp_set_num_threads(atoi(argv[1]));

double start = omp_get_wtime();

#pragma omp parallel for shared(array) reduction(+:sum) schedule(dynamic)
for( int i = 0; i < NUM; i++ ){
for( int j = 0; j < NUM; j++ ){
sum += array[ i ][ j ]; // acceso por filas
}
}
double finish = omp_get_wtime();
double elapsed = finish - start;

printf("Tiempo = %2.8f seconds\n", elapsed);
}
22 changes: 22 additions & 0 deletions src/omp/false-sharing/cache-miss-row.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
#include <stdio.h>
#include <omp.h>

#define NUM 10000

float array[NUM][NUM];

int main( int argc, char *argv[ ] ){
float sum = 0.;

double start = omp_get_wtime();

for( int i = 0; i < NUM; i++ ){
for( int j = 0; j < NUM; j++ ){
sum += array[ i ][ j ]; // acceso por filas
}
}
double finish = omp_get_wtime();
double elapsed = finish - start;

printf("Tiempo = %2.8f seconds\n", elapsed);
}
Binary file added transparencias/analisis.pdf
Binary file not shown.

0 comments on commit c328589

Please sign in to comment.