-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
105 additions
and
0 deletions.
There are no files selected for viewing
Binary file not shown.
This file contains 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
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); | ||
} |
This file contains 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
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); | ||
} |
This file contains 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
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); | ||
} |
This file contains 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
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 not shown.