Reporte
Reporte
November 3, 2023
1 Laboratorio 7
1.1 Ejericicio 1
1.1.1 A
#include <iostream>
#include <cmath>
#include <ctime>
#include <omp.h> // Incluye la cabecera de OpenMP
if (argc > 1) {
num_threads = atoi(argv[1]);
}
1
dt = (tmax - tmin) / (double)(j_max - j_min);
dx = (x_max - x_min) / (double)(n - 1);
x[0] = 0;
for (i = 1; i < n; i++) {
x[i] = x[i - 1] + dx;
}
// Inicialización
tiempo = tmin;
u[0] = 0.0;
for (i = 1; i <= n; i++) u[i] = inicial(x[i], tiempo);
u[n + 1] = 0.0;
return 0;
}
1.2 Ejercicio 2
1.2.1 A
#include <iostream>
#include <fstream>
#include <random>
#include <chrono>
#include <omp.h>
2
using namespace std;
#define LIMIT 1000000
generate_array(numeros, &size_);
// se imprime el array
// imprimir_array(numeros, size_);
// se ordena el array
auto start_time = chrono::high_resolution_clock::now();
Sort(numeros, size_);
auto end_time = chrono::high_resolution_clock::now();
3
cout << "Elapse time: " << elapse_time.count() << " s\n";
// se imprime el array ordenado
// printf("\nArray ordenado:\n");
// imprimir_array(numeros, size_);
return 0;
}
4
}
}
plt.legend()
plt.xlabel('n')
plt.ylabel('Tiempo (s)')
plt.title('Speedup')
plt.show()
5
1.2.2 B
#include <iostream>
#include <vector>
#include <random>
#include <chrono>
#include <omp.h>
6
}
}
while (!sorted) {
sorted = true;
if (argc > 1) {
LIMIT = atoi(argv[1]);
if (argc > 2)
num_threads = atoi(argv[2]);
}
std::cout << "size: " << LIMIT << " num_threads: " << num_threads << std::endl;
omp_set_num_threads(num_threads);
int numbers[LIMIT];
generate_array(numbers, &LIMIT);
7
// std::cout << numbers[i] << " ";
// }
// std::cout << "\n";
return 0;
}
[8]: import matplotlib.pyplot as plt
plt.legend()
plt.xlabel('n')
plt.ylabel('Tiempo (s)')
plt.title('Speedup')
plt.show()
8
1.2.3 C
Teniendo en cuenta las gráficas el algoritmo bubblesort es más escalable que el algoritmo par-impar.
Debido a que el comportamiento, dada la experimentación siempre tenderá a subir. En cambio, el
speedup del algoritmo par-impar para 4 threads tiene un deterioro del speedup cuando aumenta la
cantidad de datos.