-
Notifications
You must be signed in to change notification settings - Fork 0
/
matriz.cpp
72 lines (59 loc) · 1.45 KB
/
matriz.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
//MULTIPLICACION DE MATRICES
//ALUMNO: JESUS R. GONZALEZ L.
//Cedula: 23.543.415
#include <time.h>
#include <stddef.h>
#include <stdint.h>
#include <inttypes.h>
#include <omp.h>
#include <stdio.h>
#include <stdlib.h>
#include <iostream>
using namespace std;
int main()
{
int hilos,total;
//Crear matrices
cout<<"---------------------------------------------------------"<<endl;
cout << " Ingrese el tamaño de las matrices" << endl;
cin >> total;
srand(time(NULL));
int **ma = new int*[total];
int **mb = new int*[total];
int **mr = new int*[total];
for(int i = 0; i < total; i++)
{
ma[i] = new int[total];
mb[i] = new int[total];
mr[i] = new int[total];
}
//Llenado de la matriz con numeros aleatorios
for (int i = 0; i < total; i++)
{
for (int j = 0; j < total; j++)
{
ma[i][j] = rand() % 10 + 1;
mb[i][j] = rand() % 10 + 1;
}
}
//Asignar Cantidad de Hilos a Utilizar
cout << " Ingrese La cantidad de Hilos" << endl;
cin >> hilos;
omp_set_num_threads(hilos);
//Multiplicacion
clock_t begin = clock();
#pragma omp parallel for
for (int i = 0; i < total; i++)
{
#pragma omp parallel for
for (int j = 0; j < total; j++)
{
mr[i][j] = ma[i][j] * mb[j][i];
}
}
clock_t end = clock();
double time_spent = (double)(end - begin) / CLOCKS_PER_SEC;
printf("\n TIEMPO: %6f Segundos \n",time_spent);
cout<<"--------------------------------------------------------------"<<endl;
return 1;
}