#include "task_7.h"
#include <cmath>
#include <iostream>
#include <lapacke.h>
#include <vector>
using namespace std;

tuple<vector<double>, vector<double>> init_M(size_t N, size_t Nrhs) {
    vector<double> A(N*N), b(N*Nrhs);
    for (size_t i = 0; i < N; ++i) {
        for (size_t j = 0; j < N; ++j) {
            if (i != j) {
                A[i*N + j] = 1.0 / pow(abs(1.0*i-1.0*j),2);
            } else {
                A[i*N + j] = 4;
            }
        }
        for (size_t j=0; j < Nrhs; ++j) {
            b[i*Nrhs + j] = 1.0*j;
        }
    }
    return make_tuple(A, b);
}

void print_matrix(vector<double> &A, size_t M, size_t N) {
    printf("\n");
    for (size_t i = 0; i < M; ++i){
        for (size_t j = 0; j < N; ++j) {
            printf("%f ", A[i*N + j]);
        }
        printf("\n");
    }
    printf("\n\n");
}

void benchmark_lapacke(int N, int Nrhs) {
    auto [A,b] = init_M(N,Nrhs);
    int lda=N, ldb=Nrhs;
    vector<int> ipiv(N);
    LAPACKE_dgetrf(LAPACK_ROW_MAJOR, N, N, A.data(), lda, ipiv.data());
    LAPACKE_dgetrs(LAPACK_ROW_MAJOR, 'N', N, Nrhs, A.data(), lda, ipiv.data(), b.data(), ldb);
}