Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include "stdafx.h"
- #include <iostream>
- #include <stdio.h>
- #include <stdlib.h>
- #include <math.h>
- #include <intrin.h>
- #include <stdint.h>
- double *cholesky(double *A, int n) {
- double *L = (double*)calloc(n * n, sizeof(double));
- if (L == NULL)
- exit(EXIT_FAILURE);
- for (int i = 0; i < n; i++)
- for (int j = 0; j < (i + 1); j++) {
- double s = 0;
- for (int k = 0; k < j; k++)
- s += L[i * n + k] * L[j * n + k];
- L[i * n + j] = (i == j) ?
- sqrt(A[i * n + i] - s) :
- (1.0 / L[j * n + j] * (A[i * n + j] - s));
- }
- return L;
- }
- void show_matrix(double *A, int n) {
- for (int i = 0; i < n; i++) {
- for (int j = 0; j < n; j++)
- printf("%2.5f ", A[i * n + j]);
- printf("\n");
- }
- }
- uint64_t rdtsc() {
- return __rdtsc();
- }
- int main() {
- using namespace std;
- /*int n = 3;
- double m1[] = { 25, 15, -5,
- 15, 18, 0,
- -5, 0, 11 };
- double *c1 = cholesky(m1, n);
- show_matrix(c1, n);
- printf("\n");
- free(c1);*/
- //Inicio da medicao de tempo
- uint64_t uiInicio, uiFim;
- int iTam = 1;
- //definição da matriz
- int n = 5;
- double m2[] = { 1, 2, 4, 7, 11,
- 2, 13, 23, 38, 58,
- 4, 23, 77, 122, 182,
- 7, 38, 122, 294, 430,
- 11, 58, 182, 430, 855 };
- uiInicio = rdtsc();
- for (int i = 0; i < iTam; i++) {
- double *c2 = cholesky(m2, n);
- free(c2);
- }
- //show_matrix(c2, n);
- //Fim da medicao de tempo
- uiFim = rdtsc();
- cout << (uiFim - uiInicio) / iTam<<endl;
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement